Skip to content

Commit

Permalink
Merge pull request #22 from TMRh20/Adjust-Available
Browse files Browse the repository at this point in the history
Adjust available function to let the radio receive more data immediately
- Move TASKS_START from the read() function to end of available() : Essentially 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
- When returning from available(), only restart reception by calling NRF_RADIO->TASKS_START = 1; if in listening mode.
  • Loading branch information
TMRh20 committed Mar 27, 2024
2 parents 9723dc6 + e54b1bd commit 89ee96e
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 89ee96e

Please sign in to comment.