Skip to content

Commit aeba992

Browse files
committed
feat(hal): add esp32h4 PAU initial support
1 parent ee9c1ae commit aeba992

File tree

3 files changed

+397
-0
lines changed

3 files changed

+397
-0
lines changed
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// The LL layer for ESP32-H4 LP_AON register operations
8+
9+
#pragma once
10+
11+
#include <stdlib.h>
12+
#include "soc/soc.h"
13+
#include "soc/lp_aon_struct.h"
14+
#include "hal/misc.h"
15+
#include "esp32h4/rom/rtc.h"
16+
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
/**
23+
* @brief Get ext1 wakeup source status
24+
* @return The lower 8 bits of the returned value are the bitmap of
25+
* the wakeup source status, bit 0~7 corresponds to LP_IO 0~7
26+
*/
27+
static inline uint32_t lp_aon_ll_ext1_get_wakeup_status(void)
28+
{
29+
return HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl1, aon_ext_wakeup_status);
30+
}
31+
32+
/**
33+
* @brief Clear the ext1 wakeup source status
34+
*/
35+
static inline void lp_aon_ll_ext1_clear_wakeup_status(void)
36+
{
37+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl1, aon_ext_wakeup_status_clr, 1);
38+
}
39+
40+
/**
41+
* @brief Set the wake-up LP_IO of the ext1 wake-up source
42+
* @param io_mask wakeup LP_IO bitmap, bit 0~7 corresponds to LP_IO 0~7
43+
* @param level_mask LP_IO wakeup level bitmap, bit 0~7 corresponds to LP_IO 0~7 wakeup level
44+
* each bit's corresponding position is set to 0, the wakeup level will be low
45+
* on the contrary, each bit's corresponding position is set to 1, the wakeup
46+
* level will be high
47+
*/
48+
static inline void lp_aon_ll_ext1_set_wakeup_pins(uint32_t io_mask, uint32_t level_mask)
49+
{
50+
uint32_t wakeup_sel_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_sel);
51+
wakeup_sel_mask |= io_mask;
52+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_sel, wakeup_sel_mask);
53+
54+
uint32_t wakeup_level_mask = HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_lv);
55+
wakeup_level_mask |= io_mask & level_mask;
56+
wakeup_level_mask &= ~(io_mask & ~level_mask);
57+
58+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_lv, wakeup_level_mask);
59+
}
60+
61+
/**
62+
* @brief Clear all ext1 wakup-source setting
63+
*/
64+
static inline void lp_aon_ll_ext1_clear_wakeup_pins(void)
65+
{
66+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_sel, 0);
67+
}
68+
69+
/**
70+
* @brief Get ext1 wakeup source setting
71+
* @return The lower 8 bits of the returned value are the bitmap of
72+
* the wakeup source status, bit 0~7 corresponds to LP_IO 0~7
73+
*/
74+
static inline uint32_t lp_aon_ll_ext1_get_wakeup_pins(void)
75+
{
76+
return HAL_FORCE_READ_U32_REG_FIELD(LP_AON.ext_wakeup_cntl, aon_ext_wakeup_sel);
77+
}
78+
79+
80+
/**
81+
* @brief ROM obtains the wake-up type through LP_AON_STORE9_REG[0].
82+
* Set the flag to inform
83+
* @param true: deepsleep false: lightsleep
84+
*/
85+
static inline void lp_aon_ll_inform_wakeup_type(bool dslp)
86+
{
87+
if (dslp) {
88+
REG_SET_BIT(SLEEP_MODE_REG, BIT(0)); /* Tell rom to run deep sleep wake stub */
89+
90+
} else {
91+
REG_CLR_BIT(SLEEP_MODE_REG, BIT(0)); /* Tell rom to run light sleep wake stub */
92+
}
93+
}
94+
95+
/**
96+
* @brief Set the maximum number of linked lists supported by REGDMA
97+
* @param count: the maximum number of regdma link
98+
*/
99+
static inline void lp_aon_ll_set_regdma_link_count(int count)
100+
{
101+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg0, aon_branch_link_length_aon, count);
102+
}
103+
104+
static inline void lp_aon_ll_set_regdma_link_addr(uint32_t addr)
105+
{
106+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg2, aon_link_addr_aon, addr);
107+
}
108+
109+
/**
110+
* @brief Set the maximum number of times a single linked list can run for REGDMA. If a linked list continuously reads in a loop
111+
* for some reason and the execution count exceeds this configured number, a timeout will be triggered.
112+
* @param count: the maximum number of loop
113+
*/
114+
static inline void lp_aon_ll_set_regdma_link_loop_threshold(int count)
115+
{
116+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg1, aon_link_work_tout_thres_aon, count);
117+
}
118+
119+
/**
120+
* @brief Set the timeout duration for accessing registers. If REGDMA encounters bus-related issues while accessing
121+
* registers and gets stuck on the bus, a timeout will be triggered.
122+
* @param count: the maximum number of time
123+
*/
124+
static inline void lp_aon_ll_set_regdma_link_reg_access_tout_threshold(int count)
125+
{
126+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg1, aon_link_backup_tout_thres_aon, count);
127+
}
128+
129+
static inline void lp_aon_ll_set_regdma_link_wait_retry_count(int count)
130+
{
131+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg1, aon_link_wait_tout_thres_aon, count);
132+
}
133+
134+
static inline void lp_aon_ll_set_regdma_link_wait_read_interval(int interval)
135+
{
136+
HAL_FORCE_MODIFY_U32_REG_FIELD(LP_AON.backup_dma_cfg0, aon_read_interval_aon, interval);
137+
}
138+
139+
#ifdef __cplusplus
140+
}
141+
#endif
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// The LL layer for ESP32-H4 PAU(Power Assist Unit) register operations
8+
9+
#pragma once
10+
11+
#include <stdlib.h>
12+
#include <stdbool.h>
13+
#include "soc/soc.h"
14+
#include "soc/pau_reg.h"
15+
#include "soc/pau_struct.h"
16+
#include "soc/pcr_struct.h"
17+
#include "hal/pau_types.h"
18+
#include "hal/assert.h"
19+
#include "soc/lp_aon_struct.h"
20+
#include "soc/lp_aon_reg.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
static inline void pau_ll_enable_bus_clock(bool enable)
27+
{
28+
if (enable) {
29+
PCR.regdma_conf.regdma_clk_en = 1;
30+
PCR.regdma_conf.regdma_rst_en = 0;
31+
} else {
32+
PCR.regdma_conf.regdma_clk_en = 0;
33+
PCR.regdma_conf.regdma_rst_en = 1;
34+
}
35+
}
36+
37+
static inline uint32_t pau_ll_get_regdma_backup_flow_error(pau_dev_t *dev)
38+
{
39+
return LP_AON.backup_dma_cfg0.aon_regdma_error;
40+
}
41+
42+
static inline void pau_ll_select_regdma_entry_link(pau_dev_t *dev, int link)
43+
{
44+
dev->regdma_conf.link_sel = link;
45+
}
46+
47+
static inline void pau_ll_set_regdma_entry_link_backup_direction(pau_dev_t *dev, bool to_mem)
48+
{
49+
dev->regdma_conf.to_mem = to_mem ? 1 : 0;
50+
}
51+
52+
static inline void pau_ll_set_regdma_entry_link_backup_start_enable(pau_dev_t *dev)
53+
{
54+
dev->regdma_conf.start = 1;
55+
}
56+
57+
static inline void pau_ll_set_regdma_entry_link_backup_start_disable(pau_dev_t *dev)
58+
{
59+
dev->regdma_conf.start = 0;
60+
}
61+
62+
static inline void pau_ll_set_regdma_link0_addr(pau_dev_t *dev, void *link_addr)
63+
{
64+
LP_AON.backup_dma_cfg2.aon_link_addr_aon = (uint32_t)link_addr;
65+
}
66+
67+
static inline void pau_ll_set_regdma_timeout_link_backup_wait(pau_dev_t *dev, uint32_t thres)
68+
{
69+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG1_REG, LP_AON_LINK_BACKUP_TOUT_THRES_AON, thres);
70+
}
71+
72+
static inline void pau_ll_set_regdma_timeout_read_interval(pau_dev_t *dev, uint32_t thres)
73+
{
74+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG0_REG, LP_AON_READ_INTERVAL_AON, thres);
75+
}
76+
77+
static inline void pau_ll_set_regdma_timeout_burst_limit(pau_dev_t *dev, uint32_t thres)
78+
{
79+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG0_REG, LP_AON_BURST_LIMIT_AON, thres);
80+
}
81+
static inline void pau_ll_set_regdma_timeout_max_link_work(pau_dev_t *dev, uint32_t thres)
82+
{
83+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG1_REG, LP_AON_LINK_WORK_TOUT_THRES_AON, thres);
84+
}
85+
86+
static inline void pau_ll_set_regdma_timeout_read_mode_try_time(pau_dev_t *dev, uint32_t thres)
87+
{
88+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG1_REG, LP_AON_LINK_WAIT_TOUT_THRES_AON, thres);
89+
}
90+
91+
static inline void pau_ll_set_regdma_branch_max_link(pau_dev_t *dev, uint32_t max_link_len)
92+
{
93+
REG_SET_FIELD(LP_AON_BACKUP_DMA_CFG1_REG, LP_AON_BRANCH_LINK_LENGTH_AON, max_link_len);
94+
}
95+
96+
static inline uint32_t pau_ll_get_regdma_current_link_addr(pau_dev_t *dev)
97+
{
98+
return dev->regdma_current_link_addr.val;
99+
}
100+
101+
static inline uint32_t pau_ll_get_regdma_backup_addr(pau_dev_t *dev)
102+
{
103+
return dev->regdma_peri_addr.val;
104+
}
105+
106+
static inline uint32_t pau_ll_get_regdma_memory_addr(pau_dev_t *dev)
107+
{
108+
return dev->regdma_mem_addr.val;
109+
}
110+
111+
static inline uint32_t pau_ll_get_regdma_intr_raw_signal(pau_dev_t *dev)
112+
{
113+
return dev->int_raw.val;
114+
}
115+
116+
static inline uint32_t pau_ll_get_regdma_intr_status(pau_dev_t *dev)
117+
{
118+
return dev->int_st.val;
119+
}
120+
121+
static inline void pau_ll_set_regdma_backup_done_intr_enable(pau_dev_t *dev)
122+
{
123+
dev->int_ena.done_int_ena = 1;
124+
}
125+
126+
static inline void pau_ll_set_regdma_backup_done_intr_disable(pau_dev_t *dev)
127+
{
128+
dev->int_ena.done_int_ena = 0;
129+
}
130+
131+
static inline void pau_ll_set_regdma_backup_error_intr_enable(pau_dev_t *dev)
132+
{
133+
dev->int_ena.error_int_ena = 1;
134+
}
135+
136+
static inline void pau_ll_set_regdma_backup_error_intr_disable(pau_dev_t *dev)
137+
{
138+
dev->int_ena.error_int_ena = 0;
139+
}
140+
141+
static inline void pau_ll_clear_regdma_backup_done_intr_state(pau_dev_t *dev)
142+
{
143+
dev->int_clr.done_int_clr = 1;
144+
}
145+
146+
static inline void pau_ll_clear_regdma_backup_error_intr_state(pau_dev_t *dev)
147+
{
148+
dev->int_clr.error_int_clr = 1;
149+
}
150+
151+
static inline void pau_ll_arbiter_auto_retry_enable(pau_dev_t *dev, bool ena)
152+
{
153+
dev->regdma_conf.sw_retry_en = ena;
154+
}
155+
156+
static inline void pau_ll_arbiter_fix_priority_enable(pau_dev_t *dev, bool ena)
157+
{
158+
dev->regdma_conf.fix_pri_en = ena;
159+
}
160+
161+
/**
162+
* arbiter result coding:
163+
* 1: mac_req
164+
* 2: pmu_req
165+
* 3: sw_req
166+
* 4: etm0_req
167+
* 5: etm1_req
168+
* 6: etm2_req
169+
* 7: etm3_req
170+
*/
171+
static inline uint32_t pau_ll_arbiter_get_start_result(pau_dev_t *dev)
172+
{
173+
return dev->regdma_grant_result.grant_start_result;
174+
}
175+
176+
static inline uint32_t pau_ll_arbiter_get_done_result(pau_dev_t *dev)
177+
{
178+
return dev->regdma_grant_result.grant_done_result;
179+
}
180+
181+
static inline void pau_ll_arbiter_clr_result_flag(pau_dev_t *dev)
182+
{
183+
dev->regdma_grant_result.grant_result_clr = 1;
184+
}
185+
186+
static inline bool pau_ll_is_busy(pau_dev_t *dev)
187+
{
188+
return dev->regdma_conf.paudma_busy;
189+
}
190+
191+
#ifdef __cplusplus
192+
}
193+
#endif

