Statistics
| Branch: | Tag: | Revision:

amiro-lld / source / DW1000 / v0 / alld_DW100_v0.c @ c3c5444e

History | View | Annotate | Download (150.762 KB)

1 fce9feec Robin Ewers
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3 f125ae07 Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 fce9feec Robin Ewers

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 1d5bcc82 Thomas Schöpping
#include <alld_DW1000.h>
32 21076167 Thomas Schöpping
33 1d5bcc82 Thomas Schöpping
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 0)) || defined(__DOXYGEN__)
34 fce9feec Robin Ewers
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 _alld_dw1000_writespi(uint16_t headerLength,
44
               const        uint8_t *headerBuffer,
45
               uint32_t bodyLength,
46
               const        uint8_t *bodyBuffer);
47
48
static int _alld_dw1000_readspi(uint16_t headerLength,
49
                const uint8_t *headerBuffer,
50
                uint32_t readlength,
51
                uint8_t *readBuffer);
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
#define NUM_BR 3
71
#define NUM_PRF 2
72
#define NUM_PACS 4
73
#define NUM_BW 2            //2 bandwidths are supported
74
#define NUM_SFD 2           //supported number of SFDs - standard = 0, non-standard = 1
75
#define NUM_CH 6            //supported channels are 1, 2, 3, 4, 5, 7
76
#define NUM_CH_SUPPORTED 8  //supported channels are '0', 1, 2, 3, 4, 5, '6', 7
77
#define PCODES 25           //supported preamble codes
78
79
80
typedef struct {
81
    uint32_t lo32;
82
    uint16_t target[NUM_PRF];
83
} agc_cfg_struct ;
84
85
extern const agc_cfg_struct agc_config ;
86
87
//SFD threshold settings for 110k, 850k, 6.8Mb standard and non-standard
88
extern const uint16_t sftsh[NUM_BR][NUM_SFD];
89
90
extern const uint16_t dtune1[NUM_PRF];
91
92
#define XMLPARAMS_VERSION   (1.17f)
93
94
extern const uint32_t fs_pll_cfg[NUM_CH];
95
extern const uint8_t fs_pll_tune[NUM_CH];
96
extern const uint8_t rx_config[NUM_BW];
97
extern const uint32_t tx_config[NUM_CH];
98
extern const uint8_t dwnsSFDlen[NUM_BR]; //length of SFD for each of the bitrates
99
extern const uint32_t digital_bb_config[NUM_PRF][NUM_PACS];
100
extern const uint8_t chan_idx[NUM_CH_SUPPORTED];
101
extern const double txpwr_compensation[NUM_CH];
102
103
#define PEAK_MULTPLIER  (0x60) //3 -> (0x3 * 32) & 0x00E0
104
#define N_STD_FACTOR    (13)
105
#define LDE_PARAM1      (PEAK_MULTPLIER | N_STD_FACTOR)
106
107
#define LDE_PARAM3_16 (0x1607)
108
#define LDE_PARAM3_64 (0x0607)
109
110
#define MIXER_GAIN_STEP (0.5)
111
#define DA_ATTN_STEP    (2.5)
112
113
// #define DWT_API_ERROR_CHECK     // define so API checks config input parameters
114
115
//-----------------------------------------
116
// map the channel number to the index in the configuration arrays below
117
// 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
118
const uint8_t chan_idx[NUM_CH_SUPPORTED] = {0, 0, 1, 2, 3, 4, 0, 5};
119
120
//-----------------------------------------
121
const uint32_t tx_config[NUM_CH] =
122
{
123
    RF_TXCTRL_CH1,
124
    RF_TXCTRL_CH2,
125
    RF_TXCTRL_CH3,
126
    RF_TXCTRL_CH4,
127
    RF_TXCTRL_CH5,
128
    RF_TXCTRL_CH7,
129
};
130
131
//Frequency Synthesiser - PLL configuration
132
const uint32_t fs_pll_cfg[NUM_CH] =
133
{
134
    FS_PLLCFG_CH1,
135
    FS_PLLCFG_CH2,
136
    FS_PLLCFG_CH3,
137
    FS_PLLCFG_CH4,
138
    FS_PLLCFG_CH5,
139
    FS_PLLCFG_CH7
140
};
141
142
//Frequency Synthesiser - PLL tuning
143
const uint8_t fs_pll_tune[NUM_CH] =
144
{
145
    FS_PLLTUNE_CH1,
146
    FS_PLLTUNE_CH2,
147
    FS_PLLTUNE_CH3,
148
    FS_PLLTUNE_CH4,
149
    FS_PLLTUNE_CH5,
150
    FS_PLLTUNE_CH7
151
};
152
153
//bandwidth configuration
154
const uint8_t rx_config[NUM_BW] =
155
{
156
    RF_RXCTRLH_NBW,
157
    RF_RXCTRLH_WBW
158
};
159
160
161
const agc_cfg_struct agc_config =
162
{
163
    AGC_TUNE2_VAL,
164
    { AGC_TUNE1_16M , AGC_TUNE1_64M }  //adc target
165
};
166
167
//DW non-standard SFD length for 110k, 850k and 6.81M
168
const uint8_t dwnsSFDlen[NUM_BR] =
169
{
170
    DW_NS_SFD_LEN_110K,
171
    DW_NS_SFD_LEN_850K,
172
    DW_NS_SFD_LEN_6M8
173
};
174
175
// SFD Threshold
176
const uint16_t sftsh[NUM_BR][NUM_SFD] =
177
{
178
    {
179
        DRX_TUNE0b_110K_STD,
180
        DRX_TUNE0b_110K_NSTD
181
    },
182
    {
183
        DRX_TUNE0b_850K_STD,
184
        DRX_TUNE0b_850K_NSTD
185
    },
186
    {
187
        DRX_TUNE0b_6M8_STD,
188
        DRX_TUNE0b_6M8_NSTD
189
    }
190
};
191
192
const uint16_t dtune1[NUM_PRF] =
193
{
194
    DRX_TUNE1a_PRF16,
195
    DRX_TUNE1a_PRF64
196
};
197
198
const uint32_t digital_bb_config[NUM_PRF][NUM_PACS] =
199
{
200
    {
201
        DRX_TUNE2_PRF16_PAC8,
202
        DRX_TUNE2_PRF16_PAC16,
203
        DRX_TUNE2_PRF16_PAC32,
204
        DRX_TUNE2_PRF16_PAC64
205
    },
206
    {
207
        DRX_TUNE2_PRF64_PAC8,
208
        DRX_TUNE2_PRF64_PAC16,
209
        DRX_TUNE2_PRF64_PAC32,
210
        DRX_TUNE2_PRF64_PAC64
211
    }
212
};
213
214
const uint16_t lde_replicaCoeff[PCODES] =
215
{
216
    0, // No preamble code 0
217
    LDE_REPC_PCODE_1,
218
    LDE_REPC_PCODE_2,
219
    LDE_REPC_PCODE_3,
220
    LDE_REPC_PCODE_4,
221
    LDE_REPC_PCODE_5,
222
    LDE_REPC_PCODE_6,
223
    LDE_REPC_PCODE_7,
224
    LDE_REPC_PCODE_8,
225
    LDE_REPC_PCODE_9,
226
    LDE_REPC_PCODE_10,
227
    LDE_REPC_PCODE_11,
228
    LDE_REPC_PCODE_12,
229
    LDE_REPC_PCODE_13,
230
    LDE_REPC_PCODE_14,
231
    LDE_REPC_PCODE_15,
232
    LDE_REPC_PCODE_16,
233
    LDE_REPC_PCODE_17,
234
    LDE_REPC_PCODE_18,
235
    LDE_REPC_PCODE_19,
236
    LDE_REPC_PCODE_20,
237
    LDE_REPC_PCODE_21,
238
    LDE_REPC_PCODE_22,
239
    LDE_REPC_PCODE_23,
240
    LDE_REPC_PCODE_24
241
};
242
243
const double txpwr_compensation[NUM_CH] = {
244
    0.0,
245
    0.035,
246
    0.0,
247
    0.0,
248
    0.065,
249
    0.0
250
};
251
252
253
#define NUM_16M_OFFSET  (37)
254
#define NUM_16M_OFFSETWB  (68)
255
#define NUM_64M_OFFSET  (26)
256
#define NUM_64M_OFFSETWB  (59)
257
258</