Revision fce9feec

View differences:

include/alld_dw1000.h
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_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_H__
32
#define __AMIROLLD_DW1000_H__
33

  
34
#include <amiro-lld.h>
35
#if defined(AMIROLLD_CFG_USE_DW1000) || defined(__DOXYGEN__)
36

  
37

  
38

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

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

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

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

  
53

  
54
/**
55
 * @brief The DW1000 driver struct.
56
 */
57
typedef struct {
58
  apalSPIDriver_t* spid;    /**< @brief The SPI Driver */
59
  apalGpio_t* gpio_exti;    /**< @brief The GPIO indicating external interrupt */
60
  apalGpio_t* gpio_reset;  /**< @brief The GPIO indicating reset sig*/
61
  /* TODO: better apalControlGpio_t instead of apalGpio_t ? */
62
  /* TODO: EXTI, GPIO (RESET) */
63
} DW1000Driver;
64

  
65

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

  
68
#define DWT_DEVICE_ID   (0xDECA0130)        //!< DW1000 MP device ID
69

  
70
#define BUFFLEN 	(4096+128)
71

  
72
//! constants for selecting the bit rate for data TX (and RX)
73
//! These are defined for write (with just a shift) the TX_FCTRL register
74
#define DWT_BR_110K     0   //!< UWB bit rate 110 kbits/s
75
#define DWT_BR_850K     1   //!< UWB bit rate 850 kbits/s
76
#define DWT_BR_6M8      2   //!< UWB bit rate 6.8 Mbits/s
77

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

  
83
//! constants for specifying Preamble Acquisition Chunk (PAC) Size in symbols
84
#define DWT_PAC8        0   //!< PAC  8 (recommended for RX of preamble length  128 and below
85
#define DWT_PAC16       1   //!< PAC 16 (recommended for RX of preamble length  256
86
#define DWT_PAC32       2   //!< PAC 32 (recommended for RX of preamble length  512
87
#define DWT_PAC64       3   //!< PAC 64 (recommended for RX of preamble length 1024 and up
88

  
89
//! constants for specifying TX Preamble length in symbols
90
//! These are defined to allow them be directly written into byte 2 of the TX_FCTRL register
91
//! (i.e. a four bit value destined for bits 20..18 but shifted left by 2 for byte alignment)
92
#define DWT_PLEN_4096   0x0C    //! Standard preamble length 4096 symbols
93
#define DWT_PLEN_2048   0x28    //! Non-standard preamble length 2048 symbols
94
#define DWT_PLEN_1536   0x18    //! Non-standard preamble length 1536 symbols
95
#define DWT_PLEN_1024   0x08    //! Standard preamble length 1024 symbols
96
#define DWT_PLEN_512    0x34    //! Non-standard preamble length 512 symbols
97
#define DWT_PLEN_256    0x24    //! Non-standard preamble length 256 symbols
98
#define DWT_PLEN_128    0x14    //! Non-standard preamble length 128 symbols
99
#define DWT_PLEN_64     0x04    //! Standard preamble length 64 symbols
100

  
101
#define DWT_SFDTOC_DEF              0x1041  // default SFD timeout value
102

  
103
#define DWT_PHRMODE_STD             0x0     // standard PHR mode
104
#define DWT_PHRMODE_EXT             0x3     // DW proprietary extended frames PHR mode
105

  
106
// Defined constants for "mode" bitmask parameter passed into dwt_starttx() function.
107
#define DWT_START_TX_IMMEDIATE      0
108
#define DWT_START_TX_DELAYED        1
109
#define DWT_RESPONSE_EXPECTED       2
110

  
111
#define DWT_START_RX_IMMEDIATE  0
112
#define DWT_START_RX_DELAYED    1    // Set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
113
#define DWT_IDLE_ON_DLY_ERR     2    // If delayed RX failed due to "late" error then if this
114
                                     // flag is set the RX will not be re-enabled immediately, and device will be in IDLE when function exits
