From 4b422a33a0e7c64af1e154e4549a950e91999b60 Mon Sep 17 00:00:00 2001 From: "Duda, Lukasz" Date: Tue, 19 Nov 2019 22:20:15 +0100 Subject: [PATCH] [nrf528xx] ensure there is no radio pending events after diag is disabled (#4343) --- examples/platforms/nrf528xx/src/diag.c | 3 +++ examples/platforms/nrf528xx/src/platform-nrf5.h | 6 ++++++ examples/platforms/nrf528xx/src/radio.c | 15 +++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/examples/platforms/nrf528xx/src/diag.c b/examples/platforms/nrf528xx/src/diag.c index a792aba1c..7918f09a8 100644 --- a/examples/platforms/nrf528xx/src/diag.c +++ b/examples/platforms/nrf528xx/src/diag.c @@ -415,6 +415,9 @@ void otPlatDiagModeSet(bool aMode) { otPlatRadioReceive(NULL, sChannel); otPlatRadioSleep(NULL); + + // Clear all remaining events before switching to MAC callbacks. + nrf5RadioClearPendingEvents(); } else { diff --git a/examples/platforms/nrf528xx/src/platform-nrf5.h b/examples/platforms/nrf528xx/src/platform-nrf5.h index 8de1d6611..4f4e3f774 100644 --- a/examples/platforms/nrf528xx/src/platform-nrf5.h +++ b/examples/platforms/nrf528xx/src/platform-nrf5.h @@ -166,6 +166,12 @@ void nrf5RadioDeinit(void); */ void nrf5RadioProcess(otInstance *aInstance); +/** + * Function for clearing Radio driver pending events. + * + */ +void nrf5RadioClearPendingEvents(void); + /** * Initialization of hardware crypto engine. * diff --git a/examples/platforms/nrf528xx/src/radio.c b/examples/platforms/nrf528xx/src/radio.c index 86423aa51..f50d88d4e 100644 --- a/examples/platforms/nrf528xx/src/radio.c +++ b/examples/platforms/nrf528xx/src/radio.c @@ -254,6 +254,21 @@ void nrf5RadioDeinit(void) sPendingEvents = 0; } +void nrf5RadioClearPendingEvents(void) +{ + sPendingEvents = 0; + + for (uint32_t i = 0; i < NRF_802154_RX_BUFFERS; i++) + { + if (sReceivedFrames[i].mPsdu != NULL) + { + uint8_t *bufferAddress = &sReceivedFrames[i].mPsdu[-1]; + sReceivedFrames[i].mPsdu = NULL; + nrf_802154_buffer_free_raw(bufferAddress); + } + } +} + otRadioState otPlatRadioGetState(otInstance *aInstance) { OT_UNUSED_VARIABLE(aInstance);