Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_dw1000.h @ 8c47f14b

History | View | Annotate | Download (75.55 KB)

1 fce9feec Robin Ewers
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3 f125ae07 Thomas Schöpping
Copyright (C) 2016..2019  Thomas Schöpping et al.
4 fce9feec Robin Ewers

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 8c47f14b Thomas Schöpping
#ifndef AMIROLLD_DW1000_H
32
#define AMIROLLD_DW1000_H
33 fce9feec Robin Ewers
34
#include <amiro-lld.h>
35 8c47f14b Thomas Schöpping
36 fce9feec Robin Ewers
#if defined(AMIROLLD_CFG_USE_DW1000) || defined(__DOXYGEN__)
37
38
39
40
#include <stddef.h>
41
#include <stdint.h>
42
#include <stdbool.h>
43
44
#define DW1000_DRIVER_VERSION               0x040005
45
#define DW1000_DEVICE_DRIVER_VER_STRING     "DW1000 Device Driver Version 04.00.05"
46
47
#ifndef DWT_NUM_DW_DEV
48
#define DWT_NUM_DW_DEV (1)
49
#endif
50
51
#define DWT_SUCCESS (0)
52
#define DWT_ERROR   (-1)
53
54
55
/**
56
 * @brief The DW1000 driver struct.
57
 */
58
typedef struct {
59
  apalSPIDriver_t* spid;    /**< @brief The SPI Driver */
60
  apalGpio_t* gpio_exti;    /**< @brief The GPIO indicating external interrupt */
61
  apalGpio_t* gpio_reset;  /**< @brief The GPIO indicating reset sig*/
62
  /* TODO: better apalControlGpio_t instead of apalGpio_t ? */
63
  /* TODO: EXTI, GPIO (RESET) */
64
} DW1000Driver;
65
66
67
#define DWT_TIME_UNITS  (1.0/499.2e6/128.0) //!< = 15.65e-12 s
68
69
#define DWT_DEVICE_ID   (0xDECA0130)        //!< DW1000 MP device ID
70
71
#define BUFFLEN         (4096+128)
72
73
//! constants for selecting the bit rate for data TX (and RX)
74
//! These are defined for write (with just a shift) the TX_FCTRL register
75
#define DWT_BR_110K     0   //!< UWB bit rate 110 kbits/s
76
#define DWT_BR_850K     1   //!< UWB bit rate 850 kbits/s
77
#define DWT_BR_6M8      2   //!< UWB bit rate 6.8 Mbits/s
78
79
//! constants for specifying the (Nominal) mean Pulse Repetition Frequency
80
//! These are defined for direct write (with a shift if necessary) to CHAN_CTRL and TX_FCTRL regs
81
#define DWT_PRF_16M     1   //!< UWB PRF 16 MHz
82
#define DWT_PRF_64M     2   //!< UWB PRF 64 MHz
83
84
//! constants for specifying Preamble Acquisition Chunk (PAC) Size in symbols
85
#define DWT_PAC8        0   //!< PAC  8 (recommended for RX of preamble length  128 and below
86
#define DWT_PAC16       1   //!< PAC 16 (recommended for RX of preamble length  256
87
#define DWT_PAC32       2   //!< PAC 32 (recommended for RX of preamble length  512
88
#define DWT_PAC64       3   //!< PAC 64 (recommended for RX of preamble length 1024 and up
89
90
//! constants for specifying TX Preamble length in symbols
91
//! These are defined to allow them be directly written into byte 2 of the TX_FCTRL register
92
//! (i.e. a four bit value destined for bits 20..18 but shifted left by 2 for byte alignment)
93
#define DWT_PLEN_4096   0x0C    //! Standard preamble length 4096 symbols
94
#define DWT_PLEN_2048   0x28    //! Non-standard preamble length 2048 symbols
95
#define DWT_PLEN_1536   0x18    //! Non-standard preamble length 1536 symbols
96
#define DWT_PLEN_1024   0x08    //! Standard preamble length 1024 symbols
97
#define DWT_PLEN_512    0x34    //! Non-standard preamble length 512 symbols
98
#define DWT_PLEN_256    0x24    //! Non-standard preamble length 256 symbols
99
#define DWT_PLEN_128    0x14    //! Non-standard preamble length 128 symbols
100
#define DWT_PLEN_64     0x04    //! Standard preamble length 64 symbols
101
102
#define DWT_SFDTOC_DEF              0x1041  // default SFD timeout value
103
104
#define DWT_PHRMODE_STD             0x0     // standard PHR mode
105
#define DWT_PHRMODE_EXT             0x3     // DW proprietary extended frames PHR mode
106
107
// Defined constants for "mode" bitmask parameter passed into dwt_starttx() function.
108
#define DWT_START_TX_IMMEDIATE      0
109
#define DWT_START_TX_DELAYED        1
110
#define DWT_RESPONSE_EXPECTED       2
111
112
#define DWT_START_RX_IMMEDIATE  0
113
#define DWT_START_RX_DELAYED    1    // Set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
114
#define DWT_IDLE_ON_DLY_ERR     2    // If delayed RX failed due to "late" error then if this
115
                                     // flag is set the RX will not be re-enabled immediately, and device will be in IDLE when function exits
