mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'feat/basic_rng_support_h4' into 'master'
RNG support and refactor on ESP32-H4 Closes IDF-12265 See merge request espressif/esp-idf!45361
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -61,6 +61,19 @@ static inline void lp_clkrst_ll_select_modem_32k_clock_source(lp_clkrst_dev_t *h
|
||||
hw->lpperi.lp_bletimer_32k_sel = src;
|
||||
}
|
||||
|
||||
__attribute__((always_inline))
|
||||
static inline void _lp_clkrst_ll_enable_rng_clock(bool en)
|
||||
{
|
||||
LPPERI.clk_en.rng_apb_ck_en = en;
|
||||
LPPERI.clk_en.rng_ck_en = en;
|
||||
}
|
||||
|
||||
/// LPPERI.clk_en is a shared register, so this function must be used in an atomic way
|
||||
#define lp_clkrst_ll_enable_rng_clock(...) do { \
|
||||
(void)__DECLARE_RCC_ATOMIC_ENV; \
|
||||
_lp_clkrst_ll_enable_rng_clock(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -6,18 +6,91 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rng_reg.h"
|
||||
#include "soc/wdev_reg.h"
|
||||
#include "soc/lpperi_struct.h"
|
||||
#include "hal/lp_clkrst_ll.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Read random data from RNG
|
||||
*
|
||||
* @return 32-bit random data
|
||||
*/
|
||||
static inline uint32_t rng_ll_read_data(void)
|
||||
{
|
||||
// return REG_READ(WDEV_RND_REG); // TODO: IDF-12265
|
||||
return 0;
|
||||
return REG_READ(WDEV_RND_REG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable RNG sampling.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_sample(bool enable)
|
||||
{
|
||||
REG_SET_FIELD(RNG_CFG_REG, RNG_SAMPLE_ENABLE, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable rng xor rtc timer.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_rtc_timer(bool enable)
|
||||
{
|
||||
REG_SET_FIELD(RNG_CFG_REG, RNG_RTC_TIMER_EN, enable ? 0x3 : 0x0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable or disable rng xor async rng timer.
|
||||
*
|
||||
* @param enable True to enable, False to disable
|
||||
*/
|
||||
static inline void rng_ll_enable_rng_timer(bool enable)
|
||||
{
|
||||
REG_SET_FIELD(RNG_CFG_REG, RNG_TIMER_EN, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset RNG.
|
||||
*/
|
||||
static inline void rng_ll_reset(void)
|
||||
{
|
||||
LPPERI.reset_en.lp_rng_apb_reset_en = 1;
|
||||
LPPERI.reset_en.lp_rng_apb_reset_en = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable RNG module
|
||||
*
|
||||
* TODO: unify in rng_hal.c
|
||||
*/
|
||||
static inline void rng_ll_enable(void)
|
||||
{
|
||||
_lp_clkrst_ll_enable_rng_clock(true);
|
||||
rng_ll_enable_sample(true);
|
||||
rng_ll_enable_rtc_timer(true);
|
||||
rng_ll_enable_rng_timer(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disable RNG module
|
||||
*
|
||||
* TODO: unify in rng_hal.c
|
||||
*/
|
||||
static inline void rng_ll_disable(void)
|
||||
{
|
||||
rng_ll_enable_sample(false);
|
||||
rng_ll_enable_rtc_timer(false);
|
||||
rng_ll_enable_rng_timer(false);
|
||||
_lp_clkrst_ll_enable_rng_clock(false);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Reference in New Issue
Block a user