115
#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
116
                                     // re-enabling when receiving a frame in double buffer mode.
117

  
118
// Defined constants for "mode" bit field parameter passed to dwt_setleds() function.
119
#define DWT_LEDS_DISABLE     0x00
120
#define DWT_LEDS_ENABLE      0x01
121
#define DWT_LEDS_INIT_BLINK  0x02
122

  
123
//frame filtering configuration options
124
#define DWT_FF_NOTYPE_EN            0x000           // no frame types allowed (FF disabled)
125
#define DWT_FF_COORD_EN             0x002           // behave as coordinator (can receive frames with no dest address (PAN ID has to match))
126
#define DWT_FF_BEACON_EN            0x004           // beacon frames allowed
127
#define DWT_FF_DATA_EN              0x008           // data frames allowed
128
#define DWT_FF_ACK_EN               0x010           // ack frames allowed
129
#define DWT_FF_MAC_EN               0x020           // mac control frames allowed
130
#define DWT_FF_RSVD_EN              0x040           // reserved frame types allowed
131

  
132
//DW1000 interrupt events
133
#define DWT_INT_TFRS            0x00000080          // frame sent
134
#define DWT_INT_LDED            0x00000400          // micro-code has finished execution
135
#define DWT_INT_RFCG            0x00004000          // frame received with good CRC
136
#define DWT_INT_RPHE            0x00001000          // receiver PHY header error
137
#define DWT_INT_RFCE            0x00008000          // receiver CRC error
138
#define DWT_INT_RFSL            0x00010000          // receiver sync loss error
139
#define DWT_INT_RFTO            0x00020000          // frame wait timeout
140
#define DWT_INT_RXOVRR          0x00100000          // receiver overrun
141
#define DWT_INT_RXPTO           0x00200000          // preamble detect timeout
142
#define DWT_INT_SFDT            0x04000000          // SFD timeout
143
#define DWT_INT_ARFE            0x20000000          // frame rejected (due to frame filtering configuration)
144

  
145

  
146
//DW1000 SLEEP and WAKEUP configuration parameters
147
#define DWT_PRESRV_SLEEP 0x0100                      // PRES_SLEEP - on wakeup preserve sleep bit
148
#define DWT_LOADOPSET    0x0080                      // ONW_L64P - on wakeup load operating parameter set for 64 PSR
149
#define DWT_CONFIG       0x0040                      // ONW_LDC - on wakeup restore (load) the saved configurations (from AON array into HIF)
150
#define DWT_LOADEUI      0x0008                      // ONW_LEUI - on wakeup load EUI
151
#define DWT_RX_EN        0x0002                      // ONW_RX - on wakeup activate reception
152
#define DWT_TANDV        0x0001                      // ONW_RADC - on wakeup run ADC to sample temperature and voltage sensor values
153

  
154
#define DWT_XTAL_EN      0x10                       // keep XTAL running during sleep
155
#define DWT_WAKE_SLPCNT  0x8                        // wake up after sleep count
156
#define DWT_WAKE_CS      0x4                        // wake up on chip select
157
#define DWT_WAKE_WK      0x2                        // wake up on WAKEUP PIN
158
#define DWT_SLP_EN       0x1                        // enable sleep/deep sleep functionality
159

  
160
//DW1000 INIT configuration parameters
161
#define DWT_LOADUCODE     0x1
162
#define DWT_LOADNONE      0x0
163

  
164
//DW1000 OTP operating parameter set selection
165
#define DWT_OPSET_64LEN   0x0
166
#define DWT_OPSET_TIGHT   0x1
167
#define DWT_OPSET_DEFLT   0x2
168

  
169
// Call-back data RX frames flags
170
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit
171

  
172

  
173
// TX/RX call-back data
174
typedef struct
175
{
176
    uint32_t status;      //initial value of register as ISR is entered
177
    uint16_t datalength;  //length of frame
178
    uint8_t  fctrl[2];    //frame control bytes
179
    uint8_t  rx_flags;    //RX frame flags, see above
180
} dwt_cb_data_t;
181

  
182
// Call-back type for all events
183
typedef void (*dwt_cb_t)(const dwt_cb_data_t *);
184

  
185

  
186
// -------------------------------------------------------------------------------------------------------------------
187
// Structure to hold device data
188
typedef struct
189
{
190
    uint32_t      partID ;            // IC Part ID - read during initialisation
191
    uint32_t      lotID ;             // IC Lot ID - read during initialisation
192
    uint8_t       longFrames ;        // Flag in non-standard long frame mode
193
    uint8_t       otprev ;            // OTP revision number (read during initialisation)
194
    uint32_t      txFCTRL ;           // Keep TX_FCTRL register config
195
    uint8_t       init_xtrim;         // initial XTAL trim value read from OTP (or defaulted to mid-range if OTP not programmed)
196
    uint8_t       dblbuffon;          // Double RX buffer mode flag
197
    uint32_t      sysCFGreg ;         // Local copy of system config register
198
    uint16_t      sleep_mode;         // Used for automatic reloading of LDO tune and microcode at wake-up
199
    uint8_t       wait4resp ;         // wait4response was set with last TX start command
200
    dwt_cb_data_t cbData;             // Callback data structure
201
    dwt_cb_t      cbTxDone;           // Callback for TX confirmation event
202
    dwt_cb_t      cbRxOk;             // Callback for RX good frame event
203
    dwt_cb_t      cbRxTo;             // Callback for RX timeout events
204
    dwt_cb_t      cbRxErr;            // Callback for RX error events
205
    DW1000Driver  *driver;      // Reference to local hardware SPI, GPIO, ...
206
} dwt_local_data_t ;
207

  
208
/*! ------------------------------------------------------------------------------------------------------------------
209
 * Structure typedef: dwt_config_t
210
 *
211
 * Structure for setting device configuration via dwt_configure() function
212
 *
213
 */
