2021-10-04 16:01:50 -04:00
|
|
|
/*
|
2022-01-17 21:32:56 -05:00
|
|
|
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
2021-10-04 16:01:50 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2021-03-10 20:48:30 -05:00
|
|
|
|
2019-10-29 23:19:22 -04:00
|
|
|
#include "esp_system.h"
|
|
|
|
#include "esp_private/system_internal.h"
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
2021-09-06 04:22:40 -04:00
|
|
|
#if CONFIG_ESP_SYSTEM_MEMPROT_FEATURE
|
2020-07-13 09:33:23 -04:00
|
|
|
#if CONFIG_IDF_TARGET_ESP32S2
|
2020-03-10 11:46:10 -04:00
|
|
|
#include "esp32s2/memprot.h"
|
2021-09-06 04:22:40 -04:00
|
|
|
#else
|
|
|
|
#include "esp_memprot.h"
|
|
|
|
#endif
|
2020-03-10 11:46:10 -04:00
|
|
|
#endif
|
|
|
|
|
2020-12-30 08:24:31 -05:00
|
|
|
#define SHUTDOWN_HANDLERS_NO 5
|
|
|
|
|
2019-10-29 23:19:22 -04:00
|
|
|
static shutdown_handler_t shutdown_handlers[SHUTDOWN_HANDLERS_NO];
|
|
|
|
|
|
|
|
esp_err_t esp_register_shutdown_handler(shutdown_handler_t handler)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < SHUTDOWN_HANDLERS_NO; i++) {
|
|
|
|
if (shutdown_handlers[i] == handler) {
|
|
|
|
return ESP_ERR_INVALID_STATE;
|
|
|
|
} else if (shutdown_handlers[i] == NULL) {
|
|
|
|
shutdown_handlers[i] = handler;
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ESP_ERR_NO_MEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-09-23 02:33:26 -04:00
|
|
|
void esp_restart(void)
|
2019-10-29 23:19:22 -04:00
|
|
|
{
|
|
|
|
for (int i = SHUTDOWN_HANDLERS_NO - 1; i >= 0; i--) {
|
|
|
|
if (shutdown_handlers[i]) {
|
|
|
|
shutdown_handlers[i]();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-25 08:50:58 -05:00
|
|
|
#ifdef CONFIG_FREERTOS_SMP
|
|
|
|
//Note: Scheduler suspension behavior changed in FreeRTOS SMP
|
|
|
|
vTaskPreemptionDisable(NULL);
|
|
|
|
#else
|
2019-10-29 23:19:22 -04:00
|
|
|
// Disable scheduler on this core.
|
|
|
|
vTaskSuspendAll();
|
2022-02-25 08:50:58 -05:00
|
|
|
#endif // CONFIG_FREERTOS_SMP
|
2019-10-29 23:19:22 -04:00
|
|
|
|
|
|
|
esp_restart_noos();
|
|
|
|
}
|