From 6a0da03809543ca9e0100e6d9043a0d76b7d6cf1 Mon Sep 17 00:00:00 2001 From: Our Air Quality Date: Thu, 20 Jul 2017 16:24:45 +1000 Subject: [PATCH] Use hwrand for the sdk uses of rand, in particular with the NMI. The fiq NMI calls rand() from lmac:lmac.a:sdk_lmacTxFrame and the NMI must not touch the newlib reent structure or enter critical regions etc, so just use the simple and safe hwrand implementation as a substitute. --- core/esp_hwrand.c | 9 +++++++-- lib/allsymbols.rename | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/core/esp_hwrand.c b/core/esp_hwrand.c index 7a591eb..f6890c7 100644 --- a/core/esp_hwrand.c +++ b/core/esp_hwrand.c @@ -10,8 +10,13 @@ #include #include -/* Return a random 32-bit number */ -uint32_t hwrand(void) +/* Return a random 32-bit number. + * + * This is also used as a substitute for rand() called from + * lmac.a:sdk_lmacTxFrame to avoid touching the newlib reent structures within + * the NMI and the NMI code needs to be in IRAM. + */ +uint32_t IRAM hwrand(void) { return WDEV.HWRNG; } diff --git a/lib/allsymbols.rename b/lib/allsymbols.rename index 2d609bc..5425845 100644 --- a/lib/allsymbols.rename +++ b/lib/allsymbols.rename @@ -419,6 +419,7 @@ ram_set_txbb_atten sdk_ram_set_txbb_atten ram_start_noisefloor sdk_ram_start_noisefloor ram_tx_mac_disable sdk_ram_tx_mac_disable ram_tx_mac_enable sdk_ram_tx_mac_enable +rand hwrand rc4_skip sdk_rc4_skip rcAttach sdk_rcAttach rc_cal sdk_rc_cal