116
#define DWT_NO_SYNC_PTRS        4    // Do not try to sync IC side and Host side buffer pointers when enabling RX. This is used to perform manual RX
117
                                     // re-enabling when receiving a frame in double buffer mode.
118
119
// Defined constants for "mode" bit field parameter passed to dwt_setleds() function.
120
#define DWT_LEDS_DISABLE     0x00
121
#define DWT_LEDS_ENABLE      0x01
122
#define DWT_LEDS_INIT_BLINK  0x02
123
124
//frame filtering configuration options
125
#define DWT_FF_NOTYPE_EN            0x000           // no frame types allowed (FF disabled)
126
#define DWT_FF_COORD_EN             0x002           // behave as coordinator (can receive frames with no dest address (PAN ID has to match))
127
#define DWT_FF_BEACON_EN            0x004           // beacon frames allowed
128
#define DWT_FF_DATA_EN              0x008           // data frames allowed
129
#define DWT_FF_ACK_EN               0x010           // ack frames allowed
130
#define DWT_FF_MAC_EN               0x020           // mac control frames allowed
131
#define DWT_FF_RSVD_EN              0x040           // reserved frame types allowed
132
133
//DW1000 interrupt events
134
#define DWT_INT_TFRS            0x00000080          // frame sent
135
#define DWT_INT_LDED            0x00000400          // micro-code has finished execution
136
#define DWT_INT_RFCG            0x00004000          // frame received with good CRC
137
#define DWT_INT_RPHE            0x00001000          // receiver PHY header error
138
#define DWT_INT_RFCE            0x00008000          // receiver CRC error
139
#define DWT_INT_RFSL            0x00010000          // receiver sync loss error
140
#define DWT_INT_RFTO            0x00020000          // frame wait timeout
141
#define DWT_INT_RXOVRR          0x00100000          // receiver overrun
142
#define DWT_INT_RXPTO           0x00200000          // preamble detect timeout
143
#define DWT_INT_SFDT            0x04000000          // SFD timeout
144
#define DWT_INT_ARFE            0x20000000          // frame rejected (due to frame filtering configuration)
145
146
147
//DW1000 SLEEP and WAKEUP configuration parameters
148
#define DWT_PRESRV_SLEEP 0x0100                      // PRES_SLEEP - on wakeup preserve sleep bit
149
#define DWT_LOADOPSET    0x0080                      // ONW_L64P - on wakeup load operating parameter set for 64 PSR
150
#define DWT_CONFIG       0x0040                      // ONW_LDC - on wakeup restore (load) the saved configurations (from AON array into HIF)
151
#define DWT_LOADEUI      0x0008                      // ONW_LEUI - on wakeup load EUI
152
#define DWT_RX_EN        0x0002                      // ONW_RX - on wakeup activate reception
153
#define DWT_TANDV        0x0001                      // ONW_RADC - on wakeup run ADC to sample temperature and voltage sensor values
154
155
#define DWT_XTAL_EN      0x10                       // keep XTAL running during sleep
156
#define DWT_WAKE_SLPCNT  0x8                        // wake up after sleep count
157
#define DWT_WAKE_CS      0x4                        // wake up on chip select
158
#define DWT_WAKE_WK      0x2                        // wake up on WAKEUP PIN
159
#define DWT_SLP_EN       0x1                        // enable sleep/deep sleep functionality
160
161
//DW1000 INIT configuration parameters
162
#define DWT_LOADUCODE     0x1
163
#define DWT_LOADNONE      0x0
164
165
//DW1000 OTP operating parameter set selection
166
#define DWT_OPSET_64LEN   0x0
167
#define DWT_OPSET_TIGHT   0x1
168
#define DWT_OPSET_DEFLT   0x2
169
170
// Call-back data RX frames flags
171
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit
172
173
174
// TX/RX call-back data
175
typedef struct
176
{
177
    uint32_t status;      //initial value of register as ISR is entered
178
    uint16_t datalength;  //length of frame
179
    uint8_t  fctrl[2];    //frame control bytes
180
    uint8_t  rx_flags;    //RX frame flags, see above
181
} dwt_cb_data_t;
182
183
// Call-back type for all events
184
typedef void (*dwt_cb_t)(const dwt_cb_data_t *);
185
186
187
// -------------------------------------------------------------------------------------------------------------------
188
// Structure to hold device data
189
typedef struct
190
{
191
    uint32_t      partID ;            // IC Part ID - read during initialisation
192
    uint32_t      lotID ;             // IC Lot ID - read during initialisation
193
    uint8_t       longFrames ;        // Flag in non-standard long frame mode
194
    uint8_t       otprev ;            // OTP revision number (read during initialisation)
195
    uint32_t      txFCTRL ;           // Keep TX_FCTRL register config
196
    uint8_t       init_xtrim;         // initial XTAL trim value read from OTP (or defaulted to mid-range if OTP not programmed)
197
    uint8_t       dblbuffon;          // Double RX buffer mode flag
198
    uint32_t      sysCFGreg ;         // Local copy of system config register
199
    uint16_t      sleep_mode;         // Used for automatic reloading of LDO tune and microcode at wake-up
200
    uint8_t       wait4resp ;         // wait4response was set with last TX start command
201
    dwt_cb_data_t cbData;             // Callback data structure
202
    dwt_cb_t      cbTxDone;           // Callback for TX confirmation event
203
    dwt_cb_t      cbRxOk;             // Callback for RX good frame event
204
    dwt_cb_t      cbRxTo;             // Callback for RX timeout events
205
    dwt_cb_t      cbRxErr;            // Callback for RX error events
206
    DW1000Driver  *driver;      // Reference to local hardware SPI, GPIO, ...
207
} dwt_local_data_t ;
208
209
/*! ------------------------------------------------------------------------------------------------------------------
210
 * Structure typedef: dwt_config_t
211
 *
212
 * Structure for setting device configuration via dwt_configure() function
213
 *
214
 */
215
typedef struct
216
{
217
    uint8_t chan ;           //!< channel number {1, 2, 3, 4, 5, 7 }
218
    uint8_t prf ;            //!< Pulse Repetition Frequency {DWT_PRF_16M or DWT_PRF_64M}
219
    uint8_t txPreambLength ; //!< DWT_PLEN_64..DWT_PLEN_4096
220
    uint8_t rxPAC ;          //!< Acquisition Chunk Size (Relates to RX preamble length)
221
    uint8_t txCode ;         //!< TX preamble code
222
    uint8_t rxCode ;         //!< RX preamble code
223
    uint8_t nsSFD ;          //!< Boolean should we use non-standard SFD for better performance
224