Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / DW1000 / v0 / alld_dw1000_v0.h @ 5d4d14a3

History | View | Annotate | Download (75.55 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_H
32
#define AMIROLLD_DW1000_H
33

    
34
#include <amiro-lld.h>
35

    
36
#if defined(AMIROLLD_CFG_USE_DW1000) || defined(__DOXYGEN__)
37

    
38

    
39

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

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

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

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

    
54

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

    
66

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

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

    
71
#define BUFFLEN         (4096+128)
72

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

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

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

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

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

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

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

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

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

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

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

    
146

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

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

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

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

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

    
173

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

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

    
186

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

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

    
229

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

    
241

    
242
typedef struct
243
{
244

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

    
255

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

    
272
} dwt_deviceentcnts_t ;
273

    
274

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

    
302
/********************************************************************************************************************/
303
/*                                                     API LIST                                                     */
304
/********************************************************************************************************************/
305

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

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

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

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

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

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

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

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

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

    
441
/*! ------------------------------------------------------------------------------------------------------------------
442
 * @fn dwt_initialise()
443
 *
444
 * @brief This function initiates communications with the DW1000 transceiver
445
 * and reads its DEV_ID register (address 0x00) to verify the IC is one supported
446
 * by this software (e.g. DW1000 32-bit device ID value is 0xDECA0130).  Then it
447
 * does any initial once only device configurations needed for use and initialises
448
 * as necessary any static data items belonging to this low-level driver.
449
 *
450
 * NOTES:
451
 * 1.this function needs to be run before dwt_configuresleep, also the SPI frequency has to be < 3MHz
452
 * 2.it also reads and applies LDO tune and crystal trim values from OTP memory
453
 *
454
 * input parameters
455
 * @param config    -   specifies what configuration to load
456
 *                  DWT_LOADUCODE     0x1 - load the LDE microcode from ROM - enabled accurate RX timestamp
457
 *                  DWT_LOADNONE      0x0 - do not load any values from OTP memory
458
 * @param drv       -   hardware specifc struct containg refernce to SPI, GPIO etc.
459
 *
460
 * output parameters
461
 *
462
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
463
 */
464
int dwt_initialise(uint16_t config, DW1000Driver* drv) ;
465

    
466
/*! ------------------------------------------------------------------------------------------------------------------
467
 * @fn dwt_configure()
468
 *
469
 * @brief This function provides the main API for the configuration of the
470
 * DW1000 and this low-level driver.  The input is a pointer to the data structure
471
 * of type dwt_config_t that holds all the configurable items.
472
 * The dwt_config_t structure shows which ones are supported
473
 *
474
 * input parameters
475
 * @param config    -   pointer to the configuration structure, which contains the device configuration data.
476
 *
477
 * output parameters
478
 *
479
 * no return value
480
 */
481
void dwt_configure(dwt_config_t* config) ;
482

    
483
/*! ------------------------------------------------------------------------------------------------------------------
484
 * @fn dwt_configuretxrf()
485
 *
486
 * @brief This function provides the API for the configuration of the TX spectrum
487
 * including the power and pulse generator delay. The input is a pointer to the data structure
488
 * of type dwt_txconfig_t that holds all the configurable items.
489
 *
490
 * input parameters
491
 * @param config    -   pointer to the txrf configuration structure, which contains the tx rf config data
492
 *
493
 * output parameters
494
 *
495
 * no return value
496
 */
497
void dwt_configuretxrf(dwt_txconfig_t *config) ;
498

    
499
/*! ------------------------------------------------------------------------------------------------------------------
500
 * @fn dwt_setrxantennadelay()
501
 *
502
 * @brief This API function writes the antenna delay (in time units) to RX registers
503
 *
504
 * input parameters:
505
 * @param rxDelay - this is the total (RX) antenna delay value, which
506
 *                          will be programmed into the RX register
507
 *
508
 * output parameters
509
 *
510
 * no return value
511
 */
512
void dwt_setrxantennadelay(uint16_t antennaDly);
513

    
514
/*! ------------------------------------------------------------------------------------------------------------------
515
 * @fn dwt_settxantennadelay()
516
 *
517
 * @brief This API function writes the antenna delay (in time units) to TX registers
518
 *
519
 * input parameters:
520
 * @param txDelay - this is the total (TX) antenna delay value, which
521
 *                          will be programmed into the TX delay register
522
 *
523
 * output parameters
524
 *
525
 * no return value
526
 */
527
void dwt_settxantennadelay(uint16_t antennaDly);
528

    
529
/*! ------------------------------------------------------------------------------------------------------------------
530
 * @fn dwt_setsmarttxpower()
531
 *
532
 * @brief This call enables or disables the smart TX power feature.
533
 *
534
 * input parameters
535
 * @param enable - this enables or disables the TX smart power (1 = enable, 0 = disable)
536
 *
537
 * output parameters
538
 *
539
 * no return value
540
 */
541
void dwt_setsmarttxpower(int enable);
542

    
543
/*! ------------------------------------------------------------------------------------------------------------------
544
 * @fn dwt_writetxdata()
545
 *
546
 * @brief This API function writes the supplied TX data into the DW1000's
547
 * TX buffer.  The input parameters are the data length in bytes and a pointer
548
 * to those data bytes.
549
 *
550
 * input parameters
551
 * @param txFrameLength  - This is the total frame length, including the two byte CRC.
552
 *                         Note: this is the length of TX message (including the 2 byte CRC) - max is 1023
553
 *                         standard PHR mode allows up to 127 bytes
554
 *                         if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
555
 *                         see dwt_configure function
556
 * @param txFrameBytes   - Pointer to the user’s buffer containing the data to send.
557
 * @param txBufferOffset - This specifies an offset in the DW1000’s TX Buffer at which to start writing data.
558
 *
559
 * output parameters
560
 *
561
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
562
 */
563
int dwt_writetxdata(uint16_t txFrameLength, uint8_t *txFrameBytes, uint16_t txBufferOffset) ;
564

    
565
/*! ------------------------------------------------------------------------------------------------------------------
566
 * @fn dwt_writetxfctrl()
567
 *
568
 * @brief This API function configures the TX frame control register before the transmission of a frame
569
 *
570
 * input parameters:
571
 * @param txFrameLength - this is the length of TX message (including the 2 byte CRC) - max is 1023
572
 *                              NOTE: standard PHR mode allows up to 127 bytes
573
 *                              if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
574
 *                              see dwt_configure function
575
 * @param txBufferOffset - the offset in the tx buffer to start writing the data
576
 * @param ranging - 1 if this is a ranging frame, else 0
577
 *
578
 * output parameters
579
 *
580
 * no return value
581
 */
582
void dwt_writetxfctrl(uint16_t txFrameLength, uint16_t txBufferOffset, int ranging);
583

    
584
/*! ------------------------------------------------------------------------------------------------------------------
585
 * @fn dwt_starttx()
586
 *
587
 * @brief This call initiates the transmission, input parameter indicates which TX mode is used see below
588
 *
589
 * input parameters:
590
 * @param mode - is a bitmask for which the following values can be combined to define the operation
591
 *               DWT_START_TX_IMMEDIATE (0)            - to begin transmission immediatelty.
592
 *               DWT_START_TX_DELAYED   (to set bit 0) - to begin TX at pre-configured delay time
593
 *               DWT_RESPONSE_EXPECTED  (to set bit 1) - to turn the receiver on automatically (after the TX) after a pre-programmed delay
594
 * output parameters
595
 *
596
 * returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed transmission will fail if the delayed time has passed)
597
 */
598
int dwt_starttx(uint8_t mode) ;
599

    
600
/*! ------------------------------------------------------------------------------------------------------------------
601
 * @fn dwt_setdelayedtrxtime()
602
 *
603
 * @brief This API function configures the delayed transmit time or the delayed RX on time
604
 *
605
 * input parameters
606
 * @param starttime - the TX/RX start time (the 32 bits should be the high 32 bits of the system time at which to send the message,
607
 * or at which to turn on the receiver)
608
 *
609
 * output parameters none
610
 *
611
 * no return value
612
 */
613
void dwt_setdelayedtrxtime(uint32_t starttime) ;
614

    
615
/*! ------------------------------------------------------------------------------------------------------------------
616
 * @fn dwt_readtxtimestamp()
617
 *
618
 * @brief This is used to read the TX timestamp (adjusted with the programmed antenna delay)
619
 *
620
 * input parameters
621
 * @param timestamp - a pointer to a 5-byte buffer which will store the read TX timestamp time
622
 *
623
 * output parameters - the timestamp buffer will contain the value after the function call
624
 *
625
 * no return value
626
 */
627
void dwt_readtxtimestamp(uint8_t * timestamp);
628

    
629
/*! ------------------------------------------------------------------------------------------------------------------
630
 * @fn dwt_readtxtimestamphi32()
631
 *
632
 * @brief This is used to read the high 32-bits of the TX timestamp (adjusted with the programmed antenna delay)
633
 *
634
 * input parameters
635
 *
636
 * output parameters
637
 *
638
 * returns high 32-bits of TX timestamp
639
 */
640
uint32_t dwt_readtxtimestamphi32(void);
641

    
642
/*! ------------------------------------------------------------------------------------------------------------------
643
 * @fn dwt_readtxtimestamplo32()
644
 *
645
 * @brief This is used to read the low 32-bits of the TX timestamp (adjusted with the programmed antenna delay)
646
 *
647
 * input parameters
648
 *
649
 * output parameters
650
 *
651
 * returns low 32-bits of TX timestamp
652
 */
653
uint32_t dwt_readtxtimestamplo32(void);
654

    
655
/*! ------------------------------------------------------------------------------------------------------------------
656
 * @fn dwt_readrxtimestamp()
657
 *
658
 * @brief This is used to read the RX timestamp (adjusted time of arrival)
659
 *
660
 * input parameters
661
 * @param timestamp - a pointer to a 5-byte buffer which will store the read RX timestamp time
662
 *
663
 * output parameters - the timestamp buffer will contain the value after the function call
664
 *
665
 * no return value
666
 */
667
void dwt_readrxtimestamp(uint8_t * timestamp);
668

    
669
/*! ------------------------------------------------------------------------------------------------------------------
670
 * @fn dwt_readrxtimestamphi32()
671
 *
672
 * @brief This is used to read the high 32-bits of the RX timestamp (adjusted with the programmed antenna delay)
673
 *
674
 * input parameters
675
 *
676
 * output parameters
677
 *
678
 * returns high 32-bits of RX timestamp
679
 */
680
uint32_t dwt_readrxtimestamphi32(void);
681

    
682
/*! ------------------------------------------------------------------------------------------------------------------
683
 * @fn dwt_readrxtimestamplo32()
684
 *
685
 * @brief This is used to read the low 32-bits of the RX timestamp (adjusted with the programmed antenna delay)
686
 *
687
 * input parameters
688
 *
689
 * output parameters
690
 *
691
 * returns low 32-bits of RX timestamp
692
 */
693
uint32_t dwt_readrxtimestamplo32(void);
694

    
695
/*! ------------------------------------------------------------------------------------------------------------------
696
 * @fn dwt_readsystimestamphi32()
697
 *
698
 * @brief This is used to read the high 32-bits of the system time
699
 *
700
 * input parameters
701
 *
702
 * output parameters
703
 *
704
 * returns high 32-bits of system time timestamp
705
 */
706
uint32_t dwt_readsystimestamphi32(void);
707

    
708
/*! ------------------------------------------------------------------------------------------------------------------
709
 * @fn dwt_readsystime()
710
 *
711
 * @brief This is used to read the system time
712
 *
713
 * input parameters
714
 * @param timestamp - a pointer to a 5-byte buffer which will store the read system time
715
 *
716
 * output parameters
717
 * @param timestamp - the timestamp buffer will contain the value after the function call
718
 *
719
 * no return value
720
 */
721
void dwt_readsystime(uint8_t * timestamp);
722

    
723
/*! ------------------------------------------------------------------------------------------------------------------
724
 * @fn dwt_forcetrxoff()
725
 *
726
 * @brief This is used to turn off the transceiver
727
 *
728
 * input parameters
729
 *
730
 * output parameters
731
 *
732
 * no return value
733
 */
734
void dwt_forcetrxoff(void);
735

    
736
/*! ------------------------------------------------------------------------------------------------------------------
737
 * @fn dwt_syncrxbufptrs()
738
 *
739
 * @brief this function synchronizes rx buffer pointers
740
 * need to make sure that the host/IC buffer pointers are aligned before starting RX
741
 *
742
 * input parameters:
743
 *
744
 * output parameters
745
 *
746
 * no return value
747
 */
748
void dwt_syncrxbufptrs(void);
749

    
750
/*! ------------------------------------------------------------------------------------------------------------------
751
 * @fn dwt_rxenable()
752
 *
753
 * @brief This call turns on the receiver, can be immediate or delayed (depending on the mode parameter). In the case of a
754
 * "late" error the receiver will only be turned on if the DWT_IDLE_ON_DLY_ERR is not set.
755
 * The receiver will stay turned on, listening to any messages until
756
 * it either receives a good frame, an error (CRC, PHY header, Reed Solomon) or  it times out (SFD, Preamble or Frame).
757
 *
758
 * input parameters
759
 * @param mode - this can be one of the following allowed values:
760
 *
761
 * DWT_START_RX_IMMEDIATE      0 used to enbale receiver immediately
762
 * DWT_START_RX_DELAYED        1 used to set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
763
 * (DWT_START_RX_DELAYED | DWT_IDLE_ON_DLY_ERR) 3 used to disable re-enabling of receiver if delayed RX failed due to "late" error
764
 * (DWT_START_RX_IMMEDIATE | DWT_NO_SYNC_PTRS) 4 used to re-enable RX without trying to sync IC and host side buffer pointers, typically when
765
 *                                               performing manual RX re-enabling in double buffering mode
766
 *
767
 * returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed receive enable will be too far in the future if delayed time has passed)
768
 */
769
int dwt_rxenable(int mode);
770

    
771
/*! ------------------------------------------------------------------------------------------------------------------
772
 * @fn dwt_setsniffmode()
773
 *
774
 * @brief enable/disable and configure SNIFF mode.
775
 *
776
 * SNIFF mode is a low-power reception mode where the receiver is sequenced on and off instead of being on all the time.
777
 * The time spent in each state (on/off) is specified through the parameters below.
778
 * See DW1000 User Manual section 4.5 "Low-Power SNIFF mode" for more details.
779
 *
780
 * input parameters:
781
 * @param enable - 1 to enable SNIFF mode, 0 to disable. When 0, all other parameters are not taken into account.
782
 * @param timeOn - duration of receiver ON phase, expressed in multiples of PAC size. The counter automatically adds 1 PAC
783
 *                 size to the value set. Min value that can be set is 1 (i.e. an ON time of 2 PAC size), max value is 15.
784
 * @param timeOff - duration of receiver OFF phase, expressed in multiples of 128/125 µs (~1 µs). Max value is 255.
785
 *
786
 * output parameters
787
 *
788
 * no return value
789
 */
790
void dwt_setsniffmode(int enable, uint8_t timeOn, uint8_t timeOff);
791

    
792
/*! ------------------------------------------------------------------------------------------------------------------
793
 * @fn dwt_setlowpowerlistening()
794
 *
795
 * @brief enable/disable low-power listening mode.
796
 *
797
 * Low-power listening is a feature whereby the DW1000 is predominantly in the SLEEP state but wakes periodically, (after
798
 * this "long sleep"), for a very short time to sample the air for a preamble sequence. This preamble sampling "listening"
799
 * phase is actually two reception phases separated by a "short sleep" time. See DW1000 User Manual section "Low-Power
800
 * Listening" for more details.
801
 *
802
 * NOTE: Before enabling low-power listening, the following functions have to be called to fully configure it:
803
 *           - dwt_configuresleep() to configure long sleep phase. "mode" parameter should at least have DWT_PRESRV_SLEEP,
804
 *             DWT_CONFIG and DWT_RX_EN set and "wake" parameter should at least have both DWT_WAKE_SLPCNT and DWT_SLP_EN set.
805
 *           - dwt_calibratesleepcnt() and dwt_configuresleepcnt() to define the "long sleep" phase duration.
806
 *           - dwt_setsnoozetime() to define the "short sleep" phase duration.
807
 *           - dwt_setpreambledetecttimeout() to define the reception phases duration.
808
 *           - dwt_setinterrupt() to activate RX good frame interrupt (DWT_INT_RFCG) only.
809
 *       When configured, low-power listening mode can be triggered either by putting the DW1000 to sleep (using
810
 *       dwt_entersleep()) or by activating reception (using dwt_rxenable()).
811
 *
812
 *       Please refer to the low-power listening examples (examples 8a/8b accompanying the API distribution on Decawave's
813
 *       website). They form a working example code that shows how to use low-power listening correctly.
814
 *
815
 * input parameters:
816
 * @param enable - 1 to enable low-power listening, 0 to disable.
817
 *
818
 * output parameters
819
 *
820
 * no return value
821
 */
822
void dwt_setlowpowerlistening(int enable);
823

    
824
/*! ------------------------------------------------------------------------------------------------------------------
825
 * @fn dwt_setsnoozetime()
826
 *
827
 * @brief Set duration of "short sleep" phase when in low-power listening mode.
828
 *
829
 * input parameters:
830
 * @param snooze_time - "short sleep" phase duration, expressed in multiples of 512/19.2 µs (~26.7 µs). The counter
831
 *                      automatically adds 1 to the value set. The smallest working value that should be set is 1,
832
 *                      i.e. giving a snooze time of 2 units (or ~53 µs).
833
 *
834
 * output parameters
835
 *
836
 * no return value
837
 */
838
void dwt_setsnoozetime(uint8_t snooze_time);
839

    
840
/*! ------------------------------------------------------------------------------------------------------------------
841
 * @fn dwt_setdblrxbuffmode()
842
 *
843
 * @brief This call enables the double receive buffer mode
844
 *
845
 * input parameters
846
 * @param enable - 1 to enable, 0 to disable the double buffer mode
847
 *
848
 * output parameters
849
 *
850
 * no return value
851
 */
852
void dwt_setdblrxbuffmode(int enable);
853

    
854
/*! ------------------------------------------------------------------------------------------------------------------
855
 * @fn dwt_setrxtimeout()
856
 *
857
 * @brief This call enables RX timeout (SY_STAT_RFTO event)
858
 *
859
 * input parameters
860
 * @param time - how long the receiver remains on from the RX enable command
861
 *               The time parameter used here is in 1.0256 us (512/499.2MHz) units
862
 *               If set to 0 the timeout is disabled.
863
 *
864
 * output parameters
865
 *
866
 * no return value
867
 */
868
void dwt_setrxtimeout(uint16_t time);
869

    
870
/*! ------------------------------------------------------------------------------------------------------------------
871
 * @fn dwt_setpreambledetecttimeout()
872
 *
873
 * @brief This call enables preamble timeout (SY_STAT_RXPTO event)
874
 *
875
 * input parameters
876
 * @param  timeout - Preamble detection timeout, expressed in multiples of PAC size. The counter automatically adds 1 PAC
877
 *                   size to the value set. Min value that can be set is 1 (i.e. a timeout of 2 PAC size).
878
 *
879
 * output parameters
880
 *
881
 * no return value
882
 */
883
void dwt_setpreambledetecttimeout(uint16_t timeout);
884

    
885

    
886
/*! ------------------------------------------------------------------------------------------------------------------
887
 * @fn dwt_calibratesleepcnt()
888
 *
889
 * @brief calibrates the local oscillator as its frequency can vary between 7 and 13kHz depending on temp and voltage
890
 *
891
 * NOTE: this function needs to be run before dwt_configuresleepcnt, so that we know what the counter units are
892
 *
893
 * input parameters
894
 *
895
 * output parameters
896
 *
897
 * returns the number of XTAL/2 cycles per low-power oscillator cycle. LP OSC frequency = 19.2 MHz/return value
898
 */
899
uint16_t dwt_calibratesleepcnt(void);
900

    
901
/*! ------------------------------------------------------------------------------------------------------------------
902
 * @fn dwt_configuresleepcnt()
903
 *
904
 * @brief sets the sleep counter to new value, this function programs the high 16-bits of the 28-bit counter
905
 *
906
 * NOTE: this function needs to be run before dwt_configuresleep, also the SPI frequency has to be < 3MHz
907
 *
908
 * input parameters
909
 * @param sleepcnt - this it value of the sleep counter to program
910
 *
911
 * output parameters
912
 *
913
 * no return value
914
 */
915
 void dwt_configuresleepcnt(uint16_t sleepcnt);
916

    
917
 /*! ------------------------------------------------------------------------------------------------------------------
918
  * @fn dwt_configuresleep()
919
  *
920
  * @brief configures the device for both DEEP_SLEEP and SLEEP modes, and on-wake mode
921
  * i.e. before entering the sleep, the device should be programmed for TX or RX, then upon "waking up" the TX/RX settings
922
  * will be preserved and the device can immediately perform the desired action TX/RX
923
  *
924
  * NOTE: e.g. Tag operation - after deep sleep, the device needs to just load the TX buffer and send the frame
925
  *
926
  *
927
  *      mode: the array and LDE code (OTP/ROM) and LDO tune, and set sleep persist
928
  *      DWT_PRESRV_SLEEP 0x0100 - preserve sleep
929
  *      DWT_LOADOPSET    0x0080 - load operating parameter set on wakeup
930
  *      DWT_CONFIG       0x0040 - download the AON array into the HIF (configuration download)
931
  *      DWT_LOADEUI      0x0008
932
  *      DWT_GOTORX       0x0002
933
  *      DWT_TANDV        0x0001
934
  *
935
  *      wake: wake up parameters
936
  *      DWT_XTAL_EN      0x10 - keep XTAL running during sleep
937
  *      DWT_WAKE_SLPCNT  0x8 - wake up after sleep count
938
  *      DWT_WAKE_CS      0x4 - wake up on chip select
939
  *      DWT_WAKE_WK      0x2 - wake up on WAKEUP PIN
940
  *      DWT_SLP_EN       0x1 - enable sleep/deep sleep functionality
941
  *
942
  * input parameters
943
  * @param mode - config on-wake parameters
944
  * @param wake - config wake up parameters
945
  *
946
  * output parameters
947
  *
948
  * no return value
949
  */
950
void dwt_configuresleep(uint16_t mode, uint8_t wake);
951

    
952
/*! ------------------------------------------------------------------------------------------------------------------
953
 * @fn dwt_entersleep()
954
 *
955
 * @brief This function puts the device into deep sleep or sleep. dwt_configuresleep() should be called first
956
 * to configure the sleep and on-wake/wake-up parameters
957
 *
958
 * input parameters
959
 *
960
 * output parameters
961
 *
962
 * no return value
963
 */
964
void dwt_entersleep(void);
965

    
966
/*! ------------------------------------------------------------------------------------------------------------------
967
 * @fn dwt_entersleepaftertx(int enable)
968
 *
969
 * @brief sets the auto TX to sleep bit. This means that after a frame
970
 * transmission the device will enter deep sleep mode. The dwt_configuresleep() function
971
 * needs to be called before this to configure the on-wake settings
972
 *
973
 * NOTE: the IRQ line has to be low/inactive (i.e. no pending events)
974
 *
975
 * input parameters
976
 * @param enable - 1 to configure the device to enter deep sleep after TX, 0 - disables the configuration
977
 *
978
 * output parameters
979
 *
980
 * no return value
981
 */
982
void dwt_entersleepaftertx(int enable);
983

    
984
/*! ------------------------------------------------------------------------------------------------------------------
985
 * @fn dwt_spicswakeup()
986
 *
987
 * @brief wake up the device from sleep mode using the SPI read,
988
 * the device will wake up on chip select line going low if the line is held low for at least 500us.
989
 * To define the length depending on the time one wants to hold
990
 * the chip select line low, use the following formula:
991
 *
992
 *      length (bytes) = time (s) * byte_rate (Hz)
993
 *
994
 * where fastest byte_rate is spi_rate (Hz) / 8 if the SPI is sending the bytes back-to-back.
995
 * To save time and power, a system designer could determine byte_rate value more precisely.
996
 *
997
 * NOTE: Alternatively the device can be waken up with WAKE_UP pin if configured for that operation
998
 *
999
 * input parameters
1000
 * @param buff   - this is a pointer to the dummy buffer which will be used in the SPI read transaction used for the WAKE UP of the device
1001
 * @param length - this is the length of the dummy buffer
1002
 *
1003
 * output parameters
1004
 *
1005
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
1006
 */
1007
int dwt_spicswakeup(uint8_t *buff, uint16_t length);
1008

    
1009
/*! ------------------------------------------------------------------------------------------------------------------
1010
 * @fn dwt_setcallbacks()
1011
 *
1012
 * @brief This function is used to register the different callbacks called when one of the corresponding event occurs.
1013
 *
1014
 * NOTE: Callbacks can be undefined (set to NULL). In this case, dwt_isr() will process the event as usual but the 'null'
1015
 * callback will not be called.
1016
 *
1017
 * input parameters
1018
 * @param cbTxDone - the pointer to the TX confirmation event callback function
1019
 * @param cbRxOk - the pointer to the RX good frame event callback function
1020
 * @param cbRxTo - the pointer to the RX timeout events callback function
1021
 * @param cbRxErr - the pointer to the RX error events callback function
1022
 *
1023
 * output parameters
1024
 *
1025
 * no return value
1026
 */
1027
void dwt_setcallbacks(dwt_cb_t cbTxDone, dwt_cb_t cbRxOk, dwt_cb_t cbRxTo, dwt_cb_t cbRxErr);
1028

    
1029
/*! ------------------------------------------------------------------------------------------------------------------
1030
 * @fn dwt_checkirq()
1031
 *
1032
 * @brief This function checks if the IRQ line is active - this is used instead of interrupt handler
1033
 *
1034
 * input parameters
1035
 *
1036
 * output parameters
1037
 *
1038
 * return value is 1 if the IRQS bit is set and 0 otherwise
1039
 */
1040
uint8_t dwt_checkirq(void);
1041

    
1042
/*! ------------------------------------------------------------------------------------------------------------------
1043
 * @fn dwt_isr()
1044
 *
1045
 * @brief This is the DW1000's general Interrupt Service Routine. It will process/report the following events:
1046
 *          - RXFCG (through cbRxOk callback)
1047
 *          - TXFRS (through cbTxDone callback)
1048
 *          - RXRFTO/RXPTO (through cbRxTo callback)
1049
 *          - RXPHE/RXFCE/RXRFSL/RXSFDTO/AFFREJ/LDEERR (through cbRxTo cbRxErr)
1050
 *        For all events, corresponding interrupts are cleared and necessary resets are performed. In addition, in the RXFCG case,
1051
 *        received frame information and frame control are read before calling the callback. If double buffering is activated, it
1052
 *        will also toggle between reception buffers once the reception callback processing has ended.
1053
 *
1054
 *        /!\ This version of the ISR supports double buffering but does not support automatic RX re-enabling!
1055
 *
1056
 * NOTE:  In PC based system using (Cheetah or ARM) USB to SPI converter there can be no interrupts, however we still need something
1057
 *        to take the place of it and operate in a polled way. In an embedded system this function should be configured to be triggered
1058
 *        on any of the interrupts described above.
1059

1060
 * input parameters
1061
 *
1062
 * output parameters
1063
 *
1064
 * no return value
1065
 */
1066
void dwt_isr(void);
1067

    
1068
/*! ------------------------------------------------------------------------------------------------------------------
1069
 * @fn dwt_isr_lplisten()
1070
 *
1071
 * @brief This is the DW1000's Interrupt Service Routine to use when low-power listening scheme is implemented. It will
1072
 *        only process/report the RXFCG event (through cbRxOk callback).
1073
 *        It clears RXFCG interrupt and reads received frame information and frame control before calling the callback.
1074
 *
1075
 *        /!\ This version of the ISR is designed for single buffering case only!
1076
 *
1077
 * input parameters
1078
 *
1079
 * output parameters
1080
 *
1081
 * no return value
1082
 */
1083
void dwt_lowpowerlistenisr(void);
1084

    
1085
/*! ------------------------------------------------------------------------------------------------------------------
1086
 * @fn void dwt_setinterrupt()
1087
 *
1088
 * @brief This function enables the specified events to trigger an interrupt.
1089
 * The following events can be enabled:
1090
 * DWT_INT_TFRS         0x00000080          // frame sent
1091
 * DWT_INT_RFCG         0x00004000          // frame received with good CRC
1092
 * DWT_INT_RPHE         0x00001000          // receiver PHY header error
1093
 * DWT_INT_RFCE         0x00008000          // receiver CRC error
1094
 * DWT_INT_RFSL         0x00010000          // receiver sync loss error
1095
 * DWT_INT_RFTO         0x00020000          // frame wait timeout
1096
 * DWT_INT_RXPTO        0x00200000          // preamble detect timeout
1097
 * DWT_INT_SFDT         0x04000000          // SFD timeout
1098
 * DWT_INT_ARFE         0x20000000          // frame rejected (due to frame filtering configuration)
1099
 *
1100
 *
1101
 * input parameters:
1102
 * @param bitmask - sets the events which will generate interrupt
1103
 * @param enable - if set the interrupts are enabled else they are cleared
1104
 *
1105
 * output parameters
1106
 *
1107
 * no return value
1108
 */
1109
void dwt_setinterrupt( uint32_t bitmask, uint8_t enable);
1110

    
1111
/*! ------------------------------------------------------------------------------------------------------------------
1112
 * @fn dwt_setpanid()
1113
 *
1114
 * @brief This is used to set the PAN ID
1115
 *
1116
 * input parameters
1117
 * @param panID - this is the PAN ID
1118
 *
1119
 * output parameters
1120
 *
1121
 * no return value
1122
 */
1123
void dwt_setpanid(uint16_t panID);
1124

    
1125
/*! ------------------------------------------------------------------------------------------------------------------
1126
 * @fn dwt_setaddress16()
1127
 *
1128
 * @brief This is used to set 16-bit (short) address
1129
 *
1130
 * input parameters
1131
 * @param shortAddress - this sets the 16 bit short address
1132
 *
1133
 * output parameters
1134
 *
1135
 * no return value
1136
 */
1137
void dwt_setaddress16(uint16_t shortAddress);
1138

    
1139
/*! ------------------------------------------------------------------------------------------------------------------
1140
 * @fn dwt_seteui()
1141
 *
1142
 * @brief This is used to set the EUI 64-bit (long) address
1143
 *
1144
 * input parameters
1145
 * @param eui64 - this is the pointer to a buffer that contains the 64bit address
1146
 *
1147
 * output parameters
1148
 *
1149
 * no return value
1150
 */
1151
void dwt_seteui(uint8_t *eui64);
1152

    
1153
/*! ------------------------------------------------------------------------------------------------------------------
1154
 * @fn dwt_geteui()
1155
 *
1156
 * @brief This is used to get the EUI 64-bit from the DW1000
1157
 *
1158
 * input parameters
1159
 * @param eui64 - this is the pointer to a buffer that will contain the read 64-bit EUI value
1160
 *
1161
 * output parameters
1162
 *
1163
 * no return value
1164
 */
1165
void dwt_geteui(uint8_t *eui64);
1166

    
1167
/*! ------------------------------------------------------------------------------------------------------------------
1168
 * @fn dwt_otpread()
1169
 *
1170
 * @brief This is used to read the OTP data from given address into provided array
1171
 *
1172
 * input parameters
1173
 * @param address - this is the OTP address to read from
1174
 * @param array - this is the pointer to the array into which to read the data
1175
 * @param length - this is the number of 32 bit words to read (array needs to be at least this length)
1176
 *
1177
 * output parameters
1178
 *
1179
 * no return value
1180
 */
1181
void dwt_otpread(uint32_t address, uint32_t *array, uint8_t length);
1182

    
1183
/*! ------------------------------------------------------------------------------------------------------------------
1184
 * @fn dwt_enableframefilter()
1185
 *
1186
 * @brief This is used to enable the frame filtering - (the default option is to
1187
 * accept any data and ACK frames with correct destination address
1188
 *
1189
 * input parameters
1190
 * @param - bitmask - enables/disables the frame filtering options according to
1191
 *      DWT_FF_NOTYPE_EN        0x000   no frame types allowed
1192
 *      DWT_FF_COORD_EN         0x002   behave as coordinator (can receive frames with no destination address (PAN ID has to match))
1193
 *      DWT_FF_BEACON_EN        0x004   beacon frames allowed
1194
 *      DWT_FF_DATA_EN          0x008   data frames allowed
1195
 *      DWT_FF_ACK_EN           0x010   ack frames allowed
1196
 *      DWT_FF_MAC_EN           0x020   mac control frames allowed
1197
 *      DWT_FF_RSVD_EN          0x040   reserved frame types allowed
1198
 *
1199
 * output parameters
1200
 *
1201
 * no return value
1202
 */
1203
void dwt_enableframefilter(uint16_t bitmask);
1204

    
1205
/*! ------------------------------------------------------------------------------------------------------------------
1206
 * @fn dwt_enableautoack()
1207
 *
1208
 * @brief This call enables the auto-ACK feature. If the responseDelayTime (parameter) is 0, the ACK will be sent a.s.a.p.
1209
 * otherwise it will be sent with a programmed delay (in symbols), max is 255.
1210
 * NOTE: needs to have frame filtering enabled as well
1211
 *
1212
 * input parameters
1213
 * @param responseDelayTime - if non-zero the ACK is sent after this delay, max is 255.
1214
 *
1215
 * output parameters
1216
 *
1217
 * no return value
1218
 */
1219
void dwt_enableautoack(uint8_t responseDelayTime);
1220

    
1221
/*! ------------------------------------------------------------------------------------------------------------------
1222
 * @fn dwt_setrxaftertxdelay()
1223
 *
1224
 * @brief This sets the receiver turn on delay time after a transmission of a frame
1225
 *
1226
 * input parameters
1227
 * @param rxDelayTime - (20 bits) - the delay is in UWB microseconds
1228
 *
1229
 * output parameters
1230
 *
1231
 * no return value
1232
 */
1233
void dwt_setrxaftertxdelay(uint32_t rxDelayTime);
1234

    
1235
/*! ------------------------------------------------------------------------------------------------------------------
1236
 * @fn dwt_rxreset()
1237
 *
1238
 * @brief this function resets the receiver of the DW1000
1239
 *
1240
 * input parameters:
1241
 *
1242
 * output parameters
1243
 *
1244
 * no return value
1245
 */
1246
void dwt_rxreset(void);
1247

    
1248
/*! ------------------------------------------------------------------------------------------------------------------
1249
 * @fn dwt_softreset()
1250
 *
1251
 * @brief this function resets the DW1000
1252
 *
1253
 * input parameters:
1254
 *
1255
 * output parameters
1256
 *
1257
 * no return value
1258
 */
1259
void dwt_softreset(void) ;
1260

    
1261
/*! ------------------------------------------------------------------------------------------------------------------
1262
 * @fn dwt_readrxdata()
1263
 *
1264
 * @brief This is used to read the data from the RX buffer, from an offset location give by offset parameter
1265
 *
1266
 * input parameters
1267
 * @param buffer - the buffer into which the data will be read
1268
 * @param length - the length of data to read (in bytes)
1269
 * @param rxBufferOffset - the offset in the rx buffer from which to read the data
1270
 *
1271
 * output parameters
1272
 *
1273
 * no return value
1274
 */
1275
void dwt_readrxdata(uint8_t *buffer, uint16_t length, uint16_t rxBufferOffset);
1276

    
1277
/*! ------------------------------------------------------------------------------------------------------------------
1278
 * @fn dwt_readaccdata()
1279
 *
1280
 * @brief This is used to read the data from the Accumulator buffer, from an offset location give by offset parameter
1281
 *
1282
 * NOTE: Because of an internal memory access delay when reading the accumulator the first octet output is a dummy octet
1283
 *       that should be discarded. This is true no matter what sub-index the read begins at.
1284
 *
1285
 * input parameters
1286
 * @param buffer - the buffer into which the data will be read
1287
 * @param length - the length of data to read (in bytes)
1288
 * @param accOffset - the offset in the acc buffer from which to read the data
1289
 *
1290
 * output parameters
1291
 *
1292
 * no return value
1293
 */
1294
void dwt_readaccdata(uint8_t *buffer, uint16_t length, uint16_t rxBufferOffset);
1295

    
1296
/*! ------------------------------------------------------------------------------------------------------------------
1297
 * @fn dwt_readdiagnostics()
1298
 *
1299
 * @brief this function reads the RX signal quality diagnostic data
1300
 *
1301
 * input parameters
1302
 * @param diagnostics - diagnostic structure pointer, this will contain the diagnostic data read from the DW1000
1303
 *
1304
 * output parameters
1305
 *
1306
 * no return value
1307
 */
1308
void dwt_readdiagnostics(dwt_rxdiag_t * diagnostics);
1309

    
1310
/*! ------------------------------------------------------------------------------------------------------------------
1311
 * @fn dwt_loadopsettabfromotp()
1312
 *
1313
 * @brief This is used to select which Operational Parameter Set table to load from OTP memory
1314
 *
1315
 * input parameters
1316
 * @param ops_sel - Operational Parameter Set table to load:
1317
 *                  DWT_OPSET_64LEN = 0x0 - load the operational parameter set table for 64 length preamble configuration
1318
 *                  DWT_OPSET_TIGHT = 0x1 - load the operational parameter set table for tight xtal offsets (<1ppm)
1319
 *                  DWT_OPSET_DEFLT = 0x2 - load the default operational parameter set table (this is loaded from reset)
1320
 *
1321
 * output parameters
1322
 *
1323
 * no return value
1324
 */
1325
void dwt_loadopsettabfromotp(uint8_t ops_sel);
1326

    
1327
/*! ------------------------------------------------------------------------------------------------------------------
1328
 * @fn dwt_configeventcounters()
1329
 *
1330
 * @brief This is used to enable/disable the event counter in the IC
1331
 *
1332
 * input parameters
1333
 * @param - enable - 1 enables (and reset), 0 disables the event counters
1334
 * output parameters
1335
 *
1336
 * no return value
1337
 */
1338
void dwt_configeventcounters(int enable);
1339

    
1340
/*! ------------------------------------------------------------------------------------------------------------------
1341
 * @fn dwt_readeventcounters()
1342
 *
1343
 * @brief This is used to read the event counters in the IC
1344
 *
1345
 * input parameters
1346
 * @param counters - pointer to the dwt_deviceentcnts_t structure which will hold the read data
1347
 *
1348
 * output parameters
1349
 *
1350
 * no return value
1351
 */
1352
void dwt_readeventcounters(dwt_deviceentcnts_t *counters);
1353

    
1354
/*! ------------------------------------------------------------------------------------------------------------------
1355
 * @fn dwt_otpwriteandverify()
1356
 *
1357
 * @brief This is used to program 32-bit value into the DW1000 OTP memory.
1358
 *
1359
 * input parameters
1360
 * @param value - this is the 32-bit value to be programmed into OTP
1361
 * @param address - this is the 16-bit OTP address into which the 32-bit value is programmed
1362
 *
1363
 * output parameters
1364
 *
1365
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
1366
 */
1367
int dwt_otpwriteandverify(uint32_t value, uint16_t address);
1368

    
1369
/*! ------------------------------------------------------------------------------------------------------------------
1370
 * @fn dwt_setleds()
1371
 *
1372
 * @brief This is used to set up Tx/Rx GPIOs which could be used to control LEDs
1373
 * Note: not completely IC dependent, also needs board with LEDS fitted on right I/O lines
1374
 *       this function enables GPIOs 2 and 3 which are connected to LED3 and LED4 on EVB1000
1375
 *
1376
 * input parameters
1377
 * @param mode - this is a bit field interpreted as follows:
1378
 *          - bit 0: 1 to enable LEDs, 0 to disable them
1379
 *          - bit 1: 1 to make LEDs blink once on init. Only valid if bit 0 is set (enable LEDs)
1380
 *          - bit 2 to 7: reserved
1381
 *
1382
 * output parameters none
1383
 *
1384
 * no return value
1385
 */
1386
void dwt_setleds(uint8_t mode);
1387

    
1388
/*! ------------------------------------------------------------------------------------------------------------------
1389
 * @fn dwt_setxtaltrim()
1390
 *
1391
 * @brief This is used to adjust the crystal frequency
1392
 *
1393
 * input parameters:
1394
 * @param   value - crystal trim value (in range 0x0 to 0x1F) 31 steps (~1.5ppm per step)
1395
 *
1396
 * output parameters
1397
 *
1398
 * no return value
1399
 */
1400
void dwt_setxtaltrim(uint8_t value);
1401

    
1402
/*! ------------------------------------------------------------------------------------------------------------------
1403
 * @fn dwt_getinitxtaltrim()
1404
 *
1405
 * @brief This function returns the value of XTAL trim that has been applied during initialisation (dwt_init). This can
1406
 *        be either the value read in OTP memory or a default value.
1407
 *
1408
 * NOTE: The value returned by this function is the initial value only! It is not updated on dwt_setxtaltrim calls.
1409
 *
1410
 * input parameters
1411
 *
1412
 * output parameters
1413
 *
1414
 * returns the XTAL trim value set upon initialisation
1415
 */
1416
uint8_t dwt_getinitxtaltrim(void);
1417

    
1418
/*! ------------------------------------------------------------------------------------------------------------------
1419
 * @fn dwt_configcwmode()
1420
 *
1421
 * @brief this function sets the DW1000 to transmit cw signal at specific channel frequency
1422
 *
1423
 * input parameters:
1424
 * @param chan - specifies the operating channel (e.g. 1, 2, 3, 4, 5, 6 or 7)
1425
 *
1426
 * output parameters
1427
 *
1428
 * no return value
1429
 */
1430
void dwt_configcwmode(uint8_t chan);
1431

    
1432
/*! ------------------------------------------------------------------------------------------------------------------
1433
 * @fn dwt_configcontinuousframemode()
1434
 *
1435
 * @brief this function sets the DW1000 to continuous tx frame mode for regulatory approvals testing.
1436
 *
1437
 * input parameters:
1438
 * @param framerepetitionrate - This is a 32-bit value that is used to set the interval between transmissions.
1439
*  The minimum value is 4. The units are approximately 8 ns. (or more precisely 512/(499.2e6*128) seconds)).
1440
 *
1441
 * output parameters
1442
 *
1443
 * no return value
1444
 */
1445
void dwt_configcontinuousframemode(uint32_t framerepetitionrate);
1446

    
1447
/*! ------------------------------------------------------------------------------------------------------------------
1448
 * @fn dwt_readtempvbat()
1449
 *
1450
 * @brief this function reads the battery voltage and temperature of the MP
1451
 * The values read here will be the current values sampled by DW1000 AtoD converters.
1452
 * Note on Temperature: the temperature value needs to be converted to give the real temperature
1453
 * the formula is: 1.13 * reading - 113.0
1454
 * Note on Voltage: the voltage value needs to be converted to give the real voltage
1455
 * the formula is: 0.0057 * reading + 2.3
1456
 *
1457
 * NB: To correctly read the temperature this read should be done with xtal clock
1458
 * however that means that the receiver will be switched off, if receiver needs to be on then
1459
 * the timer is used to make sure the value is stable before reading
1460
 *
1461
 * input parameters:
1462
 * @param fastSPI - set to 1 if SPI rate > than 3MHz is used
1463
 *
1464
 * output parameters
1465
 *
1466
 * returns  (temp_raw<<8)|(vbat_raw)
1467
 */
1468
uint16_t dwt_readtempvbat(uint8_t fastSPI);
1469

    
1470
/*! ------------------------------------------------------------------------------------------------------------------
1471
 * @fn dwt_readwakeuptemp()
1472
 *
1473
 * @brief this function reads the temperature of the DW1000 that was sampled
1474
 * on waking from Sleep/Deepsleep. They are not current values, but read on last
1475
 * wakeup if DWT_TANDV bit is set in mode parameter of dwt_configuresleep
1476
 *
1477
 * input parameters:
1478
 *
1479
 * output parameters:
1480
 *
1481
 * returns: 8-bit raw temperature sensor value
1482
 */
1483
uint8_t dwt_readwakeuptemp(void) ;
1484

    
1485
/*! ------------------------------------------------------------------------------------------------------------------
1486
 * @fn dwt_readwakeupvbat()
1487
 *
1488
 * @brief this function reads the battery voltage of the DW1000 that was sampled
1489
 * on waking from Sleep/Deepsleep. They are not current values, but read on last
1490
 * wakeup if DWT_TANDV bit is set in mode parameter of dwt_configuresleep
1491
 *
1492
 * input parameters:
1493
 *
1494
 * output parameters:
1495
 *
1496
 * returns: 8-bit raw battery voltage sensor value
1497
 */
1498
uint8_t dwt_readwakeupvbat(void) ;
1499

    
1500
/*! ------------------------------------------------------------------------------------------------------------------
1501
 * @fn dwt_calcbandwidthtempadj()
1502
 *
1503
 * @brief this function determines the corrected bandwidth setting (PG_DELAY register setting)
1504
 * of the DW1000 which changes over temperature.
1505
 *
1506
 * input parameters:
1507
 * @param target_count - uint16_t - the PG count target to reach in order to correct the bandwidth
1508
 *
1509
 * output parameters:
1510
 *
1511
 * returns: (uint32) The setting to be programmed into the PG_DELAY value
1512
 */
1513
uint32_t dwt_calcbandwidthtempadj(uint16_t target_count);
1514

    
1515
/*! ------------------------------------------------------------------------------------------------------------------
1516
 * @fn dwt_calcpowertempadj()
1517
 *
1518
 * @brief this function determines the corrected power setting (TX_POWER setting) for the
1519
 * DW1000 which changes over temperature.
1520
 *
1521
 * input parameters:
1522
 * @param channel - uint8_t - the channel at which compensation of power level will be applied
1523
 * @param ref_powerreg - uint32_t - the TX_POWER register value recorded when reference measurements were made
1524
 * @param current_temperature - double - the current ambient temperature in degrees Celcius
1525
 * @param reference_temperature - double - the temperature at which reference measurements were made
1526
 * output parameters: None
1527
 *
1528
 * returns: (uint32) The corrected TX_POWER register value
1529
 */
1530
uint32_t dwt_calcpowertempadj(uint8_t channel, uint32_t ref_powerreg, double current_temperature, double reference_temperature);
1531

    
1532
/*! ------------------------------------------------------------------------------------------------------------------
1533
 * @fn dwt_calcpgcount()
1534
 *
1535
 * @brief this function calculates the value in the pulse generator counter register (PGC_STATUS) for a given PG_DELAY
1536
 * This is used to take a reference measurement, and the value recorded as the reference is used to adjust the
1537
 * bandwidth of the device when the temperature changes.
1538
 *
1539
 * input parameters:
1540
 * @param pgdly - uint8_t - the PG_DELAY to set (to control bandwidth), and to find the corresponding count value for
1541
 * output parameters: None
1542
 *
1543
 * returns: (uint16) PGC_STATUS count value calculated from the provided PG_DELAY value - used as reference for later
1544
 * bandwidth adjustments
1545
 */
1546
uint16_t dwt_calcpgcount(uint8_t pgdly);
1547

    
1548
/*! ------------------------------------------------------------------------------------------------------------------
1549
 * @fn dwt_writetodevice()
1550
 *
1551
 * @brief  this function is used to write to the DW1000 device registers
1552
 * Notes:
1553
 *        1. Firstly we create a header (the first byte is a header byte)
1554
 *        a. check if sub index is used, if subindexing is used - set bit-6 to 1 to signify that the sub-index address follows the register index byte
1555
 *        b. set bit-7 (or with 0x80) for write operation
1556
 *        c. if extended sub address index is used (i.e. if index > 127) set bit-7 of the first sub-index byte following the first header byte
1557
 *
1558
 *        2. Write the header followed by the data bytes to the DW1000 device
1559
 *
1560
 *
1561
 * input parameters:
1562
 * @param recordNumber  - ID of register file or buffer being accessed
1563
 * @param index         - byte index into register file or buffer being accessed
1564
 * @param length        - number of bytes being written
1565
 * @param buffer        - pointer to buffer containing the 'length' bytes to be written
1566
 *
1567
 * output parameters
1568
 *
1569
 * no return value
1570
 */
1571
void dwt_writetodevice
1572
(
1573
    uint16_t      recordNumber,   // input parameter - ID of register file or buffer being accessed
1574
    uint16_t      index,          // input parameter - byte index into register file or buffer being accessed
1575
    uint32_t      length,         // input parameter - number of bytes being written
1576
    const uint8_t *buffer         // input parameter - pointer to buffer containing the 'length' bytes to be written
1577
) ;
1578

    
1579
/*! ------------------------------------------------------------------------------------------------------------------
1580
 * @fn dwt_readfromdevice()
1581
 *
1582
 * @brief  this function is used to read from the DW1000 device registers
1583
 * Notes:
1584
 *        1. Firstly we create a header (the first byte is a header byte)
1585
 *        a. check if sub index is used, if subindexing is used - set bit-6 to 1 to signify that the sub-index address follows the register index byte
1586
 *        b. set bit-7 (or with 0x80) for write operation
1587
 *        c. if extended sub address index is used (i.e. if index > 127) set bit-7 of the first sub-index byte following the first header byte
1588
 *
1589
 *        2. Write the header followed by the data bytes to the DW1000 device
1590
 *        3. Store the read data in the input buffer
1591
 *
1592
 * input parameters:
1593
 * @param recordNumber  - ID of register file or buffer being accessed
1594
 * @param index         - byte index into register file or buffer being accessed
1595
 * @param length        - number of bytes being read
1596
 * @param buffer        - pointer to buffer in which to return the read data.
1597
 *
1598
 * output parameters
1599
 *
1600
 * no return value
1601
 */
1602
void dwt_readfromdevice
1603
(
1604
    uint16_t  recordNumber,       // input parameter - ID of register file or buffer being accessed
1605
    uint16_t  index,              // input parameter - byte index into register file or buffer being accessed
1606
    uint32_t  length,             // input parameter - number of bytes being read
1607
    uint8_t   *buffer             // input parameter - pointer to buffer in which to return the read data.
1608
) ;
1609

    
1610
/*! ------------------------------------------------------------------------------------------------------------------
1611
 * @fn dwt_read32bitoffsetreg()
1612
 *
1613
 * @brief  this function is used to read 32-bit value from the DW1000 device registers
1614
 *
1615
 * input parameters:
1616
 * @param regFileID - ID of register file or buffer being accessed
1617
 * @param regOffset - the index into register file or buffer being accessed
1618
 *
1619
 * output parameters
1620
 *
1621
 * returns 32 bit register value
1622
 */
1623
uint32_t dwt_read32bitoffsetreg(int regFileID, int regOffset) ;
1624

    
1625
/*! ------------------------------------------------------------------------------------------------------------------
1626
 * @fn dwt_write32bitoffsetreg()
1627
 *
1628
 * @brief  this function is used to write 32-bit value to the DW1000 device registers
1629
 *
1630
 * input parameters:
1631
 * @param regFileID - ID of register file or buffer being accessed
1632
 * @param regOffset - the index into register file or buffer being accessed
1633
 * @param regval    - the value to write
1634
 *
1635
 * output parameters
1636
 *
1637
 * no return value
1638
 */
1639
void dwt_write32bitoffsetreg(int regFileID, int regOffset, uint32_t regval);
1640

    
1641
#define dwt_write32bitreg(x,y)  dwt_write32bitoffsetreg(x,0,y)
1642
#define dwt_read32bitreg(x)     dwt_read32bitoffsetreg(x,0)
1643

    
1644
/*! ------------------------------------------------------------------------------------------------------------------
1645
 * @fn dwt_read16bitoffsetreg()
1646
 *
1647
 * @brief  this function is used to read 16-bit value from the DW1000 device registers
1648
 *
1649
 * input parameters:
1650
 * @param regFileID - ID of register file or buffer being accessed
1651
 * @param regOffset - the index into register file or buffer being accessed
1652
 *
1653
 * output parameters
1654
 *
1655
 * returns 16 bit register value
1656
 */
1657
uint16_t dwt_read16bitoffsetreg(int regFileID, int regOffset);
1658

    
1659
/*! ------------------------------------------------------------------------------------------------------------------
1660
 * @fn dwt_write16bitoffsetreg()
1661
 *
1662
 * @brief  this function is used to write 16-bit value to the DW1000 device registers
1663
 *
1664
 * input parameters:
1665
 * @param regFileID - ID of register file or buffer being accessed
1666
 * @param regOffset - the index into register file or buffer being accessed
1667
 * @param regval    - the value to write
1668
 *
1669
 * output parameters
1670
 *
1671
 * no return value
1672
 */
1673
void dwt_write16bitoffsetreg(int regFileID, int regOffset, uint16_t regval) ;
1674

    
1675
/*! ------------------------------------------------------------------------------------------------------------------
1676
 * @fn dwt_read8bitoffsetreg()
1677
 *
1678
 * @brief  this function is used to read an 8-bit value from the DW1000 device registers
1679
 *
1680
 * input parameters:
1681
 * @param regFileID - ID of register file or buffer being accessed
1682
 * @param regOffset - the index into register file or buffer being accessed
1683
 *
1684
 * output parameters
1685
 *
1686
 * returns 8-bit register value
1687
 */
1688
uint8_t dwt_read8bitoffsetreg(int regFileID, int regOffset);
1689

    
1690
/*! ------------------------------------------------------------------------------------------------------------------
1691
 * @fn dwt_write8bitoffsetreg()
1692
 *
1693
 * @brief  this function is used to write an 8-bit value to the DW1000 device registers
1694
 *
1695
 * input parameters:
1696
 * @param regFileID - ID of register file or buffer being accessed
1697
 * @param regOffset - the index into register file or buffer being accessed
1698
 * @param regval    - the value to write
1699
 *
1700
 * output parameters
1701
 *
1702
 * no return value
1703
 */
1704
void dwt_write8bitoffsetreg(int regFileID, int regOffset, uint8_t regval);
1705

    
1706

    
1707
/****************************************************************************************************************************************************
1708
 *
1709
 * Declaration of platform-dependent lower level functions.
1710
 *
1711
 ****************************************************************************************************************************************************/
1712

    
1713

    
1714
/*! ------------------------------------------------------------------------------------------------------------------
1715
 * @fn writetospi()
1716
 *
1717
 * @brief
1718
 * NB: In porting this to a particular microprocessor, the implementer needs to define the two low
1719
 * level abstract functions to write to and read from the SPI.
1720
 * Low level abstract function to write to the SPI
1721
 * Takes two separate byte buffers for write header and write data
1722
 * returns 0 for success, or -1 for error
1723
 *
1724
 * Note: The body of this function is platform specific
1725
 *
1726
 * input parameters:
1727
 * @param headerLength  - number of bytes header being written
1728
 * @param headerBuffer  - pointer to buffer containing the 'headerLength' bytes of header to be written
1729
 * @param bodylength    - number of bytes data being written
1730
 * @param bodyBuffer    - pointer to buffer containing the 'bodylength' bytes od data to be written
1731
 *
1732
 * output parameters
1733
 *
1734
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
1735
 */
1736
extern int writetospi(uint16_t headerLength, const uint8_t *headerBuffer, uint32_t bodylength, const uint8_t *bodyBuffer);
1737

    
1738
/*! ------------------------------------------------------------------------------------------------------------------
1739
 * @fn readfromspi()
1740
 *
1741
 * @brief
1742
 * NB: In porting this to a particular microprocessor, the implementer needs to define the two low
1743
 * level abstract functions to write to and read from the SPI.
1744
 * Low level abstract function to write to the SPI
1745
 * Takes two separate byte buffers for write header and write data
1746
 * returns 0 for success, or -1 for error
1747
 *
1748
 * Note: The body of this function is platform specific
1749
 *
1750
 * input parameters:
1751
 * @param headerLength  - number of bytes header to write
1752
 * @param headerBuffer  - pointer to buffer containing the 'headerLength' bytes of header to write
1753
 * @param readlength    - number of bytes data being read
1754
 * @param readBuffer    - pointer to buffer containing to return the data (NB: size required = headerLength + readlength)
1755
 *
1756
 * output parameters
1757
 *
1758
 * returns DWT_SUCCESS for success (and the position in the buffer at which data begins), or DWT_ERROR for error
1759
 */
1760
extern int readfromspi(uint16_t headerLength, const uint8_t *headerBuffer, uint32_t readlength, uint8_t *readBuffer);
1761

    
1762
// ---------------------------------------------------------------------------
1763
//
1764
// NB: The purpose of the deca_mutex.c file is to provide for microprocessor interrupt enable/disable, this is used for
1765
//     controlling mutual exclusion from critical sections in the code where interrupts and background
1766
//     processing may interact.  The code using this is kept to a minimum and the disabling time is also
1767
//     kept to a minimum, so blanket interrupt disable may be the easiest way to provide this.  But at a
1768
//     minimum those interrupts coming from the decawave device should be disabled/re-enabled by this activity.
1769
//
1770
//     In porting this to a particular microprocessor, the implementer may choose to use #defines here
1771
//     to map these calls transparently to the target system.  Alternatively the appropriate code may
1772
//     be embedded in the functions provided in the deca_irq.c file.
1773
//
1774
// ---------------------------------------------------------------------------
1775

    
1776
typedef int decaIrqStatus_t ; // Type for remembering IRQ status
1777

    
1778

    
1779
/*! ------------------------------------------------------------------------------------------------------------------
1780
 * @fn decamutexon()
1781
 *
1782
 * @brief This function should disable interrupts. This is called at the start of a critical section
1783
 * It returns the IRQ state before disable, this value is used to re-enable in decamutexoff call
1784
 *
1785
 * Note: The body of this function is platform specific
1786
 *
1787
 * input parameters:
1788
 *
1789
 * output parameters
1790
 *
1791
 * returns the state of the DW1000 interrupt
1792
 */
1793
decaIrqStatus_t decamutexon(void) ;
1794

    
1795
/*! ------------------------------------------------------------------------------------------------------------------
1796
 * @fn decamutexoff()
1797
 *
1798
 * @brief This function should re-enable interrupts, or at least restore their state as returned(&saved) by decamutexon
1799
 * This is called at the end of a critical section
1800
 *
1801
 * Note: The body of this function is platform specific
1802
 *
1803
 * input parameters:
1804
 * @param s - the state of the DW1000 interrupt as returned by decamutexon
1805
 *
1806
 * output parameters
1807
 *
1808
 * returns the state of the DW1000 interrupt
1809
 */
1810
void decamutexoff(decaIrqStatus_t s) ;
1811

    
1812
/*! ------------------------------------------------------------------------------------------------------------------
1813
 * @fn deca_sleep()
1814
 *
1815
 * @brief Wait for a given amount of time.
1816
 * NB: The body of this function is platform specific
1817
 *
1818
 * input parameters:
1819
 * @param time_ms - time to wait in milliseconds
1820
 *
1821
 * output parameters
1822
 *
1823
 * no return value
1824
 */
1825
void deca_sleep(unsigned int time_ms);
1826

    
1827

    
1828
void port_set_dw1000_slowrate(void);
1829
void port_set_dw1000_fastrate(void);
1830
void port_wakeup_dw1000_fast(void);
1831
uint32_t portGetTickCnt(void);
1832

    
1833
#endif /* defined(AMIROLLD_CFG_USE_DW1000) */
1834

    
1835
#endif /* AMIROLLD_DW1000_H */