Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LoRaWAN-SanJose_Bootcamp LoRaWAN-grove-cayenne LoRaWAN-classC-demo LoRaWAN-grove-cayenne ... more
Diff: radio/radio.cpp
- Revision:
- 4:e4bfe9183f94
- Parent:
- 0:6b3ac9c5a042
- Child:
- 7:4b6f960dcca2
--- a/radio/radio.cpp Mon Mar 05 16:49:15 2018 -0800 +++ b/radio/radio.cpp Mon Mar 19 14:39:06 2018 -0700 @@ -189,17 +189,17 @@ } #endif /* if 0 */ -//volatile bool fooEnable = false; - -void Radio::dio0callback() -{ - us_timestamp_t now = lpt.read_us(); +volatile struct pe { + uint8_t dio0 : 1; + uint8_t dio1 : 1; + uint8_t txing : 1; +} pinEvent; +volatile us_timestamp_t dio0at; - lora.RegIrqFlags.octet = radio.read_reg(REG_LR_IRQFLAGS); - - if (radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER || - radio.RegOpMode.bits.Mode == RF_OPMODE_RECEIVER_SINGLE) - { +void +Radio::dio0UserContext() +{ + if (!pinEvent.txing) { lora.service(); if (!lora.RegIrqFlags.bits.RxDone) { MAC_PRINTF("not-rxdone\r\n"); @@ -211,19 +211,27 @@ if (snr < 0) rssi += snr; //MAC_PRINTF("rxdone snr:%.2f, rssi:%d\r\n", snr, rssi); - //fooEnable = true; - RadioEvents->RxDone(radio.rx_buf, lora.RegRxNbBytes, rssi, snr, now); + RadioEvents->RxDone(radio.rx_buf, lora.RegRxNbBytes, rssi, snr, dio0at); } - } else if (radio.RegOpMode.bits.Mode == RF_OPMODE_TRANSMITTER) { - if (!lora.RegIrqFlags.bits.TxDone) { - MAC_PRINTF("not-txdone\r\n"); - } else if (RadioEvents->TxDone) - RadioEvents->TxDone(now); + } +} + +void Radio::dio0isr() +{ + dio0at = lpt.read_us(); + + if (pinEvent.txing) { + /* TxDone handling requires low latency */ + if (RadioEvents->TxDone) + RadioEvents->TxDone(dio0at); + lora.service(); - } -} // ..dio0callback() + pinEvent.txing = 0; + } else + pinEvent.dio0 = 1; +} -void Radio::dio1callback() +void Radio::dio1UserContext() { lora.RegIrqFlags.octet = radio.read_reg(REG_LR_IRQFLAGS); @@ -234,10 +242,15 @@ RadioEvents->RxTimeout(); } +void Radio::dio1isr() +{ + pinEvent.dio1 = 1; +} + void Radio::Init(const RadioEvents_t* e) { - dio0.rise(dio0callback); - dio1.rise(dio1callback); + dio0.rise(dio0isr); + dio1.rise(dio1isr); radio.rf_switch = rfsw_callback; boardInit(); @@ -256,6 +269,7 @@ lora.RegPayloadLength = size; radio.write_reg(REG_LR_PAYLOADLENGTH, lora.RegPayloadLength); lora.start_tx(size); + pinEvent.txing = 1; } /*volatile RadioState_t state; @@ -272,6 +286,8 @@ else lora.start_rx(RF_OPMODE_RECEIVER_SINGLE); + pinEvent.txing = 0; + MAC_PRINTF("start_rx "); } @@ -382,3 +398,15 @@ } #endif /* DUTY_ENABLE */ +void Radio::UserContext() +{ + if (pinEvent.dio0) { + dio0UserContext(); + pinEvent.dio0 = 0; + } + + if (pinEvent.dio1) { + dio1UserContext(); + pinEvent.dio1 = 0; + } +}