Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / DW1000 / v1 / alld_dw1000_v1.h @ 84450926

History | View | Annotate | Download (74.826 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_api.h
21
 * @brief   DW1000 API Functions
22
 *
23
 * @attention
24
 *
25
 * Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
26
 *
27
 * All rights reserved.
28
 *
29
 */
30

    
31
#ifndef __AMIROLLD_DW1000_V1_H
32
#define AMIROLLD_DW1000_V1_H
33

    
34

    
35
#include <amiro-lld.h>
36
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__)
37

    
38
#include <stddef.h>
39
#include <stdint.h>
40
#include <stdbool.h>
41

    
42
#define DW1000_DRIVER_VERSION               0x040005
43
#define DW1000_DEVICE_DRIVER_VER_STRING     "DW1000 Device Driver Version 04.00.05"
44

    
45
#ifndef DWT_NUM_DW_DEV
46
#define DWT_NUM_DW_DEV (1)
47
#endif
48

    
49
#define DWT_SUCCESS (0)
50
#define DWT_ERROR   (-1)
51

    
52
/**
53
 * Parameter declarations
54
 */
55

    
56
#define NUM_BR 3
57
#define NUM_PRF 2
58
#define NUM_PACS 4
59
#define NUM_BW 2            //2 bandwidths are supported
60
#define NUM_SFD 2           //supported number of SFDs - standard = 0, non-standard = 1
61
#define NUM_CH 6            //supported channels are 1, 2, 3, 4, 5, 7
62
#define NUM_CH_SUPPORTED 8  //supported channels are '0', 1, 2, 3, 4, 5, '6', 7
63
#define PCODES 25           //supported preamble codes
64

    
65
#define NUM_16M_OFFSET  (37)
66
#define NUM_16M_OFFSETWB  (68)
67
#define NUM_64M_OFFSET  (26)
68
#define NUM_64M_OFFSETWB  (59)
69

    
70
#define SPIBUFFLEN     (32)
71

    
72

    
73
extern const uint8_t chan_idx[NUM_CH_SUPPORTED];
74
extern const uint16_t lde_replicaCoeff[PCODES];
75
extern const uint8_t chan_idxnb[NUM_CH_SUPPORTED];
76
extern const uint8_t chan_idxwb[NUM_CH_SUPPORTED];
77
extern const uint8_t range25cm16PRFnb[4][NUM_16M_OFFSET];
78
extern const uint8_t range25cm16PRFwb[2][NUM_16M_OFFSETWB];
79
extern const uint8_t range25cm64PRFnb[4][NUM_64M_OFFSET];
80
extern const uint8_t range25cm64PRFwb[2][NUM_64M_OFFSETWB];
81

    
82

    
83
/**
84
 * @brief The DW1000 driver struct.
85
 */
