feat(hal): Add LL-API to check whether RNG is enabled

- Also add RNG LL-APIs for ESP32-C61
- Add SOC_RNG_CLOCK_IS_INDEPENDENT for ESP32-C61: now that
  rng_ll_disable() actually clears the RNG clock gate, the application
  needs the esp_hw_support startup hook to re-enable the RNG after
  bootloader_random_disable()
This commit is contained in:
Laukik Hase
2026-08-28 10:20:54 +05:30
parent 74512f74a4
commit 52a6ad71ee
9 changed files with 172 additions and 2 deletions
@@ -14,6 +14,9 @@
#include "soc/lpperi_struct.h"
#include "hal/lp_clkrst_ll.h"
//Default value for the RNG timer clock divider
#define RNG_LL_CFG_PSCALE 255
#ifdef __cplusplus
extern "C" {
#endif
@@ -38,6 +41,16 @@ static inline void rng_ll_enable_sample(bool enable)
REG_SET_FIELD(RNG_CFG_REG, RNG_SAMPLE_ENABLE, enable);
}
/**
* @brief Set RNG timer prescaler
*
* @param prescaler Timer prescaler value (0-255)
*/
static inline void rng_ll_set_timer_prescaler(uint8_t prescaler)
{
REG_SET_FIELD(RNG_CFG_REG, RNG_TIMER_PSCALE, prescaler);
}
/**
* @brief Enable or disable rng xor rtc timer.
*
@@ -75,6 +88,7 @@ static inline void rng_ll_reset(void)
static inline void rng_ll_enable(void)
{
_lp_clkrst_ll_enable_rng_clock(true);
rng_ll_set_timer_prescaler(RNG_LL_CFG_PSCALE);
rng_ll_enable_sample(true);
rng_ll_enable_rtc_timer(true);
rng_ll_enable_rng_timer(true);
@@ -93,6 +107,16 @@ static inline void rng_ll_disable(void)
_lp_clkrst_ll_enable_rng_clock(false);
}
/**
* @brief Check that the RNG is live: clocked and out of reset.
*
* @return True if the RNG is enabled and operational, false otherwise.
*/
static inline bool rng_ll_is_enabled(void)
{
return LPPERI.clk_en.rng_ck_en && LPPERI.clk_en.rng_apb_ck_en && !LPPERI.reset_en.lp_rng_apb_reset_en;
}
#ifdef __cplusplus
}
#endif