1
1
/*
2
- * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2
+ * SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
11
11
#include "soc/periph_defs.h"
12
12
#include "soc/pcr_reg.h"
13
13
#include "soc/soc.h"
14
+ #include "soc/lpperi_reg.h"
14
15
15
16
#ifdef __cplusplus
16
17
extern "C" {
@@ -77,8 +78,6 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
77
78
return PCR_TSENS_CLK_EN ;
78
79
case PERIPH_REGDMA_MODULE :
79
80
return PCR_REGDMA_CLK_EN ;
80
- // case PERIPH_RNG_MODULE:
81
- // return PCR_WIFI_CLK_RNG_EN;
82
81
// case PERIPH_WIFI_MODULE:
83
82
// return PCR_WIFI_CLK_WIFI_EN_M;
84
83
// case PERIPH_BT_MODULE:
@@ -89,6 +88,8 @@ static inline uint32_t periph_ll_get_clk_en_mask(periph_module_t periph)
89
88
// return PCR_BT_BASEBAND_EN;
90
89
// case PERIPH_BT_LC_MODULE:
91
90
// return PCR_BT_LC_EN;
91
+ case PERIPH_RNG_MODULE :
92
+ return LPPERI_RNG_CK_EN ;
92
93
default :
93
94
return 0 ;
94
95
}
@@ -197,7 +198,6 @@ static inline uint32_t periph_ll_get_rst_en_mask(periph_module_t periph, bool en
197
198
static uint32_t periph_ll_get_clk_en_reg (periph_module_t periph )
198
199
{// ESP32H2-TODO: IDF-6400
199
200
switch (periph ) {
200
- // case PERIPH_RNG_MODULE:
201
201
// case PERIPH_WIFI_MODULE:
202
202
// case PERIPH_BT_MODULE:
203
203
// case PERIPH_WIFI_BT_COMMON_MODULE:
@@ -263,6 +263,8 @@ static uint32_t periph_ll_get_clk_en_reg(periph_module_t periph)
263
263
return PCR_TSENS_CLK_CONF_REG ;
264
264
case PERIPH_REGDMA_MODULE :
265
265
return PCR_REGDMA_CONF_REG ;
266
+ case PERIPH_RNG_MODULE :
267
+ return LPPERI_CLK_EN_REG ;
266
268
default :
267
269
return 0 ;
268
270
}
@@ -337,14 +339,30 @@ static uint32_t periph_ll_get_rst_en_reg(periph_module_t periph)
337
339
338
340
static inline void periph_ll_enable_clk_clear_rst (periph_module_t periph )
339
341
{
340
- SET_PERI_REG_MASK (periph_ll_get_clk_en_reg (periph ), periph_ll_get_clk_en_mask (periph ));
341
- CLEAR_PERI_REG_MASK (periph_ll_get_rst_en_reg (periph ), periph_ll_get_rst_en_mask (periph , true));
342
+ uint32_t clk_en_reg = periph_ll_get_clk_en_reg (periph );
343
+ uint32_t rst_en_reg = periph_ll_get_rst_en_reg (periph );
344
+
345
+ if (clk_en_reg != 0 ) {
346
+ SET_PERI_REG_MASK (clk_en_reg , periph_ll_get_clk_en_mask (periph ));
347
+ }
348
+
349
+ if (rst_en_reg != 0 ) {
350
+ CLEAR_PERI_REG_MASK (rst_en_reg , periph_ll_get_rst_en_mask (periph , true));
351
+ }
342
352
}
343
353
344
354
static inline void periph_ll_disable_clk_set_rst (periph_module_t periph )
345
355
{
346
- CLEAR_PERI_REG_MASK (periph_ll_get_clk_en_reg (periph ), periph_ll_get_clk_en_mask (periph ));
347
- SET_PERI_REG_MASK (periph_ll_get_rst_en_reg (periph ), periph_ll_get_rst_en_mask (periph , false));
356
+ uint32_t clk_en_reg = periph_ll_get_clk_en_reg (periph );
357
+ uint32_t rst_en_reg = periph_ll_get_rst_en_reg (periph );
358
+
359
+ if (clk_en_reg != 0 ) {
360
+ CLEAR_PERI_REG_MASK (clk_en_reg , periph_ll_get_clk_en_mask (periph ));
361
+ }
362
+
363
+ if (rst_en_reg != 0 ) {
364
+ SET_PERI_REG_MASK (rst_en_reg , periph_ll_get_rst_en_mask (periph , false));
365
+ }
348
366
}
349
367
350
368
static inline void periph_ll_wifi_bt_module_enable_clk (void )
@@ -359,14 +377,26 @@ static inline void periph_ll_wifi_bt_module_disable_clk(void)
359
377
360
378
static inline void periph_ll_reset (periph_module_t periph )
361
379
{
362
- SET_PERI_REG_MASK (periph_ll_get_rst_en_reg (periph ), periph_ll_get_rst_en_mask (periph , false));
363
- CLEAR_PERI_REG_MASK (periph_ll_get_rst_en_reg (periph ), periph_ll_get_rst_en_mask (periph , false));
380
+ uint32_t rst_en_reg = periph_ll_get_rst_en_reg (periph );
381
+
382
+ if (rst_en_reg != 0 ) {
383
+ SET_PERI_REG_MASK (rst_en_reg , periph_ll_get_rst_en_mask (periph , false));
384
+ CLEAR_PERI_REG_MASK (rst_en_reg , periph_ll_get_rst_en_mask (periph , false));
385
+ }
364
386
}
365
387
366
388
static inline bool periph_ll_periph_enabled (periph_module_t periph )
367
389
{
368
- return REG_GET_BIT (periph_ll_get_rst_en_reg (periph ), periph_ll_get_rst_en_mask (periph , false)) == 0 &&
369
- REG_GET_BIT (periph_ll_get_clk_en_reg (periph ), periph_ll_get_clk_en_mask (periph )) != 0 ;
390
+ uint32_t clk_en_reg = periph_ll_get_clk_en_reg (periph );
391
+ uint32_t rst_en_reg = periph_ll_get_rst_en_reg (periph );
392
+
393
+ bool clk_enabled = (clk_en_reg != 0 ) &&
394
+ (REG_GET_BIT (clk_en_reg , periph_ll_get_clk_en_mask (periph )) != 0 );
395
+
396
+ bool rst_disabled = (rst_en_reg == 0 ) ||
397
+ (REG_GET_BIT (rst_en_reg , periph_ll_get_rst_en_mask (periph , false)) == 0 );
398
+
399
+ return clk_enabled && rst_disabled ;
370
400
}
371
401
372
402
static inline void periph_ll_wifi_module_enable_clk_clear_rst (void )
0 commit comments