86
typedef struct {
87
  apalSPIDriver_t* spid;    /**< @brief The SPI Driver */
88
  const apalControlGpio_t* gpio_exti;    /**< @brief The GPIO indicating external interrupt */
89
  const apalControlGpio_t* gpio_reset;  /**< @brief The GPIO indicating reset sig*/
90
//  const apalGpio_t* gpio_exti;    /**< @brief The GPIO indicating external interrupt */
91
//  const apalGpio_t* gpio_reset;  /**< @brief The GPIO indicating reset sig*/
92
} DW1000Driver;
93

    
94

    
95
#define DWT_TIME_UNITS  (1.0/499.2e6/128.0) //!< = 15.65e-12 s
96

    
97
#define DWT_DEVICE_ID   (0xDECA0130)        //!< DW1000 MP device ID
98

    
99
#define BUFFLEN         (4096+128)
100

    
101
//! constants for selecting the bit rate for data TX (and RX)
102
//! These are defined for write (with just a shift) the TX_FCTRL register
103
#define DWT_BR_110K     0   //!< UWB bit rate 110 kbits/s
104
#define DWT_BR_850K     1   //!< UWB bit rate 850 kbits/s
105
#define DWT_BR_6M8      2   //!< UWB bit rate 6.8 Mbits/s
106

    
107
//! constants for specifying the (Nominal) mean Pulse Repetition Frequency
108
//! These are defined for direct write (with a shift if necessary) to CHAN_CTRL and TX_FCTRL regs
109
#define DWT_PRF_16M     1   //!< UWB PRF 16 MHz
110
#define DWT_PRF_64M     2   //!< UWB PRF 64 MHz
111

    
112
//! constants for specifying Preamble Acquisition Chunk (PAC) Size in symbols
113
#define DWT_PAC8        0   //!< PAC  8 (recommended for RX of preamble length  128 and below
114
#define DWT_PAC16       1   //!< PAC 16 (recommended for RX of preamble length  256
115
#define DWT_PAC32       2   //!< PAC 32 (recommended for RX of preamble length  512
116
#define DWT_PAC64       3   //!< PAC 64 (recommended for RX of preamble length 1024 and up
117

    
118
//! constants for specifying TX Preamble length in symbols
119
//! These are defined to allow them be directly written into byte 2 of the TX_FCTRL register
120
//! (i.e. a four bit value destined for bits 20..18 but shifted left by 2 for byte alignment)
121
#define DWT_PLEN_4096   0x0C    //! Standard preamble length 4096 symbols
122
#define DWT_PLEN_2048   0x28    //! Non-standard preamble length 2048 symbols
123
#define DWT_PLEN_1536   0x18    //! Non-standard preamble length 1536 symbols
124
#define DWT_PLEN_1024   0x08    //! Standard preamble length 1024 symbols
125
#define DWT_PLEN_512    0x34    //! Non-standard preamble length 512 symbols
126
#define DWT_PLEN_256    0x24    //! Non-standard preamble length 256 symbols
127
#define DWT_PLEN_128    0x14    //! Non-standard preamble length 128 symbols
128
#define DWT_PLEN_64     0x04    //! Standard preamble length 64 symbols
129

    
130
#define DWT_SFDTOC_DEF              0x1041  // default SFD timeout value
131

    
132
#define DWT_PHRMODE_STD             0x0     // standard PHR mode
133
#define DWT_PHRMODE_EXT             0x3     // DW proprietary extended frames PHR mode
134

    
135
// Defined constants for "mode" bitmask parameter passed into dwt_starttx() function.
136
#define DWT_START_TX_IMMEDIATE      0
137
#define DWT_START_TX_DELAYED        1
138
#define DWT_RESPONSE_EXPECTED       2
139

    
140
#define DWT_START_RX_IMMEDIATE  0
141
#define DWT_START_RX_DELAYED    1    // Set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
142
#define DWT_IDLE_ON_DLY_ERR     2    // If delayed RX failed due to "late" error then if this
143
                                     // flag is set the RX will not be re-enabled immediately, and device will be in IDLE when function exits
144
#define DWT_NO_SYNC_PTRS        4    // Do not try to sync IC side and Host side buffer pointers when enabling RX. This is used to perform manual RX
145
                                     // re-enabling when receiving a frame in double buffer mode.
