feat(rng): refactor rng bootloader to rng ll API

This commit is contained in:
gaoxu
2026-07-20 17:15:26 +08:00
parent f704fbb5ec
commit d31a63d246
3 changed files with 70 additions and 28 deletions

View File

@@ -5,36 +5,14 @@
*/
#include "sdkconfig.h"
#include "bootloader_random.h"
#include "soc/lpperi_reg.h"
#include "rom/ets_sys.h"
#include "rom/uart.h"
#include "hal/rng_ll.h"
void bootloader_random_enable(void)
{
// Disable rtc_timer update for rng
SET_PERI_REG_BITS(LPPERI_RNG_CFG_REG, LPPERI_RTC_TIMER_EN, 0, LPPERI_RTC_TIMER_EN_S);
// Enable entropy source of ring
SET_PERI_REG_MASK(LPPERI_RNG_CFG_REG, LPPERI_RNG_SAMPLE_ENABLE);
//For dieharder test
ets_printf("H21: Random bytes (%s) follow:\n", "test");
while (1) {
uint32_t w = READ_PERI_REG(LPPERI_RNG_DATA_SYNC_REG);
ets_printf("rng_data:%d\n", w);
uart_tx_wait_idle(0);
// uart_tx_one_char(w >> 24);
// uart_tx_one_char(w >> 16);
// uart_tx_one_char(w >> 8);
// uart_tx_one_char(w);
}
rng_ll_enable();
}
void bootloader_random_disable(void)
{
// Disable rtc_timer update for rng
SET_PERI_REG_BITS(LPPERI_RNG_CFG_REG, LPPERI_RTC_TIMER_EN, 0, LPPERI_RTC_TIMER_EN_S);
// Disable entropy source of ring
CLEAR_PERI_REG_MASK(LPPERI_RNG_CFG_REG, LPPERI_RNG_SAMPLE_ENABLE);
rng_ll_disable();
}