diff --git a/examples/platforms/nrf52811/entropy.c b/examples/platforms/nrf52811/entropy.c index a6eff1615..0099d3269 100644 --- a/examples/platforms/nrf52811/entropy.c +++ b/examples/platforms/nrf52811/entropy.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,7 @@ static uint8_t sBuffer[RNG_BUFFER_SIZE]; static volatile uint32_t sReadPosition; static volatile uint32_t sWritePosition; +static volatile bool sEntropyGetEntered; static inline uint32_t bufferCount(void) { @@ -176,6 +178,9 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) uint8_t copyLength; uint16_t index = 0; + assert(!sEntropyGetEntered); + sEntropyGetEntered = true; + otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); do @@ -201,5 +206,7 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) } while (index < aOutputLength); exit: + sEntropyGetEntered = false; + return error; } diff --git a/examples/platforms/nrf52840/entropy.c b/examples/platforms/nrf52840/entropy.c index d086d270d..93c988561 100644 --- a/examples/platforms/nrf52840/entropy.c +++ b/examples/platforms/nrf52840/entropy.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,8 @@ #include "platform-nrf5.h" +static volatile bool sEntropyGetEntered; + #if SOFTDEVICE_PRESENT #include "softdevice.h" #else @@ -193,6 +196,9 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) uint8_t copyLength; uint16_t index = 0; + assert(!sEntropyGetEntered); + sEntropyGetEntered = true; + otEXPECT_ACTION(aOutput && aOutputLength, error = OT_ERROR_INVALID_ARGS); do @@ -228,5 +234,7 @@ otError otPlatEntropyGet(uint8_t *aOutput, uint16_t aOutputLength) } while (index < aOutputLength); exit: + sEntropyGetEntered = false; + return error; }