214
typedef struct
215
{
216
    uint8_t chan ;           //!< channel number {1, 2, 3, 4, 5, 7 }
217
    uint8_t prf ;            //!< Pulse Repetition Frequency {DWT_PRF_16M or DWT_PRF_64M}
218
    uint8_t txPreambLength ; //!< DWT_PLEN_64..DWT_PLEN_4096
219
    uint8_t rxPAC ;          //!< Acquisition Chunk Size (Relates to RX preamble length)
220
    uint8_t txCode ;         //!< TX preamble code
221
    uint8_t rxCode ;         //!< RX preamble code
222
    uint8_t nsSFD ;          //!< Boolean should we use non-standard SFD for better performance
223
    uint8_t dataRate ;       //!< Data Rate {DWT_BR_110K, DWT_BR_850K or DWT_BR_6M8}
224
    uint8_t phrMode ;        //!< PHR mode {0x0 - standard DWT_PHRMODE_STD, 0x3 - extended frames DWT_PHRMODE_EXT}
225
    uint16_t sfdTO ;         //!< SFD timeout value (in symbols)
226
} dwt_config_t ;
227

  
228

  
229
typedef struct
230
{
231
    uint8_t   PGdly;
232
    //TX POWER
233
    //31:24     BOOST_0.125ms_PWR
234
    //23:16     BOOST_0.25ms_PWR-TX_SHR_PWR
235
    //15:8      BOOST_0.5ms_PWR-TX_PHR_PWR
236
    //7:0       DEFAULT_PWR-TX_DATA_PWR
237
    uint32_t  power;
238
} dwt_txconfig_t ;
239

  
240

  
241
typedef struct
242
{
243

  
244
    uint16_t      maxNoise ;          // LDE max value of noise
245
    uint16_t      firstPathAmp1 ;     // Amplitude at floor(index FP) + 1
246
    uint16_t      stdNoise ;          // Standard deviation of noise
247
    uint16_t      firstPathAmp2 ;     // Amplitude at floor(index FP) + 2
248
    uint16_t      firstPathAmp3 ;     // Amplitude at floor(index FP) + 3
249
    uint16_t      maxGrowthCIR ;      // Channel Impulse Response max growth CIR
250
    uint16_t      rxPreamCount ;      // Count of preamble symbols accumulated
251
    uint16_t      firstPath ;         // First path index (10.6 bits fixed point integer)
252
}dwt_rxdiag_t ;
253

  
254

  
255
typedef struct
256
{
257
    //all of the below are mapped to a 12-bit register in DW1000
258
    uint16_t PHE ;                    //number of received header errors
259
    uint16_t RSL ;                    //number of received frame sync loss events
260
    uint16_t CRCG ;                   //number of good CRC received frames
261
    uint16_t CRCB ;                   //number of bad CRC (CRC error) received frames
262
    uint16_t ARFE ;                   //number of address filter errors
263
    uint16_t OVER ;                   //number of receiver overflows (used in double buffer mode)
264
    uint16_t SFDTO ;                  //SFD timeouts
265
    uint16_t PTO ;                    //Preamble timeouts
266
    uint16_t RTO ;                    //RX frame wait timeouts
267
    uint16_t TXF ;                    //number of transmitted frames
268
    uint16_t HPW ;                    //half period warn
269
    uint16_t TXW ;                    //power up warn
270

  
271
} dwt_deviceentcnts_t ;
272

  
273

  
274
/********************************************************************************************************************/
275
/*                                                 REMOVED API LIST                                                 */
276
/********************************************************************************************************************/
277
/*
278
 * From version 4.0.0:
279
 *  - dwt_setGPIOforEXTTRX: Replaced by dwt_setlnapamode to get equivalent functionality.
280
 *  - dwt_setGPIOdirection: Renamed to dwt_setgpiodirection.
281
 *  - dwt_setGPIOvalue: Renamed to dwt_setgpiovalue.
282
 *  - dwt_setrxmode: Replaced by dwt_setsniffmode and dwt_setlowpowerlistening depending on the RX mode the user
283
 *    wants to set up.
284
 *  - dwt_checkoverrun: As automatic RX re-enabling is not supported anymore, this functions has become useless.
285
 *  - dwt_setautorxreenable: As automatic RX re-enabling is not supported anymore, this functions has become
286
 *    useless.
287
 *  - dwt_getrangebias: Range bias correction values are platform dependent and should therefore be managed at user
288
 *    application level.
289
 *  - dwt_xtaltrim: Renamed to dwt_setxtaltrim.
290
 *  - dwt_checkIRQ: Renamed to dwt_checkirq.
291
 *
292
 * From version 3.0.0:
293
 *  - dwt_getldotune: As LDO loading is now automatically managed by the driver, this function has become useless.
294
 *  - dwt_getotptxpower: TX power values and location in OTP memory are platform dependent and should therefore be
295
 *    managed at user application level.
296
 *  - dwt_readantennadelay: Antenna delay values and location in OTP memory are platform dependent and should
297
 *    therefore be managed at user application level.
298
 *  - dwt_readdignostics: Renamed to dwt_readdiagnostics.
299
 */
