From 4011a4de745183e02f9cc2abe30a9b3c41bc2996 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 11 Jun 2026 11:32:31 +0800 Subject: [PATCH] feat(esp_hw_support): support sleep retention destroy callback --- .../include/esp_private/sleep_retention.h | 8 +++++++- components/esp_hw_support/sleep_retention.c | 19 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) 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 aed019c1202..bd0f2a2d4bc 100644 --- a/components/esp_hw_support/include/esp_private/sleep_retention.h +++ b/components/esp_hw_support/include/esp_private/sleep_retention.h @@ -52,7 +52,13 @@ typedef struct { } sleep_retention_create_callback_t; typedef struct { - sleep_retention_create_callback_t create; /*!< A function handle is used to register the implementation of creating a sleep retention linked list and is executed when the corresponding module is created */ + sleep_retention_callback_t handle; + void *arg; +} sleep_retention_destroy_callback_t; + +typedef struct { + sleep_retention_create_callback_t create; /*!< A function handle is used to register the implementation of creating a sleep retention linked list and is executed when the corresponding module is created */ + sleep_retention_destroy_callback_t destroy; /*!< The callback function handle is invoked after the sleep retention linked list is destroyed */ } sleep_retention_module_callbacks_t; typedef enum { diff --git a/components/esp_hw_support/sleep_retention.c b/components/esp_hw_support/sleep_retention.c index 54bad4f9901..c1423f88572 100644 --- a/components/esp_hw_support/sleep_retention.c +++ b/components/esp_hw_support/sleep_retention.c @@ -60,7 +60,10 @@ static inline void sleep_retention_module_object_ctor(struct sleep_retention_mod static inline void sleep_retention_module_object_dtor(struct sleep_retention_module_object * const self) { - self->cbs = (sleep_retention_module_callbacks_t) { .create = { .handle = NULL, .arg = NULL } }; + self->cbs = (sleep_retention_module_callbacks_t) { + .create = { .handle = NULL, .arg = NULL }, + .destroy = { .handle = NULL, .arg = NULL } + }; } static inline void set_dependencies(struct sleep_retention_module_object * const self, sleep_retention_module_bitmap_t depends) @@ -1075,7 +1078,12 @@ static esp_err_t passive_module_free(sleep_retention_module_t module) if (!references_exist(instance(module))) { if (!module_is_retained(module)) { sleep_retention_entries_destroy(module); - err = module_action_wrapper(module, (BIT(31) | action(2)), passive_module_free); + if (instance(module)->cbs.destroy.handle) { + err = instance(module)->cbs.destroy.handle(instance(module)->cbs.destroy.arg); + } + if (err == ESP_OK) { + err = module_action_wrapper(module, (BIT(31) | action(2)), passive_module_free); + } } else { err = ESP_ERR_INVALID_STATE; } @@ -1096,7 +1104,12 @@ esp_err_t sleep_retention_module_free(sleep_retention_module_t module) if (!module_is_passive(instance(module))) { if (module_is_inited(module) && module_is_created(module) && !module_is_retained(module)) { sleep_retention_entries_destroy(module); - err = module_action_wrapper(module, action(2), passive_module_free); + if (instance(module)->cbs.destroy.handle) { + err = instance(module)->cbs.destroy.handle(instance(module)->cbs.destroy.arg); + } + if (err == ESP_OK) { + err = module_action_wrapper(module, action(2), passive_module_free); + } } else { err = ESP_ERR_INVALID_STATE; }