146

    
147
// Defined constants for "mode" bit field parameter passed to dwt_setleds() function.
148
#define DWT_LEDS_DISABLE     0x00
149
#define DWT_LEDS_ENABLE      0x01
150
#define DWT_LEDS_INIT_BLINK  0x02
151

    
152
//frame filtering configuration options
153
#define DWT_FF_NOTYPE_EN            0x000           // no frame types allowed (FF disabled)
154
#define DWT_FF_COORD_EN             0x002           // behave as coordinator (can receive frames with no dest address (PAN ID has to match))
155
#define DWT_FF_BEACON_EN            0x004           // beacon frames allowed
156
#define DWT_FF_DATA_EN              0x008           // data frames allowed
157
#define DWT_FF_ACK_EN               0x010           // ack frames allowed
158
#define DWT_FF_MAC_EN               0x020           // mac control frames allowed
159
#define DWT_FF_RSVD_EN              0x040           // reserved frame types allowed
160

    
161
//DW1000 interrupt events
162
#define DWT_INT_TFRS            0x00000080          // frame sent
163
#define DWT_INT_LDED            0x00000400          // micro-code has finished execution
164
#define DWT_INT_RFCG            0x00004000          // frame received with good CRC
165
#define DWT_INT_RPHE            0x00001000          // receiver PHY header error
166
#define DWT_INT_RFCE            0x00008000          // receiver CRC error
167
#define DWT_INT_RFSL            0x00010000          // receiver sync loss error
168
#define DWT_INT_RFTO            0x00020000          // frame wait timeout
169
#define DWT_INT_RXOVRR          0x00100000          // receiver overrun
170
#define DWT_INT_RXPTO           0x00200000          // preamble detect timeout
171
#define DWT_INT_SFDT            0x04000000          // SFD timeout
172
#define DWT_INT_ARFE            0x20000000          // frame rejected (due to frame filtering configuration)
173

    
174

    
175
//DW1000 SLEEP and WAKEUP configuration parameters
176
#define DWT_PRESRV_SLEEP 0x0100                      // PRES_SLEEP - on wakeup preserve sleep bit
177
#define DWT_LOADOPSET    0x0080                      // ONW_L64P - on wakeup load operating parameter set for 64 PSR
178
#define DWT_CONFIG       0x0040                      // ONW_LDC - on wakeup restore (load) the saved configurations (from AON array into HIF)
179
#define DWT_LOADEUI      0x0008                      // ONW_LEUI - on wakeup load EUI
180
#define DWT_RX_EN        0x0002                      // ONW_RX - on wakeup activate reception
181
#define DWT_TANDV        0x0001                      // ONW_RADC - on wakeup run ADC to sample temperature and voltage sensor values
182

    
183
#define DWT_XTAL_EN      0x10                       // keep XTAL running during sleep
184
#define DWT_WAKE_SLPCNT  0x8                        // wake up after sleep count
185
#define DWT_WAKE_CS      0x4                        // wake up on chip select
186
#define DWT_WAKE_WK      0x2                        // wake up on WAKEUP PIN
187
#define DWT_SLP_EN       0x1                        // enable sleep/deep sleep functionality
188

    
189
//DW1000 INIT configuration parameters
190
#define DWT_LOADUCODE     0x1
191
#define DWT_LOADNONE      0x0
192

    
193
//DW1000 OTP operating parameter set selection
194
#define DWT_OPSET_64LEN   0x0
195
#define DWT_OPSET_TIGHT   0x1
196
#define DWT_OPSET_DEFLT   0x2
197

    
198
// Call-back data RX frames flags
199
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit
200

    
201

    
202
// TX/RX call-back data
203
typedef struct
204
{
205
    uint32_t status;      //initial value of register as ISR is entered
206
    uint16_t datalength;  //length of frame
207
    uint8_t  fctrl[2];    //frame control bytes
208
    uint8_t  rx_flags;    //RX frame flags, see above
209
} dwt_cb_data_t;
210

    
211
// Call-back type for all events
212
typedef void (*dwt_cb_t)(const dwt_cb_data_t *);
213

    
214

    
215
// -------------------------------------------------------------------------------------------------------------------
216
// Structure to hold device data
217
typedef struct
218
{
219
    uint32_t      partID ;            // IC Part ID - read during initialisation
220
    uint32_t      lotID ;             // IC Lot ID - read during initialisation
221
    uint8_t       longFrames ;        // Flag in non-standard long frame mode
222
    uint8_t       otprev ;            // OTP revision number (read during initialisation)
223
    uint32_t      txFCTRL ;           // Keep TX_FCTRL register config
224
    uint8_t       init_xtrim;         // initial XTAL trim value read from OTP (or defaulted to mid-range if OTP not programmed)
225
    uint8_t       dblbuffon;          // Double RX buffer mode flag
226
    uint32_t      sysCFGreg ;         // Local copy of system config register
227
    uint16_t      sleep_mode;         // Used for automatic reloading of LDO tune and microcode at wake-up
228
    uint8_t       wait4resp ;         // wait4response was set with last TX start command
229
    dwt_cb_data_t cbData;             // Callback data structure
230
    dwt_cb_t      cbTxDone;           // Callback for TX confirmation event
231
    dwt_cb_t      cbRxOk;             // Callback for RX good frame event
232
    dwt_cb_t      cbRxTo;             // Callback for RX timeout events
233
    dwt_cb_t      cbRxErr;            // Callback for RX error events
234
    DW1000Driver  *driver;      // Reference to local hardware SPI, GPIO, ...
235
} dwt_local_data_t ;
236

    
237
/*! ------------------------------------------------------------------------------------------------------------------
238
 * Structure typedef: dwt_config_t
239
 *
240
 * Structure for setting device configuration via dwt_configure() function
241
 *
242
 */