300

  
301
/********************************************************************************************************************/
302
/*                                                     API LIST                                                     */
303
/********************************************************************************************************************/
304

  
305
/*! ------------------------------------------------------------------------------------------------------------------
306
 * @fn dwt_setdevicedataptr()
307
 *
308
 * @brief This function sets the local data structure pointer to point to the structure in the local array as given by the index.
309
 *
310
 * input parameters
311
 * @param index    - selects the array object to point to. Must be within the array bounds, i.e. < DWT_NUM_DW_DEV
312
 *
313
 * output parameters
314
 *
315
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
316
 */
317
int dwt_setdevicedataptr(unsigned int index);
318

  
319
/*! ------------------------------------------------------------------------------------------------------------------
320
 * @fn dwt_getpartid()
321
 *
322
 * @brief This is used to return the read part ID of the device
323
 *
324
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
325
 *
326
 * input parameters
327
 *
328
 * output parameters
329
 *
330
 * returns the 32 bit part ID value as programmed in the factory
331
 */
332
uint32_t dwt_getpartid(void);
333

  
334
/*! ------------------------------------------------------------------------------------------------------------------
335
 * @fn dwt_getlotid()
336
 *
337
 * @brief This is used to return the read lot ID of the device
338
 *
339
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
340
 *
341
 * input parameters
342
 *
343
 * output parameters
344
 *
345
 * returns the 32 bit lot ID value as programmed in the factory
346
 */
