esp_system.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_SYSTEM_H__
  14. #define __ESP_SYSTEM_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_attr.h"
  19. #include "esp_bit_defs.h"
  20. #include "esp_idf_version.h"
  21. #include "sdkconfig.h"
  22. // For backward compatibility. These headers
  23. // contains hardware operation functions and definitions
  24. // that were originally declared in this header.
  25. #include "esp_mac.h"
  26. #include "esp_chip_info.h"
  27. #include "esp_random.h"
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. * @brief Reset reasons
  33. */
  34. typedef enum {
  35. ESP_RST_UNKNOWN, //!< Reset reason can not be determined
  36. ESP_RST_POWERON, //!< Reset due to power-on event
  37. ESP_RST_EXT, //!< Reset by external pin (not applicable for ESP32)
  38. ESP_RST_SW, //!< Software reset via esp_restart
  39. ESP_RST_PANIC, //!< Software reset due to exception/panic
  40. ESP_RST_INT_WDT, //!< Reset (software or hardware) due to interrupt watchdog
  41. ESP_RST_TASK_WDT, //!< Reset due to task watchdog
  42. ESP_RST_WDT, //!< Reset due to other watchdogs
  43. ESP_RST_DEEPSLEEP, //!< Reset after exiting deep sleep mode
  44. ESP_RST_BROWNOUT, //!< Brownout reset (software or hardware)
  45. ESP_RST_SDIO, //!< Reset over SDIO
  46. } esp_reset_reason_t;
  47. /**
  48. * Shutdown handler type
  49. */
  50. typedef void (*shutdown_handler_t)(void);
  51. /**
  52. * @brief Register shutdown handler
  53. *
  54. * This function allows you to register a handler that gets invoked before
  55. * the application is restarted using esp_restart function.
  56. * @param handle function to execute on restart
  57. * @return
  58. * - ESP_OK on success
  59. * - ESP_ERR_INVALID_STATE if the handler has already been registered
  60. * - ESP_ERR_NO_MEM if no more shutdown handler slots are available
  61. */
  62. esp_err_t esp_register_shutdown_handler(shutdown_handler_t handle);
  63. /**
  64. * @brief Unregister shutdown handler
  65. *
  66. * This function allows you to unregister a handler which was previously
  67. * registered using esp_register_shutdown_handler function.
  68. * - ESP_OK on success
  69. * - ESP_ERR_INVALID_STATE if the given handler hasn't been registered before
  70. */
  71. esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handle);
  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 WiFi, 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. * @brief Get reason of last reset
  83. * @return See description of esp_reset_reason_t for explanation of each value.
  84. */
  85. esp_reset_reason_t esp_reset_reason(void);
  86. /**
  87. * @brief Get the size of available heap.
  88. *
  89. * Note that the returned value may be larger than the maximum contiguous block
  90. * which can be allocated.
  91. *
  92. * @return Available heap size, in bytes.
  93. */
  94. uint32_t esp_get_free_heap_size(void);
  95. /**
  96. * @brief Get the size of available internal heap.
  97. *
  98. * Note that the returned value may be larger than the maximum contiguous block
  99. * which can be allocated.
  100. *
  101. * @return Available internal heap size, in bytes.
  102. */
  103. uint32_t esp_get_free_internal_heap_size(void);
  104. /**
  105. * @brief Get the minimum heap that has ever been available
  106. *
  107. * @return Minimum free heap ever available
  108. */
  109. uint32_t esp_get_minimum_free_heap_size( void );
  110. /**
  111. * @brief Trigger a software abort
  112. *
  113. * @param details Details that will be displayed during panic handling.
  114. */
  115. void __attribute__((noreturn)) esp_system_abort(const char* details);
  116. #ifdef __cplusplus
  117. }
  118. #endif
  119. #endif /* __ESP_SYSTEM_H__ */