1

Committer:
Wayne Roberts
Date:
Fri Feb 05 16:35:05 2021 -0800
Revision:
21:96db08266089
Parent:
17:5f34cbe2ac53
lr1110: handle tcxo when hf-xosc fails to start

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wayne Roberts 17:5f34cbe2ac53 1 #include "radio.h"
Wayne Roberts 17:5f34cbe2ac53 2 #ifdef SX1265_H
Wayne Roberts 17:5f34cbe2ac53 3 #include "SPIu.h"
Wayne Roberts 17:5f34cbe2ac53 4
Wayne Roberts 17:5f34cbe2ac53 5 #ifdef TARGET_FF_ARDUINO
Wayne Roberts 17:5f34cbe2ac53 6 SPI spi(D11, D12, D13); // mosi, miso, sclk
Wayne Roberts 17:5f34cbe2ac53 7 //spi, nss, busy, dio9, nreset
Wayne Roberts 17:5f34cbe2ac53 8 SX1265 Radio::radio(spi, D7, D3, D5, A0);
Wayne Roberts 17:5f34cbe2ac53 9
Wayne Roberts 17:5f34cbe2ac53 10 static void initRfSwDIO()
Wayne Roberts 17:5f34cbe2ac53 11 {
Wayne Roberts 17:5f34cbe2ac53 12 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 13 uint8_t dioBuf[8];
Wayne Roberts 17:5f34cbe2ac53 14 /* antenna truth table
Wayne Roberts 17:5f34cbe2ac53 15 * V1 V2 port
Wayne Roberts 17:5f34cbe2ac53 16 * 0 0 shutdown
Wayne Roberts 17:5f34cbe2ac53 17 * 1 0 J2 rx RFI
Wayne Roberts 17:5f34cbe2ac53 18 * 0 1 J1 HP tx RFO
Wayne Roberts 17:5f34cbe2ac53 19 * 1 1 J3 LP tx RFO
Wayne Roberts 17:5f34cbe2ac53 20 * DIO5 DIO6
Wayne Roberts 17:5f34cbe2ac53 21 */
Wayne Roberts 17:5f34cbe2ac53 22 dioBuf[ DIO_en_IDX] = DIO5_BIT | DIO6_BIT;
Wayne Roberts 17:5f34cbe2ac53 23 dioBuf[DIO_stby_IDX] = 0;
Wayne Roberts 17:5f34cbe2ac53 24 dioBuf[ DIO_rx_IDX] = DIO5_BIT;
Wayne Roberts 17:5f34cbe2ac53 25 dioBuf[ DIO_tx_IDX] = DIO5_BIT | DIO6_BIT;
Wayne Roberts 17:5f34cbe2ac53 26 dioBuf[DIO_txhp_IDX] = DIO6_BIT;
Wayne Roberts 17:5f34cbe2ac53 27 dioBuf[DIO_gnss_IDX] = 0;
Wayne Roberts 17:5f34cbe2ac53 28 dioBuf[DIO_wifi_IDX] = 0;
Wayne Roberts 17:5f34cbe2ac53 29 /*stat.word =*/ Radio::radio.xfer(OPCODE_SET_DIO_AS_RFSWITCH, 8, 0, dioBuf);
Wayne Roberts 17:5f34cbe2ac53 30 }
Wayne Roberts 17:5f34cbe2ac53 31 #else
Wayne Roberts 17:5f34cbe2ac53 32 /* declare pins for form-factor */
Wayne Roberts 17:5f34cbe2ac53 33 #error non-ardiuno-form-factor
Wayne Roberts 17:5f34cbe2ac53 34 #endif /* TARGET_FF_ARDUINO */
Wayne Roberts 17:5f34cbe2ac53 35
Wayne Roberts 17:5f34cbe2ac53 36 uint8_t gfsk_pp_buf[9];
Wayne Roberts 17:5f34cbe2ac53 37 uint8_t gfsk_mp_buf[10];
Wayne Roberts 17:5f34cbe2ac53 38 uint8_t lora_pp_buf[6];
Wayne Roberts 17:5f34cbe2ac53 39 uint8_t lora_mp_buf[4];
Wayne Roberts 17:5f34cbe2ac53 40
Wayne Roberts 17:5f34cbe2ac53 41 const RadioEvents_t* RadioEvents;
Wayne Roberts 17:5f34cbe2ac53 42 LowPowerTimer Radio::lpt;
Wayne Roberts 17:5f34cbe2ac53 43 volatile us_timestamp_t Radio::irqAt;
Wayne Roberts 17:5f34cbe2ac53 44 uint8_t Radio::loraTimeoutSymbols;
Wayne Roberts 17:5f34cbe2ac53 45
Wayne Roberts 17:5f34cbe2ac53 46 void Radio::LoRaPacketConfig(unsigned preambleLen, bool fixLen, bool crcOn, bool invIQ)
Wayne Roberts 17:5f34cbe2ac53 47 {
Wayne Roberts 17:5f34cbe2ac53 48 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 49 if (radio.getPacketType() != PACKET_TYPE_LORA)
Wayne Roberts 17:5f34cbe2ac53 50 radio.setPacketType(PACKET_TYPE_LORA);
Wayne Roberts 17:5f34cbe2ac53 51
Wayne Roberts 17:5f34cbe2ac53 52 radio.to_big_endian16(preambleLen, lora_pp_buf);
Wayne Roberts 17:5f34cbe2ac53 53 lora_pp_buf[2] = fixLen;
Wayne Roberts 17:5f34cbe2ac53 54 /* lora_pp_buf[3] = set when txing, initialized to zero in Init */
Wayne Roberts 17:5f34cbe2ac53 55 lora_pp_buf[4] = crcOn;
Wayne Roberts 17:5f34cbe2ac53 56 lora_pp_buf[5] = invIQ;
Wayne Roberts 17:5f34cbe2ac53 57 /*stat.word =*/ radio.xfer(OPCODE_SET_PACKET_PARAM, 6, 0, lora_pp_buf);
Wayne Roberts 17:5f34cbe2ac53 58 }
Wayne Roberts 17:5f34cbe2ac53 59
Wayne Roberts 17:5f34cbe2ac53 60 void Radio::set_tx_dbm(int8_t dbm)
Wayne Roberts 17:5f34cbe2ac53 61 {
Wayne Roberts 17:5f34cbe2ac53 62 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 63 uint8_t buf[4];
Wayne Roberts 17:5f34cbe2ac53 64 int8_t txpower;
Wayne Roberts 17:5f34cbe2ac53 65 unsigned PaSel, RegPaSupply, PaDutyCycle, PaHPSel;
Wayne Roberts 17:5f34cbe2ac53 66
Wayne Roberts 17:5f34cbe2ac53 67 if (dbm > 20) {
Wayne Roberts 17:5f34cbe2ac53 68 txpower = 22;
Wayne Roberts 17:5f34cbe2ac53 69 PaSel = 1;
Wayne Roberts 17:5f34cbe2ac53 70 RegPaSupply = 1;
Wayne Roberts 17:5f34cbe2ac53 71 PaDutyCycle = 4;
Wayne Roberts 17:5f34cbe2ac53 72 PaHPSel = 7;
Wayne Roberts 17:5f34cbe2ac53 73 } else if (dbm > 17) {
Wayne Roberts 17:5f34cbe2ac53 74 txpower = 22;
Wayne Roberts 17:5f34cbe2ac53 75 PaSel = 1;
Wayne Roberts 17:5f34cbe2ac53 76 RegPaSupply = 1;
Wayne Roberts 17:5f34cbe2ac53 77 PaDutyCycle = 2;
Wayne Roberts 17:5f34cbe2ac53 78 PaHPSel = 7;
Wayne Roberts 17:5f34cbe2ac53 79 } else if (dbm > 15) {
Wayne Roberts 17:5f34cbe2ac53 80 txpower = 22;
Wayne Roberts 17:5f34cbe2ac53 81 PaSel = 1;
Wayne Roberts 17:5f34cbe2ac53 82 RegPaSupply = 1;
Wayne Roberts 17:5f34cbe2ac53 83 PaDutyCycle = 4;
Wayne Roberts 17:5f34cbe2ac53 84 PaHPSel = 3;
Wayne Roberts 17:5f34cbe2ac53 85 } else {
Wayne Roberts 17:5f34cbe2ac53 86 txpower = 14;
Wayne Roberts 17:5f34cbe2ac53 87 PaSel = 0;
Wayne Roberts 17:5f34cbe2ac53 88 RegPaSupply = 0;
Wayne Roberts 17:5f34cbe2ac53 89 if (dbm > 14)
Wayne Roberts 17:5f34cbe2ac53 90 PaDutyCycle = 7;
Wayne Roberts 17:5f34cbe2ac53 91 else if (dbm > 10)
Wayne Roberts 17:5f34cbe2ac53 92 PaDutyCycle = 4;
Wayne Roberts 17:5f34cbe2ac53 93 else
Wayne Roberts 17:5f34cbe2ac53 94 PaDutyCycle = 0;
Wayne Roberts 17:5f34cbe2ac53 95 PaHPSel = 0;
Wayne Roberts 17:5f34cbe2ac53 96 }
Wayne Roberts 17:5f34cbe2ac53 97
Wayne Roberts 17:5f34cbe2ac53 98 buf[0] = PaSel;
Wayne Roberts 17:5f34cbe2ac53 99 buf[1] = RegPaSupply;
Wayne Roberts 17:5f34cbe2ac53 100 buf[2] = PaDutyCycle;
Wayne Roberts 17:5f34cbe2ac53 101 buf[3] = PaHPSel;
Wayne Roberts 17:5f34cbe2ac53 102 /*stat.word =*/ radio.xfer(OPCODE_SET_PA_CONFIG, 4, 0, buf);
Wayne Roberts 17:5f34cbe2ac53 103
Wayne Roberts 17:5f34cbe2ac53 104 buf[0] = txpower;
Wayne Roberts 17:5f34cbe2ac53 105 buf[1] = 4;
Wayne Roberts 17:5f34cbe2ac53 106 /*stat.word =*/ radio.xfer(OPCODE_SET_TXPARAMS, 2, 0, buf);
Wayne Roberts 17:5f34cbe2ac53 107 }
Wayne Roberts 17:5f34cbe2ac53 108
Wayne Roberts 17:5f34cbe2ac53 109 void Radio::SetChannel(unsigned hz)
Wayne Roberts 17:5f34cbe2ac53 110 {
Wayne Roberts 17:5f34cbe2ac53 111 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 112 uint8_t buf[4];
Wayne Roberts 17:5f34cbe2ac53 113 radio.to_big_endian32(hz, buf);
Wayne Roberts 17:5f34cbe2ac53 114 /*stat.word =*/ radio.xfer(OPCODE_SET_RF_FREQ_HZ, 4, 0, buf);
Wayne Roberts 17:5f34cbe2ac53 115 }
Wayne Roberts 17:5f34cbe2ac53 116
Wayne Roberts 17:5f34cbe2ac53 117 void Radio::Standby()
Wayne Roberts 17:5f34cbe2ac53 118 {
Wayne Roberts 17:5f34cbe2ac53 119 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 120 uint8_t buf = 0; // 0=rc, 1=xosc
Wayne Roberts 17:5f34cbe2ac53 121 /*stat.word =*/ radio.xfer(OPCODE_SET_STANDBY, 1, 0, &buf);
Wayne Roberts 17:5f34cbe2ac53 122 }
Wayne Roberts 17:5f34cbe2ac53 123
Wayne Roberts 17:5f34cbe2ac53 124 void Radio::LoRaModemConfig(unsigned bwKHz, uint8_t sf, uint8_t cr)
Wayne Roberts 17:5f34cbe2ac53 125 {
Wayne Roberts 17:5f34cbe2ac53 126 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 127 uint8_t buf[4];
Wayne Roberts 17:5f34cbe2ac53 128 uint8_t ldro = 0;
Wayne Roberts 17:5f34cbe2ac53 129
Wayne Roberts 17:5f34cbe2ac53 130 if (radio.getPacketType() != PACKET_TYPE_LORA)
Wayne Roberts 17:5f34cbe2ac53 131 radio.setPacketType(PACKET_TYPE_LORA);
Wayne Roberts 17:5f34cbe2ac53 132
Wayne Roberts 17:5f34cbe2ac53 133 if (bwKHz > 500)
Wayne Roberts 17:5f34cbe2ac53 134 buf[1] = LORA_BW_1000KHz;
Wayne Roberts 17:5f34cbe2ac53 135 else if (bwKHz > 250)
Wayne Roberts 17:5f34cbe2ac53 136 buf[1] = LORA_BW_500KHz;
Wayne Roberts 17:5f34cbe2ac53 137 else if (bwKHz > 125) {
Wayne Roberts 17:5f34cbe2ac53 138 buf[1] = LORA_BW_250KHz;
Wayne Roberts 17:5f34cbe2ac53 139 } else if (bwKHz > 80) {
Wayne Roberts 17:5f34cbe2ac53 140 buf[1] = LORA_BW_125KHz;
Wayne Roberts 17:5f34cbe2ac53 141 if (sf > 11)
Wayne Roberts 17:5f34cbe2ac53 142 ldro = 1;
Wayne Roberts 17:5f34cbe2ac53 143 } else if (bwKHz > 16) {
Wayne Roberts 17:5f34cbe2ac53 144 buf[1] = LORA_BW_31_25KHz;
Wayne Roberts 17:5f34cbe2ac53 145 if (sf > 10)
Wayne Roberts 17:5f34cbe2ac53 146 ldro = 1;
Wayne Roberts 17:5f34cbe2ac53 147 } else if (bwKHz > 8) {
Wayne Roberts 17:5f34cbe2ac53 148 buf[1] = LORA_BW_15_6KHz;
Wayne Roberts 17:5f34cbe2ac53 149 if (sf > 9)
Wayne Roberts 17:5f34cbe2ac53 150 ldro = 1;
Wayne Roberts 17:5f34cbe2ac53 151 } else {
Wayne Roberts 17:5f34cbe2ac53 152 buf[1] = LORA_BW_7_8KHz;
Wayne Roberts 17:5f34cbe2ac53 153 if (sf > 8)
Wayne Roberts 17:5f34cbe2ac53 154 ldro = 1;
Wayne Roberts 17:5f34cbe2ac53 155 }
Wayne Roberts 17:5f34cbe2ac53 156
Wayne Roberts 17:5f34cbe2ac53 157 buf[0] = sf;
Wayne Roberts 17:5f34cbe2ac53 158 buf[2] = cr;
Wayne Roberts 17:5f34cbe2ac53 159 buf[3] = ldro;
Wayne Roberts 17:5f34cbe2ac53 160 /*stat.word =*/ radio.xfer(OPCODE_SET_MODULATION, 4, 0, buf);
Wayne Roberts 17:5f34cbe2ac53 161 }
Wayne Roberts 17:5f34cbe2ac53 162
Wayne Roberts 17:5f34cbe2ac53 163 int Radio::Send(uint8_t size, timestamp_t maxListenTime, timestamp_t channelFreeTime, int rssiThresh)
Wayne Roberts 17:5f34cbe2ac53 164 {
Wayne Roberts 17:5f34cbe2ac53 165 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 166 uint8_t pktType;
Wayne Roberts 17:5f34cbe2ac53 167
Wayne Roberts 17:5f34cbe2ac53 168 pktType = radio.getPacketType();
Wayne Roberts 17:5f34cbe2ac53 169 if (pktType == PACKET_TYPE_LORA) {
Wayne Roberts 17:5f34cbe2ac53 170 lora_pp_buf[3] = size;
Wayne Roberts 17:5f34cbe2ac53 171 /*stat.word =*/ radio.xfer(OPCODE_SET_PACKET_PARAM, 6, 0, lora_pp_buf);
Wayne Roberts 17:5f34cbe2ac53 172 } else if (pktType == PACKET_TYPE_GFSK) {
Wayne Roberts 17:5f34cbe2ac53 173 gfsk_pp_buf[6] = size;
Wayne Roberts 17:5f34cbe2ac53 174 /*stat.word =*/ radio.xfer(OPCODE_SET_PACKET_PARAM, 9, 0, gfsk_pp_buf);
Wayne Roberts 17:5f34cbe2ac53 175 }
Wayne Roberts 17:5f34cbe2ac53 176
Wayne Roberts 17:5f34cbe2ac53 177 /* TODO: LBT */
Wayne Roberts 17:5f34cbe2ac53 178
Wayne Roberts 17:5f34cbe2ac53 179 radio.start_tx(size);
Wayne Roberts 17:5f34cbe2ac53 180 return 0;
Wayne Roberts 17:5f34cbe2ac53 181 }
Wayne Roberts 17:5f34cbe2ac53 182
Wayne Roberts 17:5f34cbe2ac53 183 void Radio::service()
Wayne Roberts 17:5f34cbe2ac53 184 {
Wayne Roberts 17:5f34cbe2ac53 185 irq_t irq;
Wayne Roberts 17:5f34cbe2ac53 186 irq.dword = radio.service();
Wayne Roberts 17:5f34cbe2ac53 187 if (irq.dword != 0) {
Wayne Roberts 17:5f34cbe2ac53 188 }
Wayne Roberts 17:5f34cbe2ac53 189 }
Wayne Roberts 17:5f34cbe2ac53 190
Wayne Roberts 21:96db08266089 191 bool Radio::init_irq;
Wayne Roberts 21:96db08266089 192 void Radio::my_irq_handler()
Wayne Roberts 21:96db08266089 193 {
Wayne Roberts 21:96db08266089 194 /* radio irq immediately after hardware reset: hf_xosc start due to TCXO */
Wayne Roberts 21:96db08266089 195 init_irq = true;
Wayne Roberts 21:96db08266089 196 }
Wayne Roberts 21:96db08266089 197
Wayne Roberts 17:5f34cbe2ac53 198 void Radio::dio9_top_half()
Wayne Roberts 17:5f34cbe2ac53 199 {
Wayne Roberts 17:5f34cbe2ac53 200 irqAt = lpt.read_us();
Wayne Roberts 17:5f34cbe2ac53 201
Wayne Roberts 17:5f34cbe2ac53 202 if (RadioEvents->DioPin_top_half)
Wayne Roberts 17:5f34cbe2ac53 203 RadioEvents->DioPin_top_half();
Wayne Roberts 17:5f34cbe2ac53 204
Wayne Roberts 17:5f34cbe2ac53 205 if (radio.chipMode == CHIPMODE_TX) {
Wayne Roberts 17:5f34cbe2ac53 206 /* TxDone handling requires low latency */
Wayne Roberts 17:5f34cbe2ac53 207 if (RadioEvents->TxDone_topHalf) {
Wayne Roberts 17:5f34cbe2ac53 208 RadioEvents->TxDone_topHalf();
Wayne Roberts 17:5f34cbe2ac53 209 }
Wayne Roberts 17:5f34cbe2ac53 210 } else {
Wayne Roberts 17:5f34cbe2ac53 211 #ifdef RX_INDICATION
Wayne Roberts 17:5f34cbe2ac53 212 RX_INDICATION = 0;
Wayne Roberts 17:5f34cbe2ac53 213 #endif
Wayne Roberts 17:5f34cbe2ac53 214 }
Wayne Roberts 17:5f34cbe2ac53 215 }
Wayne Roberts 17:5f34cbe2ac53 216
Wayne Roberts 17:5f34cbe2ac53 217 void Radio::timeout_callback(bool tx)
Wayne Roberts 17:5f34cbe2ac53 218 {
Wayne Roberts 17:5f34cbe2ac53 219 if (!tx) {
Wayne Roberts 17:5f34cbe2ac53 220 if (RadioEvents->RxTimeout)
Wayne Roberts 17:5f34cbe2ac53 221 RadioEvents->RxTimeout();
Wayne Roberts 17:5f34cbe2ac53 222 } // else TODO tx timeout
Wayne Roberts 17:5f34cbe2ac53 223 }
Wayne Roberts 17:5f34cbe2ac53 224
Wayne Roberts 17:5f34cbe2ac53 225 void Radio::rx_done(uint8_t size, float rssi, float snr)
Wayne Roberts 17:5f34cbe2ac53 226 {
Wayne Roberts 17:5f34cbe2ac53 227 RadioEvents->RxDone(size, rssi, snr);
Wayne Roberts 17:5f34cbe2ac53 228 }
Wayne Roberts 17:5f34cbe2ac53 229
Wayne Roberts 17:5f34cbe2ac53 230 void Radio::txDoneBottom()
Wayne Roberts 17:5f34cbe2ac53 231 {
Wayne Roberts 17:5f34cbe2ac53 232 if (RadioEvents->TxDone_botHalf)
Wayne Roberts 17:5f34cbe2ac53 233 RadioEvents->TxDone_botHalf();
Wayne Roberts 17:5f34cbe2ac53 234 }
Wayne Roberts 17:5f34cbe2ac53 235
Wayne Roberts 17:5f34cbe2ac53 236 void Radio::Init(const RadioEvents_t* e, unsigned spi_hz)
Wayne Roberts 17:5f34cbe2ac53 237 {
Wayne Roberts 21:96db08266089 238 uint64_t a, b;
Wayne Roberts 17:5f34cbe2ac53 239 /* initialize payload length to zero in packet params */
Wayne Roberts 17:5f34cbe2ac53 240 lora_pp_buf[3] = 0;
Wayne Roberts 17:5f34cbe2ac53 241 gfsk_pp_buf[6] = 0;
Wayne Roberts 17:5f34cbe2ac53 242
Wayne Roberts 17:5f34cbe2ac53 243 radio.txDone = txDoneBottom;
Wayne Roberts 17:5f34cbe2ac53 244 radio.rxDone = rx_done;
Wayne Roberts 17:5f34cbe2ac53 245 radio.timeout = timeout_callback;
Wayne Roberts 17:5f34cbe2ac53 246 //radio.chipModeChange = chipModeChange;
Wayne Roberts 17:5f34cbe2ac53 247
Wayne Roberts 17:5f34cbe2ac53 248 RadioEvents = e;
Wayne Roberts 17:5f34cbe2ac53 249 lpt.start();
Wayne Roberts 17:5f34cbe2ac53 250
Wayne Roberts 17:5f34cbe2ac53 251 spi.frequency(spi_hz);
Wayne Roberts 17:5f34cbe2ac53 252
Wayne Roberts 21:96db08266089 253 radio.dio9_topHalf = my_irq_handler;
Wayne Roberts 21:96db08266089 254 init_irq = false;
Wayne Roberts 17:5f34cbe2ac53 255 radio.hw_reset();
Wayne Roberts 21:96db08266089 256 a = Kernel::get_ms_count();
Wayne Roberts 21:96db08266089 257 do {
Wayne Roberts 21:96db08266089 258 b = Kernel::get_ms_count();
Wayne Roberts 21:96db08266089 259 /* wait for radio interrupt at hardware reset, failure to start hf_xosc */
Wayne Roberts 21:96db08266089 260 if (init_irq) {
Wayne Roberts 21:96db08266089 261 radio.service();
Wayne Roberts 21:96db08266089 262 break;
Wayne Roberts 21:96db08266089 263 }
Wayne Roberts 21:96db08266089 264 } while ((b - a) < 30);
Wayne Roberts 21:96db08266089 265
Wayne Roberts 21:96db08266089 266 radio.dio9_topHalf = dio9_top_half;
Wayne Roberts 17:5f34cbe2ac53 267
Wayne Roberts 17:5f34cbe2ac53 268 initRfSwDIO();
Wayne Roberts 17:5f34cbe2ac53 269 }
Wayne Roberts 17:5f34cbe2ac53 270
Wayne Roberts 17:5f34cbe2ac53 271 void Radio::SetLoRaSymbolTimeout(uint16_t symbs)
Wayne Roberts 17:5f34cbe2ac53 272 {
Wayne Roberts 17:5f34cbe2ac53 273 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 274 if (radio.getPacketType() != PACKET_TYPE_LORA)
Wayne Roberts 17:5f34cbe2ac53 275 radio.setPacketType(PACKET_TYPE_LORA);
Wayne Roberts 17:5f34cbe2ac53 276
Wayne Roberts 17:5f34cbe2ac53 277 loraTimeoutSymbols = symbs;
Wayne Roberts 17:5f34cbe2ac53 278 /*stat.word =*/ radio.xfer(OPCODE_SET_LORA_SYNC_TIMEOUT, 1, 0, &loraTimeoutSymbols);
Wayne Roberts 17:5f34cbe2ac53 279 }
Wayne Roberts 17:5f34cbe2ac53 280
Wayne Roberts 17:5f34cbe2ac53 281 void Radio::Rx(unsigned timeout)
Wayne Roberts 17:5f34cbe2ac53 282 {
Wayne Roberts 17:5f34cbe2ac53 283 /*stat_t stat;*/
Wayne Roberts 17:5f34cbe2ac53 284 uint8_t buf[3];
Wayne Roberts 17:5f34cbe2ac53 285 unsigned rx_timeout;
Wayne Roberts 17:5f34cbe2ac53 286
Wayne Roberts 17:5f34cbe2ac53 287 if (radio.getPacketType() == PACKET_TYPE_LORA) {
Wayne Roberts 17:5f34cbe2ac53 288 /*stat.word =*/ radio.xfer(OPCODE_SET_LORA_SYNC_TIMEOUT, 1, 0, &loraTimeoutSymbols);
Wayne Roberts 17:5f34cbe2ac53 289 }
Wayne Roberts 17:5f34cbe2ac53 290
Wayne Roberts 17:5f34cbe2ac53 291 if (timeout == 0)
Wayne Roberts 17:5f34cbe2ac53 292 rx_timeout = 0xffffff; // receive until instructed otherwise
Wayne Roberts 17:5f34cbe2ac53 293 else
Wayne Roberts 17:5f34cbe2ac53 294 rx_timeout = timeout;
Wayne Roberts 17:5f34cbe2ac53 295
Wayne Roberts 17:5f34cbe2ac53 296 radio.to_big_endian24(rx_timeout, buf);
Wayne Roberts 17:5f34cbe2ac53 297 /*stat.word =*/ radio.xfer(OPCODE_SET_RX, 3, 0, buf);
Wayne Roberts 17:5f34cbe2ac53 298
Wayne Roberts 17:5f34cbe2ac53 299 }
Wayne Roberts 17:5f34cbe2ac53 300
Wayne Roberts 17:5f34cbe2ac53 301 #endif /* ..SX126x_H */