init
Dependencies: aconno_I2C Lis2dh12 WatchdogTimer
DW1000/DW1000Utils.h@58:8d4a354816b1, 2020-02-17 (annotated)
- Committer:
- pathfindr
- Date:
- Mon Feb 17 23:24:52 2020 +0000
- Revision:
- 58:8d4a354816b1
usb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pathfindr | 58:8d4a354816b1 | 1 | #pragma once |
pathfindr | 58:8d4a354816b1 | 2 | |
pathfindr | 58:8d4a354816b1 | 3 | #include <mbed.h> |
pathfindr | 58:8d4a354816b1 | 4 | #include "DW1000.h" |
pathfindr | 58:8d4a354816b1 | 5 | |
pathfindr | 58:8d4a354816b1 | 6 | class DW1000Utils |
pathfindr | 58:8d4a354816b1 | 7 | { |
pathfindr | 58:8d4a354816b1 | 8 | public: |
pathfindr | 58:8d4a354816b1 | 9 | // Recommended settings: |
pathfindr | 58:8d4a354816b1 | 10 | // Data rate 110 kbps - Preamble length 2048 or 4096. |
pathfindr | 58:8d4a354816b1 | 11 | // Data rate 850 kbps - Preamble length 256, 512 or 1024. |
pathfindr | 58:8d4a354816b1 | 12 | // Data rate 6.8 Mbps - Preamble length 64. |
pathfindr | 58:8d4a354816b1 | 13 | |
pathfindr | 58:8d4a354816b1 | 14 | const static uint32_t PREAMBLE_LENGTH_64 = (1 << 18); |
pathfindr | 58:8d4a354816b1 | 15 | const static uint32_t PREAMBLE_LENGTH_128 = (1 << 18) | (1 << 20); |
pathfindr | 58:8d4a354816b1 | 16 | const static uint32_t PREAMBLE_LENGTH_256 = (1 << 18) | (1 << 21); |
pathfindr | 58:8d4a354816b1 | 17 | const static uint32_t PREAMBLE_LENGTH_512 = (1 << 18) | (1 << 20) | (1 << 21); |
pathfindr | 58:8d4a354816b1 | 18 | const static uint32_t PREAMBLE_LENGTH_1024 = (1 << 19); |
pathfindr | 58:8d4a354816b1 | 19 | const static uint32_t PREAMBLE_LENGTH_2048 = (1 << 19) | (1 << 21); |
pathfindr | 58:8d4a354816b1 | 20 | const static uint32_t PREAMBLE_LENGTH_4096 = (1 << 18) | (1 << 19); |
pathfindr | 58:8d4a354816b1 | 21 | |
pathfindr | 58:8d4a354816b1 | 22 | enum PrfSetting |
pathfindr | 58:8d4a354816b1 | 23 | { |
pathfindr | 58:8d4a354816b1 | 24 | PRF_16_MHz = 1, |
pathfindr | 58:8d4a354816b1 | 25 | PRF_64_MHz, |
pathfindr | 58:8d4a354816b1 | 26 | }; |
pathfindr | 58:8d4a354816b1 | 27 | |
pathfindr | 58:8d4a354816b1 | 28 | enum DataRateSetting |
pathfindr | 58:8d4a354816b1 | 29 | { |
pathfindr | 58:8d4a354816b1 | 30 | RATE_110_kbps = 1, |
pathfindr | 58:8d4a354816b1 | 31 | RATE_850_kbps, |
pathfindr | 58:8d4a354816b1 | 32 | RATE_6_8_Mbps, |
pathfindr | 58:8d4a354816b1 | 33 | }; |
pathfindr | 58:8d4a354816b1 | 34 | |
pathfindr | 58:8d4a354816b1 | 35 | // Set pulse repetition frequency |
pathfindr | 58:8d4a354816b1 | 36 | static void setPulseRepetitionFrequency(DW1000* dw_ptr, PrfSetting prf_setting) |
pathfindr | 58:8d4a354816b1 | 37 | { |
pathfindr | 58:8d4a354816b1 | 38 | // Transmit PRF setting (see page 75 of user manual) |
pathfindr | 58:8d4a354816b1 | 39 | uint32_t prf_value; |
pathfindr | 58:8d4a354816b1 | 40 | if (prf_setting == PRF_16_MHz) |
pathfindr | 58:8d4a354816b1 | 41 | { |
pathfindr | 58:8d4a354816b1 | 42 | prf_value = (1 << 16); |
pathfindr | 58:8d4a354816b1 | 43 | } |
pathfindr | 58:8d4a354816b1 | 44 | else |
pathfindr | 58:8d4a354816b1 | 45 | { |
pathfindr | 58:8d4a354816b1 | 46 | prf_value = (1 << 17); |
pathfindr | 58:8d4a354816b1 | 47 | } |
pathfindr | 58:8d4a354816b1 | 48 | uint32_t prf_mask = (1 << 16) | (1 << 17); |
pathfindr | 58:8d4a354816b1 | 49 | uint32_t tx_ctrl = dw_ptr->readRegister32(DW1000_TX_FCTRL, 0x00); |
pathfindr | 58:8d4a354816b1 | 50 | tx_ctrl &= ~prf_mask; |
pathfindr | 58:8d4a354816b1 | 51 | tx_ctrl |= (prf_value & prf_mask); |
pathfindr | 58:8d4a354816b1 | 52 | dw_ptr->writeRegister32(DW1000_TX_FCTRL, 0x00, tx_ctrl); |
pathfindr | 58:8d4a354816b1 | 53 | |
pathfindr | 58:8d4a354816b1 | 54 | // Receive PRF setting (see page 109 and of user manual) |
pathfindr | 58:8d4a354816b1 | 55 | if (prf_setting == PRF_16_MHz) |
pathfindr | 58:8d4a354816b1 | 56 | { |
pathfindr | 58:8d4a354816b1 | 57 | prf_value = (1 << 18); |
pathfindr | 58:8d4a354816b1 | 58 | } |
pathfindr | 58:8d4a354816b1 | 59 | else |
pathfindr | 58:8d4a354816b1 | 60 | { |
pathfindr | 58:8d4a354816b1 | 61 | prf_value = (1 << 19); |
pathfindr | 58:8d4a354816b1 | 62 | } |
pathfindr | 58:8d4a354816b1 | 63 | prf_mask = (1 << 18) | (1 << 19); |
pathfindr | 58:8d4a354816b1 | 64 | uint32_t chan_ctrl = dw_ptr->readRegister32(DW1000_CHAN_CTRL, 0x00); |
pathfindr | 58:8d4a354816b1 | 65 | chan_ctrl &= ~prf_mask; |
pathfindr | 58:8d4a354816b1 | 66 | chan_ctrl |= (prf_value & prf_mask); |
pathfindr | 58:8d4a354816b1 | 67 | dw_ptr->writeRegister32(DW1000_CHAN_CTRL, 0x00, chan_ctrl); |
pathfindr | 58:8d4a354816b1 | 68 | } |
pathfindr | 58:8d4a354816b1 | 69 | |
pathfindr | 58:8d4a354816b1 | 70 | // Set preamble length (see page 76 of user manual) |
pathfindr | 58:8d4a354816b1 | 71 | static void setPreambleLength(DW1000* dw_ptr, uint32_t preamble_setting) |
pathfindr | 58:8d4a354816b1 | 72 | { |
pathfindr | 58:8d4a354816b1 | 73 | uint32_t preamble_mask = (1 << 18) | (1 << 19) | (1 << 20) | (1 << 21); |
pathfindr | 58:8d4a354816b1 | 74 | uint32_t tx_ctrl = dw_ptr->readRegister32(DW1000_TX_FCTRL, 0x00); |
pathfindr | 58:8d4a354816b1 | 75 | tx_ctrl &= ~preamble_mask; |
pathfindr | 58:8d4a354816b1 | 76 | tx_ctrl |= (preamble_setting & preamble_mask); |
pathfindr | 58:8d4a354816b1 | 77 | dw_ptr->writeRegister32(DW1000_TX_FCTRL, 0x00, tx_ctrl); |
pathfindr | 58:8d4a354816b1 | 78 | } |
pathfindr | 58:8d4a354816b1 | 79 | |
pathfindr | 58:8d4a354816b1 | 80 | // Set data rate |
pathfindr | 58:8d4a354816b1 | 81 | static void setDataRate(DW1000* dw_ptr, DataRateSetting rate_setting) |
pathfindr | 58:8d4a354816b1 | 82 | { |
pathfindr | 58:8d4a354816b1 | 83 | // Transmit data rate (see page 73 of user manual) |
pathfindr | 58:8d4a354816b1 | 84 | uint32_t rate_value; |
pathfindr | 58:8d4a354816b1 | 85 | if (rate_setting == RATE_110_kbps) |
pathfindr | 58:8d4a354816b1 | 86 | { |
pathfindr | 58:8d4a354816b1 | 87 | rate_value = 0; |
pathfindr | 58:8d4a354816b1 | 88 | } |
pathfindr | 58:8d4a354816b1 | 89 | else if (rate_setting == RATE_850_kbps) |
pathfindr | 58:8d4a354816b1 | 90 | { |
pathfindr | 58:8d4a354816b1 | 91 | rate_value = (1 << 13); |
pathfindr | 58:8d4a354816b1 | 92 | } |
pathfindr | 58:8d4a354816b1 | 93 | else |
pathfindr | 58:8d4a354816b1 | 94 | { |
pathfindr | 58:8d4a354816b1 | 95 | rate_value = (1 << 14); |
pathfindr | 58:8d4a354816b1 | 96 | } |
pathfindr | 58:8d4a354816b1 | 97 | uint32_t rate_mask = (1 << 13) | (1 << 14); |
pathfindr | 58:8d4a354816b1 | 98 | uint32_t tx_ctrl = dw_ptr->readRegister32(DW1000_TX_FCTRL, 0x00); |
pathfindr | 58:8d4a354816b1 | 99 | tx_ctrl &= ~rate_mask; |
pathfindr | 58:8d4a354816b1 | 100 | tx_ctrl |= (rate_value & rate_mask); |
pathfindr | 58:8d4a354816b1 | 101 | dw_ptr->writeRegister32(DW1000_TX_FCTRL, 0x00, tx_ctrl); |
pathfindr | 58:8d4a354816b1 | 102 | |
pathfindr | 58:8d4a354816b1 | 103 | // Receive data rate (see page 72 of user manual) |
pathfindr | 58:8d4a354816b1 | 104 | if (rate_setting == RATE_110_kbps) |
pathfindr | 58:8d4a354816b1 | 105 | { |
pathfindr | 58:8d4a354816b1 | 106 | rate_value = (1 << 18); |
pathfindr | 58:8d4a354816b1 | 107 | rate_value = (1 << 22); |
pathfindr | 58:8d4a354816b1 | 108 | } |
pathfindr | 58:8d4a354816b1 | 109 | else if (rate_setting == RATE_850_kbps) |
pathfindr | 58:8d4a354816b1 | 110 | { |
pathfindr | 58:8d4a354816b1 | 111 | rate_value = (1 << 18); |
pathfindr | 58:8d4a354816b1 | 112 | } |
pathfindr | 58:8d4a354816b1 | 113 | else |
pathfindr | 58:8d4a354816b1 | 114 | { |
pathfindr | 58:8d4a354816b1 | 115 | rate_value = 0; |
pathfindr | 58:8d4a354816b1 | 116 | } |
pathfindr | 58:8d4a354816b1 | 117 | rate_mask = (1 << 18) | (1 << 22); |
pathfindr | 58:8d4a354816b1 | 118 | uint32_t sys_cfg = dw_ptr->readRegister32(DW1000_SYS_CFG, 0x00); |
pathfindr | 58:8d4a354816b1 | 119 | sys_cfg &= ~rate_mask; |
pathfindr | 58:8d4a354816b1 | 120 | sys_cfg |= (rate_value & rate_mask); |
pathfindr | 58:8d4a354816b1 | 121 | dw_ptr->writeRegister32(DW1000_SYS_CFG, 0x00, sys_cfg); |
pathfindr | 58:8d4a354816b1 | 122 | |
pathfindr | 58:8d4a354816b1 | 123 | if (rate_setting == RATE_110_kbps) |
pathfindr | 58:8d4a354816b1 | 124 | { |
pathfindr | 58:8d4a354816b1 | 125 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x02, 0x000A); // DRX_TUNE0b for 110 kbps |
pathfindr | 58:8d4a354816b1 | 126 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x06, 0x0064); // DRX_TUNE1b for 110 kbps & > 1024 symbols |
pathfindr | 58:8d4a354816b1 | 127 | } |
pathfindr | 58:8d4a354816b1 | 128 | else if (rate_setting == RATE_850_kbps) |
pathfindr | 58:8d4a354816b1 | 129 | { |
pathfindr | 58:8d4a354816b1 | 130 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x02, 0x0001); // DRX_TUNE0b for 850 kbps |
pathfindr | 58:8d4a354816b1 | 131 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x06, 0x0020); // DRX_TUNE1b for 850 kbps & 128 - 1024 symbols |
pathfindr | 58:8d4a354816b1 | 132 | } |
pathfindr | 58:8d4a354816b1 | 133 | else |
pathfindr | 58:8d4a354816b1 | 134 | { |
pathfindr | 58:8d4a354816b1 | 135 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x02, 0x0001); // DRX_TUNE0b for 6.8 Mbps |
pathfindr | 58:8d4a354816b1 | 136 | dw_ptr->writeRegister16(DW1000_DRX_CONF, 0x06, 0x0010); // DRX_TUNE1b for 6.8 Mbps & 64 symbols |
pathfindr | 58:8d4a354816b1 | 137 | } |
pathfindr | 58:8d4a354816b1 | 138 | } |
pathfindr | 58:8d4a354816b1 | 139 | |
pathfindr | 58:8d4a354816b1 | 140 | // Improved settings for direct path detection in non-line-of-sight environments. |
pathfindr | 58:8d4a354816b1 | 141 | // See DecaWave Application Note APS006. |
pathfindr | 58:8d4a354816b1 | 142 | static void setNLOSSettings(DW1000* dw_ptr, DataRateSetting rate_setting = RATE_850_kbps, PrfSetting prf_setting = PRF_16_MHz, uint32_t preamble_setting = PREAMBLE_LENGTH_1024) |
pathfindr | 58:8d4a354816b1 | 143 | { |
pathfindr | 58:8d4a354816b1 | 144 | setDataRate(dw_ptr, rate_setting); |
pathfindr | 58:8d4a354816b1 | 145 | setPulseRepetitionFrequency(dw_ptr, prf_setting); |
pathfindr | 58:8d4a354816b1 | 146 | setPreambleLength(dw_ptr, preamble_setting); |
pathfindr | 58:8d4a354816b1 | 147 | |
pathfindr | 58:8d4a354816b1 | 148 | // Setting for Noise Threshold Multiplier 1 |
pathfindr | 58:8d4a354816b1 | 149 | dw_ptr->writeRegister8(DW1000_LDE_CTRL, 0x0806, 0x07); // LDE_CFG1 |
pathfindr | 58:8d4a354816b1 | 150 | // Setting for Noise Threshold Multiplier 2 |
pathfindr | 58:8d4a354816b1 | 151 | if (prf_setting == PRF_16_MHz) |
pathfindr | 58:8d4a354816b1 | 152 | { |
pathfindr | 58:8d4a354816b1 | 153 | dw_ptr->writeRegister16(DW1000_LDE_CTRL, 0x1806, 0x0003); // LDE_CFG2 for 16 MHz PRF |
pathfindr | 58:8d4a354816b1 | 154 | } |
pathfindr | 58:8d4a354816b1 | 155 | else |
pathfindr | 58:8d4a354816b1 | 156 | { |
pathfindr | 58:8d4a354816b1 | 157 | dw_ptr->writeRegister16(DW1000_LDE_CTRL, 0x1806, 0x1603); // LDE_CFG2 for 64 MHz PRF |
pathfindr | 58:8d4a354816b1 | 158 | } |
pathfindr | 58:8d4a354816b1 | 159 | } |
pathfindr | 58:8d4a354816b1 | 160 | |
pathfindr | 58:8d4a354816b1 | 161 | // Default settings for line-of-sight environments |
pathfindr | 58:8d4a354816b1 | 162 | static void setLOSSettings(DW1000* dw_ptr, DataRateSetting rate_setting = RATE_850_kbps, PrfSetting prf_setting = PRF_16_MHz, uint32_t preamble_setting = PREAMBLE_LENGTH_1024) |
pathfindr | 58:8d4a354816b1 | 163 | { |
pathfindr | 58:8d4a354816b1 | 164 | setDataRate(dw_ptr, rate_setting); |
pathfindr | 58:8d4a354816b1 | 165 | setPulseRepetitionFrequency(dw_ptr, prf_setting); |
pathfindr | 58:8d4a354816b1 | 166 | setPreambleLength(dw_ptr, preamble_setting); |
pathfindr | 58:8d4a354816b1 | 167 | |
pathfindr | 58:8d4a354816b1 | 168 | // Setting for Noise Threshold Multiplier 1 |
pathfindr | 58:8d4a354816b1 | 169 | dw_ptr->writeRegister8(DW1000_LDE_CTRL, 0x0806, 0x0c); // LDE_CFG1 |
pathfindr | 58:8d4a354816b1 | 170 | // dw_ptr->writeRegister8(DW1000_LDE_CTRL, 0x0806, 0x0d); // LDE_CFG1 |
pathfindr | 58:8d4a354816b1 | 171 | // Setting for Noise Threshold Multiplier 2 |
pathfindr | 58:8d4a354816b1 | 172 | if (prf_setting == PRF_16_MHz) |
pathfindr | 58:8d4a354816b1 | 173 | { |
pathfindr | 58:8d4a354816b1 | 174 | dw_ptr->writeRegister16(DW1000_LDE_CTRL, 0x1806, 0x1607); // LDE_CFG2 for 16 MHz PRF |
pathfindr | 58:8d4a354816b1 | 175 | } |
pathfindr | 58:8d4a354816b1 | 176 | else |
pathfindr | 58:8d4a354816b1 | 177 | { |
pathfindr | 58:8d4a354816b1 | 178 | dw_ptr->writeRegister16(DW1000_LDE_CTRL, 0x1806, 0x0607); // LDE_CFG2 for 64 MHz PRF |
pathfindr | 58:8d4a354816b1 | 179 | } |
pathfindr | 58:8d4a354816b1 | 180 | } |
pathfindr | 58:8d4a354816b1 | 181 | }; |