[SX126x] Fixed blocking receive (#777)
This commit is contained in:
parent
9472d5b635
commit
7f40ee49c6
1 changed files with 18 additions and 4 deletions
|
@ -304,17 +304,31 @@ int16_t SX126x::receive(uint8_t* data, size_t len) {
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
// wait for packet reception or timeout
|
// wait for packet reception or timeout
|
||||||
|
bool softTimeout = false;
|
||||||
uint32_t start = this->mod->hal->micros();
|
uint32_t start = this->mod->hal->micros();
|
||||||
while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
|
while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||||
this->mod->hal->yield();
|
this->mod->hal->yield();
|
||||||
|
// safety check, the timeout should be done by the radio
|
||||||
if(this->mod->hal->micros() - start > timeout) {
|
if(this->mod->hal->micros() - start > timeout) {
|
||||||
fixImplicitTimeout();
|
softTimeout = true;
|
||||||
clearIrqStatus();
|
break;
|
||||||
standby();
|
|
||||||
return(RADIOLIB_ERR_RX_TIMEOUT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if it was a timeout, this will return an error code
|
||||||
|
state = standby();
|
||||||
|
if((state != RADIOLIB_ERR_NONE) && (state != RADIOLIB_ERR_SPI_CMD_TIMEOUT)) {
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check whether this was a timeout or not
|
||||||
|
if((getIrqStatus() & RADIOLIB_SX126X_IRQ_TIMEOUT) || softTimeout) {
|
||||||
|
standby();
|
||||||
|
fixImplicitTimeout();
|
||||||
|
clearIrqStatus();
|
||||||
|
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
// fix timeout in implicit LoRa mode
|
// fix timeout in implicit LoRa mode
|
||||||
if(((this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) {
|
if(((this->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (getPacketType() == RADIOLIB_SX126X_PACKET_TYPE_LORA))) {
|
||||||
state = fixImplicitTimeout();
|
state = fixImplicitTimeout();
|
||||||
|
|
Loading…
Add table
Reference in a new issue