esp_system.h 3.5 KB

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