components/hal/esp32h4/pau_hal.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// The HAL layer for PAU (ESP32-H4 specific part)
8+
9+
#include "soc/soc.h"
10+
#include "esp_attr.h"
11+
#include "hal/pau_hal.h"
12+
#include "hal/pau_types.h"
13+
#include "hal/lp_aon_ll.h"
14+
15+
void pau_hal_set_regdma_entry_link_addr(pau_hal_context_t *hal, pau_regdma_link_addr_t *link_addr)
16+
{
17+
lp_aon_ll_set_regdma_link_addr((uint32_t)(*link_addr)[0]);
18+
}
19+
20+
void IRAM_ATTR pau_hal_start_regdma_extra_link(pau_hal_context_t *hal, bool backup_or_restore)
21+
{
22+
pau_ll_clear_regdma_backup_done_intr_state(hal->dev);
23+
/* The link 3 of REGDMA is reserved, we use it as an extra linked list to
24+
* provide backup and restore services for BLE, IEEE802.15.4 and possibly
25+
* other modules.
26+
* It is also used as software trigger REGDMA to backup and restore, and is
27+
* used by the UT to test module driver retention function.
28+
*/
29+
pau_ll_select_regdma_entry_link(hal->dev, 3);
30+
pau_ll_set_regdma_entry_link_backup_direction(hal->dev, backup_or_restore);
31+
pau_ll_set_regdma_entry_link_backup_start_enable(hal->dev);
32+
33+
while (!(pau_ll_get_regdma_intr_raw_signal(hal->dev) & PAU_DONE_INT_RAW));
34+
}
35+
36+
void IRAM_ATTR pau_hal_stop_regdma_extra_link(pau_hal_context_t *hal)
37+
{
38+
pau_ll_set_regdma_entry_link_backup_start_disable(hal->dev);
39+
pau_ll_select_regdma_entry_link(hal->dev, 0); /* restore link select to default */
40+
pau_ll_clear_regdma_backup_done_intr_state(hal->dev);
41+
}
42+
43+
#if SOC_PM_PAU_REGDMA_LINK_CONFIGURABLE
44+
void pau_hal_regdma_link_count_config(pau_hal_context_t *hal, int count)
45+
{
46+
HAL_ASSERT(count > 0);
47+
lp_aon_ll_set_regdma_link_count(count - 1);
48+
}
49+
#endif
50+
51+
void pau_hal_set_regdma_work_timeout(pau_hal_context_t *hal, uint32_t loop_num, uint32_t time)
52+
{
53+
HAL_ASSERT(loop_num > 0 && time > 0);
54+
lp_aon_ll_set_regdma_link_loop_threshold(loop_num);
55+
lp_aon_ll_set_regdma_link_reg_access_tout_threshold(time);
56+
}
57+
58+
void pau_hal_set_regdma_wait_timeout(pau_hal_context_t *hal, int count, int interval)
59+
{
60+
HAL_ASSERT(count > 0 && interval > 0);
61+
lp_aon_ll_set_regdma_link_wait_retry_count(count);
62+
lp_aon_ll_set_regdma_link_wait_read_interval(interval);
63+
}

0 commit comments

Comments
 (0)