amiro-lld / drivers / DW1000 / v1 / alld_DW1000.h @ 9466e34d
History | View | Annotate | Download (74.65 KB)
| 1 | 69a601a5 | Cung Sang | /*
|
|---|---|---|---|
| 2 | AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
||
| 3 | 84450926 | Thomas Schöpping | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
| 4 | 69a601a5 | Cung Sang | |
| 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 | 9466e34d | Thomas Schöpping | #ifndef AMIROLLD_DW1000_H
|
| 32 | #define AMIROLLD_DW1000_H
|
||
| 33 | 69a601a5 | Cung Sang | |
| 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 | 26dead12 | Cung Sang | #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 | 69a601a5 | Cung Sang | extern const uint8_t chan_idx[NUM_CH_SUPPORTED]; |
| 71 | 26dead12 | Cung Sang | 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 | 69a601a5 | Cung Sang | |
| 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 |