1 /* 2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef __ESP_SYSTEM_H__ 8 #define __ESP_SYSTEM_H__ 9 10 #include <stdint.h> 11 #include <stdbool.h> 12 #include "esp_err.h" 13 #include "esp_attr.h" 14 #include "esp_bit_defs.h" 15 #include "esp_idf_version.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 /** 22 * @brief Reset reasons 23 */ 24 typedef enum { 25 ESP_RST_UNKNOWN, //!< Reset reason can not be determined 26 ESP_RST_POWERON, //!< Reset due to power-on event 27 ESP_RST_EXT, //!< Reset by external pin (not applicable for ESP32) 28 ESP_RST_SW, //!< Software reset via esp_restart 29 ESP_RST_PANIC, //!< Software reset due to exception/panic 30 ESP_RST_INT_WDT, //!< Reset (software or hardware) due to interrupt watchdog 31 ESP_RST_TASK_WDT, //!< Reset due to task watchdog 32 ESP_RST_WDT, //!< Reset due to other watchdogs 33 ESP_RST_DEEPSLEEP, //!< Reset after exiting deep sleep mode 34 ESP_RST_BROWNOUT, //!< Brownout reset (software or hardware) 35 ESP_RST_SDIO, //!< Reset over SDIO 36 ESP_RST_USB, //!< Reset by USB peripheral 37 ESP_RST_JTAG, //!< Reset by JTAG 38 ESP_RST_EFUSE, //!< Reset due to efuse error 39 ESP_RST_PWR_GLITCH, //!< Reset due to power glitch detected 40 ESP_RST_CPU_LOCKUP, //!< Reset due to CPU lock up 41 } esp_reset_reason_t; 42 43 /** 44 * Shutdown handler type 45 */ 46 typedef void (*shutdown_handler_t)(void); 47 48 /** 49 * @brief Register shutdown handler 50 * 51 * This function allows you to register a handler that gets invoked before 52 * the application is restarted using esp_restart function. 53 * @param handle function to execute on restart 54 * @return 55 * - ESP_OK on success 56 * - ESP_ERR_INVALID_STATE if the handler has already been registered 57 * - ESP_ERR_NO_MEM if no more shutdown handler slots are available 58 */ 59 esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle); 60 61 /** 62 * @brief Unregister shutdown handler 63 * 64 * This function allows you to unregister a handler which was previously 65 * registered using esp_register_shutdown_handler function. 66 * - ESP_OK on success 67 * - ESP_ERR_INVALID_STATE if the given handler hasn't been registered before 68 */ 69 esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handle); 70 71 72 /** 73 * @brief Restart PRO and APP CPUs. 74 * 75 * This function can be called both from PRO and APP CPUs. 76 * After successful restart, CPU reset reason will be SW_CPU_RESET. 77 * Peripherals (except for Wi-Fi, BT, UART0, SPI1, and legacy timers) are not reset. 78 * This function does not return. 79 */ 80 void esp_restart(void) __attribute__ ((__noreturn__)); 81 82 /** 83 * @brief Get reason of last reset 84 * @return See description of esp_reset_reason_t for explanation of each value. 85 */ 86 esp_reset_reason_t esp_reset_reason(void); 87 88 /** 89 * @brief Get the size of available heap. 90 * 91 * @note Note that the returned value may be larger than the maximum contiguous block 92 * which can be allocated. 93 * 94 * @return Available heap size, in bytes. 95 */ 96 uint32_t esp_get_free_heap_size(void); 97 98 /** 99 * @brief Get the size of available internal heap. 100 * 101 * @note Note that the returned value may be larger than the maximum contiguous block 102 * which can be allocated. 103 * 104 * @return Available internal heap size, in bytes. 105 */ 106 uint32_t esp_get_free_internal_heap_size(void); 107 108 /** 109 * @brief Get the minimum heap that has ever been available 110 * 111 * @return Minimum free heap ever available 112 */ 113 uint32_t esp_get_minimum_free_heap_size( void ); 114 115 /** 116 * @brief Trigger a software abort 117 * 118 * @param details Details that will be displayed during panic handling. 119 */ 120 void __attribute__((__noreturn__)) esp_system_abort(const char* details); 121 122 #ifdef __cplusplus 123 } 124 #endif 125 126 #endif /* __ESP_SYSTEM_H__ */ 127