esp_system.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_RST_USB, //!< Reset by USB peripheral
  33. ESP_RST_JTAG, //!< Reset by JTAG
  34. } esp_reset_reason_t;
  35. /**
  36. * Shutdown handler type
  37. */
  38. typedef void (*shutdown_handler_t)(void);
  39. /**
  40. * @brief Register shutdown handler
  41. *
  42. * This function allows you to register a handler that gets invoked before
  43. * the application is restarted using esp_restart function.
  44. * @param handle function to execute on restart
  45. * @return
  46. * - ESP_OK on success
  47. * - ESP_ERR_INVALID_STATE if the handler has already been registered
  48. * - ESP_ERR_NO_MEM if no more shutdown handler slots are available
  49. */
  50. esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle);
  51. /**
  52. * @brief Unregister shutdown handler
  53. *
  54. * This function allows you to unregister a handler which was previously
  55. * registered using esp_register_shutdown_handler function.
  56. * - ESP_OK on success
  57. * - ESP_ERR_INVALID_STATE if the given handler hasn't been registered before
  58. */
  59. esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handle);
  60. /**
  61. * @brief Restart PRO and APP CPUs.
  62. *
  63. * This function can be called both from PRO and APP CPUs.
  64. * After successful restart, CPU reset reason will be SW_CPU_RESET.
  65. * Peripherals (except for Wi-Fi, BT, UART0, SPI1, and legacy timers) are not reset.
  66. * This function does not return.
  67. */
  68. void esp_restart(void) __attribute__ ((__noreturn__));
  69. /**
  70. * @brief Get reason of last reset
  71. * @return See description of esp_reset_reason_t for explanation of each value.
  72. */
  73. esp_reset_reason_t esp_reset_reason(void);
  74. /**
  75. * @brief Get the size of available heap.
  76. *
  77. * @note Note that the returned value may be larger than the maximum contiguous block
  78. * which can be allocated.
  79. *
  80. * @return Available heap size, in bytes.
  81. */
  82. uint32_t esp_get_free_heap_size(void);
  83. /**
  84. * @brief Get the size of available internal heap.
  85. *
  86. * @note Note that the returned value may be larger than the maximum contiguous block
  87. * which can be allocated.
  88. *
  89. * @return Available internal heap size, in bytes.
  90. */
  91. uint32_t esp_get_free_internal_heap_size(void);
  92. /**
  93. * @brief Get the minimum heap that has ever been available
  94. *
  95. * @return Minimum free heap ever available
  96. */
  97. uint32_t esp_get_minimum_free_heap_size( void );
  98. /**
  99. * @brief Trigger a software abort
  100. *
  101. * @param details Details that will be displayed during panic handling.
  102. */
  103. void __attribute__((__noreturn__)) esp_system_abort(const char* details);
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* __ESP_SYSTEM_H__ */