esp_system.h 3.5 KB

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