Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / DW1000 / v1 / alld_DW1000.h @ 9466e34d

History | View | Annotate | Download (74.65 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
#include <stddef.h>
36
#include <stdint.h>
37
#include <stdbool.h>
38

    
39
#define DW1000_DRIVER_VERSION               0x040005
40
#define DW1000_DEVICE_DRIVER_VER_STRING     "DW1000 Device Driver Version 04.00.05"
41

    
42
#ifndef DWT_NUM_DW_DEV
43
#define DWT_NUM_DW_DEV (1)
44
#endif
45

    
46
#define DWT_SUCCESS (0)
47
#define DWT_ERROR   (-1)
48

    
49
/**
50
 * Parameter declarations
51
 */
52

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

    
62
#define NUM_16M_OFFSET  (37)
63
#define NUM_16M_OFFSETWB  (68)
64
#define NUM_64M_OFFSET  (26)
65
#define NUM_64M_OFFSETWB  (59)
66

    
67
#define SPIBUFFLEN     (32)
68

    
69

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

    
79

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

    
91

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

    
94
#define DWT_DEVICE_ID   (0xDECA0130)        //!< DW1000 MP device ID
95

    
96
#define BUFFLEN         (4096+128)
97

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

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

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

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

    
127
#define DWT_SFDTOC_DEF              0x1041  // default SFD timeout value
128

    
129
#define DWT_PHRMODE_STD             0x0     // standard PHR mode
130
#define DWT_PHRMODE_EXT             0x3     // DW proprietary extended frames PHR mode
131

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

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

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

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

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

    
171

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

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

    
186
//DW1000 INIT configuration parameters
187
#define DWT_LOADUCODE     0x1
188
#define DWT_LOADNONE      0x0
189

    
190
//DW1000 OTP operating parameter set selection
191
#define DWT_OPSET_64LEN   0x0
192
#define DWT_OPSET_TIGHT   0x1
193
#define DWT_OPSET_DEFLT   0x2
194

    
195
// Call-back data RX frames flags
196
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit
197

    
198

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

    
208
// Call-back type for all events
209
typedef void (*dwt_cb_t)(const dwt_cb_data_t *);
210

    
211

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

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

    
255

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

    
267

    
268
typedef struct
269
{
270

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

    
281

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

    
298
} dwt_deviceentcnts_t ;
299

    
300

    
301
/********************************************************************************************************************/
302
/*                                                 REMOVED API LIST                                                 */
303
/********************************************************************************************************************/
304
/*
305
 * From version 4.0.0:
306
 *  - dwt_setGPIOforEXTTRX: Replaced by dwt_setlnapamode to get equivalent functionality.
307
 *  - dwt_setGPIOdirection: Renamed to dwt_setgpiodirection.
308
 *  - dwt_setGPIOvalue: Renamed to dwt_setgpiovalue.
309
 *  - dwt_setrxmode: Replaced by dwt_setsniffmode and dwt_setlowpowerlistening depending on the RX mode the user
310
 *    wants to set up.
311
 *  - dwt_checkoverrun: As automatic RX re-enabling is not supported anymore, this functions has become useless.
312
 *  - dwt_setautorxreenable: As automatic RX re-enabling is not supported anymore, this functions has become
313
 *    useless.
314
 *  - dwt_getrangebias: Range bias correction values are platform dependent and should therefore be managed at user
315
 *    application level.
316
 *  - dwt_xtaltrim: Renamed to dwt_setxtaltrim.
317
 *  - dwt_checkIRQ: Renamed to dwt_checkirq.
318
 *
319
 * From version 3.0.0:
320
 *  - dwt_getldotune: As LDO loading is now automatically managed by the driver, this function has become useless.
321
 *  - dwt_getotptxpower: TX power values and location in OTP memory are platform dependent and should therefore be
322
 *    managed at user application level.
323
 *  - dwt_readantennadelay: Antenna delay values and location in OTP memory are platform dependent and should
324
 *    therefore be managed at user application level.
325
 *  - dwt_readdignostics: Renamed to dwt_readdiagnostics.
326
 */
327

    
328
/********************************************************************************************************************/
329
/*                                                     API LIST                                                     */
330
/********************************************************************************************************************/
331

    
332
/*! ------------------------------------------------------------------------------------------------------------------
333
 * @fn dwt_setdevicedataptr()
334
 *
335
 * @brief This function sets the local data structure pointer to point to the structure in the local array as given by the index.
336
 *
337
 * input parameters
338
 * @param index    - selects the array object to point to. Must be within the array bounds, i.e. < DWT_NUM_DW_DEV
339
 *
340
 * output parameters
341
 *
342
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
343
 */
344
int dwt_setdevicedataptr(unsigned int index);
345

    
346
/*! ------------------------------------------------------------------------------------------------------------------
347
 * @fn dwt_getpartid()
348
 *
349
 * @brief This is used to return the read part ID of the device
350
 *
351
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
352
 *
353
 * input parameters
354
 *
355
 * output parameters
356
 *
357
 * returns the 32 bit part ID value as programmed in the factory
358
 */
359
uint32_t dwt_getpartid(void);
360

    
361
/*! ------------------------------------------------------------------------------------------------------------------
362
 * @fn dwt_getlotid()
363
 *
364
 * @brief This is used to return the read lot ID of the device
365
 *
366
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
367
 *
368
 * input parameters
369
 *
370
 * output parameters
371
 *
372
 * returns the 32 bit lot ID value as programmed in the factory
373
 */
374
uint32_t dwt_getlotid(void);
375

    
376
/*! ------------------------------------------------------------------------------------------------------------------
377
 * @fn dwt_readdevid()
378
 *
379
 * @brief This is used to return the read device type and revision information of the DW1000 device (MP part is 0xDECA0130)
380
 *
381
 * input parameters
382
 *
383
 * output parameters
384
 *
385
 * returns the read value which for DW1000 is 0xDECA0130
386
 */
387
uint32_t dwt_readdevid(void);
388

    
389
/*! ------------------------------------------------------------------------------------------------------------------
390
 * @fn dwt_otprevision()
391
 *
392
 * @brief This is used to return the read OTP revision
393
 *
394
 * NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
395
 *
396
 * input parameters
397
 *
398
 * output parameters
399
 *
400
 * returns the read OTP revision value
401
 */
402
uint8_t dwt_otprevision(void);
403

    
404
/*! ------------------------------------------------------------------------------------------------------------------
405
 * @fn dwt_setfinegraintxseq()
406
 *
407
 * @brief This function enables/disables the fine grain TX sequencing (enabled by default).
408
 *
409
 * input parameters
410
 * @param enable - 1 to enable fine grain TX sequencing, 0 to disable it.
411
 *
412
 * output parameters none
413
 *
414
 * no return value
415
 */
416
void dwt_setfinegraintxseq(int enable);
417

    
418
/*! ------------------------------------------------------------------------------------------------------------------
419
 * @fn dwt_setlnapamode()
420
 *
421
 * @brief This is used to enable GPIO for external LNA or PA functionality - HW dependent, consult the DW1000 User Manual.
422
 *        This can also be used for debug as enabling TX and RX GPIOs is quite handy to monitor DW1000's activity.
423
 *
424
 * NOTE: Enabling PA functionality requires that fine grain TX sequencing is deactivated. This can be done using
425
 *       dwt_setfinegraintxseq().
426
 *
427
 * input parameters
428
 * @param lna - 1 to enable LNA functionality, 0 to disable it
429
 * @param pa - 1 to enable PA functionality, 0 to disable it
430
 *
431
 * output parameters
432
 *
433
 * no return value
434
 */
435
void dwt_setlnapamode(int lna, int pa);
436

    
437
/*! ------------------------------------------------------------------------------------------------------------------
438
 * @fn dwt_setgpiodirection()
439
 *
440
 * @brief This is used to set GPIO direction as an input (1) or output (0)
441
 *
442
 * input parameters
443
 * @param gpioNum    -   this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
444
 * @param direction  -   this sets the GPIO direction - see GxP0... GxP8 in the deca_regs.h file
445
 *
446
 * output parameters
447
 *
448
 * no return value
449
 */
450
void dwt_setgpiodirection(uint32_t gpioNum, uint32_t direction);
451

    
452
/*! ------------------------------------------------------------------------------------------------------------------
453
 * @fn dwt_setgpiovalue()
454
 *
455
 * @brief This is used to set GPIO value as (1) or (0) only applies if the GPIO is configured as output
456
 *
457
 * input parameters
458
 * @param gpioNum    -   this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
459
 * @param value  -   this sets the GPIO value - see GDP0... GDP8 in the deca_regs.h file
460
 *
461
 * output parameters
462
 *
463
 * no return value
464
 */
465
void dwt_setgpiovalue(uint32_t gpioNum, uint32_t value);
466

    
467
/*! ------------------------------------------------------------------------------------------------------------------
468
 * @fn dwt_initialise()
469
 *
470
 * @brief This function initiates communications with the DW1000 transceiver
471
 * and reads its DEV_ID register (address 0x00) to verify the IC is one supported
472
 * by this software (e.g. DW1000 32-bit device ID value is 0xDECA0130).  Then it
473
 * does any initial once only device configurations needed for use and initialises
474
 * as necessary any static data items belonging to this low-level driver.
475
 *
476
 * NOTES:
477
 * 1.this function needs to be run before dwt_configuresleep, also the SPI frequency has to be < 3MHz
478
 * 2.it also reads and applies LDO tune and crystal trim values from OTP memory
479
 *
480
 * input parameters
481
 * @param config    -   specifies what configuration to load
482
 *                  DWT_LOADUCODE     0x1 - load the LDE microcode from ROM - enabled accurate RX timestamp
483
 *                  DWT_LOADNONE      0x0 - do not load any values from OTP memory
484
 * @param drv       -   hardware specifc struct containg refernce to SPI, GPIO etc.
485
 *
486
 * output parameters
487
 *
488
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
489
 */
490
int dwt_initialise(uint16_t config, DW1000Driver* drv) ;
491

    
492
/*! ------------------------------------------------------------------------------------------------------------------
493
 * @fn dwt_configure()
494
 *
495
 * @brief This function provides the main API for the configuration of the
496
 * DW1000 and this low-level driver.  The input is a pointer to the data structure
497
 * of type dwt_config_t that holds all the configurable items.
498
 * The dwt_config_t structure shows which ones are supported
499
 *
500
 * input parameters
501
 * @param config    -   pointer to the configuration structure, which contains the device configuration data.
502
 *
503
 * output parameters
504
 *
505
 * no return value
506
 */
507
void dwt_configure(dwt_config_t* config) ;
508

    
509
/*! ------------------------------------------------------------------------------------------------------------------
510
 * @fn dwt_configuretxrf()
511
 *
512
 * @brief This function provides the API for the configuration of the TX spectrum
513
 * including the power and pulse generator delay. The input is a pointer to the data structure
514
 * of type dwt_txconfig_t that holds all the configurable items.
515
 *
516
 * input parameters
517
 * @param config    -   pointer to the txrf configuration structure, which contains the tx rf config data
518
 *
519
 * output parameters
520
 *
521
 * no return value
522
 */
523
void dwt_configuretxrf(dwt_txconfig_t *config) ;
524

    
525
/*! ------------------------------------------------------------------------------------------------------------------
526
 * @fn dwt_setrxantennadelay()
527
 *
528
 * @brief This API function writes the antenna delay (in time units) to RX registers
529
 *
530
 * input parameters:
531
 * @param rxDelay - this is the total (RX) antenna delay value, which
532
 *                          will be programmed into the RX register
533
 *
534
 * output parameters
535
 *
536
 * no return value
537
 */
538
void dwt_setrxantennadelay(uint16_t antennaDly);
539

    
540
/*! ------------------------------------------------------------------------------------------------------------------
541
 * @fn dwt_settxantennadelay()
542
 *
543
 * @brief This API function writes the antenna delay (in time units) to TX registers
544
 *
545
 * input parameters:
546
 * @param txDelay - this is the total (TX) antenna delay value, which
547
 *                          will be programmed into the TX delay register
548
 *
549
 * output parameters
550
 *
551
 * no return value
552
 */
553
void dwt_settxantennadelay(uint16_t antennaDly);
554

    
555
/*! ------------------------------------------------------------------------------------------------------------------
556
 * @fn dwt_setsmarttxpower()
557
 *
558
 * @brief This call enables or disables the smart TX power feature.
559
 *
560
 * input parameters
561
 * @param enable - this enables or disables the TX smart power (1 = enable, 0 = disable)
562
 *
563
 * output parameters
564
 *
565
 * no return value
566
 */
567
void dwt_setsmarttxpower(int enable);
568

    
569
/*! ------------------------------------------------------------------------------------------------------------------
570
 * @fn dwt_writetxdata()
571
 *
572
 * @brief This API function writes the supplied TX data into the DW1000's
573
 * TX buffer.  The input parameters are the data length in bytes and a pointer
574
 * to those data bytes.
575
 *
576
 * input parameters
577
 * @param txFrameLength  - This is the total frame length, including the two byte CRC.
578
 *                         Note: this is the length of TX message (including the 2 byte CRC) - max is 1023
579
 *                         standard PHR mode allows up to 127 bytes
580
 *                         if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
581
 *                         see dwt_configure function
582
 * @param txFrameBytes   - Pointer to the user’s buffer containing the data to send.
583
 * @param txBufferOffset - This specifies an offset in the DW1000’s TX Buffer at which to start writing data.
584
 *
585
 * output parameters
586
 *
587
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
588
 */
589
int dwt_writetxdata(uint16_t txFrameLength, uint8_t *txFrameBytes, uint16_t txBufferOffset) ;
590

    
591
/*! ------------------------------------------------------------------------------------------------------------------
592
 * @fn dwt_writetxfctrl()
593
 *
594
 * @brief This API function configures the TX frame control register before the transmission of a frame
595
 *
596
 * input parameters:
597
 * @param txFrameLength - this is the length of TX message (including the 2 byte CRC) - max is 1023
598
 *                              NOTE: standard PHR mode allows up to 127 bytes
599
 *                              if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
600
 *                              see dwt_configure function
601
 * @param txBufferOffset - the offset in the tx buffer to start writing the data
602
 * @param ranging - 1 if this is a ranging frame, else 0
603
 *
604
 * output parameters
605
 *
606
 * no return value
607
 */
608
void dwt_writetxfctrl(uint16_t txFrameLength, uint16_t txBufferOffset, int ranging);
609

    
610
/*! ------------------------------------------------------------------------------------------------------------------
611
 * @fn dwt_starttx()
612
 *
613
 * @brief This call initiates the transmission, input parameter indicates which TX mode is used see below
614
 *
615
 * input parameters:
616
 * @param mode - is a bitmask for which the following values can be combined to define the operation
617
 *               DWT_START_TX_IMMEDIATE (0)            - to begin transmission immediatelty.
618
 *               DWT_START_TX_DELAYED   (to set bit 0) - to begin TX at pre-configured delay time
619
 *               DWT_RESPONSE_EXPECTED  (to set bit 1) - to turn the receiver on automatically (after the TX) after a pre-programmed delay
620
 * output parameters
621
 *
622
 * returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed transmission will fail if the delayed time has passed)
623
 */
624
int dwt_starttx(uint8_t mode) ;
625

    
626
/*! ------------------------------------------------------------------------------------------------------------------
627
 * @fn dwt_setdelayedtrxtime()
628
 *
629
 * @brief This API function configures the delayed transmit time or the delayed RX on time
630
 *
631
 * input parameters
632
 * @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,
633
 * or at which to turn on the receiver)
634
 *
635
 * output parameters none
636
 *
637
 * no return value
638
 */
639
void dwt_setdelayedtrxtime(uint32_t starttime) ;
640

    
641
/*! ------------------------------------------------------------------------------------------------------------------
642
 * @fn dwt_readtxtimestamp()
643
 *
644
 * @brief This is used to read the TX timestamp (adjusted with the programmed antenna delay)
645
 *
646
 * input parameters
647
 * @param timestamp - a pointer to a 5-byte buffer which will store the read TX timestamp time
648
 *
649
 * output parameters - the timestamp buffer will contain the value after the function call
650
 *
651
 * no return value
652
 */
653
void dwt_readtxtimestamp(uint8_t * timestamp);
654

    
655
/*! ------------------------------------------------------------------------------------------------------------------
656
 * @fn dwt_readtxtimestamphi32()
657
 *
658
 * @brief This is used to read the high 32-bits of the TX timestamp (adjusted with the programmed antenna delay)
659
 *
660
 * input parameters
661
 *
662
 * output parameters
663
 *
664
 * returns high 32-bits of TX timestamp
665
 */
666
uint32_t dwt_readtxtimestamphi32(void);
667

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

    
681
/*! ------------------------------------------------------------------------------------------------------------------
682
 * @fn dwt_readrxtimestamp()
683
 *
684
 * @brief This is used to read the RX timestamp (adjusted time of arrival)
685
 *
686
 * input parameters
687
 * @param timestamp - a pointer to a 5-byte buffer which will store the read RX timestamp time
688
 *
689
 * output parameters - the timestamp buffer will contain the value after the function call
690
 *
691
 * no return value
692
 */
693
void dwt_readrxtimestamp(uint8_t * timestamp);
694

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

    
708
/*! ------------------------------------------------------------------------------------------------------------------
709
 * @fn dwt_readrxtimestamplo32()
710
 *
711
 * @brief This is used to read the low 32-bits of the RX timestamp (adjusted with the programmed antenna delay)
712
 *
713
 * input parameters
714
 *
715
 * output parameters
716
 *
717
 * returns low 32-bits of RX timestamp
718
 */
719
uint32_t dwt_readrxtimestamplo32(void);
720

    
721
/*! ------------------------------------------------------------------------------------------------------------------
722
 * @fn dwt_readsystimestamphi32()
723
 *
724
 * @brief This is used to read the high 32-bits of the system time
725
 *
726
 * input parameters
727
 *
728
 * output parameters
729
 *
730
 * returns high 32-bits of system time timestamp
731
 */
732
uint32_t dwt_readsystimestamphi32(void);
733

    
734
/*! ------------------------------------------------------------------------------------------------------------------
735
 * @fn dwt_readsystime()
736
 *
737
 * @brief This is used to read the system time
738
 *
739
 * input parameters
740
 * @param timestamp - a pointer to a 5-byte buffer which will store the read system time
741
 *
742
 * output parameters
743
 * @param timestamp - the timestamp buffer will contain the value after the function call
744
 *
745
 * no return value
746
 */
747
void dwt_readsystime(uint8_t * timestamp);
748

    
749
/*! ------------------------------------------------------------------------------------------------------------------
750
 * @fn dwt_forcetrxoff()
751
 *
752
 * @brief This is used to turn off the transceiver
753
 *
754
 * input parameters
755
 *
756
 * output parameters
757
 *
758
 * no return value
759
 */
760
void dwt_forcetrxoff(void);
761

    
762
/*! ------------------------------------------------------------------------------------------------------------------
763
 * @fn dwt_syncrxbufptrs()
764
 *
765
 * @brief this function synchronizes rx buffer pointers
766
 * need to make sure that the host/IC buffer pointers are aligned before starting RX
767
 *
768
 * input parameters:
769
 *
770
 * output parameters
771
 *
772
 * no return value
773
 */
774
void dwt_syncrxbufptrs(void);
775

    
776
/*! ------------------------------------------------------------------------------------------------------------------
777
 * @fn dwt_rxenable()
778
 *
779
 * @brief This call turns on the receiver, can be immediate or delayed (depending on the mode parameter). In the case of a
780
 * "late" error the receiver will only be turned on if the DWT_IDLE_ON_DLY_ERR is not set.
781
 * The receiver will stay turned on, listening to any messages until
782
 * it either receives a good frame, an error (CRC, PHY header, Reed Solomon) or  it times out (SFD, Preamble or Frame).
783
 *
784
 * input parameters
785
 * @param mode - this can be one of the following allowed values:
786
 *
787
 * DWT_START_RX_IMMEDIATE      0 used to enbale receiver immediately
788
 * DWT_START_RX_DELAYED        1 used to set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
789
 * (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
790
 * (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
791
 *                                               performing manual RX re-enabling in double buffering mode
792
 *
793
 * 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)
794
 */
795
int dwt_rxenable(int mode);
796

    
797
/*! ------------------------------------------------------------------------------------------------------------------
798
 * @fn dwt_setsniffmode()
799
 *
800
 * @brief enable/disable and configure SNIFF mode.
801
 *
802
 * SNIFF mode is a low-power reception mode where the receiver is sequenced on and off instead of being on all the time.
803
 * The time spent in each state (on/off) is specified through the parameters below.
804
 * See DW1000 User Manual section 4.5 "Low-Power SNIFF mode" for more details.
805
 *
806
 * input parameters:
807
 * @param enable - 1 to enable SNIFF mode, 0 to disable. When 0, all other parameters are not taken into account.
808
 * @param timeOn - duration of receiver ON phase, expressed in multiples of PAC size. The counter automatically adds 1 PAC
809
 *                 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.
810
 * @param timeOff - duration of receiver OFF phase, expressed in multiples of 128/125 µs (~1 µs). Max value is 255.
811
 *
812
 * output parameters
813
 *
814
 * no return value
815
 */
816
void dwt_setsniffmode(int enable, uint8_t timeOn, uint8_t timeOff);
817

    
818
/*! ------------------------------------------------------------------------------------------------------------------
819
 * @fn dwt_setlowpowerlistening()
820
 *
821
 * @brief enable/disable low-power listening mode.
822
 *
823
 * Low-power listening is a feature whereby the DW1000 is predominantly in the SLEEP state but wakes periodically, (after
824
 * this "long sleep"), for a very short time to sample the air for a preamble sequence. This preamble sampling "listening"
825
 * phase is actually two reception phases separated by a "short sleep" time. See DW1000 User Manual section "Low-Power
826
 * Listening" for more details.
827
 *
828
 * NOTE: Before enabling low-power listening, the following functions have to be called to fully configure it:
829
 *           - dwt_configuresleep() to configure long sleep phase. "mode" parameter should at least have DWT_PRESRV_SLEEP,
830
 *             DWT_CONFIG and DWT_RX_EN set and "wake" parameter should at least have both DWT_WAKE_SLPCNT and DWT_SLP_EN set.
831
 *           - dwt_calibratesleepcnt() and dwt_configuresleepcnt() to define the "long sleep" phase duration.
832
 *           - dwt_setsnoozetime() to define the "short sleep" phase duration.
833
 *           - dwt_setpreambledetecttimeout() to define the reception phases duration.
834
 *           - dwt_setinterrupt() to activate RX good frame interrupt (DWT_INT_RFCG) only.
835
 *       When configured, low-power listening mode can be triggered either by putting the DW1000 to sleep (using
836
 *       dwt_entersleep()) or by activating reception (using dwt_rxenable()).
837
 *
838
 *       Please refer to the low-power listening examples (examples 8a/8b accompanying the API distribution on Decawave's
839
 *       website). They form a working example code that shows how to use low-power listening correctly.
840
 *
841
 * input parameters:
842
 * @param enable - 1 to enable low-power listening, 0 to disable.
843
 *
844
 * output parameters
845
 *
846
 * no return value
847
 */
848
void dwt_setlowpowerlistening(int enable);
849

    
850
/*! ------------------------------------------------------------------------------------------------------------------
851
 * @fn dwt_setsnoozetime()
852
 *
853
 * @brief Set duration of "short sleep" phase when in low-power listening mode.
854
 *
855
 * input parameters:
856
 * @param snooze_time - "short sleep" phase duration, expressed in multiples of 512/19.2 µs (~26.7 µs). The counter
857
 *                      automatically adds 1 to the value set. The smallest working value that should be set is 1,
858
 *                      i.e. giving a snooze time of 2 units (or ~53 µs).
859
 *
860
 * output parameters
861
 *
862
 * no return value
863
 */
864
void dwt_setsnoozetime(uint8_t snooze_time);
865

    
866
/*! ------------------------------------------------------------------------------------------------------------------
867
 * @fn dwt_setdblrxbuffmode()
868
 *
869
 * @brief This call enables the double receive buffer mode
870
 *
871
 * input parameters
872
 * @param enable - 1 to enable, 0 to disable the double buffer mode
873
 *
874
 * output parameters
875
 *
876
 * no return value
877
 */
878
void dwt_setdblrxbuffmode(int enable);
879

    
880
/*! ------------------------------------------------------------------------------------------------------------------
881
 * @fn dwt_setrxtimeout()
882
 *
883
 * @brief This call enables RX timeout (SY_STAT_RFTO event)
884
 *
885
 * input parameters
886
 * @param time - how long the receiver remains on from the RX enable command
887
 *               The time parameter used here is in 1.0256 us (512/499.2MHz) units
888
 *               If set to 0 the timeout is disabled.
889
 *
890
 * output parameters
891
 *
892
 * no return value
893
 */
894
void dwt_setrxtimeout(uint16_t time);
895

    
896
/*! ------------------------------------------------------------------------------------------------------------------
897
 * @fn dwt_setpreambledetecttimeout()
898
 *
899
 * @brief This call enables preamble timeout (SY_STAT_RXPTO event)
900
 *
901
 * input parameters
902
 * @param  timeout - Preamble detection timeout, expressed in multiples of PAC size. The counter automatically adds 1 PAC
903
 *                   size to the value set. Min value that can be set is 1 (i.e. a timeout of 2 PAC size).
904
 *
905
 * output parameters
906
 *
907
 * no return value
908
 */
909
void dwt_setpreambledetecttimeout(uint16_t timeout);
910

    
911

    
912
/*! ------------------------------------------------------------------------------------------------------------------
913
 * @fn dwt_calibratesleepcnt()
914
 *
915
 * @brief calibrates the local oscillator as its frequency can vary between 7 and 13kHz depending on temp and voltage
916
 *
917
 * NOTE: this function needs to be run before dwt_configuresleepcnt, so that we know what the counter units are
918
 *
919
 * input parameters
920
 *
921
 * output parameters
922
 *
923
 * returns the number of XTAL/2 cycles per low-power oscillator cycle. LP OSC frequency = 19.2 MHz/return value
924
 */
925
uint16_t dwt_calibratesleepcnt(void);
926

    
927
/*! ------------------------------------------------------------------------------------------------------------------
928
 * @fn dwt_configuresleepcnt()
929
 *
930
 * @brief sets the sleep counter to new value, this function programs the high 16-bits of the 28-bit counter
931
 *
932
 * NOTE: this function needs to be run before dwt_configuresleep, also the SPI frequency has to be < 3MHz
933
 *
934
 * input parameters
935
 * @param sleepcnt - this it value of the sleep counter to program
936
 *
937
 * output parameters
938
 *
939
 * no return value
940
 */
941
 void dwt_configuresleepcnt(uint16_t sleepcnt);
942

    
943
 /*! ------------------------------------------------------------------------------------------------------------------
944
  * @fn dwt_configuresleep()
945
  *
946
  * @brief configures the device for both DEEP_SLEEP and SLEEP modes, and on-wake mode
947
  * i.e. before entering the sleep, the device should be programmed for TX or RX, then upon "waking up" the TX/RX settings
948
  * will be preserved and the device can immediately perform the desired action TX/RX
949
  *
950
  * NOTE: e.g. Tag operation - after deep sleep, the device needs to just load the TX buffer and send the frame
951
  *
952
  *
953
  *      mode: the array and LDE code (OTP/ROM) and LDO tune, and set sleep persist
954
  *      DWT_PRESRV_SLEEP 0x0100 - preserve sleep
955
  *      DWT_LOADOPSET    0x0080 - load operating parameter set on wakeup
956
  *      DWT_CONFIG       0x0040 - download the AON array into the HIF (configuration download)
957
  *      DWT_LOADEUI      0x0008
958
  *      DWT_GOTORX       0x0002
959
  *      DWT_TANDV        0x0001
960
  *
961
  *      wake: wake up parameters
962
  *      DWT_XTAL_EN      0x10 - keep XTAL running during sleep
963
  *      DWT_WAKE_SLPCNT  0x8 - wake up after sleep count
964
  *      DWT_WAKE_CS      0x4 - wake up on chip select
965
  *      DWT_WAKE_WK      0x2 - wake up on WAKEUP PIN
966
  *      DWT_SLP_EN       0x1 - enable sleep/deep sleep functionality
967
  *
968
  * input parameters
969
  * @param mode - config on-wake parameters
970
  * @param wake - config wake up parameters
971
  *
972
  * output parameters
973
  *
974
  * no return value
975
  */
976
void dwt_configuresleep(uint16_t mode, uint8_t wake);
977

    
978
/*! ------------------------------------------------------------------------------------------------------------------
979
 * @fn dwt_entersleep()
980
 *
981
 * @brief This function puts the device into deep sleep or sleep. dwt_configuresleep() should be called first
982
 * to configure the sleep and on-wake/wake-up parameters
983
 *
984
 * input parameters
985
 *
986
 * output parameters
987
 *
988
 * no return value
989
 */
990
void dwt_entersleep(void);
991

    
992
/*! ------------------------------------------------------------------------------------------------------------------
993
 * @fn dwt_entersleepaftertx(int enable)
994
 *
995
 * @brief sets the auto TX to sleep bit. This means that after a frame
996
 * transmission the device will enter deep sleep mode. The dwt_configuresleep() function
997
 * needs to be called before this to configure the on-wake settings
998
 *
999
 * NOTE: the IRQ line has to be low/inactive (i.e. no pending events)
1000
 *
1001
 * input parameters
1002
 * @param enable - 1 to configure the device to enter deep sleep after TX, 0 - disables the configuration
1003
 *
1004
 * output parameters
1005
 *
1006
 * no return value
1007
 */
1008
void dwt_entersleepaftertx(int enable);
1009

    
1010
/*! ------------------------------------------------------------------------------------------------------------------
1011
 * @fn dwt_spicswakeup()
1012
 *
1013
 * @brief wake up the device from sleep mode using the SPI read,
1014
 * the device will wake up on chip select line going low if the line is held low for at least 500us.
1015
 * To define the length depending on the time one wants to hold
1016
 * the chip select line low, use the following formula:
1017
 *
1018
 *      length (bytes) = time (s) * byte_rate (Hz)
1019
 *
1020
 * where fastest byte_rate is spi_rate (Hz) / 8 if the SPI is sending the bytes back-to-back.
1021
 * To save time and power, a system designer could determine byte_rate value more precisely.
1022
 *
1023
 * NOTE: Alternatively the device can be waken up with WAKE_UP pin if configured for that operation
1024
 *
1025
 * input parameters
1026
 * @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
1027
 * @param length - this is the length of the dummy buffer
1028
 *
1029
 * output parameters
1030
 *
1031
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
1032
 */
1033
int dwt_spicswakeup(uint8_t *buff, uint16_t length);
1034

    
1035
/*! ------------------------------------------------------------------------------------------------------------------
1036
 * @fn dwt_setcallbacks()
1037
 *
1038
 * @brief This function is used to register the different callbacks called when one of the corresponding event occurs.
1039
 *
1040
 * NOTE: Callbacks can be undefined (set to NULL). In this case, dwt_isr() will process the event as usual but the 'null'
1041
 * callback will not be called.
1042
 *
1043
 * input parameters
1044
 * @param cbTxDone - the pointer to the TX confirmation event callback function
1045
 * @param cbRxOk - the pointer to the RX good frame event callback function
1046
 * @param cbRxTo - the pointer to the RX timeout events callback function
1047
 * @param cbRxErr - the pointer to the RX error events callback function
1048
 *
1049
 * output parameters
1050
 *
1051
 * no return value
1052
 */
1053
void dwt_setcallbacks(dwt_cb_t cbTxDone, dwt_cb_t cbRxOk, dwt_cb_t cbRxTo, dwt_cb_t cbRxErr);
1054

    
1055
/*! ------------------------------------------------------------------------------------------------------------------
1056
 * @fn dwt_checkirq()
1057
 *
1058
 * @brief This function checks if the IRQ line is active - this is used instead of interrupt handler
1059
 *
1060
 * input parameters
1061
 *
1062
 * output parameters
1063
 *
1064
 * return value is 1 if the IRQS bit is set and 0 otherwise
1065
 */
1066
uint8_t dwt_checkirq(void);
1067

    
1068
/*! ------------------------------------------------------------------------------------------------------------------
1069
 * @fn dwt_isr()
1070
 *
1071
 * @brief This is the DW1000's general Interrupt Service Routine. It will process/report the following events:
1072
 *          - RXFCG (through cbRxOk callback)
1073
 *          - TXFRS (through cbTxDone callback)
1074
 *          - RXRFTO/RXPTO (through cbRxTo callback)
1075
 *          - RXPHE/RXFCE/RXRFSL/RXSFDTO/AFFREJ/LDEERR (through cbRxTo cbRxErr)
1076
 *        For all events, corresponding interrupts are cleared and necessary resets are performed. In addition, in the RXFCG case,
1077
 *        received frame information and frame control are read before calling the callback. If double buffering is activated, it
1078
 *        will also toggle between reception buffers once the reception callback processing has ended.
1079
 *
1080
 *        /!\ This version of the ISR supports double buffering but does not support automatic RX re-enabling!
1081
 *
1082
 * NOTE:  In PC based system using (Cheetah or ARM) USB to SPI converter there can be no interrupts, however we still need something
1083
 *        to take the place of it and operate in a polled way. In an embedded system this function should be configured to be triggered
1084
 *        on any of the interrupts described above.
1085

1086
 * input parameters
1087
 *
1088
 * output parameters
1089
 *
1090
 * no return value
1091
 */
1092
void dwt_isr(void);
1093

    
1094
/*! ------------------------------------------------------------------------------------------------------------------
1095
 * @fn dwt_isr_lplisten()
1096
 *
1097
 * @brief This is the DW1000's Interrupt Service Routine to use when low-power listening scheme is implemented. It will
1098
 *        only process/report the RXFCG event (through cbRxOk callback).
1099
 *        It clears RXFCG interrupt and reads received frame information and frame control before calling the callback.
1100
 *
1101
 *        /!\ This version of the ISR is designed for single buffering case only!
1102
 *
1103
 * input parameters
1104
 *
1105
 * output parameters
1106
 *
1107
 * no return value
1108
 */
1109
void dwt_lowpowerlistenisr(void);
1110

    
1111
/*! ------------------------------------------------------------------------------------------------------------------
1112
 * @fn void dwt_setinterrupt()
1113
 *
1114
 * @brief This function enables the specified events to trigger an interrupt.
1115
 * The following events can be enabled:
1116
 * DWT_INT_TFRS         0x00000080          // frame sent
1117
 * DWT_INT_RFCG         0x00004000          // frame received with good CRC
1118
 * DWT_INT_RPHE         0x00001000          // receiver PHY header error
1119
 * DWT_INT_RFCE         0x00008000          // receiver CRC error
1120
 * DWT_INT_RFSL         0x00010000          // receiver sync loss error
1121
 * DWT_INT_RFTO         0x00020000          // frame wait timeout
1122
 * DWT_INT_RXPTO        0x00200000          // preamble detect timeout
1123
 * DWT_INT_SFDT         0x04000000          // SFD timeout
1124
 * DWT_INT_ARFE         0x20000000          // frame rejected (due to frame filtering configuration)
1125
 *
1126
 *
1127
 * input parameters:
1128
 * @param bitmask - sets the events which will generate interrupt
1129
 * @param enable - if set the interrupts are enabled else they are cleared
1130
 *
1131
 * output parameters
1132
 *
1133
 * no return value
1134
 */
1135
void dwt_setinterrupt( uint32_t bitmask, uint8_t enable);
1136

    
1137
/*! ------------------------------------------------------------------------------------------------------------------
1138
 * @fn dwt_setpanid()
1139
 *
1140
 * @brief This is used to set the PAN ID
1141
 *
1142
 * input parameters
1143
 * @param panID - this is the PAN ID
1144
 *
1145
 * output parameters
1146
 *
1147
 * no return value
1148
 */
1149
void dwt_setpanid(uint16_t panID);
1150

    
1151
/*! ------------------------------------------------------------------------------------------------------------------
1152
 * @fn dwt_setaddress16()
1153
 *
1154
 * @brief This is used to set 16-bit (short) address
1155
 *
1156
 * input parameters
1157
 * @param shortAddress - this sets the 16 bit short address
1158
 *
1159
 * output parameters
1160
 *
1161
 * no return value
1162
 */
1163
void dwt_setaddress16(uint16_t shortAddress);
1164

    
1165
/*! ------------------------------------------------------------------------------------------------------------------
1166
 * @fn dwt_seteui()
1167
 *
1168
 * @brief This is used to set the EUI 64-bit (long) address
1169
 *
1170
 * input parameters
1171
 * @param eui64 - this is the pointer to a buffer that contains the 64bit address
1172
 *
1173
 * output parameters
1174
 *
1175
 * no return value
1176
 */
1177
void dwt_seteui(uint8_t *eui64);
1178

    
1179
/*! ------------------------------------------------------------------------------------------------------------------
1180
 * @fn dwt_geteui()
1181
 *
1182
 * @brief This is used to get the EUI 64-bit from the DW1000
1183
 *
1184
 * input parameters
1185
 * @param eui64 - this is the pointer to a buffer that will contain the read 64-bit EUI value
1186
 *
1187
 * output parameters
1188
 *
1189
 * no return value
1190
 */
1191
void dwt_geteui(uint8_t *eui64);
1192

    
1193
/*! ------------------------------------------------------------------------------------------------------------------
1194
 * @fn dwt_otpread()
1195
 *
1196
 * @brief This is used to read the OTP data from given address into provided array
1197
 *
1198
 * input parameters
1199
 * @param address - this is the OTP address to read from
1200
 * @param array - this is the pointer to the array into which to read the data
1201
 * @param length - this is the number of 32 bit words to read (array needs to be at least this length)
1202
 *
1203
 * output parameters
1204
 *
1205
 * no return value
1206
 */
1207
void dwt_otpread(uint32_t address, uint32_t *array, uint8_t length);
1208

    
1209
/*! ------------------------------------------------------------------------------------------------------------------
1210
 * @fn dwt_enableframefilter()
1211
 *
1212
 * @brief This is used to enable the frame filtering - (the default option is to
1213
 * accept any data and ACK frames with correct destination address
1214
 *
1215
 * input parameters
1216
 * @param - bitmask - enables/disables the frame filtering options according to
1217
 *      DWT_FF_NOTYPE_EN        0x000   no frame types allowed
1218
 *      DWT_FF_COORD_EN         0x002   behave as coordinator (can receive frames with no destination address (PAN ID has to match))
1219
 *      DWT_FF_BEACON_EN        0x004   beacon frames allowed
1220
 *      DWT_FF_DATA_EN          0x008   data frames allowed
1221
 *      DWT_FF_ACK_EN           0x010   ack frames allowed
1222
 *      DWT_FF_MAC_EN           0x020   mac control frames allowed
1223
 *      DWT_FF_RSVD_EN          0x040   reserved frame types allowed
1224
 *
1225
 * output parameters
1226
 *
1227
 * no return value
1228
 */
1229
void dwt_enableframefilter(uint16_t bitmask);
1230

    
1231
/*! ------------------------------------------------------------------------------------------------------------------
1232
 * @fn dwt_enableautoack()
1233
 *
1234
 * @brief This call enables the auto-ACK feature. If the responseDelayTime (parameter) is 0, the ACK will be sent a.s.a.p.
1235
 * otherwise it will be sent with a programmed delay (in symbols), max is 255.
1236
 * NOTE: needs to have frame filtering enabled as well
1237
 *
1238
 * input parameters
1239
 * @param responseDelayTime - if non-zero the ACK is sent after this delay, max is 255.
1240
 *
1241
 * output parameters
1242
 *
1243
 * no return value
1244
 */
1245
void dwt_enableautoack(uint8_t responseDelayTime);
1246

    
1247
/*! ------------------------------------------------------------------------------------------------------------------
1248
 * @fn dwt_setrxaftertxdelay()
1249
 *
1250
 * @brief This sets the receiver turn on delay time after a transmission of a frame
1251
 *
1252
 * input parameters
1253
 * @param rxDelayTime - (20 bits) - the delay is in UWB microseconds
1254
 *
1255
 * output parameters
1256
 *
1257
 * no return value
1258
 */
1259
void dwt_setrxaftertxdelay(uint32_t rxDelayTime);
1260

    
1261
/*! ------------------------------------------------------------------------------------------------------------------
1262
 * @fn dwt_rxreset()
1263
 *
1264
 * @brief this function resets the receiver of the DW1000
1265
 *
1266
 * input parameters:
1267
 *
1268
 * output parameters
1269
 *
1270
 * no return value
1271
 */
1272
void dwt_rxreset(void);
1273

    
1274
/*! ------------------------------------------------------------------------------------------------------------------
1275
 * @fn dwt_softreset()
1276
 *
1277
 * @brief this function resets the DW1000
1278
 *
1279
 * input parameters:
1280
 *
1281
 * output parameters
1282
 *
1283
 * no return value
1284
 */
1285
void dwt_softreset(void) ;
1286

    
1287
/*! ------------------------------------------------------------------------------------------------------------------
1288
 * @fn dwt_readrxdata()
1289
 *
1290
 * @brief This is used to read the data from the RX buffer, from an offset location give by offset parameter
1291
 *
1292
 * input parameters
1293
 * @param buffer - the buffer into which the data will be read
1294
 * @param length - the length of data to read (in bytes)
1295
 * @param rxBufferOffset - the offset in the rx buffer from which to read the data
1296
 *
1297
 * output parameters
1298
 *
1299
 * no return value
1300
 */
1301
void dwt_readrxdata(uint8_t *buffer, uint16_t length, uint16_t rxBufferOffset);
1302

    
1303
/*! ------------------------------------------------------------------------------------------------------------------
1304
 * @fn dwt_readaccdata()
1305
 *
1306
 * @brief This is used to read the data from the Accumulator buffer, from an offset location give by offset parameter
1307
 *
1308
 * NOTE: Because of an internal memory access delay when reading the accumulator the first octet output is a dummy octet
1309
 *       that should be discarded. This is true no matter what sub-index the read begins at.
1310
 *
1311
 * input parameters
1312
 * @param buffer - the buffer into which the data will be read
1313
 * @param length - the length of data to read (in bytes)
1314
 * @param accOffset - the offset in the acc buffer from which to read the data
1315
 *
1316
 * output parameters
1317
 *
1318
 * no return value
1319
 */
1320
void dwt_readaccdata(uint8_t *buffer, uint16_t length, uint16_t rxBufferOffset);
1321

    
1322
/*! ------------------------------------------------------------------------------------------------------------------
1323
 * @fn dwt_readdiagnostics()
1324
 *
1325
 * @brief this function reads the RX signal quality diagnostic data
1326
 *
1327
 * input parameters
1328
 * @param diagnostics - diagnostic structure pointer, this will contain the diagnostic data read from the DW1000
1329
 *
1330
 * output parameters
1331
 *
1332
 * no return value
1333
 */
1334
void dwt_readdiagnostics(dwt_rxdiag_t * diagnostics);
1335

    
1336
/*! ------------------------------------------------------------------------------------------------------------------
1337
 * @fn dwt_loadopsettabfromotp()
1338
 *
1339
 * @brief This is used to select which Operational Parameter Set table to load from OTP memory
1340
 *
1341
 * input parameters
1342
 * @param ops_sel - Operational Parameter Set table to load:
1343
 *                  DWT_OPSET_64LEN = 0x0 - load the operational parameter set table for 64 length preamble configuration
1344
 *                  DWT_OPSET_TIGHT = 0x1 - load the operational parameter set table for tight xtal offsets (<1ppm)
1345
 *                  DWT_OPSET_DEFLT = 0x2 - load the default operational parameter set table (this is loaded from reset)
1346
 *
1347
 * output parameters
1348
 *
1349
 * no return value
1350
 */
1351
void dwt_loadopsettabfromotp(uint8_t ops_sel);
1352

    
1353
/*! ------------------------------------------------------------------------------------------------------------------
1354
 * @fn dwt_configeventcounters()
1355
 *
1356
 * @brief This is used to enable/disable the event counter in the IC
1357
 *
1358
 * input parameters
1359
 * @param - enable - 1 enables (and reset), 0 disables the event counters
1360
 * output parameters
1361
 *
1362
 * no return value
1363
 */
1364
void dwt_configeventcounters(int enable);
1365

    
1366
/*! ------------------------------------------------------------------------------------------------------------------
1367
 * @fn dwt_readeventcounters()
1368
 *
1369
 * @brief This is used to read the event counters in the IC
1370
 *
1371
 * input parameters
1372
 * @param counters - pointer to the dwt_deviceentcnts_t structure which will hold the read data
1373
 *
1374
 * output parameters
1375
 *
1376
 * no return value
1377
 */
1378
void dwt_readeventcounters(dwt_deviceentcnts_t *counters);
1379

    
1380
/*! ------------------------------------------------------------------------------------------------------------------
1381
 * @fn dwt_otpwriteandverify()
1382
 *
1383
 * @brief This is used to program 32-bit value into the DW1000 OTP memory.
1384
 *
1385
 * input parameters
1386
 * @param value - this is the 32-bit value to be programmed into OTP
1387
 * @param address - this is the 16-bit OTP address into which the 32-bit value is programmed
1388
 *
1389
 * output parameters
1390
 *
1391
 * returns DWT_SUCCESS for success, or DWT_ERROR for error
1392
 */
1393
int dwt_otpwriteandverify(uint32_t value, uint16_t address);
1394

    
1395
/*! ------------------------------------------------------------------------------------------------------------------
1396
 * @fn dwt_setleds()
1397
 *
1398
 * @brief This is used to set up Tx/Rx GPIOs which could be used to control LEDs
1399
 * Note: not completely IC dependent, also needs board with LEDS fitted on right I/O lines
1400
 *       this function enables GPIOs 2 and 3 which are connected to LED3 and LED4 on EVB1000
1401
 *
1402
 * input parameters
1403
 * @param mode - this is a bit field interpreted as follows:
1404
 *          - bit 0: 1 to enable LEDs, 0 to disable them
1405
 *          - bit 1: 1 to make LEDs blink once on init. Only valid if bit 0 is set (enable LEDs)
1406
 *          - bit 2 to 7: reserved
1407
 *
1408
 * output parameters none
1409
 *
1410
 * no return value
1411
 */
1412
void dwt_setleds(uint8_t mode);
1413

    
1414
/*! ------------------------------------------------------------------------------------------------------------------
1415
 * @fn dwt_setxtaltrim()
1416
 *
1417
 * @brief This is used to adjust the crystal frequency
1418
 *
1419
 * input parameters:
1420
 * @param   value - crystal trim value (in range 0x0 to 0x1F) 31 steps (~1.5ppm per step)
1421
 *
1422
 * output parameters
1423
 *
1424
 * no return value
1425
 */
1426
void dwt_setxtaltrim(uint8_t value);
1427

    
1428
/*! ------------------------------------------------------------------------------------------------------------------
1429
 * @fn dwt_getinitxtaltrim()
1430
 *
1431
 * @brief This function returns the value of XTAL trim that has been applied during initialisation (dwt_init). This can
1432
 *        be either the value read in OTP memory or a default value.
1433
 *
1434
 * NOTE: The value returned by this function is the initial value only! It is not updated on dwt_setxtaltrim calls.
1435
 *
1436
 * input parameters
1437
 *
1438
 * output parameters
1439
 *
1440
 * returns the XTAL trim value set upon initialisation
1441
 */
1442
uint8_t dwt_getinitxtaltrim(void);
1443

    
1444
/*! ------------------------------------------------------------------------------------------------------------------
1445
 * @fn dwt_configcwmode()
1446
 *
1447
 * @brief this function sets the DW1000 to transmit cw signal at specific channel frequency
1448
 *
1449
 * input parameters:
1450
 * @param chan - specifies the operating channel (e.g. 1, 2, 3, 4, 5, 6 or 7)
1451
 *
1452
 * output parameters
1453
 *
1454
 * no return value
1455
 */
1456
void dwt_configcwmode(uint8_t chan);
1457

    
1458
/*! ------------------------------------------------------------------------------------------------------------------
1459
 * @fn dwt_configcontinuousframemode()
1460
 *
1461
 * @brief this function sets the DW1000 to continuous tx frame mode for regulatory approvals testing.
1462
 *
1463
 * input parameters:
1464
 * @param framerepetitionrate - This is a 32-bit value that is used to set the interval between transmissions.
1465
*  The minimum value is 4. The units are approximately 8 ns. (or more precisely 512/(499.2e6*128) seconds)).
1466
 *
1467
 * output parameters
1468
 *
1469
 * no return value
1470
 */
1471
void dwt_configcontinuousframemode(uint32_t framerepetitionrate);
1472

    
1473
/*! ------------------------------------------------------------------------------------------------------------------
1474
 * @fn dwt_readtempvbat()
1475
 *
1476
 * @brief this function reads the battery voltage and temperature of the MP
1477
 * The values read here will be the current values sampled by DW1000 AtoD converters.
1478
 * Note on Temperature: the temperature value needs to be converted to give the real temperature
1479
 * the formula is: 1.13 * reading - 113.0
1480
 * Note on Voltage: the voltage value needs to be converted to give the real voltage
1481
 * the formula is: 0.0057 * reading + 2.3
1482
 *
1483
 * NB: To correctly read the temperature this read should be done with xtal clock
1484
 * however that means that the receiver will be switched off, if receiver needs to be on then
1485
 * the timer is used to make sure the value is stable before reading
1486
 *
1487
 * input parameters:
1488
 * @param fastSPI - set to 1 if SPI rate > than 3MHz is used
1489
 *
1490
 * output parameters
1491
 *
1492
 * returns  (temp_raw<<8)|(vbat_raw)
1493
 */
1494
uint16_t dwt_readtempvbat(uint8_t fastSPI);
1495

    
1496
/*! ------------------------------------------------------------------------------------------------------------------
1497
 * @fn dwt_readwakeuptemp()
1498
 *
1499
 * @brief this function reads the temperature of the DW1000 that was sampled
1500
 * on waking from Sleep/Deepsleep. They are not current values, but read on last
1501
 * wakeup if DWT_TANDV bit is set in mode parameter of dwt_configuresleep
1502
 *
1503
 * input parameters:
1504
 *
1505
 * output parameters:
1506
 *
1507
 * returns: 8-bit raw temperature sensor value
1508
 */
1509
uint8_t dwt_readwakeuptemp(void) ;
1510

    
1511
/*! ------------------------------------------------------------------------------------------------------------------
1512
 * @fn dwt_readwakeupvbat()
1513
 *
1514
 * @brief this function reads the battery voltage of the DW1000 that was sampled
1515
 * on waking from Sleep/Deepsleep. They are not current values, but read on last
1516
 * wakeup if DWT_TANDV bit is set in mode parameter of dwt_configuresleep
1517
 *
1518
 * input parameters:
1519
 *
1520
 * output parameters:
1521
 *
1522
 * returns: 8-bit raw battery voltage sensor value
1523
 */
1524
uint8_t dwt_readwakeupvbat(void) ;
1525

    
1526
/*! ------------------------------------------------------------------------------------------------------------------
1527
 * @fn dwt_calcbandwidthtempadj()
1528
 *
1529
 * @brief this function determines the corrected bandwidth setting (PG_DELAY register setting)
1530
 * of the DW1000 which changes over temperature.
1531
 *
1532
 * input parameters:
1533
 * @param target_count - uint16_t - the PG count target to reach in order to correct the bandwidth
1534
 *
1535
 * output parameters:
1536
 *
1537
 * returns: (uint32) The setting to be programmed into the PG_DELAY value
1538
 */
1539
uint32_t dwt_calcbandwidthtempadj(uint16_t target_count);
1540

    
1541
/*! ------------------------------------------------------------------------------------------------------------------
1542
 * @fn dwt_calcpowertempadj()
1543
 *
1544
 * @brief this function determines the corrected power setting (TX_POWER setting) for the
1545
 * DW1000 which changes over temperature.
1546
 *
1547
 * input parameters:
1548
 * @param channel - uint8_t - the channel at which compensation of power level will be applied
1549
 * @param ref_powerreg - uint32_t - the TX_POWER register value recorded when reference measurements were made
1550
 * @param current_temperature - double - the current ambient temperature in degrees Celcius
1551
 * @param reference_temperature - double - the temperature at which reference measurements were made
1552
 * output parameters: None
1553
 *
1554
 * returns: (uint32) The corrected TX_POWER register value
1555
 */
1556
uint32_t dwt_calcpowertempadj(uint8_t channel, uint32_t ref_powerreg, double current_temperature, double reference_temperature);
1557

    
1558
/*! ------------------------------------------------------------------------------------------------------------------
1559
 * @fn dwt_calcpgcount()
1560
 *
1561
 * @brief this function calculates the value in the pulse generator counter register (PGC_STATUS) for a given PG_DELAY
1562
 * This is used to take a reference measurement, and the value recorded as the reference is used to adjust the
1563
 * bandwidth of the device when the temperature changes.
1564
 *
1565
 * input parameters:
1566
 * @param pgdly - uint8_t - the PG_DELAY to set (to control bandwidth), and to find the corresponding count value for
1567
 * output parameters: None
1568
 *
1569
 * returns: (uint16) PGC_STATUS count value calculated from the provided PG_DELAY value - used as reference for later
1570
 * bandwidth adjustments
1571
 */
1572
uint16_t dwt_calcpgcount(uint8_t pgdly);
1573

    
1574
/*! ------------------------------------------------------------------------------------------------------------------
1575
 * @fn dwt_writetodevice()
1576
 *
1577
 * @brief  this function is used to write to the DW1000 device registers
1578
 * Notes:
1579
 *        1. Firstly we create a header (the first byte is a header byte)
1580
 *        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
1581
 *        b. set bit-7 (or with 0x80) for write operation
1582
 *        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
1583
 *
1584
 *        2. Write the header followed by the data bytes to the DW1000 device
1585
 *
1586
 *
1587
 * input parameters:
1588
 * @param recordNumber  - ID of register file or buffer being accessed
1589
 * @param index         - byte index into register file or buffer being accessed
1590
 * @param length        - number of bytes being written
1591
 * @param buffer        - pointer to buffer containing the 'length' bytes to be written
1592
 *
1593
 * output parameters
1594
 *
1595
 * no return value
1596
 */
1597
void dwt_writetodevice
1598
(
1599
    uint16_t      recordNumber,   // input parameter - ID of register file or buffer being accessed
1600
    uint16_t      index,          // input parameter - byte index into register file or buffer being accessed
1601
    uint32_t      length,         // input parameter - number of bytes being written
1602
    const uint8_t *buffer         // input parameter - pointer to buffer containing the 'length' bytes to be written
1603
) ;
1604

    
1605
/*! ------------------------------------------------------------------------------------------------------------------
1606
 * @fn dwt_readfromdevice()
1607
 *
1608
 * @brief  this function is used to read from the DW1000 device registers
1609
 * Notes:
1610
 *        1. Firstly we create a header (the first byte is a header byte)
1611
 *        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
1612
 *        b. set bit-7 (or with 0x80) for write operation
1613
 *        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
1614
 *
1615
 *        2. Write the header followed by the data bytes to the DW1000 device
1616
 *        3. Store the read data in the input buffer
1617
 *
1618
 * input parameters:
1619
 * @param recordNumber  - ID of register file or buffer being accessed
1620
 * @param index         - byte index into register file or buffer being accessed
1621
 * @param length        - number of bytes being read
1622
 * @param buffer        - pointer to buffer in which to return the read data.
1623
 *
1624
 * output parameters
1625
 *
1626
 * no return value
1627
 */
1628
void dwt_readfromdevice
1629
(
1630
    uint16_t  recordNumber,       // input parameter - ID of register file or buffer being accessed
1631
    uint16_t  index,              // input parameter - byte index into register file or buffer being accessed
1632
    uint32_t  length,             // input parameter - number of bytes being read
1633
    uint8_t   *buffer             // input parameter - pointer to buffer in which to return the read data.
1634
) ;
1635

    
1636
/*! ------------------------------------------------------------------------------------------------------------------
1637
 * @fn dwt_read32bitoffsetreg()
1638
 *
1639
 * @brief  this function is used to read 32-bit value from the DW1000 device registers
1640
 *
1641
 * input parameters:
1642
 * @param regFileID - ID of register file or buffer being accessed
1643
 * @param regOffset - the index into register file or buffer being accessed
1644
 *
1645
 * output parameters
1646
 *
1647
 * returns 32 bit register value
1648
 */
1649
uint32_t dwt_read32bitoffsetreg(int regFileID, int regOffset) ;
1650

    
1651
/*! ------------------------------------------------------------------------------------------------------------------
1652
 * @fn dwt_write32bitoffsetreg()
1653
 *
1654
 * @brief  this function is used to write 32-bit value to the DW1000 device registers
1655
 *
1656
 * input parameters:
1657
 * @param regFileID - ID of register file or buffer being accessed
1658
 * @param regOffset - the index into register file or buffer being accessed
1659
 * @param regval    - the value to write
1660
 *
1661
 * output parameters
1662
 *
1663
 * no return value
1664
 */
1665
void dwt_write32bitoffsetreg(int regFileID, int regOffset, uint32_t regval);
1666

    
1667
#define dwt_write32bitreg(x,y)  dwt_write32bitoffsetreg(x,0,y)
1668
#define dwt_read32bitreg(x)     dwt_read32bitoffsetreg(x,0)
1669

    
1670
/*! ------------------------------------------------------------------------------------------------------------------
1671
 * @fn dwt_read16bitoffsetreg()
1672
 *
1673
 * @brief  this function is used to read 16-bit value from the DW1000 device registers
1674
 *
1675
 * input parameters:
1676
 * @param regFileID - ID of register file or buffer being accessed
1677
 * @param regOffset - the index into register file or buffer being accessed
1678
 *
1679
 * output parameters
1680
 *
1681
 * returns 16 bit register value
1682
 */
1683
uint16_t dwt_read16bitoffsetreg(int regFileID, int regOffset);
1684

    
1685
/*! ------------------------------------------------------------------------------------------------------------------
1686
 * @fn dwt_write16bitoffsetreg()
1687
 *
1688
 * @brief  this function is used to write 16-bit value to the DW1000 device registers
1689
 *
1690
 * input parameters:
1691
 * @param regFileID - ID of register file or buffer being accessed
1692
 * @param regOffset - the index into register file or buffer being accessed
1693
 * @param regval    - the value to write
1694
 *
1695
 * output parameters
1696
 *
1697
 * no return value
1698
 */
1699
void dwt_write16bitoffsetreg(int regFileID, int regOffset, uint16_t regval) ;
1700

    
1701
/*! ------------------------------------------------------------------------------------------------------------------
1702
 * @fn dwt_read8bitoffsetreg()
1703
 *
1704
 * @brief  this function is used to read an 8-bit value from the DW1000 device registers
1705
 *
1706
 * input parameters:
1707
 * @param regFileID - ID of register file or buffer being accessed
1708
 * @param regOffset - the index into register file or buffer being accessed
1709
 *
1710
 * output parameters
1711
 *
1712
 * returns 8-bit register value
1713
 */
1714
uint8_t dwt_read8bitoffsetreg(int regFileID, int regOffset);
1715

    
1716
/*! ------------------------------------------------------------------------------------------------------------------
1717
 * @fn dwt_write8bitoffsetreg()
1718
 *
1719
 * @brief  this function is used to write an 8-bit value to the DW1000 device registers
1720
 *
1721
 * input parameters:
1722
 * @param regFileID - ID of register file or buffer being accessed
1723
 * @param regOffset - the index into register file or buffer being accessed
1724
 * @param regval    - the value to write
1725
 *
1726
 * output parameters
1727
 *
1728
 * no return value
1729
 */
1730
void dwt_write8bitoffsetreg(int regFileID, int regOffset, uint8_t regval);
1731

    
1732

    
1733
/****************************************************************************************************************************************************
1734
 *
1735
 * Declaration of platform-dependent lower level functions.
1736
 *
1737
 ****************************************************************************************************************************************************/
1738

    
1739

    
1740
// ---------------------------------------------------------------------------
1741
//
1742
// NB: The purpose of the deca_mutex.c file is to provide for microprocessor interrupt enable/disable, this is used for
1743
//     controlling mutual exclusion from critical sections in the code where interrupts and background
1744
//     processing may interact.  The code using this is kept to a minimum and the disabling time is also
1745
//     kept to a minimum, so blanket interrupt disable may be the easiest way to provide this.  But at a
1746
//     minimum those interrupts coming from the decawave device should be disabled/re-enabled by this activity.
1747
//
1748
//     In porting this to a particular microprocessor, the implementer may choose to use #defines here
1749
//     to map these calls transparently to the target system.  Alternatively the appropriate code may
1750
//     be embedded in the functions provided in the deca_irq.c file.
1751
//
1752
// ---------------------------------------------------------------------------
1753

    
1754
typedef int decaIrqStatus_t ; // Type for remembering IRQ status
1755

    
1756

    
1757
/*! ------------------------------------------------------------------------------------------------------------------
1758
 * @fn decamutexon()
1759
 *
1760
 * @brief This function should disable interrupts. This is called at the start of a critical section
1761
 * It returns the IRQ state before disable, this value is used to re-enable in decamutexoff call
1762
 *
1763
 * Note: The body of this function is platform specific
1764
 *
1765
 * input parameters:
1766
 *
1767
 * output parameters
1768
 *
1769
 * returns the state of the DW1000 interrupt
1770
 */
1771
decaIrqStatus_t decamutexon(void) ;
1772

    
1773
/*! ------------------------------------------------------------------------------------------------------------------
1774
 * @fn decamutexoff()
1775
 *
1776
 * @brief This function should re-enable interrupts, or at least restore their state as returned(&saved) by decamutexon
1777
 * This is called at the end of a critical section
1778
 *
1779
 * Note: The body of this function is platform specific
1780
 *
1781
 * input parameters:
1782
 * @param s - the state of the DW1000 interrupt as returned by decamutexon
1783
 *
1784
 * output parameters
1785
 *
1786
 * returns the state of the DW1000 interrupt
1787
 */
1788
void decamutexoff(decaIrqStatus_t s) ;
1789

    
1790
/*! ------------------------------------------------------------------------------------------------------------------
1791
 * @fn deca_sleep()
1792
 *
1793
 * @brief Wait for a given amount of time.
1794
 * NB: The body of this function is platform specific
1795
 *
1796
 * input parameters:
1797
 * @param time_ms - time to wait in milliseconds
1798
 *
1799
 * output parameters
1800
 *
1801
 * no return value
1802
 */
1803
void deca_sleep(unsigned int time_ms);
1804
void Sleep(unsigned int time_ms);
1805

    
1806

    
1807
void port_EnableEXT_IRQ(void);
1808
void port_DisableEXT_IRQ(void);
1809
decaIrqStatus_t port_GetEXT_IRQStatus(void);
1810

    
1811
void port_set_dw1000_slowrate(void);
1812
void port_set_dw1000_fastrate(void);
1813
void port_wakeup_dw1000_fast(void);
1814
uint32_t portGetTickCnt(void);
1815

    
1816

    
1817
/**
1818
 * @brief   Pad specific IRQn handler. modify it if the PIN no. is changed
1819
 */
1820
#define DW1000_EXTI_IRQn    EXTI15_10_IRQn
1821

    
1822
#endif //AMIROLLD_DW1000_H
1823