Skip to content

Commit 89ee96e

Browse files
authored
Merge pull request #22 from TMRh20/Adjust-Available
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.
2 parents 9723dc6 + e54b1bd commit 89ee96e

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/nrf_to_nrf.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,21 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
204204
NRF_RADIO->EVENTS_CRCOK = 0;
205205
if (DPL){
206206
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 4 && NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
207-
NRF_RADIO->TASKS_START = 1;
207+
if (inRxMode) {
208+
NRF_RADIO->TASKS_START = 1;
209+
}
208210
return 0;
209211
}else
210212
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 3 && NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
211-
NRF_RADIO->TASKS_START = 1;
213+
if (inRxMode) {
214+
NRF_RADIO->TASKS_START = 1;
215+
}
212216
return 0;
213217
}else
214218
if (radioData[0] > ACTUAL_MAX_PAYLOAD_SIZE - 2 && NRF_RADIO->CRCCNF == 0) {
215-
NRF_RADIO->TASKS_START = 1;
219+
if (inRxMode) {
220+
NRF_RADIO->TASKS_START = 1;
221+
}
216222
return 0;
217223
}
218224
}
@@ -299,7 +305,9 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
299305
// duplicate
300306
if(NRF_RADIO->CRCCNF != 0) { //If CRC enabled, check this data
301307
if (packetCtr == lastPacketCounter && packetData == lastData) {
302-
NRF_RADIO->TASKS_START = 1;
308+
if (inRxMode) {
309+
NRF_RADIO->TASKS_START = 1;
310+
}
303311
return 0;
304312
}
305313
}
@@ -312,14 +320,18 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
312320
if (DPL) {
313321
if (!decrypt(&rxBuffer[1], rxBuffer[0] - CCM_IV_SIZE - CCM_COUNTER_SIZE)) {
314322
Serial.println("DECRYPT FAIL");
315-
NRF_RADIO->TASKS_START = 1;
323+
if (inRxMode) {
324+
NRF_RADIO->TASKS_START = 1;
325+
}
316326
return 0;
317327
}
318328
}
319329
else {
320330
if (!decrypt(&rxBuffer[1], staticPayloadSize - CCM_IV_SIZE - CCM_COUNTER_SIZE)) {
321331
Serial.println("DECRYPT FAIL");
322-
NRF_RADIO->TASKS_START = 1;
332+
if (inRxMode) {
333+
NRF_RADIO->TASKS_START = 1;
334+
}
323335
return 0;
324336
}
325337
}
@@ -339,6 +351,9 @@ bool nrf_to_nrf::available(uint8_t* pipe_num)
339351
lastPacketCounter = packetCtr;
340352
lastData = packetData;
341353
payloadAvailable = true;
354+
if (inRxMode) {
355+
NRF_RADIO->TASKS_START = 1;
356+
}
342357
return 1;
343358
}
344359
if(NRF_RADIO->EVENTS_CRCERROR) {
@@ -354,9 +369,6 @@ void nrf_to_nrf::read(void* buf, uint8_t len)
354369
{
355370
memcpy(buf, &rxBuffer[1], len);
356371
ackPayloadAvailable = false;
357-
if (inRxMode) {
358-
NRF_RADIO->TASKS_START = 1;
359-
}
360372
payloadAvailable = false;
361373
}
362374

0 commit comments

Comments
 (0)