From c60d991c28025723cec44c216f8354916331535b Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Wed, 18 Sep 2024 16:44:22 +0800 Subject: [PATCH 1/6] feat(esp_hw_support): extend sleep retention module bitmap bit width --- .../include/esp_private/esp_regdma.h | 42 ++-- .../include/esp_private/sleep_retention.h | 78 ++++++- components/esp_hw_support/port/regdma_link.c | 68 +++---- components/esp_hw_support/sleep_retention.c | 190 +++++++++++++----- components/soc/include/soc/regdma.h | 2 +- 5 files changed, 267 insertions(+), 113 deletions(-) diff --git a/components/esp_hw_support/include/esp_private/esp_regdma.h b/components/esp_hw_support/include/esp_private/esp_regdma.h index 9e904997f7..3857863559 100644 --- a/components/esp_hw_support/include/esp_private/esp_regdma.h +++ b/components/esp_hw_support/include/esp_private/esp_regdma.h @@ -35,7 +35,7 @@ extern "C" { * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_continuous(void *backup, void *buff, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_continuous(void *backup, void *buff, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA addr_map type linked list node without retention buffer and the retention buffer is passed in by the caller @@ -52,7 +52,7 @@ void *regdma_link_new_continuous(void *backup, void *buff, int len, void *restor * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA write type linked list node without retention buffer and the retention buffer is passed in by the caller @@ -66,7 +66,7 @@ void *regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], int * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA write type linked list node without retention buffer and the retention buffer is passed in by the caller @@ -80,7 +80,7 @@ void *regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void *n * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA continuouos branch list node without retention buffer and the retention buffer is passed in by the caller @@ -95,7 +95,7 @@ void *regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *ne * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_continuous(void *backup, void *buff, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_continuous(void *backup, void *buff, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA addr_map branch list node without retention buffer and the retention buffer is passed in by the caller @@ -112,7 +112,7 @@ void *regdma_link_new_branch_continuous(void *backup, void *buff, int len, void * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA write branch list node without retention buffer and the retention buffer is passed in by the caller @@ -126,7 +126,7 @@ void *regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap[ * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a REGDMA wait branch list node without retention buffer and the retention buffer is passed in by the caller @@ -140,7 +140,7 @@ void *regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA continuous type linked list node with retention buffer @@ -154,7 +154,7 @@ void *regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, r * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_continuous_default(void *backup, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_continuous_default(void *backup, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA addr_map type linked list node with retention buffer @@ -170,7 +170,7 @@ void *regdma_link_new_continuous_default(void *backup, int len, void *restore, v * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA write type linked list node with retention buffer @@ -184,7 +184,7 @@ void *regdma_link_new_addr_map_default(void *backup, uint32_t bitmap[4], int len * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_write_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_write_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA wait type linked list node with retention buffer @@ -198,7 +198,7 @@ void *regdma_link_new_write_default(void *backup, uint32_t value, uint32_t mask, * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_wait_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_wait_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA continuous branch list node with retention buffer @@ -212,7 +212,7 @@ void *regdma_link_new_wait_default(void *backup, uint32_t value, uint32_t mask, * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_continuous_default(void *backup, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_continuous_default(void *backup, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA addr_map branch list node with retention buffer @@ -228,7 +228,7 @@ void *regdma_link_new_branch_continuous_default(void *backup, int len, void *res * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA write branch list node with retention buffer @@ -242,7 +242,7 @@ void *regdma_link_new_branch_addr_map_default(void *backup, uint32_t bitmap[4], * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_write_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_write_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create a default REGDMA wait branch list node with retention buffer @@ -256,7 +256,7 @@ void *regdma_link_new_branch_write_default(void *backup, uint32_t value, uint32_ * @param module The module identifier of the current linked list node * @return Created REGDMA linked list node pointer */ -void *regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module); +void *regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module); /** * @brief Create and initialize a REGDMA linked list node through configuration parameters @@ -267,7 +267,7 @@ void *regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t * @param args next pointer, Since REGDMA supports 4 entries, it supports up to 4 variable parameter next pointers, and more will be ignored * @return Initialized REGDMA linked list head node pointer */ -void *regdma_link_init(const regdma_link_config_t *config, bool branch, uint32_t module, int nentry, ...); +void *regdma_link_init(const regdma_link_config_t *config, bool branch, int module, int nentry, ...); /** * @brief Get REGDMA linked list node mode through configuration parameters @@ -361,7 +361,7 @@ uint32_t regdma_link_get_owner_bitmap(void *link, void *tail, int entry); * @param module Module bitmap Identification * @return The found head node pointer or NULL */ -void *regdma_find_module_link_head(void *link, void *tail, int entry, uint32_t module); +void *regdma_find_module_link_head(void *link, void *tail, int entry, int module); /** * @brief Find the tail node of the specified module in the REGDMA linked list indicated by the @@ -372,7 +372,7 @@ void *regdma_find_module_link_head(void *link, void *tail, int entry, uint32_t m * @param module Module bitmap Identification * @return The found tail node pointer or NULL */ -void *regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t module); +void *regdma_find_module_link_tail(void *link, void *tail, int entry, int module); /** * @brief Find the tail node of the previous module of the specified module in the REGDMA linked list @@ -383,7 +383,7 @@ void *regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t m * @param module Module bitmap Identification * @return The found tail node pointer or NULL */ -void *regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint32_t module); +void *regdma_find_prev_module_link_tail(void *link, void *tail, int entry, int module); /** * @brief Find the head node of the next module of the specified module in the REGDMA linked list @@ -394,7 +394,7 @@ void *regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint3 * @param module Module bitmap Identification * @return The found head node pointer or NULL */ -void *regdma_find_next_module_link_head(void *link, void *tail, int entry, uint32_t module); +void *regdma_find_next_module_link_head(void *link, void *tail, int entry, int module); #define regdma_link_init_safe(pcfg, branch, module, ...) regdma_link_init((pcfg), (branch), (module), __VA_NARG__(__VA_ARGS__), ##__VA_ARGS__) diff --git a/components/esp_hw_support/include/esp_private/sleep_retention.h b/components/esp_hw_support/include/esp_private/sleep_retention.h index 85f96f7c51..2d83f29b0b 100644 --- a/components/esp_hw_support/include/esp_private/sleep_retention.h +++ b/components/esp_hw_support/include/esp_private/sleep_retention.h @@ -17,6 +17,8 @@ extern "C" { #include "esp_regdma.h" #include "soc/retention_periph_defs.h" +#define SLEEP_RETENTION_MODULE_BITMAP_SZ ((SLEEP_RETENTION_MODULE_MAX >> 5) + 1) + /** * @file sleep_retention.h * @@ -24,7 +26,10 @@ extern "C" { * includes sleep retention list creation, destruction and debugging interfaces. */ typedef periph_retention_module_t sleep_retention_module_t; -typedef periph_retention_module_bitmap_t sleep_retention_module_bitmap_t; +typedef struct { +#define RETENTION_MODULE_BITMAP_INIT(module) { .bitmap[(SLEEP_RETENTION_MODULE_ ## module) >> 5] = BIT((SLEEP_RETENTION_MODULE_ ## module) % 32) } + uint32_t bitmap[SLEEP_RETENTION_MODULE_BITMAP_SZ]; +} sleep_retention_module_bitmap_t; typedef regdma_entry_buf_t sleep_retention_entries_t; typedef regdma_entries_config_t sleep_retention_entries_config_t; @@ -149,7 +154,7 @@ esp_err_t sleep_retention_module_free(sleep_retention_module_t module); * * @return the bitmap for all modules that require sleep retention */ -uint32_t sleep_retention_get_inited_modules(void); +sleep_retention_module_bitmap_t sleep_retention_get_inited_modules(void); /** * @brief Get all created modules that require sleep retention @@ -162,7 +167,74 @@ uint32_t sleep_retention_get_inited_modules(void); * @return the bitmap for all modules that have successfully created a sleep * retention context */ -uint32_t sleep_retention_get_created_modules(void); +sleep_retention_module_bitmap_t sleep_retention_get_created_modules(void); + +/** + * @brief Get the initialization state of module + * + * @param module module number + * + * @return false if the module is not initialized or the module number is + * invalid, otherwise return true + */ +bool sleep_retention_is_module_inited(sleep_retention_module_t module); + +/** + * @brief Get the creation state of module + * + * @param module module number + * + * @return false if the module is not created or the module number is + * invalid, otherwise return true + */ +bool sleep_retention_is_module_created(sleep_retention_module_t module); + +/** + * @brief Calculates the bitwise logical and of the module bitmap and return results + * + * This is an unprotected interface. It can only be called by the sleep procedure. + * + * @param op0 module bitmap operator 0 + * @param op1 module bitmap operator 1 + * + * @return the bitwise logical and result of module bitmap + */ +sleep_retention_module_bitmap_t sleep_retention_module_bitmap_and(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1); + +/** + * @brief Calculates the bitwise logical or of the module bitmap and return results + * + * This is an unprotected interface. It can only be called by the sleep procedure. + * + * @param op0 module bitmap operator 0 + * @param op1 module bitmap operator 1 + * + * @return the bitwise logical or result of module bitmap + */ +sleep_retention_module_bitmap_t sleep_retention_module_bitmap_or(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1); + +/** + * @brief Calculates the bitwise logical not of the module bitmap and return results + * + * This is an unprotected interface. It can only be called by the sleep procedure. + * + * @param op0 module bitmap operator + * + * @return the bitwise logical not result of module bitmap + */ +sleep_retention_module_bitmap_t sleep_retention_module_bitmap_not(sleep_retention_module_bitmap_t op); + +/** + * @brief Compares the module bitmap values are equal and return results + * + * This is an unprotected interface. It can only be called by the sleep procedure. + * + * @param op0 module bitmap operator 0 + * @param op1 module bitmap operator 1 + * + * @return If the module bitmap values are equal then return true, otherwise return false + */ +bool sleep_retention_module_bitmap_eq(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1); #if SOC_PM_RETENTION_HAS_CLOCK_BUG /** diff --git a/components/esp_hw_support/port/regdma_link.c b/components/esp_hw_support/port/regdma_link.c index 45fc26a6cb..2ac719ce90 100644 --- a/components/esp_hw_support/port/regdma_link.c +++ b/components/esp_hw_support/port/regdma_link.c @@ -21,7 +21,7 @@ #define REGDMA_LINK_ADDR_ALIGN (4) #define REGDMA_LINK_MEM_TYPE_CAPS (MALLOC_CAP_DMA | MALLOC_CAP_DEFAULT) -void * regdma_link_new_continuous(void *backup, void *buff, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_continuous(void *backup, void *buff, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_continuous_t *link = (regdma_link_continuous_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, @@ -37,7 +37,7 @@ void * regdma_link_new_continuous(void *backup, void *buff, int len, void *resto return NULL; } -void * regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_addr_map_t *link = (regdma_link_addr_map_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, @@ -53,7 +53,7 @@ void * regdma_link_new_addr_map(void *backup, void *buff, uint32_t bitmap[4], in return NULL; } -void * regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_write_wait_t *link = (regdma_link_write_wait_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, sizeof(regdma_link_write_wait_t), REGDMA_LINK_MEM_TYPE_CAPS); @@ -65,7 +65,7 @@ void * regdma_link_new_write(void *backup, uint32_t value, uint32_t mask, void * return NULL; } -void * regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_write_wait_t *link = (regdma_link_write_wait_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, sizeof(regdma_link_write_wait_t), REGDMA_LINK_MEM_TYPE_CAPS); @@ -77,7 +77,7 @@ void * regdma_link_new_wait(void *backup, uint32_t value, uint32_t mask, void *n return NULL; } -void * regdma_link_new_branch_continuous(void *backup, void *buff, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_continuous(void *backup, void *buff, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_branch_continuous_t *link = (regdma_link_branch_continuous_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, @@ -93,7 +93,7 @@ void * regdma_link_new_branch_continuous(void *backup, void *buff, int len, void return NULL; } -void * regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_branch_addr_map_t *link = (regdma_link_branch_addr_map_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, @@ -109,7 +109,7 @@ void * regdma_link_new_branch_addr_map(void *backup, void *buff, uint32_t bitmap return NULL; } -void * regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_branch_write_wait_t *link = (regdma_link_branch_write_wait_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, sizeof(regdma_link_branch_write_wait_t), REGDMA_LINK_MEM_TYPE_CAPS); @@ -121,7 +121,7 @@ void * regdma_link_new_branch_write(void *backup, uint32_t value, uint32_t mask, return NULL; } -void * regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { regdma_link_branch_write_wait_t *link = (regdma_link_branch_write_wait_t *)heap_caps_aligned_alloc( REGDMA_LINK_ADDR_ALIGN, sizeof(regdma_link_branch_write_wait_t), REGDMA_LINK_MEM_TYPE_CAPS); @@ -133,48 +133,48 @@ void * regdma_link_new_branch_wait(void *backup, uint32_t value, uint32_t mask, return NULL; } -void * regdma_link_new_continuous_default(void *backup, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_continuous_default(void *backup, int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_continuous(backup, NULL, len, restore, next, skip_b, skip_r, id, module); } -void * regdma_link_new_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, void *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_addr_map(backup, NULL, bitmap, len, restore, next, skip_b, skip_r, id, module); } -void * regdma_link_new_write_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_write_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_write(backup, value, mask, next, skip_b, skip_r, id, module); } -void * regdma_link_new_wait_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_wait_default(void *backup, uint32_t value, uint32_t mask, void *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_wait(backup, value, mask, next, skip_b, skip_r, id, module); } -void * regdma_link_new_branch_continuous_default(void *backup, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_continuous_default(void *backup, int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_branch_continuous(backup, NULL, len, restore, next, skip_b, skip_r, id, module); } -void * regdma_link_new_branch_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_addr_map_default(void *backup, uint32_t bitmap[4], int len, void *restore, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_branch_addr_map(backup, NULL, bitmap, len, restore, next, skip_b, skip_r, id, module); } -void * regdma_link_new_branch_write_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_write_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_branch_write(backup, value, mask, next, skip_b, skip_r, id, module); } -void * regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, uint32_t module) +void * regdma_link_new_branch_wait_default(void *backup, uint32_t value, uint32_t mask, regdma_entry_buf_t *next, bool skip_b, bool skip_r, int id, int module) { return regdma_link_new_branch_wait(backup, value, mask, next, skip_b, skip_r, id, module); } -static void * regdma_link_init_continuous_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_continuous_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -187,7 +187,7 @@ static void * regdma_link_init_continuous_wrapper(const regdma_link_config_t *co config->head.skip_r, config->id, module); } -static void * regdma_link_init_addr_map_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_addr_map_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -200,7 +200,7 @@ static void * regdma_link_init_addr_map_wrapper(const regdma_link_config_t *conf config->head.skip_r, config->id, module); } -static void * regdma_link_init_write_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_write_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -213,7 +213,7 @@ static void * regdma_link_init_write_wrapper(const regdma_link_config_t *config, config->id, module); } -static void * regdma_link_init_wait_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_wait_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -226,7 +226,7 @@ static void * regdma_link_init_wait_wrapper(const regdma_link_config_t *config, config->id, module); } -static void * regdma_link_init_branch_continuous_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_branch_continuous_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -239,7 +239,7 @@ static void * regdma_link_init_branch_continuous_wrapper(const regdma_link_confi config->head.skip_b, config->head.skip_r, config->id, module); } -static void * regdma_link_init_branch_addr_map_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_branch_addr_map_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -252,7 +252,7 @@ static void * regdma_link_init_branch_addr_map_wrapper(const regdma_link_config_ &next, config->head.skip_b, config->head.skip_r, config->id, module); } -static void * regdma_link_init_branch_write_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_branch_write_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -265,7 +265,7 @@ static void * regdma_link_init_branch_write_wrapper(const regdma_link_config_t * config->head.skip_r, config->id, module); } -static void * regdma_link_init_branch_wait_wrapper(const regdma_link_config_t *config, uint32_t module, int n, va_list args) +static void * regdma_link_init_branch_wait_wrapper(const regdma_link_config_t *config, int module, int n, va_list args) { regdma_entry_buf_t next; @@ -278,7 +278,7 @@ static void * regdma_link_init_branch_wait_wrapper(const regdma_link_config_t *c config->head.skip_r, config->id, module); } -static void * regdma_link_init_wrapper(const regdma_link_config_t *config, bool branch, uint32_t module, int nentry, va_list args) +static void * regdma_link_init_wrapper(const regdma_link_config_t *config, bool branch, int module, int nentry, va_list args) { typedef void * (*init_fn_t)(const void *, uint32_t, int, va_list); @@ -301,7 +301,7 @@ static void * regdma_link_init_wrapper(const regdma_link_config_t *config, bool return (*pfn)(config, module, nentry, args); } -void * regdma_link_init(const regdma_link_config_t *config, bool branch, uint32_t module, int nentry, ...) +void * regdma_link_init(const regdma_link_config_t *config, bool branch, int module, int nentry, ...) { assert(config != NULL); @@ -640,7 +640,7 @@ uint32_t regdma_link_get_owner_bitmap(void *link, void *tail, int entry) return owner; } -void * regdma_find_module_link_head(void *link, void *tail, int entry, uint32_t module) +void * regdma_find_module_link_head(void *link, void *tail, int entry, int module) { assert(entry < REGDMA_LINK_ENTRY_NUM); @@ -648,7 +648,7 @@ void * regdma_find_module_link_head(void *link, void *tail, int entry, uint32_t void *next = link; if (link) { do { - if (regdma_link_get_stats(next)->module & module) { + if (regdma_link_get_stats(next)->module == module) { find_link = next; break; } @@ -660,7 +660,7 @@ void * regdma_find_module_link_head(void *link, void *tail, int entry, uint32_t return find_link; } -void * regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t module) +void * regdma_find_module_link_tail(void *link, void *tail, int entry, int module) { assert(entry < REGDMA_LINK_ENTRY_NUM); @@ -670,13 +670,13 @@ void * regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t do { if (next != tail) { void *temp = regdma_link_get_next(next, entry); - if ((regdma_link_get_stats(next)->module & module) && - !(regdma_link_get_stats(temp)->module & module)) { + if ((regdma_link_get_stats(next)->module == module) && + !(regdma_link_get_stats(temp)->module == module)) { find_tail = next; break; } } else { - if (regdma_link_get_stats(next)->module & module) { + if (regdma_link_get_stats(next)->module == module) { find_tail = next; break; } @@ -686,7 +686,7 @@ void * regdma_find_module_link_tail(void *link, void *tail, int entry, uint32_t return find_tail; } -void * regdma_find_next_module_link_head(void *link, void *tail, int entry, uint32_t module) +void * regdma_find_next_module_link_head(void *link, void *tail, int entry, int module) { assert(entry < REGDMA_LINK_ENTRY_NUM); void *find_tail = regdma_find_module_link_tail(link, tail, entry, module); @@ -696,7 +696,7 @@ void * regdma_find_next_module_link_head(void *link, void *tail, int entry, uint return NULL; } -void * regdma_find_prev_module_link_tail(void *link, void *tail, int entry, uint32_t module) +void * regdma_find_prev_module_link_tail(void *link, void *tail, int entry, int module) { assert(entry < REGDMA_LINK_ENTRY_NUM); void *find_head = regdma_find_module_link_head(link, tail, entry, module); diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index fcfbf694c6..6ccbd445a4 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -38,8 +38,8 @@ struct sleep_retention_module_object { static inline void sleep_retention_module_object_ctor(struct sleep_retention_module_object * const self, sleep_retention_module_callbacks_t *cbs) { self->cbs = *cbs; - self->dependents = 0; - self->references = 0; + self->dependents = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; + self->references = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; self->attributes = 0; } @@ -55,7 +55,7 @@ static inline void set_dependencies(struct sleep_retention_module_object * const static inline void clr_dependencies(struct sleep_retention_module_object * const self) { - self->dependents = 0; + self->dependents = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; } static inline sleep_retention_module_bitmap_t get_dependencies(struct sleep_retention_module_object * const self) @@ -65,12 +65,12 @@ static inline sleep_retention_module_bitmap_t get_dependencies(struct sleep_rete static inline void set_reference(struct sleep_retention_module_object * const self, sleep_retention_module_t module) { - self->references |= BIT(module); + self->references.bitmap[module >> 5] |= BIT(module % 32); } static inline void clr_reference(struct sleep_retention_module_object * const self, sleep_retention_module_t module) { - self->references &= ~BIT(module); + self->references.bitmap[module >> 5] &= ~BIT(module % 32); } static inline sleep_retention_module_bitmap_t get_references(struct sleep_retention_module_object * const self) @@ -80,7 +80,12 @@ static inline sleep_retention_module_bitmap_t get_references(struct sleep_retent static inline bool references_exist(struct sleep_retention_module_object * const self) { - return (get_references(self) != 0); + uint32_t references = 0; + sleep_retention_module_bitmap_t map = get_references(self); + for (int i = 0; i < SLEEP_RETENTION_MODULE_BITMAP_SZ; i++) { + references |= map.bitmap[i]; + } + return (references != 0); } static inline void set_attributes(struct sleep_retention_module_object * const self, sleep_retention_module_attribute_t attributes) @@ -105,12 +110,14 @@ static inline bool module_is_passive(struct sleep_retention_module_object * cons static inline bool module_is_inited(sleep_retention_module_t module) { - return (sleep_retention_get_inited_modules() & BIT(module)) ? true : false; + sleep_retention_module_bitmap_t inited_modules = sleep_retention_get_inited_modules(); + return (inited_modules.bitmap[module >> 5] & BIT(module % 32)) ? true : false; } static inline bool module_is_created(sleep_retention_module_t module) { - return (sleep_retention_get_created_modules() & BIT(module)) ? true : false; + sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules(); + return (created_modules.bitmap[module >> 5] & BIT(module % 32)) ? true : false; } /** @@ -182,10 +189,10 @@ typedef struct { } lists[SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES]; _lock_t lock; regdma_link_priority_t highpri; - uint32_t inited_modules; - uint32_t created_modules; + sleep_retention_module_bitmap_t inited_modules; + sleep_retention_module_bitmap_t created_modules; - struct sleep_retention_module_object instance[32]; + struct sleep_retention_module_object instance[SLEEP_RETENTION_MODULE_MAX + 1]; #if SOC_PM_RETENTION_HAS_CLOCK_BUG #define EXTRA_LINK_NUM (REGDMA_LINK_ENTRY_NUM - 1) @@ -193,7 +200,9 @@ typedef struct { } sleep_retention_t; static DRAM_ATTR __attribute__((unused)) sleep_retention_t s_retention = { - .highpri = (uint8_t)-1, .inited_modules = 0, .created_modules = 0 + .highpri = (uint8_t)-1, + .inited_modules = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }, + .created_modules = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } } }; #define SLEEP_RETENTION_ENTRY_BITMAP_MASK (BIT(REGDMA_LINK_ENTRY_NUM) - 1) @@ -202,11 +211,6 @@ static DRAM_ATTR __attribute__((unused)) sleep_retention_t s_retention = { static esp_err_t sleep_retention_entries_create_impl(const sleep_retention_entries_config_t retent[], int num, regdma_link_priority_t priority, sleep_retention_module_t module); static void sleep_retention_entries_join(void); -static inline sleep_retention_module_bitmap_t module_num2map(sleep_retention_module_t module) -{ - return (module == SLEEP_RETENTION_MODULE_INVALID) ? 0 : BIT(module); -} - static inline bool sleep_retention_entries_require_branch(uint32_t owner, uint32_t runtime_bitmap) { bool use_new_entry = SLEEP_RETENTION_ENTRY_BITMAP(owner & ~runtime_bitmap) ? true : false; @@ -265,9 +269,8 @@ static void * sleep_retention_entries_try_create(const regdma_link_config_t *con _lock_acquire_recursive(&s_retention.lock); if (sleep_retention_entries_require_branch(owner, s_retention.lists[priority].runtime_bitmap)) { if (sleep_retention_entries_check_and_create_default(owner, s_retention.lists[priority].runtime_bitmap, - s_retention.lists[priority].entries_bitmap, priority, module_num2map(module)) == ESP_OK) { /* branch node can't as tail node */ - link = regdma_link_init_safe( - config, true, module_num2map(module), + s_retention.lists[priority].entries_bitmap, priority, module) == ESP_OK) { /* branch node can't as tail node */ + link = regdma_link_init_safe(config, true, module, (owner & BIT(0)) ? s_retention.lists[priority].entries[0] : NULL, (owner & BIT(1)) ? s_retention.lists[priority].entries[1] : NULL, (owner & BIT(2)) ? s_retention.lists[priority].entries[2] : NULL, @@ -275,7 +278,7 @@ static void * sleep_retention_entries_try_create(const regdma_link_config_t *con ); } } else { - link = regdma_link_init_safe(config, false, module_num2map(module), s_retention.lists[priority].entries[__builtin_ffs(owner) - 1]); + link = regdma_link_init_safe(config, false, module, s_retention.lists[priority].entries[__builtin_ffs(owner) - 1]); } _lock_release_recursive(&s_retention.lock); return link; @@ -285,8 +288,7 @@ static void * sleep_retention_entries_try_create_bonding(const regdma_link_confi { assert(owner > 0 && owner < BIT(REGDMA_LINK_ENTRY_NUM)); _lock_acquire_recursive(&s_retention.lock); - void *link = regdma_link_init_safe( - config, true, module_num2map(module), + void *link = regdma_link_init_safe(config, true, module, (owner & BIT(0)) ? s_retention.lists[priority].entries[0] : NULL, (owner & BIT(1)) ? s_retention.lists[priority].entries[1] : NULL, (owner & BIT(2)) ? s_retention.lists[priority].entries[2] : NULL, @@ -355,13 +357,13 @@ static bool sleep_retention_entries_get_destroy_context(regdma_link_priority_t p _lock_acquire_recursive(&s_retention.lock); for (int entry = 0; entry < ARRAY_SIZE(s_retention.lists[priority].entries); entry++) { (*destroy_entries)[entry] = regdma_find_module_link_head( - s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module_num2map(module)); + s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module); destroy_tails [entry] = regdma_find_module_link_tail( - s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module_num2map(module)); + s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module); (*next_entries) [entry] = regdma_find_next_module_link_head( - s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module_num2map(module)); + s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module); prev_tails [entry] = regdma_find_prev_module_link_tail( - s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module_num2map(module)); + s_retention.lists[priority].entries[entry], s_retention.lists[priority].entries_tail, entry, module); if ((*destroy_entries)[entry] && destroy_tails[entry]) { exist = true; } @@ -420,7 +422,11 @@ static void sleep_retention_entries_check_and_distroy_final_default(void) { _lock_acquire_recursive(&s_retention.lock); assert(s_retention.highpri == SLEEP_RETENTION_REGDMA_LINK_LOWEST_PRIORITY); - assert(s_retention.created_modules == 0); + uint32_t created_modules = 0; + for (int i = 0; i < SLEEP_RETENTION_MODULE_BITMAP_SZ; i++) { + created_modules |= s_retention.created_modules.bitmap[i]; + } + assert(created_modules == 0); sleep_retention_entries_destroy_wrapper(&s_retention.lists[SLEEP_RETENTION_REGDMA_LINK_LOWEST_PRIORITY].entries); _lock_release_recursive(&s_retention.lock); } @@ -446,7 +452,7 @@ static void sleep_retention_entries_all_destroy_wrapper(sleep_retention_module_t priority++; } } while (priority < SLEEP_RETENTION_REGDMA_LINK_NR_PRIORITIES); - s_retention.created_modules &= ~module_num2map(module); + s_retention.created_modules.bitmap[module >> 5] &= ~BIT(module % 32); _lock_release_recursive(&s_retention.lock); } @@ -465,7 +471,11 @@ static void sleep_retention_entries_destroy(sleep_retention_module_t module) assert(SLEEP_RETENTION_MODULE_MIN <= module && module <= SLEEP_RETENTION_MODULE_MAX); _lock_acquire_recursive(&s_retention.lock); sleep_retention_entries_do_destroy(module); - if (s_retention.created_modules == 0) { + uint32_t created_modules = 0; + for (int i = 0; i < SLEEP_RETENTION_MODULE_BITMAP_SZ; i++) { + created_modules |= s_retention.created_modules.bitmap[i]; + } + if (created_modules == 0) { sleep_retention_entries_check_and_distroy_final_default(); pmu_sleep_disable_regdma_backup(); memset((void *)s_retention.lists, 0, sizeof(s_retention.lists)); @@ -570,7 +580,7 @@ static esp_err_t sleep_retention_entries_create_wrapper(const sleep_retention_en if(err) goto error; err = sleep_retention_entries_create_bonding(priority, module); if(err) goto error; - s_retention.created_modules |= module_num2map(module); + s_retention.created_modules.bitmap[module >> 5] |= BIT(module % 32); sleep_retention_entries_join(); error: @@ -611,16 +621,72 @@ void sleep_retention_entries_get(sleep_retention_entries_t *entries) _lock_release_recursive(&s_retention.lock); } -uint32_t IRAM_ATTR sleep_retention_get_inited_modules(void) +sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_get_inited_modules(void) { return s_retention.inited_modules; } -uint32_t IRAM_ATTR sleep_retention_get_created_modules(void) +sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_get_created_modules(void) { return s_retention.created_modules; } +bool sleep_retention_is_module_inited(sleep_retention_module_t module) +{ + if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + return false; + } + _lock_acquire_recursive(&s_retention.lock); + bool inited = module_is_inited(module); + _lock_release_recursive(&s_retention.lock); + return inited; +} + +bool sleep_retention_is_module_created(sleep_retention_module_t module) +{ + if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { + return false; + } + _lock_acquire_recursive(&s_retention.lock); + bool created = module_is_created(module); + _lock_release_recursive(&s_retention.lock); + return created; +} + +sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_module_bitmap_and(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1) +{ + sleep_retention_module_bitmap_t and; + for (int i = 0; i < ARRAY_SIZE(and.bitmap); i++) { + and.bitmap[i] = op0.bitmap[i] & op1.bitmap[i]; + } + return and; +} +sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_module_bitmap_or(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1) +{ + sleep_retention_module_bitmap_t or; + for (int i = 0; i < ARRAY_SIZE(or.bitmap); i++) { + or.bitmap[i] = op0.bitmap[i] | op1.bitmap[i]; + } + return or; +} +sleep_retention_module_bitmap_t IRAM_ATTR sleep_retention_module_bitmap_not(sleep_retention_module_bitmap_t op) +{ + sleep_retention_module_bitmap_t not; + for (int i = 0; i < ARRAY_SIZE(not.bitmap); i++) { + not.bitmap[i] = ~op.bitmap[i]; + } + return not; +} +bool IRAM_ATTR sleep_retention_module_bitmap_eq(sleep_retention_module_bitmap_t op0, sleep_retention_module_bitmap_t op1) +{ + for (int i = 0; i < ARRAY_SIZE(op0.bitmap); i++) { + if (op0.bitmap[i] != op1.bitmap[i]) { + return false; + } + } + return true; +} + esp_err_t sleep_retention_module_init(sleep_retention_module_t module, sleep_retention_module_init_param_t *param) { if (module < SLEEP_RETENTION_MODULE_MIN || module > SLEEP_RETENTION_MODULE_MAX) { @@ -648,7 +714,7 @@ esp_err_t sleep_retention_module_init(sleep_retention_module_t module, sleep_ret sleep_retention_module_object_ctor(&s_retention.instance[module], ¶m->cbs); set_dependencies(&s_retention.instance[module], param->depends); set_attributes(&s_retention.instance[module], param->attribute); - s_retention.inited_modules |= module_num2map(module); + s_retention.inited_modules.bitmap[module >> 5] |= BIT(module % 32); } _lock_release_recursive(&s_retention.lock); return err; @@ -669,8 +735,12 @@ esp_err_t sleep_retention_module_deinit(sleep_retention_module_t module) clr_attributes(&s_retention.instance[module]); clr_dependencies(&s_retention.instance[module]); sleep_retention_module_object_dtor(&s_retention.instance[module]); - s_retention.inited_modules &= ~module_num2map(module); - do_lock_release = (sleep_retention_get_inited_modules() == 0); + s_retention.inited_modules.bitmap[module >> 5] &= ~BIT(module % 32); + uint32_t inited_modules = 0; + for (int i = 0; i < SLEEP_RETENTION_MODULE_BITMAP_SZ; i++) { + inited_modules |= s_retention.inited_modules.bitmap[i]; + } + do_lock_release = (inited_modules == 0); } _lock_release_recursive(&s_retention.lock); @@ -691,10 +761,13 @@ static esp_err_t sleep_retention_passive_module_allocate(sleep_retention_module_ assert(module_is_inited(module) && "All passive module must be inited first!"); if (!module_is_created(module)) { sleep_retention_module_bitmap_t depends = get_dependencies(&s_retention.instance[module]); - for (int i = 0; (err == ESP_OK) && depends; depends >>= 1, i++) { - if (depends & BIT(0)) { - set_reference(&s_retention.instance[i], module); - err = sleep_retention_passive_module_allocate(i); + for (int i = 0; ((err == ESP_OK) && (i < SLEEP_RETENTION_MODULE_BITMAP_SZ)); i++) { + uint32_t bitmap = depends.bitmap[i]; + for (int j = 0; (err == ESP_OK) && bitmap; bitmap >>= 1, j++) { + if (bitmap & BIT(0)) { + set_reference(&s_retention.instance[(i << 5) + j], module); + err = sleep_retention_passive_module_allocate((i << 5) + j); + } } } if (err == ESP_OK) { @@ -719,11 +792,14 @@ esp_err_t sleep_retention_module_allocate(sleep_retention_module_t module) if (!module_is_passive(&s_retention.instance[module])) { if (module_is_inited(module) && !module_is_created(module)) { sleep_retention_module_bitmap_t depends = get_dependencies(&s_retention.instance[module]); - for (int i = 0; (err == ESP_OK) && depends; depends >>= 1, i++) { - if (depends & BIT(0)) { - set_reference(&s_retention.instance[i], module); - if (module_is_passive(&s_retention.instance[i])) { /* the callee ensures this module is inited */ - err = sleep_retention_passive_module_allocate(i); + for (int i = 0; ((err == ESP_OK) && (i < SLEEP_RETENTION_MODULE_BITMAP_SZ)); i++) { + uint32_t bitmap = depends.bitmap[i]; + for (int j = 0; (err == ESP_OK) && bitmap; bitmap >>= 1, j++) { + if (bitmap & BIT(0)) { + set_reference(&s_retention.instance[(i << 5) + j], module); + if (module_is_passive(&s_retention.instance[(i << 5) + j])) { /* the callee ensures this module is inited */ + err = sleep_retention_passive_module_allocate((i << 5) + j); + } } } } @@ -756,10 +832,13 @@ static esp_err_t sleep_retention_passive_module_free(sleep_retention_module_t mo sleep_retention_entries_destroy(module); sleep_retention_module_bitmap_t depends = get_dependencies(&s_retention.instance[module]); - for (int i = 0; (err == ESP_OK) && depends; depends >>= 1, i++) { - if (depends & BIT(0)) { - clr_reference(&s_retention.instance[i], module); - err = sleep_retention_passive_module_free(i); + for (int i = 0; ((err == ESP_OK) && (i < SLEEP_RETENTION_MODULE_BITMAP_SZ)); i++) { + uint32_t bitmap = depends.bitmap[i]; + for (int j = 0; (err == ESP_OK) && bitmap; bitmap >>= 1, j++) { + if (bitmap & BIT(0)) { + clr_reference(&s_retention.instance[(i << 5) + j], module); + err = sleep_retention_passive_module_free((i << 5) + j); + } } } } @@ -781,11 +860,14 @@ esp_err_t sleep_retention_module_free(sleep_retention_module_t module) sleep_retention_entries_destroy(module); sleep_retention_module_bitmap_t depends = get_dependencies(&s_retention.instance[module]); - for (int i = 0; (err == ESP_OK) && depends; depends >>= 1, i++) { - if (depends & BIT(0)) { - clr_reference(&s_retention.instance[i], module); - if (module_is_passive(&s_retention.instance[i])) { - err = sleep_retention_passive_module_free(i); + for (int i = 0; ((err == ESP_OK) && (i < SLEEP_RETENTION_MODULE_BITMAP_SZ)); i++) { + uint32_t bitmap = depends.bitmap[i]; + for (int j = 0; (err == ESP_OK) && bitmap; bitmap >>= 1, j++) { + if (bitmap & BIT(0)) { + clr_reference(&s_retention.instance[(i << 5) + j], module); + if (module_is_passive(&s_retention.instance[(i << 5) + j])) { + err = sleep_retention_passive_module_free((i << 5) + j); + } } } } diff --git a/components/soc/include/soc/regdma.h b/components/soc/include/soc/regdma.h index 59897b1ebf..6b43b575f2 100644 --- a/components/soc/include/soc/regdma.h +++ b/components/soc/include/soc/regdma.h @@ -156,7 +156,7 @@ typedef struct regdma_link_stats { volatile uint32_t ref: REGDMA_LINK_ENTRY_NUM, /* a bitmap, identifies which entry has referenced the current link */ reserve: 16-REGDMA_LINK_ENTRY_NUM, id: 16; /* REGDMA linked list node unique identifier */ - volatile uint32_t module; /* a bitmap used to identify the module to which the current node belongs */ + volatile int module; /* a number used to identify the module to which the current node belongs */ } regdma_link_stats_t; typedef struct regdma_link_continuous { From 61b7a971d3aea0edc626e0cff3733abbebdfd282 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 19 Sep 2024 11:54:00 +0800 Subject: [PATCH 2/6] change(soc): add sleep retention module total number definition --- .../beta3/include/soc/Kconfig.soc_caps.in | 4 ++ .../beta3/include/soc/retention_periph_defs.h | 45 +------------ .../soc/esp32c5/beta3/include/soc/soc_caps.h | 2 + .../mp/include/soc/Kconfig.soc_caps.in | 4 ++ .../mp/include/soc/retention_periph_defs.h | 65 +++++++------------ .../soc/esp32c5/mp/include/soc/soc_caps.h | 2 + .../esp32c6/include/soc/Kconfig.soc_caps.in | 4 ++ .../include/soc/retention_periph_defs.h | 51 +-------------- components/soc/esp32c6/include/soc/soc_caps.h | 3 +- .../esp32c61/include/soc/Kconfig.soc_caps.in | 4 ++ .../include/soc/retention_periph_defs.h | 28 +------- .../soc/esp32c61/include/soc/soc_caps.h | 2 + .../esp32h2/include/soc/Kconfig.soc_caps.in | 4 ++ .../include/soc/retention_periph_defs.h | 51 +-------------- components/soc/esp32h2/include/soc/soc_caps.h | 2 + .../esp32p4/include/soc/Kconfig.soc_caps.in | 4 ++ .../include/soc/retention_periph_defs.h | 41 +----------- components/soc/esp32p4/include/soc/soc_caps.h | 2 + 18 files changed, 71 insertions(+), 247 deletions(-) diff --git a/components/soc/esp32c5/beta3/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/beta3/include/soc/Kconfig.soc_caps.in index a79ab56d1f..ab9d266cda 100644 --- a/components/soc/esp32c5/beta3/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/beta3/include/soc/Kconfig.soc_caps.in @@ -707,6 +707,10 @@ config SOC_PM_PAU_LINK_NUM int default 4 +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h b/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h index ac7730aaf5..85e95bed48 100644 --- a/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h @@ -7,7 +7,7 @@ #pragma once #include -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -41,50 +41,9 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_BLE_MAC = 28, SLEEP_RETENTION_MODULE_BT_BB = 29, SLEEP_RETENTION_MODULE_802154_MAC = 30, - SLEEP_RETENTION_MODULE_MAX = 31 + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - SLEEP_RETENTION_MODULE_BM_CLOCK_MODEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM), - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - /* Timer Group by target*/ - SLEEP_RETENTION_MODULE_BM_TASK_WDT = BIT(SLEEP_RETENTION_MODULE_TG0_WDT), - SLEEP_RETENTION_MODULE_BM_INT_WDT = BIT(SLEEP_RETENTION_MODULE_TG1_WDT), - SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG0_TIMER0), - SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG1_TIMER0), - /* GDMA by channel */ - SLEEP_RETENTION_MODULE_BM_GDMA_CH0 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH0), - SLEEP_RETENTION_MODULE_BM_GDMA_CH1 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH1), - SLEEP_RETENTION_MODULE_BM_GDMA_CH2 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH2), - /* MISC Peripherals */ - SLEEP_RETENTION_MODULE_BM_ADC = BIT(SLEEP_RETENTION_MODULE_ADC), - SLEEP_RETENTION_MODULE_BM_I2C0 = BIT(SLEEP_RETENTION_MODULE_I2C0), - SLEEP_RETENTION_MODULE_BM_RMT0 = BIT(SLEEP_RETENTION_MODULE_RMT0), - /* modem module, which includes WiFi, BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_BM_WIFI_MAC = BIT(SLEEP_RETENTION_MODULE_WIFI_MAC), - SLEEP_RETENTION_MODULE_BM_WIFI_BB = BIT(SLEEP_RETENTION_MODULE_WIFI_BB), - SLEEP_RETENTION_MODULE_BM_BLE_MAC = BIT(SLEEP_RETENTION_MODULE_BLE_MAC), - SLEEP_RETENTION_MODULE_BM_BT_BB = BIT(SLEEP_RETENTION_MODULE_BT_BB), - SLEEP_RETENTION_MODULE_BM_802154_MAC = BIT(SLEEP_RETENTION_MODULE_802154_MAC), - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t)-1 -} periph_retention_module_bitmap_t; - -#define TOP_DOMAIN_PERIPHERALS_BM (SLEEP_RETENTION_MODULE_BM_SYS_PERIPH \ - | SLEEP_RETENTION_MODULE_BM_TASK_WDT \ - | SLEEP_RETENTION_MODULE_BM_INT_WDT \ - | SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH1 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH2 \ - | SLEEP_RETENTION_MODULE_BM_ADC \ - | SLEEP_RETENTION_MODULE_BM_I2C0 \ - | SLEEP_RETENTION_MODULE_BM_RMT0) - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c5/beta3/include/soc/soc_caps.h b/components/soc/esp32c5/beta3/include/soc/soc_caps.h index 4406377a86..28a6b38156 100644 --- a/components/soc/esp32c5/beta3/include/soc/soc_caps.h +++ b/components/soc/esp32c5/beta3/include/soc/soc_caps.h @@ -543,6 +543,8 @@ #define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_RETENTION_MODULE_NUM (32) + /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) #define SOC_MODEM_CLOCK_IS_INDEPENDENT (1) diff --git a/components/soc/esp32c5/mp/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c5/mp/include/soc/Kconfig.soc_caps.in index 5a9fbe47f3..d1de4ca1cf 100644 --- a/components/soc/esp32c5/mp/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c5/mp/include/soc/Kconfig.soc_caps.in @@ -447,6 +447,10 @@ config SOC_PM_SUPPORT_RTC_PERIPH_PD bool default y +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h b/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h index 2ef044eb40..85e95bed48 100644 --- a/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h @@ -7,7 +7,7 @@ #pragma once #include -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -18,51 +18,32 @@ typedef enum periph_retention_module { /* clock module, which includes system and modem */ SLEEP_RETENTION_MODULE_CLOCK_SYSTEM = 1, SLEEP_RETENTION_MODULE_CLOCK_MODEM = 2, - - /* modem module, which includes WiFi, BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_WIFI_MAC = 10, - SLEEP_RETENTION_MODULE_WIFI_BB = 11, - SLEEP_RETENTION_MODULE_BLE_MAC = 12, - SLEEP_RETENTION_MODULE_BT_BB = 13, - SLEEP_RETENTION_MODULE_802154_MAC = 14, - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_SYS_PERIPH = 16, + * TEE, APM, UART, IOMUX, SPIMEM, SysTimer, etc.. */ + SLEEP_RETENTION_MODULE_SYS_PERIPH = 3, + /* Timer Group by target*/ + SLEEP_RETENTION_MODULE_TG0_WDT = 4, + SLEEP_RETENTION_MODULE_TG1_WDT = 5, + SLEEP_RETENTION_MODULE_TG0_TIMER0 = 6, + SLEEP_RETENTION_MODULE_TG1_TIMER0 = 7, + /* GDMA by channel */ + SLEEP_RETENTION_MODULE_GDMA_CH0 = 8, + SLEEP_RETENTION_MODULE_GDMA_CH1 = 9, + SLEEP_RETENTION_MODULE_GDMA_CH2 = 10, + /* MISC Peripherals */ + SLEEP_RETENTION_MODULE_ADC = 11, + SLEEP_RETENTION_MODULE_I2C0 = 12, + SLEEP_RETENTION_MODULE_RMT0 = 13, - SLEEP_RETENTION_MODULE_ADC = 17, - - SLEEP_RETENTION_MODULE_GDMA_CH0 = 24, - SLEEP_RETENTION_MODULE_GDMA_CH1 = 25, - SLEEP_RETENTION_MODULE_GDMA_CH2 = 26, - - SLEEP_RETENTION_MODULE_MAX = 31 + /* Modem module, which includes WiFi, BLE and 802.15.4 */ + SLEEP_RETENTION_MODULE_WIFI_MAC = 26, + SLEEP_RETENTION_MODULE_WIFI_BB = 27, + SLEEP_RETENTION_MODULE_BLE_MAC = 28, + SLEEP_RETENTION_MODULE_BT_BB = 29, + SLEEP_RETENTION_MODULE_802154_MAC = 30, + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - SLEEP_RETENTION_MODULE_BM_CLOCK_MODEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM), - - /* modem module, which includes WiFi, BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_BM_WIFI_MAC = BIT(SLEEP_RETENTION_MODULE_WIFI_MAC), - SLEEP_RETENTION_MODULE_BM_WIFI_BB = BIT(SLEEP_RETENTION_MODULE_WIFI_BB), - SLEEP_RETENTION_MODULE_BM_BLE_MAC = BIT(SLEEP_RETENTION_MODULE_BLE_MAC), - SLEEP_RETENTION_MODULE_BM_BT_BB = BIT(SLEEP_RETENTION_MODULE_BT_BB), - SLEEP_RETENTION_MODULE_BM_802154_MAC = BIT(SLEEP_RETENTION_MODULE_802154_MAC), - - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - - SLEEP_RETENTION_MODULE_BM_ADC = BIT(SLEEP_RETENTION_MODULE_ADC), - - SLEEP_RETENTION_MODULE_BM_GDMA_CH0 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH0), - SLEEP_RETENTION_MODULE_BM_GDMA_CH1 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH1), - SLEEP_RETENTION_MODULE_BM_GDMA_CH2 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH2), - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t)-1 -} periph_retention_module_bitmap_t; - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c5/mp/include/soc/soc_caps.h b/components/soc/esp32c5/mp/include/soc/soc_caps.h index 8771d4671c..b29e73bc80 100644 --- a/components/soc/esp32c5/mp/include/soc/soc_caps.h +++ b/components/soc/esp32c5/mp/include/soc/soc_caps.h @@ -537,6 +537,8 @@ // #define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_RETENTION_MODULE_NUM (32) + /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) #define SOC_MODEM_CLOCK_IS_INDEPENDENT (1) diff --git a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in index fae8dec4d6..fbfc42e4b9 100644 --- a/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c6/include/soc/Kconfig.soc_caps.in @@ -1379,6 +1379,10 @@ config SOC_PM_PAU_LINK_NUM int default 4 +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool default y diff --git a/components/soc/esp32c6/include/soc/retention_periph_defs.h b/components/soc/esp32c6/include/soc/retention_periph_defs.h index acfedf8472..e50a9fc67f 100644 --- a/components/soc/esp32c6/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c6/include/soc/retention_periph_defs.h @@ -7,7 +7,7 @@ #pragma once #include -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -43,55 +43,10 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_BLE_MAC = 28, SLEEP_RETENTION_MODULE_BT_BB = 29, SLEEP_RETENTION_MODULE_802154_MAC = 30, - SLEEP_RETENTION_MODULE_MAX = 31 + + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - SLEEP_RETENTION_MODULE_BM_CLOCK_MODEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM), - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - /* Timer Group by target*/ - SLEEP_RETENTION_MODULE_BM_TASK_WDT = BIT(SLEEP_RETENTION_MODULE_TG0_WDT), - SLEEP_RETENTION_MODULE_BM_INT_WDT = BIT(SLEEP_RETENTION_MODULE_TG1_WDT), - SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG0_TIMER0), - SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG1_TIMER0), - /* GDMA by channel */ - SLEEP_RETENTION_MODULE_BM_GDMA_CH0 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH0), - SLEEP_RETENTION_MODULE_BM_GDMA_CH1 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH1), - SLEEP_RETENTION_MODULE_BM_GDMA_CH2 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH2), - /* MISC Peripherals */ - SLEEP_RETENTION_MODULE_BM_ADC = BIT(SLEEP_RETENTION_MODULE_ADC), - SLEEP_RETENTION_MODULE_BM_I2C0 = BIT(SLEEP_RETENTION_MODULE_I2C0), - SLEEP_RETENTION_MODULE_BM_RMT0 = BIT(SLEEP_RETENTION_MODULE_RMT0), - SLEEP_RETENTION_MODULE_BM_UART0 = BIT(SLEEP_RETENTION_MODULE_UART0), - SLEEP_RETENTION_MODULE_BM_UART1 = BIT(SLEEP_RETENTION_MODULE_UART1), - /* modem module, which includes WiFi, BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_BM_WIFI_MAC = BIT(SLEEP_RETENTION_MODULE_WIFI_MAC), - SLEEP_RETENTION_MODULE_BM_WIFI_BB = BIT(SLEEP_RETENTION_MODULE_WIFI_BB), - SLEEP_RETENTION_MODULE_BM_BLE_MAC = BIT(SLEEP_RETENTION_MODULE_BLE_MAC), - SLEEP_RETENTION_MODULE_BM_BT_BB = BIT(SLEEP_RETENTION_MODULE_BT_BB), - SLEEP_RETENTION_MODULE_BM_802154_MAC = BIT(SLEEP_RETENTION_MODULE_802154_MAC), - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t)-1 -} periph_retention_module_bitmap_t; - -#define TOP_DOMAIN_PERIPHERALS_BM (SLEEP_RETENTION_MODULE_BM_SYS_PERIPH \ - | SLEEP_RETENTION_MODULE_BM_TASK_WDT \ - | SLEEP_RETENTION_MODULE_BM_INT_WDT \ - | SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH1 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH2 \ - | SLEEP_RETENTION_MODULE_BM_ADC \ - | SLEEP_RETENTION_MODULE_BM_I2C0 \ - | SLEEP_RETENTION_MODULE_BM_RMT0 \ - | SLEEP_RETENTION_MODULE_BM_UART0 \ - | SLEEP_RETENTION_MODULE_BM_UART1 \ - ) - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c6/include/soc/soc_caps.h b/components/soc/esp32c6/include/soc/soc_caps.h index ea6cd338e5..335a5f15b6 100644 --- a/components/soc/esp32c6/include/soc/soc_caps.h +++ b/components/soc/esp32c6/include/soc/soc_caps.h @@ -544,7 +544,8 @@ #define SOC_PM_MODEM_RETENTION_BY_REGDMA (1) #define SOC_PM_RETENTION_HAS_CLOCK_BUG (1) -#define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_RETENTION_MODULE_NUM (32) #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 0f09c495a7..c2dc6e807b 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -971,6 +971,10 @@ config SOC_PM_PAU_LINK_NUM int default 4 +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32c61/include/soc/retention_periph_defs.h b/components/soc/esp32c61/include/soc/retention_periph_defs.h index d5d03d00e7..321a688c1d 100644 --- a/components/soc/esp32c61/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c61/include/soc/retention_periph_defs.h @@ -7,7 +7,7 @@ #pragma once #include -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -35,33 +35,9 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_GDMA_CH2 = 26, SLEEP_RETENTION_MODULE_I2C0 = 27, - SLEEP_RETENTION_MODULE_MAX = 31 + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - SLEEP_RETENTION_MODULE_BM_CLOCK_MODEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM), - - /* modem module, which includes WiFi, BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_BM_WIFI_MAC = BIT(SLEEP_RETENTION_MODULE_WIFI_MAC), - SLEEP_RETENTION_MODULE_BM_WIFI_BB = BIT(SLEEP_RETENTION_MODULE_WIFI_BB), - SLEEP_RETENTION_MODULE_BM_BLE_MAC = BIT(SLEEP_RETENTION_MODULE_BLE_MAC), - SLEEP_RETENTION_MODULE_BM_BT_BB = BIT(SLEEP_RETENTION_MODULE_BT_BB), - SLEEP_RETENTION_MODULE_BM_802154_MAC = BIT(SLEEP_RETENTION_MODULE_802154_MAC), - - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - - SLEEP_RETENTION_MODULE_BM_GDMA_CH0 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH0), - SLEEP_RETENTION_MODULE_BM_GDMA_CH1 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH1), - SLEEP_RETENTION_MODULE_BM_GDMA_CH2 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH2), - SLEEP_RETENTION_MODULE_BM_I2C0 = BIT(SLEEP_RETENTION_MODULE_I2C0), - - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t)-1 -} periph_retention_module_bitmap_t; - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 896c4c4143..a56cd00db4 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -533,6 +533,8 @@ #define SOC_PM_PAU_LINK_NUM (4) +#define SOC_PM_RETENTION_MODULE_NUM (32) + /*-------------------------- CLOCK SUBSYSTEM CAPS ----------------------------------------*/ #define SOC_CLK_RC_FAST_SUPPORT_CALIBRATION (1) #define SOC_MODEM_CLOCK_IS_INDEPENDENT (1) diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 560aa46ef8..e0c1459c11 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -1359,6 +1359,10 @@ config SOC_PM_RETENTION_SW_TRIGGER_REGDMA bool default y +config SOC_PM_RETENTION_MODULE_NUM + int + default 32 + config SOC_CLK_RC_FAST_SUPPORT_CALIBRATION bool default y diff --git a/components/soc/esp32h2/include/soc/retention_periph_defs.h b/components/soc/esp32h2/include/soc/retention_periph_defs.h index e738c98a63..ab4862d500 100644 --- a/components/soc/esp32h2/include/soc/retention_periph_defs.h +++ b/components/soc/esp32h2/include/soc/retention_periph_defs.h @@ -7,7 +7,7 @@ #pragma once #include -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -42,55 +42,10 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_BLE_MAC = 28, SLEEP_RETENTION_MODULE_BT_BB = 29, SLEEP_RETENTION_MODULE_802154_MAC = 30, - SLEEP_RETENTION_MODULE_MAX = 31 + + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - SLEEP_RETENTION_MODULE_BM_CLOCK_MODEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM), - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - /* Timer Group by target*/ - SLEEP_RETENTION_MODULE_BM_TASK_WDT = BIT(SLEEP_RETENTION_MODULE_TG0_WDT), - SLEEP_RETENTION_MODULE_BM_INT_WDT = BIT(SLEEP_RETENTION_MODULE_TG1_WDT), - SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG0_TIMER0), - SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG1_TIMER0), - /* GDMA by channel */ - SLEEP_RETENTION_MODULE_BM_GDMA_CH0 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH0), - SLEEP_RETENTION_MODULE_BM_GDMA_CH1 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH1), - SLEEP_RETENTION_MODULE_BM_GDMA_CH2 = BIT(SLEEP_RETENTION_MODULE_GDMA_CH2), - /* MISC Peripherals */ - SLEEP_RETENTION_MODULE_BM_ADC = BIT(SLEEP_RETENTION_MODULE_ADC), - SLEEP_RETENTION_MODULE_BM_I2C0 = BIT(SLEEP_RETENTION_MODULE_I2C0), - SLEEP_RETENTION_MODULE_BM_I2C1 = BIT(SLEEP_RETENTION_MODULE_I2C1), - SLEEP_RETENTION_MODULE_BM_RMT0 = BIT(SLEEP_RETENTION_MODULE_RMT0), - SLEEP_RETENTION_MODULE_BM_UART0 = BIT(SLEEP_RETENTION_MODULE_UART0), - SLEEP_RETENTION_MODULE_BM_UART1 = BIT(SLEEP_RETENTION_MODULE_UART1), - /* modem module, which includes BLE and 802.15.4 */ - SLEEP_RETENTION_MODULE_BM_BLE_MAC = BIT(SLEEP_RETENTION_MODULE_BLE_MAC), - SLEEP_RETENTION_MODULE_BM_BT_BB = BIT(SLEEP_RETENTION_MODULE_BT_BB), - SLEEP_RETENTION_MODULE_BM_802154_MAC = BIT(SLEEP_RETENTION_MODULE_802154_MAC), - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t) -1 -} periph_retention_module_bitmap_t; - -#define TOP_DOMAIN_PERIPHERALS_BM (SLEEP_RETENTION_MODULE_BM_SYS_PERIPH \ - | SLEEP_RETENTION_MODULE_BM_TASK_WDT \ - | SLEEP_RETENTION_MODULE_BM_INT_WDT \ - | SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH0 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH1 \ - | SLEEP_RETENTION_MODULE_BM_GDMA_CH2 \ - | SLEEP_RETENTION_MODULE_BM_ADC \ - | SLEEP_RETENTION_MODULE_BM_I2C0 \ - | SLEEP_RETENTION_MODULE_BM_I2C1 \ - | SLEEP_RETENTION_MODULE_BM_RMT0 \ - | SLEEP_RETENTION_MODULE_BM_UART0 \ - | SLEEP_RETENTION_MODULE_BM_UART1 \ - ) - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 6d1f173e8c..a48b880456 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -553,6 +553,8 @@ #define SOC_PM_SUPPORT_DEEPSLEEP_CHECK_STUB_ONLY (1) /*! -#include "esp_bit_defs.h" +#include "soc_caps.h" #ifdef __cplusplus extern "C" { @@ -34,46 +34,9 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_UART3 = 12, SLEEP_RETENTION_MODULE_UART4 = 13, - SLEEP_RETENTION_MODULE_MAX = 31 + SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; -typedef enum periph_retention_module_bitmap { - /* clock module, which includes system and modem */ - SLEEP_RETENTION_MODULE_BM_CLOCK_SYSTEM = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), - /* digital peripheral module, which includes Interrupt Matrix, HP_SYSTEM, - * TEE, APM, UART, Timer Group, IOMUX, SPIMEM, SysTimer, etc.. */ - SLEEP_RETENTION_MODULE_BM_SYS_PERIPH = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH), - /* Timer Group by target*/ - SLEEP_RETENTION_MODULE_BM_TG0_WDT = BIT(SLEEP_RETENTION_MODULE_TG0_WDT), - SLEEP_RETENTION_MODULE_BM_TG1_WDT = BIT(SLEEP_RETENTION_MODULE_TG1_WDT), - SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG0_TIMER0), - SLEEP_RETENTION_MODULE_BM_TG0_TIMER1 = BIT(SLEEP_RETENTION_MODULE_TG0_TIMER1), - SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 = BIT(SLEEP_RETENTION_MODULE_TG1_TIMER0), - SLEEP_RETENTION_MODULE_BM_TG1_TIMER1 = BIT(SLEEP_RETENTION_MODULE_TG1_TIMER1), - /* MISC Peripherals */ - SLEEP_RETENTION_MODULE_BM_UART0 = BIT(SLEEP_RETENTION_MODULE_UART0), - SLEEP_RETENTION_MODULE_BM_UART1 = BIT(SLEEP_RETENTION_MODULE_UART1), - SLEEP_RETENTION_MODULE_BM_UART2 = BIT(SLEEP_RETENTION_MODULE_UART2), - SLEEP_RETENTION_MODULE_BM_UART3 = BIT(SLEEP_RETENTION_MODULE_UART3), - SLEEP_RETENTION_MODULE_BM_UART4 = BIT(SLEEP_RETENTION_MODULE_UART4), - - SLEEP_RETENTION_MODULE_BM_ALL = (uint32_t)-1 -} periph_retention_module_bitmap_t; - -#define TOP_DOMAIN_PERIPHERALS_BM (SLEEP_RETENTION_MODULE_BM_SYS_PERIPH \ - | SLEEP_RETENTION_MODULE_BM_TG0_WDT \ - | SLEEP_RETENTION_MODULE_BM_TG1_WDT \ - | SLEEP_RETENTION_MODULE_BM_TG0_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_TG0_TIMER1 \ - | SLEEP_RETENTION_MODULE_BM_TG1_TIMER0 \ - | SLEEP_RETENTION_MODULE_BM_TG1_TIMER1 \ - | SLEEP_RETENTION_MODULE_BM_UART0 \ - | SLEEP_RETENTION_MODULE_BM_UART1 \ - | SLEEP_RETENTION_MODULE_BM_UART2 \ - | SLEEP_RETENTION_MODULE_BM_UART3 \ - | SLEEP_RETENTION_MODULE_BM_UART4 \ - ) - #ifdef __cplusplus } #endif diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index 08ce5ab174..b932cd7c5e 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -670,6 +670,8 @@ #define SOC_PAU_IN_TOP_DOMAIN (1) #define SOC_CPU_IN_TOP_DOMAIN (1) +#define SOC_PM_RETENTION_MODULE_NUM (32) + #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) /*-------------------------- PSRAM CAPS ----------------------------*/ From 44001a9d70b85d331dac38604aafcc364769a1c1 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 19 Sep 2024 12:55:48 +0800 Subject: [PATCH 3/6] change(esp_hw_support): update some modules sleep retention init dependency bitmap --- components/bt/controller/esp32c6/bt.c | 2 +- components/bt/controller/esp32h2/bt.c | 2 +- components/esp_driver_gptimer/src/gptimer.c | 6 +++--- components/esp_driver_uart/src/uart.c | 2 +- components/esp_hw_support/dma/gdma_sleep_retention.c | 6 +++--- components/esp_phy/src/btbb_init.c | 2 +- components/esp_phy/src/phy_init.c | 2 +- components/esp_system/int_wdt.c | 2 +- components/esp_system/task_wdt/task_wdt_impl_timergroup.c | 2 +- components/esp_wifi/src/wifi_init.c | 3 ++- components/ieee802154/driver/esp_ieee802154_dev.c | 7 +++---- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/components/bt/controller/esp32c6/bt.c b/components/bt/controller/esp32c6/bt.c index 314045fe12..3f53e9aca2 100644 --- a/components/bt/controller/esp32c6/bt.c +++ b/components/bt/controller/esp32c6/bt.c @@ -612,7 +612,7 @@ static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra) int retention_args = extra; sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_modem_ble_mac_retention_init, .arg = &retention_args } }, - .depends = BIT(SLEEP_RETENTION_MODULE_BT_BB) + .depends = RETENTION_MODULE_BITMAP_INIT(BT_BB) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BLE_MAC, &init_param); if (err == ESP_OK) { diff --git a/components/bt/controller/esp32h2/bt.c b/components/bt/controller/esp32h2/bt.c index 97e0213fc3..e4168cb00b 100644 --- a/components/bt/controller/esp32h2/bt.c +++ b/components/bt/controller/esp32h2/bt.c @@ -603,7 +603,7 @@ static esp_err_t sleep_modem_ble_mac_modem_state_init(uint8_t extra) int retention_args = extra; sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_modem_ble_mac_retention_init, .arg = &retention_args } }, - .depends = BIT(SLEEP_RETENTION_MODULE_BT_BB) + .depends = RETENTION_MODULE_BITMAP_INIT(BT_BB) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BLE_MAC, &init_param); if (err == ESP_OK) { diff --git a/components/esp_driver_gptimer/src/gptimer.c b/components/esp_driver_gptimer/src/gptimer.c index 0d8ffb38bb..d02717dc38 100644 --- a/components/esp_driver_gptimer/src/gptimer.c +++ b/components/esp_driver_gptimer/src/gptimer.c @@ -41,7 +41,7 @@ static void gptimer_create_retention_module(gptimer_t *timer) int group_id = timer->group->group_id; int timer_id = timer->timer_id; sleep_retention_module_t module = tg_timer_reg_retention_info[group_id][timer_id].module; - if ((sleep_retention_get_inited_modules() & BIT(module)) && !(sleep_retention_get_created_modules() & BIT(module))) { + if (sleep_retention_is_module_inited(module) && !sleep_retention_is_module_created(module)) { if (sleep_retention_module_allocate(module) != ESP_OK) { // even though the sleep retention module create failed, GPTimer driver should still work, so just warning here ESP_LOGW(TAG, "create retention link failed on TimerGroup%d Timer%d, power domain won't be turned off during sleep", group_id, timer_id); @@ -86,7 +86,7 @@ static esp_err_t gptimer_register_to_group(gptimer_t *timer) .arg = (void *)timer }, }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; if (sleep_retention_module_init(module, &init_param) != ESP_OK) { // even though the sleep retention module init failed, RMT driver should still work, so just warning here @@ -107,7 +107,7 @@ static void gptimer_unregister_from_group(gptimer_t *timer) #if GPTIMER_USE_RETENTION_LINK sleep_retention_module_t module = tg_timer_reg_retention_info[group->group_id][timer_id].module; - if (sleep_retention_get_created_modules() & BIT(module)) { + if (sleep_retention_is_module_created(module)) { sleep_retention_module_free(module); } sleep_retention_module_deinit(module); diff --git a/components/esp_driver_uart/src/uart.c b/components/esp_driver_uart/src/uart.c index 0a316f2674..6e0506a419 100644 --- a/components/esp_driver_uart/src/uart.c +++ b/components/esp_driver_uart/src/uart.c @@ -223,7 +223,7 @@ static void uart_module_enable(uart_port_t uart_num) .arg = &uart_context[uart_num], }, }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM), + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; if (sleep_retention_module_init(module, &init_param) == ESP_OK) { uart_context[uart_num].retention_link_inited = true; diff --git a/components/esp_hw_support/dma/gdma_sleep_retention.c b/components/esp_hw_support/dma/gdma_sleep_retention.c index 00f3a75445..108952a265 100644 --- a/components/esp_hw_support/dma/gdma_sleep_retention.c +++ b/components/esp_hw_support/dma/gdma_sleep_retention.c @@ -36,7 +36,7 @@ static esp_err_t sleep_gdma_channel_retention_init(void *arg) int group_id = parg->group_id; int pair_id = parg->pair_id; - sleep_retention_module_bitmap_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id); + sleep_retention_module_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id); esp_err_t err = sleep_retention_entries_create(gdma_chx_regs_retention[group_id][pair_id].link_list, gdma_chx_regs_retention[group_id][pair_id].link_num, REGDMA_LINK_PRI_GDMA, module); if (err == ESP_OK) { ESP_LOGD(TAG, "GDMA pair (%d, %d) retention initialization", group_id, pair_id); @@ -51,9 +51,9 @@ esp_err_t gdma_sleep_retention_init(int group_id, int pair_id) gdma_channel_retention_arg_t arg = { .group_id = group_id, .pair_id = pair_id }; sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_gdma_channel_retention_init, .arg = &arg } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; - sleep_retention_module_bitmap_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id); + sleep_retention_module_t module = GDMA_CH_RETENTION_GET_MODULE_ID(group_id, pair_id); esp_err_t err = sleep_retention_module_init(module, &init_param); if (err == ESP_OK) { err = sleep_retention_module_allocate(module); diff --git a/components/esp_phy/src/btbb_init.c b/components/esp_phy/src/btbb_init.c index b73b0babd0..88e0df7573 100644 --- a/components/esp_phy/src/btbb_init.c +++ b/components/esp_phy/src/btbb_init.c @@ -63,7 +63,7 @@ void esp_btbb_enable(void) #if SOC_PM_MODEM_RETENTION_BY_REGDMA && CONFIG_FREERTOS_USE_TICKLESS_IDLE sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = btbb_sleep_retention_init, .arg = NULL } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_BT_BB, &init_param); if (err == ESP_OK) { diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 13c2a5bd09..47b507ba4c 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -520,7 +520,7 @@ void esp_mac_bb_pd_mem_init(void) #elif SOC_PM_MODEM_RETENTION_BY_REGDMA sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param); if (err != ESP_OK) { diff --git a/components/esp_system/int_wdt.c b/components/esp_system/int_wdt.c index 9a8db626f3..66e00fc493 100644 --- a/components/esp_system/int_wdt.c +++ b/components/esp_system/int_wdt.c @@ -72,7 +72,7 @@ static esp_err_t esp_int_wdt_retention_enable(uint32_t group_id) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_int_wdt_retention_init, .arg = &group_id } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; esp_err_t err = sleep_retention_module_init((group_id == 0) ? SLEEP_RETENTION_MODULE_TG0_WDT : SLEEP_RETENTION_MODULE_TG1_WDT, &init_param); if (err == ESP_OK) { diff --git a/components/esp_system/task_wdt/task_wdt_impl_timergroup.c b/components/esp_system/task_wdt/task_wdt_impl_timergroup.c index 8b8ed63180..56cf317eea 100644 --- a/components/esp_system/task_wdt/task_wdt_impl_timergroup.c +++ b/components/esp_system/task_wdt/task_wdt_impl_timergroup.c @@ -65,7 +65,7 @@ static esp_err_t esp_task_wdt_retention_enable(uint32_t group_id) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_task_wdt_retention_init, .arg = &group_id } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) + .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_SYSTEM) }; esp_err_t err = sleep_retention_module_init((group_id == 0) ? SLEEP_RETENTION_MODULE_TG0_WDT : SLEEP_RETENTION_MODULE_TG1_WDT, &init_param); if (err == ESP_OK) { diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 6c9ed3ea68..de3dbf51e8 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -352,8 +352,9 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) #if SOC_PM_MODEM_RETENTION_BY_REGDMA sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = init_wifi_mac_sleep_retention, .arg = NULL } }, - .depends = BIT(SLEEP_RETENTION_MODULE_WIFI_BB) | BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM) }; + init_param.depends.bitmap[SLEEP_RETENTION_MODULE_WIFI_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_BB % 32); + init_param.depends.bitmap[SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32); esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_MAC, &init_param); if (err != ESP_OK) { ESP_LOGW(TAG, "WiFi MAC sleep retention init failed"); diff --git a/components/ieee802154/driver/esp_ieee802154_dev.c b/components/ieee802154/driver/esp_ieee802154_dev.c index ea39aec7c1..b252457ca7 100644 --- a/components/ieee802154/driver/esp_ieee802154_dev.c +++ b/components/ieee802154/driver/esp_ieee802154_dev.c @@ -1009,10 +1009,9 @@ static esp_err_t ieee802154_sleep_init(void) { esp_err_t err = ESP_OK; #if CONFIG_PM_ENABLE - sleep_retention_module_init_param_t init_param = { - .cbs = { .create = { .handle = ieee802154_sleep_retention_init, .arg = NULL } }, - .depends = BIT(SLEEP_RETENTION_MODULE_BT_BB) | BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM) - }; + sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = ieee802154_sleep_retention_init, .arg = NULL } } }; + init_param.depends.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32); + init_param.depends.bitmap[SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32); err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_802154_MAC, &init_param); if (err == ESP_OK) { err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_802154_MAC); From 62633bcdaec4a6c79753de792cdb26bfda5e3499 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 19 Sep 2024 19:42:23 +0800 Subject: [PATCH 4/6] change(esp_hw_support): update power domain pd allowed check logic --- components/esp_hw_support/sleep_clock.c | 40 +++--- components/esp_hw_support/sleep_modem.c | 19 +-- .../esp_hw_support/sleep_system_peripheral.c | 115 +++++++++++++++++- 3 files changed, 149 insertions(+), 25 deletions(-) diff --git a/components/esp_hw_support/sleep_clock.c b/components/esp_hw_support/sleep_clock.c index 297d8f7083..a70517f6ae 100644 --- a/components/esp_hw_support/sleep_clock.c +++ b/components/esp_hw_support/sleep_clock.c @@ -8,36 +8,48 @@ bool clock_domain_pd_allowed(void) { - const uint32_t inited_modules = sleep_retention_get_inited_modules(); - const uint32_t created_modules = sleep_retention_get_created_modules(); - const uint32_t sys_clk_dep_modules = (const uint32_t) (BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH)); + const sleep_retention_module_bitmap_t inited_modules = sleep_retention_get_inited_modules(); + const sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules(); + const sleep_retention_module_bitmap_t sys_clk_dep_modules = (sleep_retention_module_bitmap_t){ .bitmap[SLEEP_RETENTION_MODULE_SYS_PERIPH >> 5] = BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH % 32) }; /* The clock and reset of MODEM (WiFi, BLE and 15.4) modules are managed * through MODEM_SYSCON, when one or more MODEMs are initialized, it is * necessary to check the state of CLOCK_MODEM to determine MODEM domain on * or off. The clock and reset of digital peripherals are managed through * PCR, with TOP domain similar to MODEM domain. */ - uint32_t modem_clk_dep_modules = 0; +#if SOC_WIFI_SUPPORTED || SOC_BT_SUPPORTED || SOC_IEEE802154_SUPPORTED + sleep_retention_module_bitmap_t modem_clk_dep_modules = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; +#endif #if SOC_WIFI_SUPPORTED - modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC) | BIT(SLEEP_RETENTION_MODULE_WIFI_BB); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_WIFI_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC % 32); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_WIFI_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_BB % 32); #endif #if SOC_BT_SUPPORTED - modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BLE_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC % 32); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32); #endif #if SOC_IEEE802154_SUPPORTED - modem_clk_dep_modules |= BIT(SLEEP_RETENTION_MODULE_802154_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_802154_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_802154_MAC % 32); + modem_clk_dep_modules.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32); #endif - uint32_t mask = 0; - if (inited_modules & sys_clk_dep_modules) { - mask |= BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM); + const sleep_retention_module_bitmap_t null_module = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; + + sleep_retention_module_bitmap_t mask = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; + const sleep_retention_module_bitmap_t system_modules = sleep_retention_module_bitmap_and(inited_modules, sys_clk_dep_modules); + if (!sleep_retention_module_bitmap_eq(system_modules, null_module)) { + mask.bitmap[SLEEP_RETENTION_MODULE_CLOCK_SYSTEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM % 32); } - if (inited_modules & modem_clk_dep_modules) { #if SOC_WIFI_SUPPORTED || SOC_BT_SUPPORTED || SOC_IEEE802154_SUPPORTED - mask |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM); -#endif + const sleep_retention_module_bitmap_t modem_modules = sleep_retention_module_bitmap_and(inited_modules, modem_clk_dep_modules); + if (!sleep_retention_module_bitmap_eq(modem_modules, null_module)) { + mask.bitmap[SLEEP_RETENTION_MODULE_CLOCK_MODEM >> 5] |= BIT(SLEEP_RETENTION_MODULE_CLOCK_MODEM % 32); } - return ((inited_modules & mask) == (created_modules & mask)); +#endif + + const sleep_retention_module_bitmap_t clock_domain_inited_modules = sleep_retention_module_bitmap_and(inited_modules, mask); + const sleep_retention_module_bitmap_t clock_domain_created_modules = sleep_retention_module_bitmap_and(created_modules, mask); + return sleep_retention_module_bitmap_eq(clock_domain_inited_modules, clock_domain_created_modules); } ESP_SYSTEM_INIT_FN(sleep_clock_startup_init, SECONDARY, BIT(0), 106) diff --git a/components/esp_hw_support/sleep_modem.c b/components/esp_hw_support/sleep_modem.c index d01de62c71..7ae3f7be8f 100644 --- a/components/esp_hw_support/sleep_modem.c +++ b/components/esp_hw_support/sleep_modem.c @@ -285,21 +285,26 @@ inline __attribute__((always_inline)) bool sleep_modem_wifi_modem_link_done(void bool modem_domain_pd_allowed(void) { #if SOC_PM_MODEM_RETENTION_BY_REGDMA - const uint32_t inited_modules = sleep_retention_get_inited_modules(); - const uint32_t created_modules = sleep_retention_get_created_modules(); + const sleep_retention_module_bitmap_t inited_modules = sleep_retention_get_inited_modules(); + const sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules(); - uint32_t mask = 0; + sleep_retention_module_bitmap_t mask = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; #if SOC_WIFI_SUPPORTED - mask |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC) | BIT(SLEEP_RETENTION_MODULE_WIFI_BB); + mask.bitmap[SLEEP_RETENTION_MODULE_WIFI_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_MAC % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_WIFI_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_WIFI_BB % 32); #endif #if SOC_BT_SUPPORTED - mask |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); + mask.bitmap[SLEEP_RETENTION_MODULE_BLE_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_BLE_MAC % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32); #endif #if SOC_IEEE802154_SUPPORTED - mask |= BIT(SLEEP_RETENTION_MODULE_802154_MAC) | BIT(SLEEP_RETENTION_MODULE_BT_BB); + mask.bitmap[SLEEP_RETENTION_MODULE_802154_MAC >> 5] |= BIT(SLEEP_RETENTION_MODULE_802154_MAC % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_BT_BB >> 5] |= BIT(SLEEP_RETENTION_MODULE_BT_BB % 32); #endif - return ((inited_modules & mask) == (created_modules & mask)); + const sleep_retention_module_bitmap_t modem_domain_inited_modules = sleep_retention_module_bitmap_and(inited_modules, mask); + const sleep_retention_module_bitmap_t modem_domain_created_modules = sleep_retention_module_bitmap_and(created_modules, mask); + return sleep_retention_module_bitmap_eq(modem_domain_inited_modules, modem_domain_created_modules); #else return false; /* MODEM power domain is controlled by each module (WiFi, Bluetooth or 15.4) of modem */ #endif diff --git a/components/esp_hw_support/sleep_system_peripheral.c b/components/esp_hw_support/sleep_system_peripheral.c index f3eb153a98..f88b78204e 100644 --- a/components/esp_hw_support/sleep_system_peripheral.c +++ b/components/esp_hw_support/sleep_system_peripheral.c @@ -159,9 +159,116 @@ error: bool peripheral_domain_pd_allowed(void) { #if CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP - const uint32_t inited_modules = sleep_retention_get_inited_modules(); - const uint32_t created_modules = sleep_retention_get_created_modules(); - return (((inited_modules ^ created_modules) & TOP_DOMAIN_PERIPHERALS_BM) == 0); + const sleep_retention_module_bitmap_t inited_modules = sleep_retention_get_inited_modules(); + const sleep_retention_module_bitmap_t created_modules = sleep_retention_get_created_modules(); + + sleep_retention_module_bitmap_t mask = (sleep_retention_module_bitmap_t){ .bitmap = { 0 } }; + mask.bitmap[SLEEP_RETENTION_MODULE_SYS_PERIPH >> 5] |= BIT(SLEEP_RETENTION_MODULE_SYS_PERIPH % 32); +#if SOC_MWDT_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_TG0_WDT >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG0_WDT % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_TG1_WDT >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG1_WDT % 32); +#endif +#if SOC_TIMER_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_TG0_TIMER0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG0_TIMER0 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_TG1_TIMER0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG1_TIMER0 % 32); +# if (SOC_TIMER_GROUP_TIMERS_PER_GROUP > 1) + mask.bitmap[SLEEP_RETENTION_MODULE_TG0_TIMER1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG0_TIMER1 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_TG1_TIMER1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TG1_TIMER1 % 32); +# endif +#endif + +#if SOC_ADC_SUPPORTED && !CONFIG_IDF_TARGET_ESP32P4 // TODO: IDF-11369 + mask.bitmap[SLEEP_RETENTION_MODULE_ADC >> 5] |= BIT(SLEEP_RETENTION_MODULE_ADC % 32); +#endif + +#if SOC_UART_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_UART0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_UART0 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_UART1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_UART1 % 32); +# if (SOC_UART_HP_NUM > 2) && !CONFIG_IDF_TARGET_ESP32C61 // TODO: IDF-11370 + mask.bitmap[SLEEP_RETENTION_MODULE_UART2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_UART2 % 32); +# endif +# if (SOC_UART_HP_NUM > 3) + mask.bitmap[SLEEP_RETENTION_MODULE_UART3 >> 5] |= BIT(SLEEP_RETENTION_MODULE_UART3 % 32); +# endif +# if (SOC_UART_HP_NUM > 4) + mask.bitmap[SLEEP_RETENTION_MODULE_UART4 >> 5] |= BIT(SLEEP_RETENTION_MODULE_UART4 % 32); +# endif +#endif /* SOC_UART_SUPPORT_SLEEP_RETENTION */ + +#if SOC_RMT_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_RMT0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_RMT0 % 32); +#endif + +#if SOC_GDMA_SUPPORT_SLEEP_RETENTION +# if SOC_GDMA_SUPPORTED && !CONFIG_IDF_TARGET_ESP32P4 // TODO: IDF-11371 + mask.bitmap[SLEEP_RETENTION_MODULE_GDMA_CH0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_GDMA_CH0 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_GDMA_CH1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_GDMA_CH1 % 32); +# if (SOC_GDMA_PAIRS_PER_GROUP_MAX > 2) + mask.bitmap[SLEEP_RETENTION_MODULE_GDMA_CH2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_GDMA_CH2 % 32); +# endif +# endif /* SOC_GDMA_SUPPORTED */ +# if SOC_AHB_GDMA_SUPPORTED && CONFIG_IDF_TARGET_ESP32P4 // TODO: IDF-11372 + mask.bitmap[SLEEP_RETENTION_MODULE_AHB_DMA_CH0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AHB_DMA_CH0 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_AHB_DMA_CH1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AHB_DMA_CH1 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_AHB_DMA_CH2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AHB_DMA_CH2 % 32); +# endif /* SOC_AHB_GDMA_SUPPORTED */ +# if SOC_AXI_GDMA_SUPPORTED + mask.bitmap[SLEEP_RETENTION_MODULE_AXI_DMA_CH0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AXI_DMA_CH0 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_AXI_DMA_CH1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AXI_DMA_CH1 % 32); + mask.bitmap[SLEEP_RETENTION_MODULE_AXI_DMA_CH2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_AXI_DMA_CH2 % 32); +# endif /* SOC_AXI_GDMA_SUPPORTED */ +#endif /* SOC_GDMA_SUPPORT_SLEEP_RETENTION */ + +#if SOC_I2S_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_I2S0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_I2S0 % 32); +# if (SOC_I2S_NUM > 1) + mask.bitmap[SLEEP_RETENTION_MODULE_I2S1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_I2S1 % 32); +# endif +# if (SOC_I2S_NUM > 2) + mask.bitmap[SLEEP_RETENTION_MODULE_I2S2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_I2S2 % 32); +# endif +#endif /* SOC_I2S_SUPPORT_SLEEP_RETENTION */ + +#if SOC_I2C_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_I2C0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_I2C0 % 32); +# if (SOC_HP_I2C_NUM > 1) + mask.bitmap[SLEEP_RETENTION_MODULE_I2C1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_I2C1 % 32); +# endif +#endif /* SOC_I2C_SUPPORT_SLEEP_RETENTION */ + +#if SOC_ETM_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_ETM0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_ETM0 % 32); +#endif + +#if SOC_TWAI_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_TWAI0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TWAI0 % 32); +# if (SOC_TWAI_CONTROLLER_NUM > 1) + mask.bitmap[SLEEP_RETENTION_MODULE_TWAI1 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TWAI1 % 32); +# endif +# if (SOC_TWAI_CONTROLLER_NUM > 2) + mask.bitmap[SLEEP_RETENTION_MODULE_TWAI2 >> 5] |= BIT(SLEEP_RETENTION_MODULE_TWAI2 % 32); +# endif +#endif /* SOC_TWAI_SUPPORT_SLEEP_RETENTION */ + +#if SOC_PARLIO_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_PARLIO0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_PARLIO0 % 32); +#endif + +#if SOC_LEDC_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_LEDC >> 5] |= BIT(SLEEP_RETENTION_MODULE_LEDC % 32); +#endif + +#if SOC_PCNT_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_PCNT0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_PCNT0 % 32); +#endif + +#if SOC_MCPWM_SUPPORT_SLEEP_RETENTION + mask.bitmap[SLEEP_RETENTION_MODULE_MCPWM0 >> 5] |= BIT(SLEEP_RETENTION_MODULE_MCPWM0 % 32); +#endif + + const sleep_retention_module_bitmap_t peripheral_domain_inited_modules = sleep_retention_module_bitmap_and(inited_modules, mask); + const sleep_retention_module_bitmap_t peripheral_domain_created_modules = sleep_retention_module_bitmap_and(created_modules, mask); + return sleep_retention_module_bitmap_eq(peripheral_domain_inited_modules, peripheral_domain_created_modules); #else return false; #endif @@ -172,7 +279,7 @@ ESP_SYSTEM_INIT_FN(sleep_sys_periph_startup_init, SECONDARY, BIT(0), 107) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_sys_periph_retention_init, .arg = NULL } }, - .depends = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) + .depends.bitmap[SLEEP_RETENTION_MODULE_CLOCK_SYSTEM >> 5] = BIT(SLEEP_RETENTION_MODULE_CLOCK_SYSTEM % 32) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_SYS_PERIPH, &init_param); if (err == ESP_OK) { From af5a9c87cd5e9cf525b97942f8156c933c342257 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Fri, 25 Oct 2024 11:25:30 +0800 Subject: [PATCH 5/6] change(soc): define sleep retention module total number to 64 for esp32p4 --- components/soc/esp32p4/include/soc/Kconfig.soc_caps.in | 2 +- components/soc/esp32p4/include/soc/soc_caps.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in index c1960b7309..ea7e5b1fe2 100644 --- a/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32p4/include/soc/Kconfig.soc_caps.in @@ -1717,7 +1717,7 @@ config SOC_CPU_IN_TOP_DOMAIN config SOC_PM_RETENTION_MODULE_NUM int - default 32 + default 64 config SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE bool diff --git a/components/soc/esp32p4/include/soc/soc_caps.h b/components/soc/esp32p4/include/soc/soc_caps.h index b932cd7c5e..fae77cace1 100644 --- a/components/soc/esp32p4/include/soc/soc_caps.h +++ b/components/soc/esp32p4/include/soc/soc_caps.h @@ -670,7 +670,7 @@ #define SOC_PAU_IN_TOP_DOMAIN (1) #define SOC_CPU_IN_TOP_DOMAIN (1) -#define SOC_PM_RETENTION_MODULE_NUM (32) +#define SOC_PM_RETENTION_MODULE_NUM (64) #define SOC_PM_PAU_REGDMA_UPDATE_CACHE_BEFORE_WAIT_COMPARE (1) From 88c1c9c344ce6493fb90d4ef888cf0f450d22011 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Tue, 5 Nov 2024 21:32:38 +0800 Subject: [PATCH 6/6] change(esp_hw_support): fix some sleep retention build error --- .../beta3/include/soc/retention_periph_defs.h | 15 +++++++++++++++ .../mp/include/soc/retention_periph_defs.h | 15 +++++++++++++++ .../include/soc/retention_periph_defs.h | 17 +++++++++++++++++ .../include/soc/retention_periph_defs.h | 9 +++++++++ .../include/soc/retention_periph_defs.h | 18 ++++++++++++++++++ .../include/soc/retention_periph_defs.h | 16 ++++++++++++++++ 6 files changed, 90 insertions(+) diff --git a/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h b/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h index 85e95bed48..f5c9a63651 100644 --- a/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c5/beta3/include/soc/retention_periph_defs.h @@ -44,6 +44,21 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ADC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_RMT0) ? true \ + : false) + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h b/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h index 85e95bed48..f5c9a63651 100644 --- a/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c5/mp/include/soc/retention_periph_defs.h @@ -44,6 +44,21 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ADC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_RMT0) ? true \ + : false) + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c6/include/soc/retention_periph_defs.h b/components/soc/esp32c6/include/soc/retention_periph_defs.h index e50a9fc67f..ca648c335c 100644 --- a/components/soc/esp32c6/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c6/include/soc/retention_periph_defs.h @@ -47,6 +47,23 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ADC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_RMT0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART1) ? true \ + : false) + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32c61/include/soc/retention_periph_defs.h b/components/soc/esp32c61/include/soc/retention_periph_defs.h index 321a688c1d..d3f9bfbb99 100644 --- a/components/soc/esp32c61/include/soc/retention_periph_defs.h +++ b/components/soc/esp32c61/include/soc/retention_periph_defs.h @@ -38,6 +38,15 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : false) + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32h2/include/soc/retention_periph_defs.h b/components/soc/esp32h2/include/soc/retention_periph_defs.h index ab4862d500..aa3396a6c9 100644 --- a/components/soc/esp32h2/include/soc/retention_periph_defs.h +++ b/components/soc/esp32h2/include/soc/retention_periph_defs.h @@ -46,6 +46,24 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_GDMA_CH2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_ADC) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_I2C1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_RMT0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART1) ? true \ + : false) + #ifdef __cplusplus } #endif diff --git a/components/soc/esp32p4/include/soc/retention_periph_defs.h b/components/soc/esp32p4/include/soc/retention_periph_defs.h index ac3785f75d..26db96bc97 100644 --- a/components/soc/esp32p4/include/soc/retention_periph_defs.h +++ b/components/soc/esp32p4/include/soc/retention_periph_defs.h @@ -37,6 +37,22 @@ typedef enum periph_retention_module { SLEEP_RETENTION_MODULE_MAX = SOC_PM_RETENTION_MODULE_NUM - 1 } periph_retention_module_t; +#define is_top_domain_module(m) \ + ( ((m) == SLEEP_RETENTION_MODULE_CLOCK_SYSTEM) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_SYS_PERIPH) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_WDT) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG0_TIMER1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_TG1_TIMER1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART0) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART1) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART2) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART3) ? true \ + : ((m) == SLEEP_RETENTION_MODULE_UART4) ? true \ + : false) + #ifdef __cplusplus } #endif