amiro-lld / source / DW1000 / v1 / alld_dw1000_v1.c @ 1473a57f
History | View | Annotate | Download (151.037 KB)
1 |
/*
|
---|---|
2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
3 |
Copyright (C) 2016..2019 Thomas Schöpping et al.
|
4 |
|
5 |
This program is free software: you can redistribute it and/or modify
|
6 |
it under the terms of the GNU Lesser General Public License as published by
|
7 |
the Free Software Foundation, either version 3 of the License, or
|
8 |
(at your option) any later version.
|
9 |
|
10 |
This program is distributed in the hope that it will be useful,
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
GNU Lesser General Public License for more details.
|
14 |
|
15 |
You should have received a copy of the GNU Lesser General Public License
|
16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17 |
*/
|
18 |
|
19 |
/*! ------------------------------------------------------------------------------------------------------------------
|
20 |
* @file deca_device.c
|
21 |
* @brief Decawave device configuration and control functions
|
22 |
*
|
23 |
* @attention
|
24 |
*
|
25 |
* Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
|
26 |
*
|
27 |
* All rights reserved.
|
28 |
*
|
29 |
*/
|
30 |
|
31 |
#include <alld_DW1000.h> |
32 |
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__) |
33 |
|
34 |
#include <v1/alld_dw1000_regs_v1.h> |
35 |
#include <assert.h> |
36 |
#include <string.h> |
37 |
#include <stdlib.h> |
38 |
#include <math.h> |
39 |
|
40 |
|
41 |
// HW dependent implementation (see bottom of file)
|
42 |
static int writetospi(uint16_t headerLength, |
43 |
const uint8_t *headerBuffer,
|
44 |
uint32_t bodyLength, |
45 |
const uint8_t *bodyBuffer);
|
46 |
|
47 |
static int readfromspi(uint16_t headerLength, |
48 |
const uint8_t *headerBuffer,
|
49 |
uint32_t readlength, |
50 |
uint8_t *readBuffer); |
51 |
|
52 |
|
53 |
// Defines for enable_clocks function
|
54 |
#define FORCE_SYS_XTI 0 |
55 |
#define ENABLE_ALL_SEQ 1 |
56 |
#define FORCE_SYS_PLL 2 |
57 |
#define READ_ACC_ON 7 |
58 |
#define READ_ACC_OFF 8 |
59 |
#define FORCE_OTP_ON 11 |
60 |
#define FORCE_OTP_OFF 12 |
61 |
#define FORCE_TX_PLL 13 |
62 |
#define FORCE_LDE 14 |
63 |
|
64 |
// Defines for ACK request bitmask in DATA and MAC COMMAND frame control (first byte) - Used to detect AAT bit wrongly set.
|
65 |
#define FCTRL_ACK_REQ_MASK 0x20 |
66 |
// Frame control maximum length in bytes.
|
67 |
#define FCTRL_LEN_MAX 2 |
68 |
|
69 |
|
70 |
typedef struct { |
71 |
uint32_t lo32; |
72 |
uint16_t target[NUM_PRF]; |
73 |
} agc_cfg_struct ; |
74 |
|
75 |
extern const agc_cfg_struct agc_config ; |
76 |
|
77 |
//SFD threshold settings for 110k, 850k, 6.8Mb standard and non-standard
|
78 |
extern const uint16_t sftsh[NUM_BR][NUM_SFD]; |
79 |
|
80 |
extern const uint16_t dtune1[NUM_PRF]; |
81 |
|
82 |
#define XMLPARAMS_VERSION (1.17f) |
83 |
|
84 |
extern const uint32_t fs_pll_cfg[NUM_CH]; |
85 |
extern const uint8_t fs_pll_tune[NUM_CH]; |
86 |
extern const uint8_t rx_config[NUM_BW]; |
87 |
extern const uint32_t tx_config[NUM_CH]; |
88 |
extern const uint8_t dwnsSFDlen[NUM_BR]; //length of SFD for each of the bitrates |
89 |
extern const uint32_t digital_bb_config[NUM_PRF][NUM_PACS]; |
90 |
//extern const uint8_t chan_idx[NUM_CH_SUPPORTED]; // move to header file
|
91 |
extern const double txpwr_compensation[NUM_CH]; |
92 |
|
93 |
#define PEAK_MULTPLIER (0x60) //3 -> (0x3 * 32) & 0x00E0 |
94 |
#define N_STD_FACTOR (13) |
95 |
#define LDE_PARAM1 (PEAK_MULTPLIER | N_STD_FACTOR)
|
96 |
|
97 |
#define LDE_PARAM3_16 (0x1607) |
98 |
#define LDE_PARAM3_64 (0x0607) |
99 |
|
100 |
#define MIXER_GAIN_STEP (0.5) |
101 |
#define DA_ATTN_STEP (2.5) |
102 |
|
103 |
// #define DWT_API_ERROR_CHECK // define so API checks config input parameters
|
104 |
|
105 |
//-----------------------------------------
|
106 |
// map the channel number to the index in the configuration arrays below
|
107 |
// 0th element is chan 1, 1st is chan 2, 2nd is chan 3, 3rd is chan 4, 4th is chan 5, 5th is chan 7
|
108 |
const uint8_t chan_idx[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 3, 4, 0, 5}; |
109 |
|
110 |
//-----------------------------------------
|
111 |
const uint32_t tx_config[NUM_CH] =
|
112 |
{ |
113 |
RF_TXCTRL_CH1, |
114 |
RF_TXCTRL_CH2, |
115 |
RF_TXCTRL_CH3, |
116 |
RF_TXCTRL_CH4, |
117 |
RF_TXCTRL_CH5, |
118 |
RF_TXCTRL_CH7, |
119 |
}; |
120 |
|
121 |
//Frequency Synthesiser - PLL configuration
|
122 |
const uint32_t fs_pll_cfg[NUM_CH] =
|
123 |
{ |
124 |
FS_PLLCFG_CH1, |
125 |
FS_PLLCFG_CH2, |
126 |
FS_PLLCFG_CH3, |
127 |
FS_PLLCFG_CH4, |
128 |
FS_PLLCFG_CH5, |
129 |
FS_PLLCFG_CH7 |
130 |
}; |
131 |
|
132 |
//Frequency Synthesiser - PLL tuning
|
133 |
const uint8_t fs_pll_tune[NUM_CH] =
|
134 |
{ |
135 |
FS_PLLTUNE_CH1, |
136 |
FS_PLLTUNE_CH2, |
137 |
FS_PLLTUNE_CH3, |
138 |
FS_PLLTUNE_CH4, |
139 |
FS_PLLTUNE_CH5, |
140 |
FS_PLLTUNE_CH7 |
141 |
}; |
142 |
|
143 |
//bandwidth configuration
|
144 |
const uint8_t rx_config[NUM_BW] =
|
145 |
{ |
146 |
RF_RXCTRLH_NBW, |
147 |
RF_RXCTRLH_WBW |
148 |
}; |
149 |
|
150 |
|
151 |
const agc_cfg_struct agc_config =
|
152 |
{ |
153 |
AGC_TUNE2_VAL, |
154 |
{ AGC_TUNE1_16M , AGC_TUNE1_64M } //adc target
|
155 |
}; |
156 |
|
157 |
//DW non-standard SFD length for 110k, 850k and 6.81M
|
158 |
const uint8_t dwnsSFDlen[NUM_BR] =
|
159 |
{ |
160 |
DW_NS_SFD_LEN_110K, |
161 |
DW_NS_SFD_LEN_850K, |
162 |
DW_NS_SFD_LEN_6M8 |
163 |
}; |
164 |
|
165 |
// SFD Threshold
|
166 |
const uint16_t sftsh[NUM_BR][NUM_SFD] =
|
167 |
{ |
168 |
{ |
169 |
DRX_TUNE0b_110K_STD, |
170 |
DRX_TUNE0b_110K_NSTD |
171 |
}, |
172 |
{ |
173 |
DRX_TUNE0b_850K_STD, |
174 |
DRX_TUNE0b_850K_NSTD |
175 |
}, |
176 |
{ |
177 |
DRX_TUNE0b_6M8_STD, |
178 |
DRX_TUNE0b_6M8_NSTD |
179 |
} |
180 |
}; |
181 |
|
182 |
const uint16_t dtune1[NUM_PRF] =
|
183 |
{ |
184 |
DRX_TUNE1a_PRF16, |
185 |
DRX_TUNE1a_PRF64 |
186 |
}; |
187 |
|
188 |
const uint32_t digital_bb_config[NUM_PRF][NUM_PACS] =
|
189 |
{ |
190 |
{ |
191 |
DRX_TUNE2_PRF16_PAC8, |
192 |
DRX_TUNE2_PRF16_PAC16, |
193 |
DRX_TUNE2_PRF16_PAC32, |
194 |
DRX_TUNE2_PRF16_PAC64 |
195 |
}, |
196 |
{ |
197 |
DRX_TUNE2_PRF64_PAC8, |
198 |
DRX_TUNE2_PRF64_PAC16, |
199 |
DRX_TUNE2_PRF64_PAC32, |
200 |
DRX_TUNE2_PRF64_PAC64 |
201 |
} |
202 |
}; |
203 |
|
204 |
const uint16_t lde_replicaCoeff[PCODES] =
|
205 |
{ |
206 |
0, // No preamble code 0 |
207 |
LDE_REPC_PCODE_1, |
208 |
LDE_REPC_PCODE_2, |
209 |
LDE_REPC_PCODE_3, |
210 |
LDE_REPC_PCODE_4, |
211 |
LDE_REPC_PCODE_5, |
212 |
LDE_REPC_PCODE_6, |
213 |
LDE_REPC_PCODE_7, |
214 |
LDE_REPC_PCODE_8, |
215 |
LDE_REPC_PCODE_9, |
216 |
LDE_REPC_PCODE_10, |
217 |
LDE_REPC_PCODE_11, |
218 |
LDE_REPC_PCODE_12, |
219 |
LDE_REPC_PCODE_13, |
220 |
LDE_REPC_PCODE_14, |
221 |
LDE_REPC_PCODE_15, |
222 |
LDE_REPC_PCODE_16, |
223 |
LDE_REPC_PCODE_17, |
224 |
LDE_REPC_PCODE_18, |
225 |
LDE_REPC_PCODE_19, |
226 |
LDE_REPC_PCODE_20, |
227 |
LDE_REPC_PCODE_21, |
228 |
LDE_REPC_PCODE_22, |
229 |
LDE_REPC_PCODE_23, |
230 |
LDE_REPC_PCODE_24 |
231 |
}; |
232 |
|
233 |
const double txpwr_compensation[NUM_CH] = { |
234 |
0.0, |
235 |
0.035, |
236 |
0.0, |
237 |
0.0, |
238 |
0.065, |
239 |
0.0 |
240 |
}; |
241 |
|
242 |
|
243 |
const uint8_t chan_idxnb[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 0, 3, 0, 0}; //only channels 1,2,3 and 5 are in the narrow band tables |
244 |
const uint8_t chan_idxwb[NUM_CH_SUPPORTED] = {0, 0, 0, 0, 0, 0, 0, 1}; //only channels 4 and 7 are in in the wide band tables |
245 |
|
246 |
//---------------------------------------------------------------------------------------------------------------------------
|
247 |
// Range Bias Correction TABLES of range values in integer units of 25 CM, for 8-bit unsigned storage, MUST END IN 255 !!!!!!
|
248 |
//---------------------------------------------------------------------------------------------------------------------------
|
249 |
|
250 |
// offsets to nearest centimeter for index 0, all rest are +1 cm per value
|
251 |
|
252 |
#define CM_OFFSET_16M_NB (-23) // for normal band channels at 16 MHz PRF |
253 |
#define CM_OFFSET_16M_WB (-28) // for wider band channels at 16 MHz PRF |
254 |
#define CM_OFFSET_64M_NB (-17) // for normal band channels at 64 MHz PRF |
255 |
#define CM_OFFSET_64M_WB (-30) // for wider band channels at 64 MHz PRF |
256 |
|
257 |
|
258 |
//---------------------------------------------------------------------------------------------------------------------------
|
259 |
// range25cm16PRFnb: Range Bias Correction table for narrow band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
|
260 |
//---------------------------------------------------------------------------------------------------------------------------
|
261 |
|
262 |
const uint8_t range25cm16PRFnb[4][NUM_16M_OFFSET] = |
263 |
{ |
264 |
// ch 1 - range25cm16PRFnb
|
265 |
{ |
266 |
1,
|
267 |
3,
|
268 |
4,
|
269 |
5,
|
270 |
7,
|
271 |
9,
|
272 |
11,
|
273 |
12,
|
274 |
13,
|
275 |
15,
|
276 |
18,
|
277 |
20,
|
278 |
23,
|
279 |
25,
|
280 |
28,
|
281 |
30,
|
282 |
33,
|
283 |
36,
|
284 |
40,
|
285 |
43,
|
286 |
47,
|
287 |
50,
|
288 |
54,
|
289 |
58,
|
290 |
63,
|
291 |
66,
|
292 |
71,
|
293 |
76,
|
294 |
82,
|
295 |
89,
|
296 |
98,
|
297 |
109,
|
298 |
127,
|
299 |
155,
|
300 |
222,
|
301 |
255,
|
302 |
255
|
303 |
}, |
304 |
|
305 |
// ch 2 - range25cm16PRFnb
|
306 |
{ |
307 |
1,
|
308 |
2,
|
309 |
4,
|
310 |
5,
|
311 |
6,
|
312 |
8,
|
313 |
9,
|
314 |
10,
|
315 |
12,
|
316 |
13,
|
317 |
15,
|
318 |
18,
|
319 |
20,
|
320 |
22,
|
321 |
24,
|
322 |
27,
|
323 |
29,
|
324 |
32,
|
325 |
35,
|
326 |
38,
|
327 |
41,
|
328 |
44,
|
329 |
47,
|
330 |
51,
|
331 |
55,
|
332 |
58,
|
333 |
62,
|
334 |
66,
|
335 |
71,
|
336 |
78,
|
337 |
85,
|
338 |
96,
|
339 |
111,
|
340 |
135,
|
341 |
194,
|
342 |
240,
|
343 |
255
|
344 |
}, |
345 |
|
346 |
// ch 3 - range25cm16PRFnb
|
347 |
{ |
348 |
1,
|
349 |
2,
|
350 |
3,
|
351 |
4,
|
352 |
5,
|
353 |
7,
|
354 |
8,
|
355 |
9,
|
356 |
10,
|
357 |
12,
|
358 |
14,
|
359 |
16,
|
360 |
18,
|
361 |
20,
|
362 |
22,
|
363 |
24,
|
364 |
26,
|
365 |
28,
|
366 |
31,
|
367 |
33,
|
368 |
36,
|
369 |
39,
|
370 |
42,
|
371 |
45,
|
372 |
49,
|
373 |
52,
|
374 |
55,
|
375 |
59,
|
376 |
63,
|
377 |
69,
|
378 |
76,
|
379 |
85,
|
380 |
98,
|
381 |
120,
|
382 |
173,
|
383 |
213,
|
384 |
255
|
385 |
}, |
386 |