Parcourir la source

system_api: add esp_unregister_shutdown_handler

Ivan Grokhotkov il y a 6 ans
Parent
commit
bd309a133f
2 fichiers modifiés avec 22 ajouts et 0 suppressions
  1. 11 0
      components/esp32/system_api.c
  2. 11 0
      components/esp_common/include/esp_system.h

+ 11 - 0
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)

+ 11 - 0
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.
   *