From bd309a133fc5fe328cf9d067c11da3aa08d5cbf9 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 8 Apr 2019 19:29:44 +0800 Subject: [PATCH] system_api: add esp_unregister_shutdown_handler --- components/esp32/system_api.c | 11 +++++++++++ components/esp_common/include/esp_system.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 120e9ec465..93763e523c 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -221,6 +221,17 @@ esp_err_t esp_register_shutdown_handler(shutdown_handler_t handler) return ESP_FAIL; } +esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handler) +{ + for (int i = 0; i < SHUTDOWN_HANDLERS_NO; i++) { + if (shutdown_handlers[i] == handler) { + shutdown_handlers[i] = NULL; + return ESP_OK; + } + } + return ESP_ERR_INVALID_STATE; +} + void esp_restart_noos() __attribute__ ((noreturn)); void IRAM_ATTR esp_restart(void) diff --git a/components/esp_common/include/esp_system.h b/components/esp_common/include/esp_system.h index 05214c8f57..5de5e5a9a2 100644 --- a/components/esp_common/include/esp_system.h +++ b/components/esp_common/include/esp_system.h @@ -83,6 +83,17 @@ typedef void (*shutdown_handler_t)(void); */ esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle); +/** + * @brief Unregister shutdown handler + * + * This function allows you to unregister a handler which was previously + * registered using esp_register_shutdown_handler function. + * - ESP_OK on success + * - ESP_ERR_INVALID_STATE if the given handler hasn't been registered before + */ +esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handle); + + /** * @brief Restart PRO and APP CPUs. * -- 2.40.0