DW1000 UWB driver based on work of Matthias Grob & Manuel Stalder - ETH Zürich - 2015

Dependencies:   BurstSPI

Committer:
AndyA
Date:
Mon Nov 13 14:29:41 2017 +0000
Revision:
18:6c2ce1749d4a
Parent:
9:326bf149c8bc
Auto apply crystal trim on startup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AndyA 8:0b408e77b701 1 #ifndef __DW1000SETUP_H__
AndyA 8:0b408e77b701 2 #define __DW1000SETUP_H__
AndyA 8:0b408e77b701 3
AndyA 8:0b408e77b701 4 #include "mbed.h"
AndyA 8:0b408e77b701 5 /** Class for holding DW1000 config options
AndyA 8:0b408e77b701 6 *
AndyA 8:0b408e77b701 7 * Defaults are channel 5, 16MHz PRF, 850kb/s, standard SFD, 128 symbol preamble, preamble code 3.
AndyA 8:0b408e77b701 8 * All pins are GPIO other than sync and IRQ.
AndyA 8:0b408e77b701 9 * Smart power is off.
AndyA 8:0b408e77b701 10 *
AndyA 8:0b408e77b701 11 */
AndyA 8:0b408e77b701 12 class DW1000Setup
AndyA 8:0b408e77b701 13 {
AndyA 8:0b408e77b701 14 public:
AndyA 8:0b408e77b701 15
AndyA 8:0b408e77b701 16 /** Supported UWB modes
AndyA 8:0b408e77b701 17 *
AndyA 8:0b408e77b701 18 * enum for preset mode combinations
AndyA 8:0b408e77b701 19 */
AndyA 8:0b408e77b701 20 typedef enum {fastLocationC5, ///< maximum data speed, short range. Channel 5
AndyA 18:6c2ce1749d4a 21 fastLocationC4, ///< maximum data speed, short range. Channel 4
AndyA 8:0b408e77b701 22 tunedDefault, ///< The power up default config with the recomended changes
AndyA 8:0b408e77b701 23 user110k, ///< 110kb/s settings used by Matthias Grob & Manuel Stalder
AndyA 8:0b408e77b701 24 rangeRateCompromise ///< 850kb/s settings aimed to give a short packet but with far greater range than the fastLocation options
AndyA 8:0b408e77b701 25 } UWBMode;
AndyA 8:0b408e77b701 26
AndyA 8:0b408e77b701 27 /** Constructor
AndyA 8:0b408e77b701 28 * @param modeToUse The operating mode to set the initial settings to.
AndyA 8:0b408e77b701 29 *
AndyA 8:0b408e77b701 30 */
AndyA 8:0b408e77b701 31 DW1000Setup(UWBMode modeToUse = tunedDefault);
AndyA 8:0b408e77b701 32
AndyA 8:0b408e77b701 33
AndyA 8:0b408e77b701 34 /// copy constructor
AndyA 8:0b408e77b701 35 DW1000Setup(DW1000Setup *orij);
AndyA 8:0b408e77b701 36
AndyA 8:0b408e77b701 37 /// Update this config to match the supplied one
AndyA 8:0b408e77b701 38 void applyConfig(DW1000Setup *orij);
AndyA 8:0b408e77b701 39
AndyA 8:0b408e77b701 40
AndyA 8:0b408e77b701 41 /// enum for PRF options
AndyA 8:0b408e77b701 42 enum prf_e {prf16MHz, ///< PRF rate of 16MHz. Lower power
AndyA 8:0b408e77b701 43 prf64MHz ///< PRF rate of 64MHz. Higher power but more accurate timing.
AndyA 8:0b408e77b701 44 };
AndyA 8:0b408e77b701 45
AndyA 8:0b408e77b701 46 /// enum for data rate options
AndyA 8:0b408e77b701 47 enum dataRate_e {kbps110, ///< Data rate of 110kb/s (non-standard)
AndyA 8:0b408e77b701 48 kbps850,///< Data rate of 850kb/s
AndyA 8:0b408e77b701 49 kbps6800///< Data rate of 6.8Mb/s
AndyA 8:0b408e77b701 50 };
AndyA 8:0b408e77b701 51
AndyA 8:0b408e77b701 52 /** enum for SFD options
AndyA 8:0b408e77b701 53 *
AndyA 8:0b408e77b701 54 * To conform to the standard the standard setting should be used.
AndyA 8:0b408e77b701 55 * The decawave setting claimes to give better performance. Doesn't work for me at 850kb/s but does at 6.8Mb/s
AndyA 8:0b408e77b701 56 */
AndyA 8:0b408e77b701 57 enum sfd_e {standard, ///< IEEE standard SFD
AndyA 8:0b408e77b701 58 decaWave, ///< Decawave defined SFD
AndyA 8:0b408e77b701 59 user ///< user defined SFD
AndyA 8:0b408e77b701 60 };
AndyA 8:0b408e77b701 61
AndyA 8:0b408e77b701 62 /// enum for preamble length options
AndyA 8:0b408e77b701 63 enum preamble_e { pre64,///< Preamble is 64 symbols
AndyA 8:0b408e77b701 64 pre128,///< Preamble is 128 symbols (non-standard)
AndyA 8:0b408e77b701 65 pre256,///< Preamble is 256 symbols (non-standard)
AndyA 8:0b408e77b701 66 pre512,///< Preamble is 512 symbols (non-standard)
AndyA 8:0b408e77b701 67 pre1024,///< Preamble is 1024 symbols
AndyA 8:0b408e77b701 68 pre1536,///< Preamble is 1536 symbols (non-standard)
AndyA 8:0b408e77b701 69 pre2048, ///< Preamble is 2048 symbols (non-standard)
AndyA 8:0b408e77b701 70 pre4096///< Preamble is 4096 symbols
AndyA 8:0b408e77b701 71 };
AndyA 8:0b408e77b701 72
AndyA 8:0b408e77b701 73 /** Set the Transmit power for smartpower operation
AndyA 8:0b408e77b701 74 * @param powerdBm The gain setting in dBm (0-33.5)
AndyA 8:0b408e77b701 75 * @param power500us The gain setting packets under 500us in dBm (0-33.5)
AndyA 8:0b408e77b701 76 * @param power250us The gain setting packets under 250us in dBm (0-33.5)
AndyA 8:0b408e77b701 77 * @param power125us The gain setting packets under 125us in dBm (0-33.5)
AndyA 8:0b408e77b701 78 * @return true if a valid option
AndyA 8:0b408e77b701 79 */
AndyA 8:0b408e77b701 80 bool setSmartTxPower(float powerdBm,float power500us=0,float power250us=0,float power125us=0) ;
AndyA 8:0b408e77b701 81
AndyA 8:0b408e77b701 82 /** Set the Transmit power for non-smartpower operation
AndyA 8:0b408e77b701 83 * @param powerdBm The gain setting in dBm for the main packet(0-33.5)
AndyA 8:0b408e77b701 84 * @param powerPRF The gain setting in dBm for the preamble (0-33.5)
AndyA 8:0b408e77b701 85 * @return true if a valid option
AndyA 8:0b408e77b701 86 */
AndyA 8:0b408e77b701 87 bool setTxPower(float powerdBm,float powerPRF=0);
AndyA 8:0b408e77b701 88
AndyA 8:0b408e77b701 89
AndyA 8:0b408e77b701 90 /** Set the PRF
AndyA 8:0b408e77b701 91 * @return true if a valid option
AndyA 8:0b408e77b701 92 */
AndyA 8:0b408e77b701 93 bool setPRF(enum prf_e newSetting) {
AndyA 8:0b408e77b701 94 prf = newSetting;
AndyA 8:0b408e77b701 95 return true;
AndyA 8:0b408e77b701 96 };
AndyA 8:0b408e77b701 97
AndyA 8:0b408e77b701 98 /** Set the Channel
AndyA 8:0b408e77b701 99 * @return true if a valid option
AndyA 8:0b408e77b701 100 *
AndyA 8:0b408e77b701 101 * channels are 1-5 & 7
AndyA 8:0b408e77b701 102 */
AndyA 8:0b408e77b701 103 bool setChannel(unsigned char newChannel) {
AndyA 8:0b408e77b701 104 if ((newChannel > 0) && ((newChannel <= 5) || (newChannel == 7))) {
AndyA 8:0b408e77b701 105 channel = newChannel;
AndyA 8:0b408e77b701 106 return true;
AndyA 8:0b408e77b701 107 }
AndyA 8:0b408e77b701 108 return false;
AndyA 8:0b408e77b701 109 };
AndyA 8:0b408e77b701 110 /** Set the SFD
AndyA 8:0b408e77b701 111 * @return true if a valid option
AndyA 8:0b408e77b701 112 */
AndyA 8:0b408e77b701 113 bool setSfd(enum sfd_e newSetting) {
AndyA 8:0b408e77b701 114 sfd = newSetting;
AndyA 8:0b408e77b701 115 return true;
AndyA 8:0b408e77b701 116 };
AndyA 8:0b408e77b701 117 /** Set the Preamble length
AndyA 8:0b408e77b701 118 * @return true if a valid option
AndyA 8:0b408e77b701 119 *
AndyA 8:0b408e77b701 120 * For 6.8Mb/s it should be 64 to 256 symbols.
AndyA 8:0b408e77b701 121 * For 850kb/s it should be 256 to 2048 symbols
AndyA 8:0b408e77b701 122 * For 110kb/s it should be >= 2048 symbols.
AndyA 8:0b408e77b701 123 */
AndyA 8:0b408e77b701 124 bool setPreambleLength(enum preamble_e newSetting) {
AndyA 8:0b408e77b701 125 preamble = newSetting;
AndyA 8:0b408e77b701 126 return true;
AndyA 8:0b408e77b701 127 };
AndyA 8:0b408e77b701 128 /** Set the Data rate
AndyA 8:0b408e77b701 129 * @return true if a valid option
AndyA 8:0b408e77b701 130 */
AndyA 8:0b408e77b701 131 bool setDataRate(enum dataRate_e newSetting) {
AndyA 8:0b408e77b701 132 dataRate = newSetting;
AndyA 8:0b408e77b701 133 return true;
AndyA 8:0b408e77b701 134 };
AndyA 8:0b408e77b701 135 /** Set the Preamble code
AndyA 8:0b408e77b701 136 * @return true if a valid option
AndyA 8:0b408e77b701 137 *
AndyA 9:326bf149c8bc 138 * @note Not all codes are valid for all channels, see the table below
AndyA 9:326bf149c8bc 139
AndyA 9:326bf149c8bc 140 <table>
AndyA 9:326bf149c8bc 141 <tr><th>channel</th><th>16MHzPrf</th><th>64MHzPrf</th></tr>
AndyA 9:326bf149c8bc 142 <tr><td>1</td><td>1, 2</td><td>9, 10, 11, 12</td></tr>
AndyA 9:326bf149c8bc 143 <tr><td>2</td><td>3, 4</td><td>9, 10, 11, 12</td></tr>
AndyA 9:326bf149c8bc 144 <tr><td>3</td><td>5, 6</td><td>9, 10, 11, 12</td></tr>
AndyA 9:326bf149c8bc 145 <tr><td>4</td><td>7, 8</td><td>17, 18, 19, 20</td></tr>
AndyA 9:326bf149c8bc 146 <tr><td>5</td><td>3, 4</td><td>9, 10, 11, 12</td></tr>
AndyA 9:326bf149c8bc 147 <tr><td>7</td><td>7, 8</td><td>17, 18, 19, 20</td></tr>
AndyA 9:326bf149c8bc 148 </table>
AndyA 8:0b408e77b701 149
AndyA 8:0b408e77b701 150 */
AndyA 8:0b408e77b701 151 bool setPreambleCode(unsigned char newCode) {
AndyA 8:0b408e77b701 152 if ((newCode > 0) && (newCode <= 24)) {
AndyA 8:0b408e77b701 153 preambleCode = newCode;
AndyA 8:0b408e77b701 154 return true;
AndyA 8:0b408e77b701 155 }
AndyA 8:0b408e77b701 156 return false;
AndyA 8:0b408e77b701 157 };
AndyA 8:0b408e77b701 158 /** Set the smartpower state
AndyA 8:0b408e77b701 159 * @return true if a valid option
AndyA 8:0b408e77b701 160 *
AndyA 8:0b408e77b701 161 * only takes effect at 6.8Mb/s
AndyA 8:0b408e77b701 162 */
AndyA 8:0b408e77b701 163 bool setSmartPower(bool enable) {
AndyA 8:0b408e77b701 164 enableSmartPower = enable;
AndyA 8:0b408e77b701 165 return true;
AndyA 8:0b408e77b701 166 };
AndyA 8:0b408e77b701 167
AndyA 8:0b408e77b701 168
AndyA 8:0b408e77b701 169 /** Get the current transmit gains
AndyA 8:0b408e77b701 170 * @return An array containing the power levels
AndyA 8:0b408e77b701 171 *
AndyA 8:0b408e77b701 172 * An array of 4 floats is returned.
AndyA 8:0b408e77b701 173 * For smart power these are the 4 power levels (normal, <500us, <250us, <125us).
AndyA 8:0b408e77b701 174 * For non-smart power the first and last values are ignored, the second is the power for the phy header, the 3rd is the power for the reaminder of the frame.
AndyA 8:0b408e77b701 175 */
AndyA 8:0b408e77b701 176 const float *getTxPowers() {
AndyA 8:0b408e77b701 177 return powers;
AndyA 8:0b408e77b701 178 }
AndyA 8:0b408e77b701 179
AndyA 8:0b408e77b701 180 /** Get the current channel
AndyA 8:0b408e77b701 181 * @return the channel number
AndyA 8:0b408e77b701 182 */
AndyA 8:0b408e77b701 183 unsigned char getChannel() {
AndyA 8:0b408e77b701 184 return channel;
AndyA 8:0b408e77b701 185 };
AndyA 8:0b408e77b701 186 /** Get the current PRF
AndyA 8:0b408e77b701 187 * @return the PRF
AndyA 8:0b408e77b701 188 */
AndyA 8:0b408e77b701 189 enum prf_e getPRF() {
AndyA 8:0b408e77b701 190 return prf;
AndyA 8:0b408e77b701 191 };
AndyA 8:0b408e77b701 192 /** Get the current data rate
AndyA 8:0b408e77b701 193 * @return the data rate
AndyA 8:0b408e77b701 194 */
AndyA 8:0b408e77b701 195 enum dataRate_e getDataRate() {
AndyA 8:0b408e77b701 196 return dataRate;
AndyA 8:0b408e77b701 197 };
AndyA 8:0b408e77b701 198
AndyA 8:0b408e77b701 199 /** Get the current SFD mode
AndyA 8:0b408e77b701 200 * @return the SFD
AndyA 8:0b408e77b701 201 */
AndyA 8:0b408e77b701 202 enum sfd_e getSfd() {
AndyA 8:0b408e77b701 203 return sfd;
AndyA 8:0b408e77b701 204 };
AndyA 8:0b408e77b701 205 /** Get the current preamble length
AndyA 8:0b408e77b701 206 * @return the preamble length
AndyA 8:0b408e77b701 207 */
AndyA 8:0b408e77b701 208 enum preamble_e getPreambleLength() {
AndyA 8:0b408e77b701 209 return preamble;
AndyA 8:0b408e77b701 210 };
AndyA 8:0b408e77b701 211 /** Get the current preamble code
AndyA 8:0b408e77b701 212 * @return the preamble code
AndyA 8:0b408e77b701 213 */
AndyA 8:0b408e77b701 214 unsigned char getPreambleCode() {
AndyA 8:0b408e77b701 215 return preambleCode;
AndyA 8:0b408e77b701 216 };
AndyA 8:0b408e77b701 217 /** Get the current smart power mode
AndyA 8:0b408e77b701 218 * @return true if smartpower is on
AndyA 8:0b408e77b701 219 */
AndyA 8:0b408e77b701 220 bool getSmartPower() {
AndyA 8:0b408e77b701 221 return enableSmartPower;
AndyA 8:0b408e77b701 222 };
AndyA 8:0b408e77b701 223
AndyA 8:0b408e77b701 224 /** Set which pins are GPIO
AndyA 8:0b408e77b701 225 *
AndyA 8:0b408e77b701 226 * @param pins A bitmask of which pins are not to be used as GPIO
AndyA 8:0b408e77b701 227 *
AndyA 8:0b408e77b701 228 * e.g. 0x01 sets GPIO0 as it's alternative function (RXOKLED) and all other pins to be GPIO.
AndyA 8:0b408e77b701 229 *
AndyA 8:0b408e77b701 230 * The default is 0x0180 - GPIO 8 = irq, GPIO 7 = sync. All others are GPIO functionality
AndyA 8:0b408e77b701 231 */
AndyA 8:0b408e77b701 232 void setGPIO(uint16_t pins) {
AndyA 8:0b408e77b701 233 GPIO_Pins = pins;
AndyA 8:0b408e77b701 234 };
AndyA 8:0b408e77b701 235
AndyA 8:0b408e77b701 236 /** Get which pins are GPIO
AndyA 8:0b408e77b701 237 *
AndyA 8:0b408e77b701 238 * @return A bitmask of which pins are not to be used as GPIO
AndyA 8:0b408e77b701 239 *
AndyA 8:0b408e77b701 240 * e.g. 0x01 Indicates that GPIO0 as it's alternative function (RXOKLED) and all other pins to be GPIO.
AndyA 8:0b408e77b701 241 *
AndyA 8:0b408e77b701 242 * The default is 0x0180 - GPIO 8 = irq, GPIO 7 = sync. All others are GPIO functionality
AndyA 8:0b408e77b701 243 */
AndyA 8:0b408e77b701 244 uint16_t getGPIO() {
AndyA 8:0b408e77b701 245 return GPIO_Pins;
AndyA 8:0b408e77b701 246 };
AndyA 8:0b408e77b701 247
AndyA 8:0b408e77b701 248 /** Check that the settings are self consistent
AndyA 8:0b408e77b701 249 *
AndyA 8:0b408e77b701 250 * @return true if the settings are valid
AndyA 8:0b408e77b701 251 *
AndyA 8:0b408e77b701 252 * Will check the following:
AndyA 8:0b408e77b701 253 * - Preamble size is sensible for the data rate
AndyA 8:0b408e77b701 254 * - Preamble code is valid for the channel
AndyA 8:0b408e77b701 255 * - That smart power is only enabled at 6.8Mb/s
AndyA 8:0b408e77b701 256 */
AndyA 8:0b408e77b701 257 bool check();
AndyA 8:0b408e77b701 258
AndyA 8:0b408e77b701 259 /** Get setup description
AndyA 8:0b408e77b701 260 *
AndyA 8:0b408e77b701 261 * @param buffer Data buffer to place description in
AndyA 8:0b408e77b701 262 * @param len Length of data buffer
AndyA 8:0b408e77b701 263 *
AndyA 8:0b408e77b701 264 * Places a text string describing the current setup into the suppled buffer.
AndyA 8:0b408e77b701 265 */
AndyA 8:0b408e77b701 266 void getSetupDescription(char *buffer, int len);
AndyA 8:0b408e77b701 267
AndyA 8:0b408e77b701 268 private:
AndyA 8:0b408e77b701 269 float powers[4];
AndyA 8:0b408e77b701 270 uint16_t GPIO_Pins;
AndyA 8:0b408e77b701 271 unsigned char channel; // 1-5 , 7
AndyA 8:0b408e77b701 272 enum prf_e prf;
AndyA 8:0b408e77b701 273 enum dataRate_e dataRate;
AndyA 8:0b408e77b701 274 enum sfd_e sfd;
AndyA 8:0b408e77b701 275 enum preamble_e preamble;
AndyA 8:0b408e77b701 276 unsigned char preambleCode; // 1-24. See section 10.5 of user manual for details.
AndyA 8:0b408e77b701 277 bool enableSmartPower;
AndyA 8:0b408e77b701 278 };
AndyA 8:0b408e77b701 279
AndyA 8:0b408e77b701 280 #endif