243
typedef struct
244
{
245
    uint8_t chan ;           //!< channel number {1, 2, 3, 4, 5, 7 }
246
    uint8_t prf ;            //!< Pulse Repetition Frequency {DWT_PRF_16M or DWT_PRF_64M}
247
    uint8_t txPreambLength ; //!< DWT_PLEN_64..DWT_PLEN_4096
248
    uint8_t rxPAC ;          //!< Acquisition Chunk Size (Relates to RX preamble length)
249
    uint8_t txCode ;         //!< TX preamble code
250
    uint8_t rxCode ;         //!< RX preamble code
251
    uint8_t nsSFD ;          //!< Boolean should we use non-standard SFD for better performance
252
    uint8_t dataRate ;       //!< Data Rate {DWT_BR_110K, DWT_BR_850K or DWT_BR_6M8}
253
    uint8_t phrMode ;        //!< PHR mode {0x0 - standard DWT_PHRMODE_STD, 0x3 - extended frames DWT_PHRMODE_EXT}
254
    uint8_t smartPowerEn ;  //!< Smart Power enable / disable
255
    uint16_t sfdTO ;         //!< SFD timeout value (in symbols)    
256
} dwt_config_t ;
257

    
258

    
259
typedef struct
260
{
261
    uint8_t   PGdly;
262
    //TX POWER
263
    //31:24     BOOST_0.125ms_PWR
264
    //23:16     BOOST_0.25ms_PWR-TX_SHR_PWR
265
    //15:8      BOOST_0.5ms_PWR-TX_PHR_PWR
266
    //7:0       DEFAULT_PWR-TX_DATA_PWR
267
    uint32_t  power;
268
} dwt_txconfig_t ;
269

    
270

    
271
typedef struct
272
{
273

    
274
    uint16_t      maxNoise ;          // LDE max value of noise
275
    uint16_t      firstPathAmp1 ;     // Amplitude at floor(index FP) + 1
276
    uint16_t      stdNoise ;          // Standard deviation of noise
277
    uint16_t      firstPathAmp2 ;     // Amplitude at floor(index FP) + 2
278
    uint16_t      firstPathAmp3 ;     // Amplitude at floor(index FP) + 3
279
    uint16_t      maxGrowthCIR ;      // Channel Impulse Response max growth CIR
280
    uint16_t      rxPreamCount ;      // Count of preamble symbols accumulated
281
    uint16_t      firstPath ;         // First path index (10.6 bits fixed point integer)
282
}dwt_rxdiag_t ;
283

    
284

    
285
typedef struct
286
{
287
    //all of the below are mapped to a 12-bit register in DW1000
288
    uint16_t PHE ;                    //number of received header errors
289
    uint16_t RSL ;                    //number of received frame sync loss events
290
    uint16_t CRCG ;                   //number of good CRC received frames
291
    uint16_t CRCB ;                   //number of bad CRC (CRC error) received frames
292
    uint16_t ARFE ;                   //number of address filter errors
293
    uint16_t OVER ;                   //number of receiver overflows (used in double buffer mode)
294
    uint16_t SFDTO ;                  //SFD timeouts
295
    uint16_t PTO ;                    //Preamble timeouts
296
    uint16_t RTO ;                    //RX frame wait timeouts
297
    uint16_t TXF ;                    //number of transmitted frames
298
    uint16_t HPW ;                    //half period warn
299
    uint16_t TXW ;                    //power up warn
300

    
301
} dwt_deviceentcnts_t ;
302

    
303

    
304
/********************************************************************************************************************/
305
/*                                                 REMOVED API LIST                                                 */
306
/********************************************************************************************************************/
307
/*
308
 * From version 4.0.0:
309
 *  - dwt_setGPIOforEXTTRX: Replaced by dwt_setlnapamode to get equivalent functionality.
310
 *  - dwt_setGPIOdirection: Renamed to dwt_setgpiodirection.
311
 *  - dwt_setGPIOvalue: Renamed to dwt_setgpiovalue.
312
 *  - dwt_setrxmode: Replaced by dwt_setsniffmode and dwt_setlowpowerlistening depending on the RX mode the user
313
 *    wants to set up.
314
 *  - dwt_checkoverrun: As automatic RX re-enabling is not supported anymore, this functions has become useless.
315
 *  - dwt_setautorxreenable: As automatic RX re-enabling is not supported anymore, this functions has become
316
 *    useless.
317
 *  - dwt_getrangebias: Range bias correction values are platform dependent and should therefore be managed at user
318
 *    application level.
319
 *  - dwt_xtaltrim: Renamed to dwt_setxtaltrim.
320
 *  - dwt_checkIRQ: Renamed to dwt_checkirq.