347
uint32_t dwt_getlotid(void);
348

  
349
/*! ------------------------------------------------------------------------------------------------------------------
350
 * @fn dwt_readdevid()
351
 *
352
 * @brief This is used to return the read device type and revision information of the DW1000 device (MP part is 0xDECA0130)
353
 *
354
 * input parameters
355
 *
356
 * output parameters
357
 *
358
 * returns the read value which for DW1000 is 0xDECA0130
359
 */
360
uint32_t dwt_readdevid(void);
361

  
362
/*! ------------------------------------------------------------------------------------------------------------------
363
 * @fn dwt_otprevision()
364
 *
365
 * @brief This is used to return the read OTP revision
366
 *
367
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
368
 *
369
 * input parameters
370
 *
371
 * output parameters
372
 *
373
 * returns the read OTP revision value
374
 */
375
uint8_t dwt_otprevision(void);
376

  
377
/*! ------------------------------------------------------------------------------------------------------------------
378
 * @fn dwt_setfinegraintxseq()
379
 *
380
 * @brief This function enables/disables the fine grain TX sequencing (enabled by default).
381
 *
382
 * input parameters
383
 * @param enable - 1 to enable fine grain TX sequencing, 0 to disable it.
384
 *
385
 * output parameters none
386
 *
387
 * no return value
388
 */
389
void dwt_setfinegraintxseq(int enable);
390

  
391
/*! ------------------------------------------------------------------------------------------------------------------
392
 * @fn dwt_setlnapamode()
393
 *
394
 * @brief This is used to enable GPIO for external LNA or PA functionality - HW dependent, consult the DW1000 User Manual.
395
 *        This can also be used for debug as enabling TX and RX GPIOs is quite handy to monitor DW1000's activity.
396
 *
397
 * NOTE: Enabling PA functionality requires that fine grain TX sequencing is deactivated. This can be done using
398
 *       dwt_setfinegraintxseq().
399
 *
400
 * input parameters
401
 * @param lna - 1 to enable LNA functionality, 0 to disable it
402
 * @param pa - 1 to enable PA functionality, 0 to disable it
403
 *
404
 * output parameters
405
 *
406
 * no return value
407
 */
408
void dwt_setlnapamode(int lna, int pa);
409

  
410
/*! ------------------------------------------------------------------------------------------------------------------
411
 * @fn dwt_setgpiodirection()
412
 *
413
 * @brief This is used to set GPIO direction as an input (1) or output (0)
414
 *
415
 * input parameters
416
 * @param gpioNum    -   this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
417
 * @param direction  -   this sets the GPIO direction - see GxP0... GxP8 in the deca_regs.h file
418
 *
419
 * output parameters
420
 *
421
 * no return value
422
 */
423
void dwt_setgpiodirection(uint32_t gpioNum, uint32_t direction);
424

  
425
/*! ------------------------------------------------------------------------------------------------------------------
426
 * @fn dwt_setgpiovalue()
427
 *
428
 * @brief This is used to set GPIO value as (1) or (0) only applies if the GPIO is configured as output
429
 *
430
 * input parameters
431
 * @param gpioNum    -   this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
432
 * @param value  -   this sets the GPIO value - see GDP0... GDP8 in the deca_regs.h file
433
 *
434
 * output parameters
435
 *
436
 * no return value