5#if defined NRF54_CCM_ENCRYPTION
6 #include <nrf54l15_hal.h>
7static xiao_nrf54l15::Ccm nrf54Ccm;
8static xiao_nrf54l15::CracenRng nrf54Rng;
12 #define __REV(x) __builtin_bswap32(x);
15#if defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || defined(NRF52811_XXAA) || defined(NRF52810_XXAA) || defined(NRF52805_XXAA)
17 #define TXPOWER_PA_MIN 0xF4
18 #define TXPOWER_PA_LOW 0xFC
19 #define TXPOWER_PA_HIGH 0x00
20 #define TXPOWER_PA_MAX 0x04
21#elif !defined(ARDUINO_NRF54L15)
23 #define TXPOWER_PA_MIN 0xF4
24 #define TXPOWER_PA_LOW 0x02
25 #define TXPOWER_PA_HIGH 0x06
26 #define TXPOWER_PA_MAX 0x08
28 #define TXPOWER_PA_MIN 0x6
29 #define TXPOWER_PA_LOW 0x1F
30 #define TXPOWER_PA_HIGH 0x33
31 #define TXPOWER_PA_MAX 0x3F
35#ifndef RADIO_MODE_MODE_Nrf_250Kbit
36 #define RADIO_MODE_MODE_Nrf_250Kbit (2UL)
38#ifdef ARDUINO_NRF54L15
39 #define RADIO_MODE_MODE_Nrf_4Mbit_OBT4 (10UL)
40 #define RADIO_MODE_MODE_Nrf_4Mbit_OBT6 (9UL)
43#define DEFAULT_TIMEOUT 250
49 uint32_t start = millis();
51 if (millis() - start > timeout) {
63 uint32_t inp = (p_inp[3] << 24) | (p_inp[2] << 16) | (p_inp[1] << 8) | (p_inp[0]);
64 inp = (inp & 0xF0F0F0F0) >> 4 | (inp & 0x0F0F0F0F) << 4;
65 inp = (inp & 0xCCCCCCCC) >> 2 | (inp & 0x33333333) << 2;
66 inp = (inp & 0xAAAAAAAA) >> 1 | (inp & 0x55555555) << 1;
85 buffer[0] = addr & 0xFF;
86 buffer[1] = (addr >> 8) & 0xFF;
87 buffer[2] = (addr >> 16) & 0xFF;
88 buffer[3] = (addr >> 24) & 0xFF;
98 staticPayloadSize = 32;
101 ackPayloadsEnabled =
false;
106 payloadAvailable =
false;
107#ifndef ARDUINO_NRF54L15
113#if defined CCM_ENCRYPTION_ENABLED
114 #if !defined NRF54_CCM_ENCRYPTION
115 NRF_CCM->INPTR = (uint32_t)inBuffer;
117 NRF_CCM->CNFPTR = (uint32_t)&ccmData;
118 NRF_CCM->SCRATCHPTR = (uint32_t)scratchPTR;
120 ccmData.counter = 12345;
130#ifndef ARDUINO_NRF54L15
131 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
132 NRF_CLOCK->TASKS_HFCLKSTART = 1;
138 NRF_POWER->TASKS_CONSTLAT = 1;
139 NRF_CLOCK->EVENTS_XOSTARTED = 0;
140 NRF_CLOCK->TASKS_XOSTART = 1;
146 NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
147 NRF_CLOCK->TASKS_LFCLKSTART = 1;
153#ifndef ARDUINO_NRF54L15
154 NRF_RADIO->POWER = 1;
157 NRF_RADIO->PCNF0 = (1 << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (1 << RADIO_PCNF0_S1LEN_Pos);
159 NRF_RADIO->PCNF1 = (RADIO_PCNF1_WHITEEN_Disabled << RADIO_PCNF1_WHITEEN_Pos) | (RADIO_PCNF1_ENDIAN_Big << RADIO_PCNF1_ENDIAN_Pos) | (4 << RADIO_PCNF1_BALEN_Pos) | (staticPayloadSize << RADIO_PCNF1_STATLEN_Pos) | (staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos);
161 NRF_RADIO->BASE0 = 0xE7E7E7E7;
162 NRF_RADIO->BASE1 = 0x43434343;
163 NRF_RADIO->PREFIX0 = 0x23C343E7;
164 NRF_RADIO->PREFIX1 = 0x13E363A3;
165 NRF_RADIO->RXADDRESSES = 0x01;
166 NRF_RADIO->TXADDRESS = 0x00;
168 txBase = NRF_RADIO->BASE0;
169 txPrefix = NRF_RADIO->PREFIX0;
170 rxBase = NRF_RADIO->BASE0;
171 rxPrefix = NRF_RADIO->PREFIX0;
173 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
174 NRF_RADIO->CRCINIT = 0xFFFFUL;
175 NRF_RADIO->CRCPOLY = 0x11021UL;
177 NRF_RADIO->PACKETPTR = (uint32_t)
radioData;
178 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
180#ifndef ARDUINO_NRF54L15
181 NRF_RADIO->MODECNF0 = 0x201;
183 NRF_RADIO->TIMING = 0x1;
185 NRF_RADIO->TXPOWER = (
TXPOWER_PA_MAX << RADIO_TXPOWER_TXPOWER_Pos);
186 NRF_RADIO->FREQUENCY = 0x4C;
192#ifdef ARDUINO_NRF54L15
193 NRF_RADIO->TASKS_START = 1;
201#ifdef NRF_HAS_ENERGY_DETECT
202 #define ED_RSSISCALE 4
203uint8_t nrf_to_nrf::sample_ed(
void)
206 NRF_RADIO->TASKS_EDSTART = 1;
210 val = NRF_RADIO->EDSAMPLE;
211 return (uint8_t)(val > 63
213 : val * ED_RSSISCALE);
221 uint8_t pipe_num = 0;
230 if (payloadAvailable) {
231 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
236 if (ackPayloadAvailable) {
237 *pipe_num = ackAvailablePipeNo;
241 if (NRF_RADIO->EVENTS_CRCOK) {
242 NRF_RADIO->EVENTS_CRCOK = 0;
245 return restartReturnRx();
249 *pipe_num = (uint8_t)NRF_RADIO->RXMATCH;
250 if (!DPL && acksEnabled(*pipe_num) ==
false) {
251#if defined CCM_ENCRYPTION_ENABLED
259 memcpy(&rxBuffer[1], &
radioData[0], staticPayloadSize);
260#if defined CCM_ENCRYPTION_ENABLED
265#if defined CCM_ENCRYPTION_ENABLED
282 memcpy(&rxBuffer[1], &
radioData[2], staticPayloadSize);
284#if defined CCM_ENCRYPTION_ENABLED
289 rxFifoAvailable =
true;
290 uint8_t packetCtr = 0;
297 rxBuffer[0] = staticPayloadSize;
301 uint16_t packetData = NRF_RADIO->RXCRC;
303 if (acksEnabled(NRF_RADIO->RXMATCH)) {
305 uint32_t txAddress = NRF_RADIO->TXADDRESS;
306 NRF_RADIO->TXADDRESS = NRF_RADIO->RXMATCH;
307 delayMicroseconds(75);
308 if (ackPayloadsEnabled) {
309 if (*pipe_num == ackPipe) {
310 write(&ackBuffer[1], ackBuffer[0], 1, 0);
317 uint8_t payloadSize = 0;
327 NRF_RADIO->TXADDRESS = txAddress;
332 if (NRF_RADIO->CRCCNF != 0) {
333 if (packetCtr == lastPacketCounter && packetData == lastData) {
334 return restartReturnRx();
339#if defined CCM_ENCRYPTION_ENABLED
341 uint8_t bufferLength = 0;
348 if (!
decrypt(&rxBuffer[1], bufferLength)) {
349 Serial.println(
"DECRYPT FAIL");
350 return restartReturnRx();
353 memset(&rxBuffer[1], 0,
sizeof(rxBuffer) - 1);
364 lastPacketCounter = packetCtr;
365 lastData = packetData;
367 if (inRxMode && !acksEnabled(NRF_RADIO->RXMATCH)) {
368 NRF_RADIO->TASKS_START = 1;
370 if ((DPL && rxBuffer[0]) || !DPL) {
371 payloadAvailable =
true;
375 if (NRF_RADIO->EVENTS_CRCERROR) {
376 NRF_RADIO->EVENTS_CRCERROR = 0;
377 NRF_RADIO->TASKS_START = 1;
384bool nrf_to_nrf::restartReturnRx()
387 NRF_RADIO->TASKS_START = 1;
396 memcpy(buf, &rxBuffer[1], len);
397 ackPayloadAvailable =
false;
398 payloadAvailable =
false;
406 uint8_t PID = ackPID;
408 PID = ((ackPID += 1) % 7) << 1;
413 uint8_t payloadSize = 0;
415#if defined CCM_ENCRYPTION_ENABLED
420 if (!generateIV(ccmData.iv)) {
423 ccmData.counter = packetCounter;
431 if (packetCounter > 200000) {
438 for (
int i = 0; i < (retries + 1); i++) {
449 uint8_t dataStart = 0;
451#if defined CCM_ENCRYPTION_ENABLED
458 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
459#if defined CCM_ENCRYPTION_ENABLED
463#if defined CCM_ENCRYPTION_ENABLED
472#if defined CCM_ENCRYPTION_ENABLED
475#ifdef ARDUINO_NRF54L15
476 uint32_t timeout = millis();
477 while (NRF_RADIO->STATE != 10) {
479 if (millis() - timeout > 250) {
484 NRF_RADIO->EVENTS_END = 0;
485 NRF_RADIO->TASKS_START = 1;
489 NRF_RADIO->EVENTS_END = 0;
490 if (!multicast && acksPerPipe[NRF_RADIO->TXADDRESS] ==
true) {
491 uint32_t rxAddress = NRF_RADIO->RXADDRESSES;
492 NRF_RADIO->RXADDRESSES = 1 << NRF_RADIO->TXADDRESS;
499 int32_t realAckTimeout = (int32_t)ackTimeout;
501 if (NRF_RADIO->MODE == (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos)) {
513 realAckTimeout += 200;
519 if (realAckTimeout < 0) {
523 uint32_t ack_timeout = micros();
524 while (!NRF_RADIO->EVENTS_CRCOK && !NRF_RADIO->EVENTS_CRCERROR) {
525 if (micros() - ack_timeout > realAckTimeout) {
529 if (NRF_RADIO->EVENTS_CRCOK) {
530 if (ackPayloadsEnabled &&
radioData[0] > 0) {
531#if defined CCM_ENCRYPTION_ENABLED
542#if defined CCM_ENCRYPTION_ENABLED
548 Serial.println(
"DECRYPT FAIL");
558 ackPayloadAvailable =
true;
559 ackAvailablePipeNo = NRF_RADIO->RXMATCH;
561 NRF_RADIO->EVENTS_CRCOK = 0;
566 NRF_RADIO->RXADDRESSES = rxAddress;
570 else if (NRF_RADIO->EVENTS_CRCERROR) {
571 NRF_RADIO->EVENTS_CRCERROR = 0;
573 uint32_t duration = 258 * retryDuration;
574 delayMicroseconds(duration);
579 NRF_RADIO->RXADDRESSES = rxAddress;
586 lastTxResult =
false;
595 uint8_t PID = ackPID;
597 PID = ((ackPID += 1) % 7) << 1;
603#if defined CCM_ENCRYPTION_ENABLED
605 uint32_t tmpCounter = 0;
610 if (!generateIV(tmpIV)) {
614 tmpCounter = packetCounter;
615 ccmData.counter = tmpCounter;
623 if (packetCounter > 200000) {
641 uint8_t dataStart = 0;
643#if defined CCM_ENCRYPTION_ENABLED
650 dataStart = (!DPL && acksEnabled(0) ==
false) ? 0 : 2;
651#if defined CCM_ENCRYPTION_ENABLED
655#if defined CCM_ENCRYPTION_ENABLED
664#if defined CCM_ENCRYPTION_ENABLED
668 NRF_RADIO->EVENTS_END = 0;
669 NRF_RADIO->TASKS_START = 1;
680#if defined CCM_ENCRYPTION_ENABLED
684 if (!generateIV(ccmData.iv)) {
689 ccmData.counter = packetCounter;
699 if (packetCounter > 200000) {
706 memcpy(&ackBuffer[1], buf, len);
707#if defined CCM_ENCRYPTION_ENABLED
728 NRF_RADIO->EVENTS_DISABLED = 0;
729 NRF_RADIO->TASKS_DISABLE = 1;
732 NRF_RADIO->EVENTS_DISABLED = 0;
734 if (resetAddresses ==
true) {
735 NRF_RADIO->BASE0 = rxBase;
736 NRF_RADIO->PREFIX0 = rxPrefix;
737#ifndef ARDUINO_NRF54L15
738 NRF_RADIO->MODECNF0 = 0x201;
740 NRF_RADIO->TIMING = 0x1;
745 NRF_RADIO->SHORTS = 0x0;
746#if defined(NRF52832_XXAA)
747 NRF_RADIO->EVENTS_READY = 0;
749 NRF_RADIO->EVENTS_RXREADY = 0;
751 NRF_RADIO->EVENTS_CRCOK = 0;
752 NRF_RADIO->TASKS_RXEN = 1;
753#if defined(NRF52832_XXAA)
760 NRF_RADIO->TASKS_START = 1;
768 NRF_RADIO->EVENTS_DISABLED = 0;
769 NRF_RADIO->TASKS_DISABLE = 1;
772 NRF_RADIO->EVENTS_DISABLED = 0;
774 if (resetAddresses) {
775 NRF_RADIO->BASE0 = txBase;
776 NRF_RADIO->PREFIX0 = txPrefix;
778 if (setWritingPipe) {
779 NRF_RADIO->TXADDRESS = 0x00;
781#ifndef ARDUINO_NRF54L15
782 NRF_RADIO->MODECNF0 = 0x200;
784 NRF_RADIO->TIMING = 0x0;
787#ifndef ARDUINO_NRF54L15
788 NRF_RADIO->SHORTS = 0x6;
790 NRF_RADIO->SHORTS = 0x80004;
792 if (NRF_RADIO->STATE < 9) {
793#if defined(NRF52832_XXAA)
794 NRF_RADIO->EVENTS_READY = 0;
796 NRF_RADIO->EVENTS_TXREADY = 0;
798 NRF_RADIO->TASKS_TXEN = 1;
799#if defined(NRF52832_XXAA)
802 NRF_RADIO->EVENTS_READY = 0;
806 NRF_RADIO->EVENTS_TXREADY = 0;
825 uint8_t size = min(staticPayloadSize, rxBuffer[0]);
834 uint32_t freq = NRF_RADIO->FREQUENCY;
835 NRF_RADIO->FREQUENCY = 0x4C;
836 if (NRF_RADIO->FREQUENCY == 0x4C) {
837 NRF_RADIO->FREQUENCY = freq;
845void nrf_to_nrf::setChannel(uint8_t channel,
bool map) { NRF_RADIO->FREQUENCY = channel | map << RADIO_FREQUENCY_MAP_Pos; }
856 for (
int i = 0; i < 8; i++) {
857 acksPerPipe[i] = enable;
869 acksPerPipe[pipe] = enable;
882 staticPayloadSize = payloadSize;
884 if (payloadSize <= 63) {
885 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (6 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
889 NRF_RADIO->PCNF0 = (0 << RADIO_PCNF0_S0LEN_Pos) | (8 << RADIO_PCNF0_LFLEN_Pos) | (3 << RADIO_PCNF0_S1LEN_Pos);
892 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
893 NRF_RADIO->PCNF1 |= payloadSize << RADIO_PCNF1_MAXLEN_Pos;
903 uint8_t lenConfig = 0;
904 if (acksEnabled(0)) {
907 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
909 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
910 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
917 staticPayloadSize = size;
920 uint8_t lenConfig = 0;
921 if (acksEnabled(0)) {
924 NRF_RADIO->PCNF0 = (lenConfig << RADIO_PCNF0_S0LEN_Pos) | (0 << RADIO_PCNF0_LFLEN_Pos) | (lenConfig << RADIO_PCNF0_S1LEN_Pos);
926 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_MAXLEN_Pos | 0xFF << RADIO_PCNF1_STATLEN_Pos);
927 NRF_RADIO->PCNF1 |= staticPayloadSize << RADIO_PCNF1_STATLEN_Pos | staticPayloadSize << RADIO_PCNF1_MAXLEN_Pos;
934 return staticPayloadSize;
943 retryDuration = retryVar;
951 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
961 uint32_t prefix =
addrConv32(address & 0xFF) >> 24;
971 uint32_t prefix =
addr_conv(&address[0]) >> 24;
983 NRF_RADIO->PREFIX0 = rxPrefix;
984 NRF_RADIO->BASE0 = base;
985 NRF_RADIO->PREFIX0 &= ~(0xFF);
986 NRF_RADIO->PREFIX0 |= prefix;
987 rxBase = NRF_RADIO->BASE0;
988 rxPrefix = NRF_RADIO->PREFIX0;
990 else if (child < 4) {
991 NRF_RADIO->PREFIX0 = rxPrefix;
992 NRF_RADIO->BASE1 = base;
993 NRF_RADIO->PREFIX0 &= ~(0xFF << (8 * child));
994 NRF_RADIO->PREFIX0 |= prefix << (8 * child);
995 rxPrefix = NRF_RADIO->PREFIX0;
998 NRF_RADIO->BASE1 = base;
999 NRF_RADIO->PREFIX1 &= ~(0xFF << (8 * (child - 4)));
1000 NRF_RADIO->PREFIX1 |= prefix << (8 * (child - 4));
1002 NRF_RADIO->RXADDRESSES |= 1 << child;
1011 uint32_t prefix =
addr_conv(&address[0]) >> 24;
1021 NRF_RADIO->BASE0 = base;
1022 NRF_RADIO->PREFIX0 &= ~(0xFF);
1023 NRF_RADIO->PREFIX0 |= prefix;
1024 NRF_RADIO->TXADDRESS = 0x00;
1025 txBase = NRF_RADIO->BASE0;
1026 txPrefix = NRF_RADIO->PREFIX0;
1032 return lastTxResult;
1039 return lastTxResult;
1046 lastTxResult =
write(buf, len, multicast);
1047 return lastTxResult;
1052bool nrf_to_nrf::acksEnabled(uint8_t pipe)
1055 if (acksPerPipe[pipe]) {
1071 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_1Mbit << RADIO_MODE_MODE_Pos);
1079 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_2Mbit << RADIO_MODE_MODE_Pos);
1082#ifdef ARDUINO_NRF54L15
1083 else if (speed == NRF_4MBPS_OBT4) {
1084 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT4 << RADIO_MODE_MODE_Pos);
1088 NRF_RADIO->MODE = (RADIO_MODE_MODE_Nrf_4Mbit_OBT6 << RADIO_MODE_MODE_Pos);
1101 uint8_t paLevel = 0x00;
1115 NRF_RADIO->TXPOWER = paLevel;
1123 uint8_t paLevel = NRF_RADIO->TXPOWER;
1154 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Three;
1155 NRF_RADIO->CRCINIT = 0x555555UL;
1156 NRF_RADIO->CRCPOLY = 0x65BUL;
1159 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_Two;
1160 NRF_RADIO->CRCINIT = 0xFFFFUL;
1161 NRF_RADIO->CRCPOLY = 0x11021UL;
1164 NRF_RADIO->CRCCNF = RADIO_CRCCNF_LEN_One;
1165 NRF_RADIO->CRCINIT = 0xFFUL;
1166 NRF_RADIO->CRCPOLY = 0x107UL;
1169 NRF_RADIO->CRCCNF = 0;
1170 NRF_RADIO->CRCINIT = 0x00L;
1171 NRF_RADIO->CRCPOLY = 0x00UL;
1179 if (NRF_RADIO->CRCCNF == 0) {
1182 else if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_One) {
1185 if (NRF_RADIO->CRCCNF == RADIO_CRCCNF_LEN_Two) {
1197#ifndef ARDUINO_NRF54L15
1198 NRF_RADIO->EVENTS_RSSIEND = 0;
1199 NRF_RADIO->TASKS_RSSISTART = 1;
1203 if (NRF_RADIO->RSSISAMPLE < RSSI) {
1221#ifndef ARDUINO_NRF54L15
1222 NRF_RADIO->EVENTS_RSSIEND = 0;
1223 NRF_RADIO->TASKS_RSSISTART = 1;
1227 return (uint8_t)NRF_RADIO->RSSISAMPLE;
1243#ifndef ARDUINO_NRF54L15
1244 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
1245 NRF_CLOCK->TASKS_HFCLKSTART = 1;
1250 NRF_RADIO->POWER = 1;
1252 NRF_POWER->TASKS_CONSTLAT = 1;
1253 NRF_CLOCK->EVENTS_XOSTARTED = 0;
1254 NRF_CLOCK->TASKS_XOSTART = 1;
1259#ifdef CCM_ENCRYPTION_ENABLED
1261 #if defined NRF54_CCM_ENCRYPTION
1264 NRF_RNG->CONFIG = 1;
1265 NRF_RNG->TASKS_START = 1;
1266 NRF_CCM->ENABLE = 2;
1276#ifndef ARDUINO_NRF54L15
1277 NRF_RADIO->POWER = 0;
1278 NRF_CLOCK->TASKS_HFCLKSTOP = 1;
1280 NRF_CLOCK->TASKS_XOSTOP = 1;
1283#ifdef CCM_ENCRYPTION_ENABLED
1285 #if defined NRF54_CCM_ENCRYPTION
1288 NRF_RNG->TASKS_STOP = 1;
1289 NRF_RNG->CONFIG = 0;
1290 NRF_CCM->ENABLE = 0;
1299 NRF_RADIO->PCNF1 &= ~(0xFF << RADIO_PCNF1_BALEN_Pos);
1300 NRF_RADIO->PCNF1 |= (a_width - 1) << RADIO_PCNF1_BALEN_Pos;
1307 uint8_t addressWidth = ((NRF_RADIO->PCNF1 >> 16) & 0xFF) + 1;
1309 Serial.println(
"================ Radio Configuration ================");
1310 Serial.print(
"STATUS\t\t= ");
1311 Serial.println(NRF_RADIO->STATE);
1314 Serial.print(
"RX_ADDR_P0-1\t= 0x");
1315 uint32_t base =
addrConv32(NRF_RADIO->BASE0);
1316 for (
int i = addressWidth - 2; i > -1; i--) {
1317 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1319 uint32_t prefixes =
addrConv32(NRF_RADIO->PREFIX0);
1320 uint8_t prefix = (prefixes >> 24) & 0xFF;
1321 Serial.print(prefix, HEX);
1322 Serial.print(
" 0x");
1324 for (
int i = addressWidth - 2; i > -1; i--) {
1325 Serial.print((base >> (i * 8)) & 0xFF, HEX);
1327 prefix = (prefixes >> 16) & 0xFF;
1328 Serial.println(prefix, HEX);
1330 Serial.print(
"RX_ADDR_P2-7\t= 0x");
1331 prefix = (prefixes >> 8) & 0xFF;
1332 Serial.print(prefix, HEX);
1333 Serial.print(
" 0x");
1334 prefix = (prefixes) & 0xFF;
1335 Serial.print(prefix, HEX);
1336 Serial.print(
" 0x");
1338 prefix = (prefixes >> 24) & 0xFF;
1339 Serial.print(prefix, HEX);
1340 Serial.print(
" 0x");
1341 prefix = (prefixes >> 16) & 0xFF;
1342 Serial.print(prefix, HEX);
1343 Serial.print(
" 0x");
1344 prefix = (prefixes >> 8) & 0xFF;
1345 Serial.print(prefix, HEX);
1346 Serial.print(
" 0x");
1347 prefix = (prefixes) & 0xFF;
1348 Serial.println(prefix, HEX);
1351 for (
int i = 0; i < 6; i++) {
1352 enAA |= acksPerPipe[i] << i;
1354 Serial.print(
"EN_AA\t\t= 0x");
1355 Serial.println(enAA, HEX);
1356 Serial.print(
"EN_RXADDR\t= 0x");
1357 Serial.println(NRF_RADIO->RXADDRESSES, HEX);
1358 Serial.print(
"RF_CH\t\t= 0x");
1359 Serial.println(NRF_RADIO->FREQUENCY, HEX);
1360 Serial.println(
"DYNPD/FEATURE\t= 0x");
1361 Serial.print(
"Data Rate\t= ");
1362 Serial.println(NRF_RADIO->MODE ?
"2 MBPS" :
"1MBPS");
1363 Serial.println(
"Model\t\t= NRF52");
1364 Serial.print(
"CRC Length\t= ");
1367 Serial.println(
"16 bits");
1370 Serial.println(
"8 bits");
1373 Serial.println(
"Disabled");
1375 Serial.print(
"PA Power\t= ");
1378 Serial.println(
"PA_MAX");
1381 Serial.println(
"PA_HIGH");
1384 Serial.println(
"PA_LOW");
1387 Serial.println(
"PA_MIN");
1390 Serial.println(
"?");
1392 Serial.print(
"ARC\t\t= ");
1393 Serial.println(arcCounter);
1398#if defined CCM_ENCRYPTION_ENABLED
1400 #if defined NRF54_CCM_ENCRYPTION
1415 if (!nrf54Ccm.encryptBlePacket(ccmData.key, ccmData.iv, ccmData.counter, ccmData.direction, 0,
static_cast<const uint8_t*
>(bufferIn), size,
1434 bool macValid =
false;
1435 if (!nrf54Ccm.decryptBlePacket(ccmData.key, ccmData.iv, ccmData.counter, ccmData.direction, 0,
static_cast<const uint8_t*
>(bufferIn), size,
1458 NRF_CCM->MODE = 0 | 1 << 24 | 1 << 16;
1474 NRF_CCM->EVENTS_ENDKSGEN = 0;
1475 NRF_CCM->EVENTS_ENDCRYPT = 0;
1476 NRF_CCM->TASKS_KSGEN = 1;
1480 if (NRF_CCM->EVENTS_ERROR) {
1490 NRF_CCM->MODE = 1 | 1 << 24 | 1 << 16;
1507 NRF_CCM->EVENTS_ENDKSGEN = 0;
1508 NRF_CCM->EVENTS_ENDCRYPT = 0;
1509 NRF_CCM->TASKS_KSGEN = 1;
1514 if (NRF_CCM->EVENTS_ERROR) {
1518 if (NRF_CCM->MICSTATUS == (CCM_MICSTATUS_MICSTATUS_CheckFailed << CCM_MICSTATUS_MICSTATUS_Pos)) {
1530 NRF_CCM->MODE = 1 << 24 | 1 << 16;
1531#ifndef NRF52832_XXAA
1534 NRF_CCM->SHORTS = 1;
1535 NRF_CCM->ENABLE = 2;
1537 NRF_RNG->CONFIG = 1;
1538 NRF_RNG->TASKS_START = 1;
1550 ccmData.counter = counter;
1551 packetCounter = counter;
1559 ccmData.iv[i] = IV[i];
1565bool nrf_to_nrf::generateIV(uint8_t iv[
CCM_IV_SIZE])
1567 #if defined NRF54_CCM_ENCRYPTION
1574 NRF_RNG->EVENTS_VALRDY = 0;
1575 iv[i] = NRF_RNG->VALUE;
void startListening(bool resetAddresses=true)
void openReadingPipe(uint8_t child, const uint8_t *address)
void setPALevel(uint8_t level, bool lnaEnable=true)
bool testCarrier(uint8_t RSSI=65)
uint8_t decrypt(void *bufferIn, uint8_t size)
uint8_t radioData[ACTUAL_MAX_PAYLOAD_SIZE+2]
uint32_t addrConv32(uint32_t addr)
void disableDynamicPayloads()
bool write(void *buf, uint8_t len, bool multicast=false, bool doEncryption=true)
bool testRPD(uint8_t RSSI=65)
void setCounter(uint64_t counter)
void setAddressWidth(uint8_t a_width)
void setChannel(uint8_t channel, bool map=0)
uint8_t getDynamicPayloadSize()
bool setDataRate(uint8_t speed)
void setKey(uint8_t key[CCM_KEY_SIZE])
bool writeAckPayload(uint8_t pipe, void *buf, uint8_t len)
void enableDynamicPayloads(uint8_t payloadSize=DEFAULT_MAX_PAYLOAD_SIZE)
uint8_t encrypt(void *bufferIn, uint8_t size)
bool startWrite(void *buf, uint8_t len, bool multicast, bool doEncryption=true)
uint16_t interframeSpacing
uint8_t outBuffer[MAX_PACKET_SIZE+CCM_MIC_SIZE+CCM_START_SIZE]
void setRetries(uint8_t retryVar, uint8_t attempts)
void openWritingPipe(const uint8_t *address)
void setCRCLength(nrf_crclength_e length)
bool writeFast(void *buf, uint8_t len, bool multicast=0)
void setAutoAck(bool enable)
void read(void *buf, uint8_t len)
void stopListening(bool setWritingPipe=true, bool resetAddresses=true)
void setIV(uint8_t IV[CCM_IV_SIZE])
void setPayloadSize(uint8_t size)
nrf_crclength_e getCRCLength()
#define RADIO_MODE_MODE_Nrf_250Kbit
static bool waitForEvent(volatile uint32_t *event, uint32_t timeout=DEFAULT_TIMEOUT)
static uint32_t bytewise_bit_swap(uint8_t const *p_inp)
static uint32_t addr_conv(uint8_t const *p_addr)
#define ACK_TIMEOUT_1MBPS_OFFSET
#define DEFAULT_MAX_PAYLOAD_SIZE
#define ACK_PAYLOAD_TIMEOUT_OFFSET
#define ACK_TIMEOUT_250KBPS_OFFSET
#define ACK_TIMEOUT_250KBPS
#define ACK_TIMEOUT_2MBPS
#define ACTUAL_MAX_PAYLOAD_SIZE
#define ACK_TIMEOUT_2MBPS_OFFSET
#define ACK_TIMEOUT_1MBPS