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

Dependencies:   BurstSPI

Committer:
AndyA
Date:
Mon Apr 18 16:58:27 2016 +0000
Revision:
8:0b408e77b701
Child:
9:326bf149c8bc
f

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 8:0b408e77b701 21 fastLocationC4, ///< maximum data speed, short range. Channel 5
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 8:0b408e77b701 138 * note - not all codes are valid for all channels
AndyA 8:0b408e77b701 139 *
AndyA 8:0b408e77b701 140 *channel 16MHzPrf 64MHzPrf
AndyA 8:0b408e77b701 141 1 1,2 9, 10, 11, 12
AndyA 8:0b408e77b701 142 2 3, 4 9, 10, 11, 12
AndyA 8:0b408e77b701 143 3 5, 6 9, 10, 11, 12
AndyA 8:0b408e77b701 144 4 7, 8 17, 18, 19, 20
AndyA 8:0b408e77b701 145 5 3, 4 9, 10, 11, 12
AndyA 8:0b408e77b701 146 7 7, 8 17, 18, 19, 20
AndyA 8:0b408e77b701 147
AndyA 8:0b408e77b701 148 */
AndyA 8:0b408e77b701 149 bool setPreambleCode(unsigned char newCode) {
AndyA 8:0b408e77b701 150 if ((newCode > 0) && (newCode <= 24)) {
AndyA 8:0b408e77b701 151 preambleCode = newCode;
AndyA 8:0b408e77b701 152 return true;
AndyA 8:0b408e77b701 153 }
AndyA 8:0b408e77b701 154 return false;
AndyA 8:0b408e77b701 155 };
AndyA 8:0b408e77b701 156 /** Set the smartpower state
AndyA 8:0b408e77b701 157 * @return true if a valid option
AndyA 8:0b408e77b701 158 *
AndyA 8:0b408e77b701 159 * only takes effect at 6.8Mb/s
AndyA 8:0b408e77b701 160 */
AndyA 8:0b408e77b701 161 bool setSmartPower(bool enable) {
AndyA 8:0b408e77b701 162 enableSmartPower = enable;
AndyA 8:0b408e77b701 163 return true;
AndyA 8:0b408e77b701 164 };
AndyA 8:0b408e77b701 165
AndyA 8:0b408e77b701 166
AndyA 8:0b408e77b701 167 /** Get the current transmit gains
AndyA 8:0b408e77b701 168 * @return An array containing the power levels
AndyA 8:0b408e77b701 169 *
AndyA 8:0b408e77b701 170 * An array of 4 floats is returned.
AndyA 8:0b408e77b701 171 * For smart power these are the 4 power levels (normal, <500us, <250us, <125us).
AndyA 8:0b408e77b701 172 * 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 173 */
AndyA 8:0b408e77b701 174 const float *getTxPowers() {
AndyA 8:0b408e77b701 175 return powers;
AndyA 8:0b408e77b701 176 }
AndyA 8:0b408e77b701 177
AndyA 8:0b408e77b701 178 /** Get the current channel
AndyA 8:0b408e77b701 179 * @return the channel number
AndyA 8:0b408e77b701 180 */
AndyA 8:0b408e77b701 181 unsigned char getChannel() {
AndyA 8:0b408e77b701 182 return channel;
AndyA 8:0b408e77b701 183 };
AndyA 8:0b408e77b701 184 /** Get the current PRF
AndyA 8:0b408e77b701 185 * @return the PRF
AndyA 8:0b408e77b701 186 */
AndyA 8:0b408e77b701 187 enum prf_e getPRF() {
AndyA 8:0b408e77b701 188 return prf;
AndyA 8:0b408e77b701 189 };
AndyA 8:0b408e77b701 190 /** Get the current data rate
AndyA 8:0b408e77b701 191 * @return the data rate
AndyA 8:0b408e77b701 192 */
AndyA 8:0b408e77b701 193 enum dataRate_e getDataRate() {
AndyA 8:0b408e77b701 194 return dataRate;
AndyA 8:0b408e77b701 195 };
AndyA 8:0b408e77b701 196
AndyA 8:0b408e77b701 197 /** Get the current SFD mode
AndyA 8:0b408e77b701 198 * @return the SFD
AndyA 8:0b408e77b701 199 */
AndyA 8:0b408e77b701 200 enum sfd_e getSfd() {
AndyA 8:0b408e77b701 201 return sfd;
AndyA 8:0b408e77b701 202 };
AndyA 8:0b408e77b701 203 /** Get the current preamble length
AndyA 8:0b408e77b701 204 * @return the preamble length
AndyA 8:0b408e77b701 205 */
AndyA 8:0b408e77b701 206 enum preamble_e getPreambleLength() {
AndyA 8:0b408e77b701 207 return preamble;
AndyA 8:0b408e77b701 208 };
AndyA 8:0b408e77b701 209 /** Get the current preamble code
AndyA 8:0b408e77b701 210 * @return the preamble code
AndyA 8:0b408e77b701 211 */
AndyA 8:0b408e77b701 212 unsigned char getPreambleCode() {
AndyA 8:0b408e77b701 213 return preambleCode;
AndyA 8:0b408e77b701 214 };
AndyA 8:0b408e77b701 215 /** Get the current smart power mode
AndyA 8:0b408e77b701 216 * @return true if smartpower is on
AndyA 8:0b408e77b701 217 */
AndyA 8:0b408e77b701 218 bool getSmartPower() {
AndyA 8:0b408e77b701 219 return enableSmartPower;
AndyA 8:0b408e77b701 220 };
AndyA 8:0b408e77b701 221
AndyA 8:0b408e77b701 222 /** Set which pins are GPIO
AndyA 8:0b408e77b701 223 *
AndyA 8:0b408e77b701 224 * @param pins A bitmask of which pins are not to be used as GPIO
AndyA 8:0b408e77b701 225 *
AndyA 8:0b408e77b701 226 * e.g. 0x01 sets GPIO0 as it's alternative function (RXOKLED) and all other pins to be GPIO.
AndyA 8:0b408e77b701 227 *
AndyA 8:0b408e77b701 228 * The default is 0x0180 - GPIO 8 = irq, GPIO 7 = sync. All others are GPIO functionality
AndyA 8:0b408e77b701 229 */
AndyA 8:0b408e77b701 230 void setGPIO(uint16_t pins) {
AndyA 8:0b408e77b701 231 GPIO_Pins = pins;
AndyA 8:0b408e77b701 232 };
AndyA 8:0b408e77b701 233
AndyA 8:0b408e77b701 234 /** Get which pins are GPIO
AndyA 8:0b408e77b701 235 *
AndyA 8:0b408e77b701 236 * @return A bitmask of which pins are not to be used as GPIO
AndyA 8:0b408e77b701 237 *
AndyA 8:0b408e77b701 238 * e.g. 0x01 Indicates that GPIO0 as it's alternative function (RXOKLED) and all other pins to be GPIO.
AndyA 8:0b408e77b701 239 *
AndyA 8:0b408e77b701 240 * The default is 0x0180 - GPIO 8 = irq, GPIO 7 = sync. All others are GPIO functionality
AndyA 8:0b408e77b701 241 */
AndyA 8:0b408e77b701 242 uint16_t getGPIO() {
AndyA 8:0b408e77b701 243 return GPIO_Pins;
AndyA 8:0b408e77b701 244 };
AndyA 8:0b408e77b701 245
AndyA 8:0b408e77b701 246 /** Check that the settings are self consistent
AndyA 8:0b408e77b701 247 *
AndyA 8:0b408e77b701 248 * @return true if the settings are valid
AndyA 8:0b408e77b701 249 *
AndyA 8:0b408e77b701 250 * Will check the following:
AndyA 8:0b408e77b701 251 * - Preamble size is sensible for the data rate
AndyA 8:0b408e77b701 252 * - Preamble code is valid for the channel
AndyA 8:0b408e77b701 253 * - That smart power is only enabled at 6.8Mb/s
AndyA 8:0b408e77b701 254 */
AndyA 8:0b408e77b701 255 bool check();
AndyA 8:0b408e77b701 256
AndyA 8:0b408e77b701 257 /** Get setup description
AndyA 8:0b408e77b701 258 *
AndyA 8:0b408e77b701 259 * @param buffer Data buffer to place description in
AndyA 8:0b408e77b701 260 * @param len Length of data buffer
AndyA 8:0b408e77b701 261 *
AndyA 8:0b408e77b701 262 * Places a text string describing the current setup into the suppled buffer.
AndyA 8:0b408e77b701 263 */
AndyA 8:0b408e77b701 264 void getSetupDescription(char *buffer, int len);
AndyA 8:0b408e77b701 265
AndyA 8:0b408e77b701 266 private:
AndyA 8:0b408e77b701 267 float powers[4];
AndyA 8:0b408e77b701 268 uint16_t GPIO_Pins;
AndyA 8:0b408e77b701 269 unsigned char channel; // 1-5 , 7
AndyA 8:0b408e77b701 270 enum prf_e prf;
AndyA 8:0b408e77b701 271 enum dataRate_e dataRate;
AndyA 8:0b408e77b701 272 enum sfd_e sfd;
AndyA 8:0b408e77b701 273 enum preamble_e preamble;
AndyA 8:0b408e77b701 274 unsigned char preambleCode; // 1-24. See section 10.5 of user manual for details.
AndyA 8:0b408e77b701 275 bool enableSmartPower;
AndyA 8:0b408e77b701 276 };
AndyA 8:0b408e77b701 277
AndyA 8:0b408e77b701 278 #endif