esp_system.h 3.7 KB

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