Skip to content

Commit

Permalink
Adjust available function
Browse files Browse the repository at this point in the history
- When returning, only restart reception by calling `NRF_RADIO->TASKS_START = 1;` if in listening mode.
- Move TASKS_START from the `read()` function to end of `available()` : Utilize the 2-layer FIFO instead of single layer - Start reception as soon as the available() function ends, so that the radio can receive a packet while we are reading in the already received packet that has been copied into the user buffer
  • Loading branch information
TMRh20 committed Mar 26, 2024
1 parent 9723dc6 commit e54b1bd
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/nrf_to_nrf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,21 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
NRF_RADIO->EVENTS_CRCOK = 0;
if (DPL){
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 4 && NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}else
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 3 && NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}else
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 2 && NRF_RADIO->CRCCNF == 0) {
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}
}
Expand Down Expand Up @@ -299,7 +305,9 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
// duplicate
if(NRF_RADIO->CRCCNF != 0) { //If CRC enabled, check this data
if (packetCtr == lastPacketCounter && packetData == lastData) {
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}
}
Expand All @@ -312,14 +320,18 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
if (DPL) {
if (!decrypt(&rxBuffer[1], rxBuffer[0] - CCM_IV_SIZE - CCM_COUNTER_SIZE)) {
Serial.println("DECRYPT FAIL");
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}
}
else {
if (!decrypt(&rxBuffer[1], staticPayloadSize - CCM_IV_SIZE - CCM_COUNTER_SIZE)) {
Serial.println("DECRYPT FAIL");
NRF_RADIO->TASKS_START = 1;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 0;
}
}
Expand All @@ -339,6 +351,9 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
lastPacketCounter = packetCtr;
lastData = packetData;
payloadAvailable = true;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
return 1;
}
if(NRF_RADIO->EVENTS_CRCERROR) {
Expand All @@ -354,9 +369,6 @@ void nrf_to_nrf::read(void* buf, uint8_t len)
{
memcpy(buf, &rxBuffer[1], len);
ackPayloadAvailable = false;
if (inRxMode) {
NRF_RADIO->TASKS_START = 1;
}
payloadAvailable = false;
}

Expand Down

0 comments on commit e54b1bd

Please sign in to comment.