amiro-lld / include / DW1000 / v1 / alld_dw1000_v1.h @ b6364b51
History | View | Annotate | Download (77.117 KB)
| 1 |
/*
|
|---|---|
| 2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
|
| 3 |
Copyright (C) 2016..2018 Thomas Schöpping et al.
|
| 4 |
|
| 5 |
This program is free software: you can redistribute it and/or modify
|
| 6 |
it under the terms of the GNU Lesser General Public License as published by
|
| 7 |
the Free Software Foundation, either version 3 of the License, or
|
| 8 |
(at your option) any later version.
|
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful,
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
GNU Lesser General Public License for more details.
|
| 14 |
|
| 15 |
You should have received a copy of the GNU Lesser General Public License
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 17 |
*/
|
| 18 |
|
| 19 |
/*! ----------------------------------------------------------------------------
|
| 20 |
* @file deca_device_api.h
|
| 21 |
* @brief DW1000 API Functions
|
| 22 |
*
|
| 23 |
* @attention
|
| 24 |
*
|
| 25 |
* Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
|
| 26 |
*
|
| 27 |
* All rights reserved.
|
| 28 |
*
|
| 29 |
*/
|
| 30 |
|
| 31 |
#ifndef __AMIROLLD_DW1000_V1_H
|
| 32 |
#define AMIROLLD_DW1000_V1_H
|
| 33 |
|
| 34 |
|
| 35 |
#include <amiro-lld.h> |
| 36 |
#if (defined(AMIROLLD_CFG_DW1000) && (AMIROLLD_CFG_DW1000 == 1)) || defined(__DOXYGEN__) |
| 37 |
|
| 38 |
#include <stddef.h> |
| 39 |
#include <stdint.h> |
| 40 |
#include <stdbool.h> |
| 41 |
|
| 42 |
#define DW1000_DRIVER_VERSION 0x040005 |
| 43 |
#define DW1000_DEVICE_DRIVER_VER_STRING "DW1000 Device Driver Version 04.00.05" |
| 44 |
|
| 45 |
#ifndef DWT_NUM_DW_DEV
|
| 46 |
#define DWT_NUM_DW_DEV (1) |
| 47 |
#endif
|
| 48 |
|
| 49 |
#define DWT_SUCCESS (0) |
| 50 |
#define DWT_ERROR (-1) |
| 51 |
|
| 52 |
/**
|
| 53 |
* Parameter declarations
|
| 54 |
*/
|
| 55 |
|
| 56 |
#define NUM_BR 3 |
| 57 |
#define NUM_PRF 2 |
| 58 |
#define NUM_PACS 4 |
| 59 |
#define NUM_BW 2 //2 bandwidths are supported |
| 60 |
#define NUM_SFD 2 //supported number of SFDs - standard = 0, non-standard = 1 |
| 61 |
#define NUM_CH 6 //supported channels are 1, 2, 3, 4, 5, 7 |
| 62 |
#define NUM_CH_SUPPORTED 8 //supported channels are '0', 1, 2, 3, 4, 5, '6', 7 |
| 63 |
#define PCODES 25 //supported preamble codes |
| 64 |
|
| 65 |
extern const uint8_t chan_idx[NUM_CH_SUPPORTED]; |
| 66 |
|
| 67 |
|
| 68 |
/**
|
| 69 |
* @brief The DW1000 driver struct.
|
| 70 |
*/
|
| 71 |
typedef struct { |
| 72 |
apalSPIDriver_t* spid; /**< @brief The SPI Driver */
|
| 73 |
const apalControlGpio_t* gpio_exti; /**< @brief The GPIO indicating external interrupt */ |
| 74 |
const apalControlGpio_t* gpio_reset; /**< @brief The GPIO indicating reset sig*/ |
| 75 |
// const apalGpio_t* gpio_exti; /**< @brief The GPIO indicating external interrupt */
|
| 76 |
// const apalGpio_t* gpio_reset; /**< @brief The GPIO indicating reset sig*/
|
| 77 |
/* TODO: better apalControlGpio_t instead of apalGpio_t ? */
|
| 78 |
/* TODO: EXTI, GPIO (RESET) */
|
| 79 |
} DW1000Driver; |
| 80 |
|
| 81 |
|
| 82 |
#define DWT_TIME_UNITS (1.0/499.2e6/128.0) //!< = 15.65e-12 s |
| 83 |
|
| 84 |
#define DWT_DEVICE_ID (0xDECA0130) //!< DW1000 MP device ID |
| 85 |
|
| 86 |
#define BUFFLEN (4096+128) |
| 87 |
|
| 88 |
//! constants for selecting the bit rate for data TX (and RX)
|
| 89 |
//! These are defined for write (with just a shift) the TX_FCTRL register
|
| 90 |
#define DWT_BR_110K 0 //!< UWB bit rate 110 kbits/s |
| 91 |
#define DWT_BR_850K 1 //!< UWB bit rate 850 kbits/s |
| 92 |
#define DWT_BR_6M8 2 //!< UWB bit rate 6.8 Mbits/s |
| 93 |
|
| 94 |
//! constants for specifying the (Nominal) mean Pulse Repetition Frequency
|
| 95 |
//! These are defined for direct write (with a shift if necessary) to CHAN_CTRL and TX_FCTRL regs
|
| 96 |
#define DWT_PRF_16M 1 //!< UWB PRF 16 MHz |
| 97 |
#define DWT_PRF_64M 2 //!< UWB PRF 64 MHz |
| 98 |
|
| 99 |
//! constants for specifying Preamble Acquisition Chunk (PAC) Size in symbols
|
| 100 |
#define DWT_PAC8 0 //!< PAC 8 (recommended for RX of preamble length 128 and below |
| 101 |
#define DWT_PAC16 1 //!< PAC 16 (recommended for RX of preamble length 256 |
| 102 |
#define DWT_PAC32 2 //!< PAC 32 (recommended for RX of preamble length 512 |
| 103 |
#define DWT_PAC64 3 //!< PAC 64 (recommended for RX of preamble length 1024 and up |
| 104 |
|
| 105 |
//! constants for specifying TX Preamble length in symbols
|
| 106 |
//! These are defined to allow them be directly written into byte 2 of the TX_FCTRL register
|
| 107 |
//! (i.e. a four bit value destined for bits 20..18 but shifted left by 2 for byte alignment)
|
| 108 |
#define DWT_PLEN_4096 0x0C //! Standard preamble length 4096 symbols |
| 109 |
#define DWT_PLEN_2048 0x28 //! Non-standard preamble length 2048 symbols |
| 110 |
#define DWT_PLEN_1536 0x18 //! Non-standard preamble length 1536 symbols |
| 111 |
#define DWT_PLEN_1024 0x08 //! Standard preamble length 1024 symbols |
| 112 |
#define DWT_PLEN_512 0x34 //! Non-standard preamble length 512 symbols |
| 113 |
#define DWT_PLEN_256 0x24 //! Non-standard preamble length 256 symbols |
| 114 |
#define DWT_PLEN_128 0x14 //! Non-standard preamble length 128 symbols |
| 115 |
#define DWT_PLEN_64 0x04 //! Standard preamble length 64 symbols |
| 116 |
|
| 117 |
#define DWT_SFDTOC_DEF 0x1041 // default SFD timeout value |
| 118 |
|
| 119 |
#define DWT_PHRMODE_STD 0x0 // standard PHR mode |
| 120 |
#define DWT_PHRMODE_EXT 0x3 // DW proprietary extended frames PHR mode |
| 121 |
|
| 122 |
// Defined constants for "mode" bitmask parameter passed into dwt_starttx() function.
|
| 123 |
#define DWT_START_TX_IMMEDIATE 0 |
| 124 |
#define DWT_START_TX_DELAYED 1 |
| 125 |
#define DWT_RESPONSE_EXPECTED 2 |
| 126 |
|
| 127 |
#define DWT_START_RX_IMMEDIATE 0 |
| 128 |
#define DWT_START_RX_DELAYED 1 // Set up delayed RX, if "late" error triggers, then the RX will be enabled immediately |
| 129 |
#define DWT_IDLE_ON_DLY_ERR 2 // If delayed RX failed due to "late" error then if this |
| 130 |
// flag is set the RX will not be re-enabled immediately, and device will be in IDLE when function exits
|
| 131 |
#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 |
| 132 |
// re-enabling when receiving a frame in double buffer mode.
|
| 133 |
|
| 134 |
// Defined constants for "mode" bit field parameter passed to dwt_setleds() function.
|
| 135 |
#define DWT_LEDS_DISABLE 0x00 |
| 136 |
#define DWT_LEDS_ENABLE 0x01 |
| 137 |
#define DWT_LEDS_INIT_BLINK 0x02 |
| 138 |
|
| 139 |
//frame filtering configuration options
|
| 140 |
#define DWT_FF_NOTYPE_EN 0x000 // no frame types allowed (FF disabled) |
| 141 |
#define DWT_FF_COORD_EN 0x002 // behave as coordinator (can receive frames with no dest address (PAN ID has to match)) |
| 142 |
#define DWT_FF_BEACON_EN 0x004 // beacon frames allowed |
| 143 |
#define DWT_FF_DATA_EN 0x008 // data frames allowed |
| 144 |
#define DWT_FF_ACK_EN 0x010 // ack frames allowed |
| 145 |
#define DWT_FF_MAC_EN 0x020 // mac control frames allowed |
| 146 |
#define DWT_FF_RSVD_EN 0x040 // reserved frame types allowed |
| 147 |
|
| 148 |
//DW1000 interrupt events
|
| 149 |
#define DWT_INT_TFRS 0x00000080 // frame sent |
| 150 |
#define DWT_INT_LDED 0x00000400 // micro-code has finished execution |
| 151 |
#define DWT_INT_RFCG 0x00004000 // frame received with good CRC |
| 152 |
#define DWT_INT_RPHE 0x00001000 // receiver PHY header error |
| 153 |
#define DWT_INT_RFCE 0x00008000 // receiver CRC error |
| 154 |
#define DWT_INT_RFSL 0x00010000 // receiver sync loss error |
| 155 |
#define DWT_INT_RFTO 0x00020000 // frame wait timeout |
| 156 |
#define DWT_INT_RXOVRR 0x00100000 // receiver overrun |
| 157 |
#define DWT_INT_RXPTO 0x00200000 // preamble detect timeout |
| 158 |
#define DWT_INT_SFDT 0x04000000 // SFD timeout |
| 159 |
#define DWT_INT_ARFE 0x20000000 // frame rejected (due to frame filtering configuration) |
| 160 |
|
| 161 |
|
| 162 |
//DW1000 SLEEP and WAKEUP configuration parameters
|
| 163 |
#define DWT_PRESRV_SLEEP 0x0100 // PRES_SLEEP - on wakeup preserve sleep bit |
| 164 |
#define DWT_LOADOPSET 0x0080 // ONW_L64P - on wakeup load operating parameter set for 64 PSR |
| 165 |
#define DWT_CONFIG 0x0040 // ONW_LDC - on wakeup restore (load) the saved configurations (from AON array into HIF) |
| 166 |
#define DWT_LOADEUI 0x0008 // ONW_LEUI - on wakeup load EUI |
| 167 |
#define DWT_RX_EN 0x0002 // ONW_RX - on wakeup activate reception |
| 168 |
#define DWT_TANDV 0x0001 // ONW_RADC - on wakeup run ADC to sample temperature and voltage sensor values |
| 169 |
|
| 170 |
#define DWT_XTAL_EN 0x10 // keep XTAL running during sleep |
| 171 |
#define DWT_WAKE_SLPCNT 0x8 // wake up after sleep count |
| 172 |
#define DWT_WAKE_CS 0x4 // wake up on chip select |
| 173 |
#define DWT_WAKE_WK 0x2 // wake up on WAKEUP PIN |
| 174 |
#define DWT_SLP_EN 0x1 // enable sleep/deep sleep functionality |
| 175 |
|
| 176 |
//DW1000 INIT configuration parameters
|
| 177 |
#define DWT_LOADUCODE 0x1 |
| 178 |
#define DWT_LOADNONE 0x0 |
| 179 |
|
| 180 |
//DW1000 OTP operating parameter set selection
|
| 181 |
#define DWT_OPSET_64LEN 0x0 |
| 182 |
#define DWT_OPSET_TIGHT 0x1 |
| 183 |
#define DWT_OPSET_DEFLT 0x2 |
| 184 |
|
| 185 |
// Call-back data RX frames flags
|
| 186 |
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit |
| 187 |
|
| 188 |
|
| 189 |
// TX/RX call-back data
|
| 190 |
typedef struct |
| 191 |
{
|
| 192 |
uint32_t status; //initial value of register as ISR is entered
|
| 193 |
uint16_t datalength; //length of frame
|
| 194 |
uint8_t fctrl[2]; //frame control bytes |
| 195 |
uint8_t rx_flags; //RX frame flags, see above
|
| 196 |
} dwt_cb_data_t; |
| 197 |
|
| 198 |
// Call-back type for all events
|
| 199 |
typedef void (*dwt_cb_t)(const dwt_cb_data_t *); |
| 200 |
|
| 201 |
|
| 202 |
// -------------------------------------------------------------------------------------------------------------------
|
| 203 |
// Structure to hold device data
|
| 204 |
typedef struct |
| 205 |
{
|
| 206 |
uint32_t partID ; // IC Part ID - read during initialisation
|
| 207 |
uint32_t lotID ; // IC Lot ID - read during initialisation
|
| 208 |
uint8_t longFrames ; // Flag in non-standard long frame mode
|
| 209 |
uint8_t otprev ; // OTP revision number (read during initialisation)
|
| 210 |
uint32_t txFCTRL ; // Keep TX_FCTRL register config
|
| 211 |
uint8_t init_xtrim; // initial XTAL trim value read from OTP (or defaulted to mid-range if OTP not programmed)
|
| 212 |
uint8_t dblbuffon; // Double RX buffer mode flag
|
| 213 |
uint32_t sysCFGreg ; // Local copy of system config register
|
| 214 |
uint16_t sleep_mode; // Used for automatic reloading of LDO tune and microcode at wake-up
|
| 215 |
uint8_t wait4resp ; // wait4response was set with last TX start command
|
| 216 |
dwt_cb_data_t cbData; // Callback data structure
|
| 217 |
dwt_cb_t cbTxDone; // Callback for TX confirmation event
|
| 218 |
dwt_cb_t cbRxOk; // Callback for RX good frame event
|
| 219 |
dwt_cb_t cbRxTo; // Callback for RX timeout events
|
| 220 |
dwt_cb_t cbRxErr; // Callback for RX error events
|
| 221 |
DW1000Driver *driver; // Reference to local hardware SPI, GPIO, ...
|
| 222 |
} dwt_local_data_t ; |
| 223 |
|
| 224 |
/*! ------------------------------------------------------------------------------------------------------------------
|
| 225 |
* Structure typedef: dwt_config_t
|
| 226 |
*
|
| 227 |
* Structure for setting device configuration via dwt_configure() function
|
| 228 |
*
|
| 229 |
*/
|
| 230 |
typedef struct |
| 231 |
{
|
| 232 |
uint8_t chan ; //!< channel number {1, 2, 3, 4, 5, 7 }
|
| 233 |
uint8_t prf ; //!< Pulse Repetition Frequency {DWT_PRF_16M or DWT_PRF_64M}
|
| 234 |
uint8_t txPreambLength ; //!< DWT_PLEN_64..DWT_PLEN_4096
|
| 235 |
uint8_t rxPAC ; //!< Acquisition Chunk Size (Relates to RX preamble length)
|
| 236 |
uint8_t txCode ; //!< TX preamble code
|
| 237 |
uint8_t rxCode ; //!< RX preamble code
|
| 238 |
uint8_t nsSFD ; //!< Boolean should we use non-standard SFD for better performance
|
| 239 |
uint8_t dataRate ; //!< Data Rate {DWT_BR_110K, DWT_BR_850K or DWT_BR_6M8}
|
| 240 |
uint8_t phrMode ; //!< PHR mode {0x0 - standard DWT_PHRMODE_STD, 0x3 - extended frames DWT_PHRMODE_EXT}
|
| 241 |
uint8_t smartPowerEn ; //!< Smart Power enable / disable (TODO: Added smartPowerEn in this struct )
|
| 242 |
uint16_t sfdTO ; //!< SFD timeout value (in symbols)
|
| 243 |
} dwt_config_t ; |
| 244 |
|
| 245 |
|
| 246 |
typedef struct |
| 247 |
{
|
| 248 |
uint8_t PGdly; |
| 249 |
//TX POWER
|
| 250 |
//31:24 BOOST_0.125ms_PWR
|
| 251 |
//23:16 BOOST_0.25ms_PWR-TX_SHR_PWR
|
| 252 |
//15:8 BOOST_0.5ms_PWR-TX_PHR_PWR
|
| 253 |
//7:0 DEFAULT_PWR-TX_DATA_PWR
|
| 254 |
uint32_t power; |
| 255 |
} dwt_txconfig_t ; |
| 256 |
|
| 257 |
|
| 258 |
typedef struct |
| 259 |
{
|
| 260 |
|
| 261 |
uint16_t maxNoise ; // LDE max value of noise
|
| 262 |
uint16_t firstPathAmp1 ; // Amplitude at floor(index FP) + 1
|
| 263 |
uint16_t stdNoise ; // Standard deviation of noise
|
| 264 |
uint16_t firstPathAmp2 ; // Amplitude at floor(index FP) + 2
|
| 265 |
uint16_t firstPathAmp3 ; // Amplitude at floor(index FP) + 3
|
| 266 |
uint16_t maxGrowthCIR ; // Channel Impulse Response max growth CIR
|
| 267 |
uint16_t rxPreamCount ; // Count of preamble symbols accumulated
|
| 268 |
uint16_t firstPath ; // First path index (10.6 bits fixed point integer)
|
| 269 |
}dwt_rxdiag_t ; |
| 270 |
|
| 271 |
|
| 272 |
typedef struct |
| 273 |
{
|
| 274 |
//all of the below are mapped to a 12-bit register in DW1000
|
| 275 |
uint16_t PHE ; //number of received header errors
|
| 276 |
uint16_t RSL ; //number of received frame sync loss events
|
| 277 |
uint16_t CRCG ; //number of good CRC received frames
|
| 278 |
uint16_t CRCB ; //number of bad CRC (CRC error) received frames
|
| 279 |
uint16_t ARFE ; //number of address filter errors
|
| 280 |
uint16_t OVER ; //number of receiver overflows (used in double buffer mode)
|
| 281 |
uint16_t SFDTO ; //SFD timeouts
|
| 282 |
uint16_t PTO ; //Preamble timeouts
|
| 283 |
uint16_t RTO ; //RX frame wait timeouts
|
| 284 |
uint16_t TXF ; //number of transmitted frames
|
| 285 |
uint16_t HPW ; //half period warn
|
| 286 |
uint16_t TXW ; //power up warn
|
| 287 |
|
| 288 |
} dwt_deviceentcnts_t ; |
| 289 |
|
| 290 |
|
| 291 |
/********************************************************************************************************************/
|
| 292 |
/* REMOVED API LIST */
|
| 293 |
/********************************************************************************************************************/
|
| 294 |
/*
|
| 295 |
* From version 4.0.0:
|
| 296 |
* - dwt_setGPIOforEXTTRX: Replaced by dwt_setlnapamode to get equivalent functionality.
|
| 297 |
* - dwt_setGPIOdirection: Renamed to dwt_setgpiodirection.
|
| 298 |
* - dwt_setGPIOvalue: Renamed to dwt_setgpiovalue.
|
| 299 |
* - dwt_setrxmode: Replaced by dwt_setsniffmode and dwt_setlowpowerlistening depending on the RX mode the user
|
| 300 |
* wants to set up.
|
| 301 |
* - dwt_checkoverrun: As automatic RX re-enabling is not supported anymore, this functions has become useless.
|
| 302 |
* - dwt_setautorxreenable: As automatic RX re-enabling is not supported anymore, this functions has become
|
| 303 |
* useless.
|
| 304 |
* - dwt_getrangebias: Range bias correction values are platform dependent and should therefore be managed at user
|
| 305 |
* application level.
|
| 306 |
* - dwt_xtaltrim: Renamed to dwt_setxtaltrim.
|
| 307 |
* - dwt_checkIRQ: Renamed to dwt_checkirq.
|
| 308 |
*
|
| 309 |
* From version 3.0.0:
|
| 310 |
* - dwt_getldotune: As LDO loading is now automatically managed by the driver, this function has become useless.
|
| 311 |
* - dwt_getotptxpower: TX power values and location in OTP memory are platform dependent and should therefore be
|
| 312 |
* managed at user application level.
|
| 313 |
* - dwt_readantennadelay: Antenna delay values and location in OTP memory are platform dependent and should
|
| 314 |
* therefore be managed at user application level.
|
| 315 |
* - dwt_readdignostics: Renamed to dwt_readdiagnostics.
|
| 316 |
*/
|
| 317 |
|
| 318 |
/********************************************************************************************************************/
|
| 319 |
/* API LIST */
|