@@ -170,10 +170,6 @@ typedef struct {
170170 uart_hal_context_t hal ; /*!< UART hal context*/
171171 DECLARE_CRIT_SECTION_LOCK_IN_STRUCT (spinlock )
172172 bool hw_enabled ;
173- #if SOC_UART_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
174- bool retention_link_inited ; /*!< Mark whether the retention link is inited */
175- bool retention_link_created ; /*!< Mark whether the retention link is created */
176- #endif
177173} uart_context_t ;
178174
179175static uart_obj_t * p_uart_obj [UART_NUM_MAX ] = {0 };
@@ -197,7 +193,7 @@ static uart_context_t uart_context[UART_NUM_MAX] = {
197193
198194static portMUX_TYPE uart_selectlock = portMUX_INITIALIZER_UNLOCKED ;
199195
200- #if SOC_UART_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
196+ #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
201197static esp_err_t uart_create_sleep_retention_link_cb (void * arg );
202198#endif
203199
@@ -218,11 +214,11 @@ static void uart_module_enable(uart_port_t uart_num)
218214 }
219215 }
220216
221- #if SOC_UART_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
217+ #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP // for targets that is ! SOC_UART_SUPPORT_SLEEP_RETENTION, retention module should still be inited to avoid TOP PD
222218 // Initialize sleep retention module for HP UART
223219 if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM ) { // Console uart retention has been taken care in sleep_sys_periph_stdout_console_uart_retention_init
224- assert (!uart_context [uart_num ].retention_link_inited );
225220 sleep_retention_module_t module = uart_reg_retention_info [uart_num ].module ;
221+ assert (!sleep_retention_is_module_inited (module ));
226222 sleep_retention_module_init_param_t init_param = {
227223 .cbs = {
228224 .create = {
@@ -232,9 +228,7 @@ static void uart_module_enable(uart_port_t uart_num)
232228 },
233229 .depends = RETENTION_MODULE_BITMAP_INIT (CLOCK_SYSTEM )
234230 };
235- if (sleep_retention_module_init (module , & init_param ) == ESP_OK ) {
236- uart_context [uart_num ].retention_link_inited = true;
237- } else {
231+ if (sleep_retention_module_init (module , & init_param ) != ESP_OK ) {
238232 ESP_LOGW (UART_TAG , "init sleep retention failed for uart%d, power domain may be turned off during sleep" , uart_num );
239233 }
240234 }
@@ -259,13 +253,12 @@ static void uart_module_disable(uart_port_t uart_num)
259253 _lock_acquire (& (uart_context [uart_num ].mutex ));
260254 if (uart_context [uart_num ].hw_enabled != false) {
261255 if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM && uart_num < SOC_UART_HP_NUM ) {
262- #if SOC_UART_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
256+ #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
263257 // Uninitialize sleep retention module for HP UART
264258 sleep_retention_module_t module = uart_reg_retention_info [uart_num ].module ;
265- assert (!uart_context [ uart_num ]. retention_link_created ); // HP UART sleep retention should have been freed at this moment
266- if (uart_context [ uart_num ]. retention_link_inited ) {
259+ assert (!sleep_retention_is_module_created ( module ) ); // HP UART sleep retention should have been freed at this moment
260+ if (sleep_retention_is_module_inited ( module ) ) {
267261 sleep_retention_module_deinit (module );
268- uart_context [uart_num ].retention_link_inited = false;
269262 }
270263#endif
271264 HP_UART_SRC_CLK_ATOMIC () {
@@ -888,21 +881,18 @@ esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_conf
888881 if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM && uart_num < SOC_UART_HP_NUM ) {
889882 _lock_acquire (& (uart_context [uart_num ].mutex ));
890883 sleep_retention_module_t module = uart_reg_retention_info [uart_num ].module ;
891- if (allow_pd && !uart_context [uart_num ].retention_link_created ) {
892- if (uart_context [uart_num ].retention_link_inited ) {
893- if (sleep_retention_module_allocate (module ) == ESP_OK ) {
894- uart_context [uart_num ].retention_link_created = true;
895- } else {
884+ if (allow_pd && !sleep_retention_is_module_created (module )) {
885+ if (sleep_retention_is_module_inited (module )) {
886+ if (sleep_retention_module_allocate (module ) != ESP_OK ) {
896887 // Even though the sleep retention module create failed, UART driver should still work, so just warning here
897888 ESP_LOGW (UART_TAG , "create retention module failed, power domain can't turn off" );
898889 }
899890 } else {
900891 ESP_LOGW (UART_TAG , "retention module not initialized first, unable to create retention module" );
901892 }
902- } else if (!allow_pd && uart_context [ uart_num ]. retention_link_created ) {
903- assert (uart_context [ uart_num ]. retention_link_inited );
893+ } else if (!allow_pd && sleep_retention_is_module_created ( module ) ) {
894+ assert (sleep_retention_is_module_inited ( module ) );
904895 sleep_retention_module_free (module );
905- uart_context [uart_num ].retention_link_created = false;
906896 }
907897 _lock_release (& (uart_context [uart_num ].mutex ));
908898 }
@@ -1831,10 +1821,9 @@ esp_err_t uart_driver_delete(uart_port_t uart_num)
18311821 if (uart_num != CONFIG_ESP_CONSOLE_UART_NUM && uart_num < SOC_UART_HP_NUM ) {
18321822 sleep_retention_module_t module = uart_reg_retention_info [uart_num ].module ;
18331823 _lock_acquire (& (uart_context [uart_num ].mutex ));
1834- if (uart_context [ uart_num ]. retention_link_created ) {
1835- assert (uart_context [ uart_num ]. retention_link_inited );
1824+ if (sleep_retention_is_module_created ( module ) ) {
1825+ assert (sleep_retention_is_module_inited ( module ) );
18361826 sleep_retention_module_free (module );
1837- uart_context [uart_num ].retention_link_created = false;
18381827 }
18391828 _lock_release (& (uart_context [uart_num ].mutex ));
18401829 }
@@ -1998,16 +1987,18 @@ void uart_set_always_rx_timeout(uart_port_t uart_num, bool always_rx_timeout)
19981987 }
19991988}
20001989
2001- #if SOC_UART_SUPPORT_SLEEP_RETENTION && CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
1990+ #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP
20021991static esp_err_t uart_create_sleep_retention_link_cb (void * arg )
20031992{
1993+ #if SOC_UART_SUPPORT_SLEEP_RETENTION
20041994 uart_context_t * group = (uart_context_t * )arg ;
20051995 uart_port_t uart_num = group -> port_id ;
20061996 sleep_retention_module_t module = uart_reg_retention_info [uart_num ].module ;
20071997 esp_err_t err = sleep_retention_entries_create (uart_reg_retention_info [uart_num ].regdma_entry_array ,
20081998 uart_reg_retention_info [uart_num ].array_size ,
20091999 REGDMA_LINK_PRI_UART , module );
20102000 ESP_RETURN_ON_ERROR (err , UART_TAG , "create retention link failed" );
2001+ #endif
20112002 return ESP_OK ;
20122003}
20132004#endif
0 commit comments