Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / DW1000 / v1 / alld_dw1000_v1.c @ 4172c48d

History | View | Annotate | Download (150.897 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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 <aos_thread.h>
36
#include <assert.h>
37
#include <string.h>
38
#include <stdlib.h>
39
#include <math.h>
40

    
41

    
42
// HW dependent implementation (see bottom of file)
43
static int writetospi(uint16_t headerLength,
44
               const        uint8_t *headerBuffer,
45
               uint32_t bodyLength,
46
               const        uint8_t *bodyBuffer);
47

    
48
static int readfromspi(uint16_t headerLength,
49
                const uint8_t *headerBuffer,
50
                uint32_t readlength,
51
                uint8_t *readBuffer);
52

    
53

    
54
// Defines for enable_clocks function
55
#define FORCE_SYS_XTI  0
56
#define ENABLE_ALL_SEQ 1
57
#define FORCE_SYS_PLL  2
58
#define READ_ACC_ON    7
59
#define READ_ACC_OFF   8
60
#define FORCE_OTP_ON   11
61
#define FORCE_OTP_OFF  12
62
#define FORCE_TX_PLL   13
63
#define FORCE_LDE      14
64

    
65
// Defines for ACK request bitmask in DATA and MAC COMMAND frame control (first byte) - Used to detect AAT bit wrongly set.
66
#define FCTRL_ACK_REQ_MASK 0x20
67
// Frame control maximum length in bytes.
68
#define FCTRL_LEN_MAX 2
69

    
70

    
71
typedef struct {
72
    uint32_t lo32;
73
    uint16_t target[NUM_PRF];
74
} agc_cfg_struct ;
75

    
76
extern const agc_cfg_struct agc_config ;
77

    
78
//SFD threshold settings for 110k, 850k, 6.8Mb standard and non-standard
79
extern const uint16_t sftsh[NUM_BR][NUM_SFD];
80

    
81
extern const uint16_t dtune1[NUM_PRF];
82

    
83
#define XMLPARAMS_VERSION   (1.17f)
84

    
85
extern const uint32_t fs_pll_cfg[NUM_CH];
86
extern const uint8_t fs_pll_tune[NUM_CH];
87
extern const uint8_t rx_config[NUM_BW];
88
extern const uint32_t tx_config[NUM_CH];
89
extern const uint8_t dwnsSFDlen[NUM_BR]; //length of SFD for each of the bitrates
90
extern const uint32_t digital_bb_config[NUM_PRF][NUM_PACS];
91
//extern const uint8_t chan_idx[NUM_CH_SUPPORTED]; // move to header file
92
extern const double txpwr_compensation[NUM_CH];
93

    
94
#define PEAK_MULTPLIER  (0x60) //3 -> (0x3 * 32) & 0x00E0
95
#define N_STD_FACTOR    (13)
96
#define LDE_PARAM1      (PEAK_MULTPLIER | N_STD_FACTOR)
97

    
98
#define LDE_PARAM3_16 (0x1607)
99
#define LDE_PARAM3_64 (0x0607)
100

    
101
#define MIXER_GAIN_STEP (0.5)
102
#define DA_ATTN_STEP    (2.5)
103

    
104
// #define DWT_API_ERROR_CHECK     // define so API checks config input parameters
105

    
106
//-----------------------------------------
107
// map the channel number to the index in the configuration arrays below
108
// 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
109
const uint8_t chan_idx[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 3, 4, 0, 5};
110

    
111
//-----------------------------------------
112
const uint32_t tx_config[NUM_CH] =
113
{
114
    RF_TXCTRL_CH1,
115
    RF_TXCTRL_CH2,
116
    RF_TXCTRL_CH3,
117
    RF_TXCTRL_CH4,
118
    RF_TXCTRL_CH5,
119
    RF_TXCTRL_CH7,
120
};
121

    
122
//Frequency Synthesiser - PLL configuration
123
const uint32_t fs_pll_cfg[NUM_CH] =
124
{
125
    FS_PLLCFG_CH1,
126
    FS_PLLCFG_CH2,
127
    FS_PLLCFG_CH3,
128
    FS_PLLCFG_CH4,
129
    FS_PLLCFG_CH5,
130
    FS_PLLCFG_CH7
131
};
132

    
133
//Frequency Synthesiser - PLL tuning
134
const uint8_t fs_pll_tune[NUM_CH] =
135
{
136
    FS_PLLTUNE_CH1,
137
    FS_PLLTUNE_CH2,
138
    FS_PLLTUNE_CH3,
139
    FS_PLLTUNE_CH4,
140
    FS_PLLTUNE_CH5,
141
    FS_PLLTUNE_CH7
142
};
143

    
144
//bandwidth configuration
145
const uint8_t rx_config[NUM_BW] =
146
{
147
    RF_RXCTRLH_NBW,
148
    RF_RXCTRLH_WBW
149
};
150

    
151

    
152
const agc_cfg_struct agc_config =
153
{
154
    AGC_TUNE2_VAL,
155
    { AGC_TUNE1_16M , AGC_TUNE1_64M }  //adc target
156
};
157

    
158
//DW non-standard SFD length for 110k, 850k and 6.81M
159
const uint8_t dwnsSFDlen[NUM_BR] =
160
{
161
    DW_NS_SFD_LEN_110K,
162
    DW_NS_SFD_LEN_850K,
163
    DW_NS_SFD_LEN_6M8
164
};
165

    
166
// SFD Threshold
167
const uint16_t sftsh[NUM_BR][NUM_SFD] =
168
{
169
    {
170
        DRX_TUNE0b_110K_STD,
171
        DRX_TUNE0b_110K_NSTD
172
    },
173
    {
174
        DRX_TUNE0b_850K_STD,
175
        DRX_TUNE0b_850K_NSTD
176
    },
177
    {
178
        DRX_TUNE0b_6M8_STD,
179
        DRX_TUNE0b_6M8_NSTD
180
    }
181
};
182

    
183
const uint16_t dtune1[NUM_PRF] =
184
{
185
    DRX_TUNE1a_PRF16,
186
    DRX_TUNE1a_PRF64
187
};
188

    
189
const uint32_t digital_bb_config[NUM_PRF][NUM_PACS] =
190
{
191
    {
192
        DRX_TUNE2_PRF16_PAC8,
193
        DRX_TUNE2_PRF16_PAC16,
194
        DRX_TUNE2_PRF16_PAC32,
195
        DRX_TUNE2_PRF16_PAC64
196
    },
197
    {
198
        DRX_TUNE2_PRF64_PAC8,
199
        DRX_TUNE2_PRF64_PAC16,
200
        DRX_TUNE2_PRF64_PAC32,
201
        DRX_TUNE2_PRF64_PAC64
202
    }
203
};
204

    
205
const uint16_t lde_replicaCoeff[PCODES] =
206
{
207
    0, // No preamble code 0
208
    LDE_REPC_PCODE_1,
209
    LDE_REPC_PCODE_2,
210
    LDE_REPC_PCODE_3,
211
    LDE_REPC_PCODE_4,
212
    LDE_REPC_PCODE_5,
213
    LDE_REPC_PCODE_6,
214
    LDE_REPC_PCODE_7,
215
    LDE_REPC_PCODE_8,
216
    LDE_REPC_PCODE_9,
217
    LDE_REPC_PCODE_10,
218
    LDE_REPC_PCODE_11,
219
    LDE_REPC_PCODE_12,
220
    LDE_REPC_PCODE_13,
221
    LDE_REPC_PCODE_14,
222
    LDE_REPC_PCODE_15,
223
    LDE_REPC_PCODE_16,
224
    LDE_REPC_PCODE_17,
225
    LDE_REPC_PCODE_18,
226
    LDE_REPC_PCODE_19,
227
    LDE_REPC_PCODE_20,
228
    LDE_REPC_PCODE_21,
229
    LDE_REPC_PCODE_22,
230
    LDE_REPC_PCODE_23,
231
    LDE_REPC_PCODE_24
232
};
233

    
234
const double txpwr_compensation[NUM_CH] = {
235
    0.0,
236
    0.035,
237
    0.0,
238
    0.0,
239
    0.065,
240
    0.0
241
};
242

    
243

    
244
#define NUM_16M_OFFSET  (37)
245
#define NUM_16M_OFFSETWB  (68)
246
#define NUM_64M_OFFSET  (26)
247
#define NUM_64M_OFFSETWB  (59)
248

    
249
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
250
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
251

    
252
//---------------------------------------------------------------------------------------------------------------------------
253
// Range Bias Correction TABLES of range values in integer units of 25 CM, for 8-bit unsigned storage, MUST END IN 255 !!!!!!
254
//---------------------------------------------------------------------------------------------------------------------------
255

    
256
// offsets to nearest centimeter for index 0, all rest are +1 cm per value
257

    
258
#define CM_OFFSET_16M_NB    (-23)   // for normal band channels at 16 MHz PRF
259
#define CM_OFFSET_16M_WB    (-28)   // for wider  band channels at 16 MHz PRF
260
#define CM_OFFSET_64M_NB    (-17)   // for normal band channels at 64 MHz PRF
261
#define CM_OFFSET_64M_WB    (-30)   // for wider  band channels at 64 MHz PRF
262

    
263

    
264
//---------------------------------------------------------------------------------------------------------------------------
265
// range25cm16PRFnb: Range Bias Correction table for narrow band channels at 16 MHz PRF, NB: !!!! each MUST END IN 255 !!!!
266
//---------------------------------------------------------------------------------------------------------------------------
267

    
268
const uint8_t range25cm16PRFnb[4][NUM_16M_OFFSET] =
269
{
270
    // ch 1 - range25cm16PRFnb
271
    {
272
           1,
273
           3,
274
           4,
275
           5,
276
           7,
277
           9,
278
          11,
279
          12,
280
          13,
281
          15,
282
          18,
283
          20,
284
          23,
285
          25,
286
          28,
287
          30,
288
          33,
289
          36,
290
          40,
291
          43,
292
          47,
293
          50,
294
          54,
295
          58,
296
          63,
297
          66,
298
          71,
299
          76,
300
          82,
301
          89,
302
          98,
303
         109,
304
         127,
305
         155,
306
         222,
307
         255,
308
         255
309
    },
310

    
311
    // ch 2 - range25cm16PRFnb
312
    {
313
           1,
314
           2,
315
           4,
316
           5,
317
           6,
318
           8,
319
           9,
320
          10,
321
          12,
322
          13,
323
          15,
324
          18,
325
          20,
326
          22,
327
          24,
328
          27,
329
          29,
330
          32,
331
          35,
332
          38,
333
          41,
334
          44,
335
          47,
336
          51,
337
          55,
338
          58,
339
          62,
340
          66,
341
          71,
342
          78,
343
          85,
344
          96,
345
         111,
346
         135,
347
         194,
348
         240,
349
         255
350
    },
351

    
352
    // ch 3 - range25cm16PRFnb
353
    {
354
           1,
355
           2,
356
           3,
357
           4,
358
           5,
359
           7,
360
           8,
361
           9,
362
          10,
363
          12,
364
          14,
365
          16,
366
          18,
367
          20,
368
          22,
369
          24,
370
          26,
371
          28,
372
          31,
373
          33,
374
          36,
375
          39,
376
          42,
377
          45,
378
          49,
379
          52,
380
          55,
381
          59,
382
          63,
383
          69,
384
          76,