esp_system.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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_deep_sleep.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. typedef enum {
  23. ESP_MAC_WIFI_STA,
  24. ESP_MAC_WIFI_SOFTAP,
  25. ESP_MAC_BT,
  26. ESP_MAC_ETH,
  27. } esp_mac_type_t;
  28. #define TWO_UNIVERSAL_MAC_ADDR 2
  29. #define FOUR_UNIVERSAL_MAC_ADDR 4
  30. #define UNIVERSAL_MAC_ADDR_NUM CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS
  31. /**
  32. * @attention application don't need to call this function anymore. It do nothing and will
  33. * be removed in future version.
  34. */
  35. void system_init(void) __attribute__ ((deprecated));
  36. /**
  37. * @brief Reset to default settings.
  38. *
  39. * Function has been deprecated, please use esp_wifi_restore instead.
  40. * This name will be removed in a future release.
  41. */
  42. void system_restore(void) __attribute__ ((deprecated));
  43. /**
  44. * @brief Restart PRO and APP CPUs.
  45. *
  46. * This function can be called both from PRO and APP CPUs.
  47. * After successful restart, CPU reset reason will be SW_CPU_RESET.
  48. * Peripherals (except for WiFi, BT, UART0, SPI1, and legacy timers) are not reset.
  49. * This function does not return.
  50. */
  51. void esp_restart(void) __attribute__ ((noreturn));
  52. /**
  53. * @brief Restart system.
  54. *
  55. * Function has been renamed to esp_restart.
  56. * This name will be removed in a future release.
  57. */
  58. void system_restart(void) __attribute__ ((deprecated, noreturn));
  59. /**
  60. * @brief Get system time, unit: microsecond.
  61. *
  62. * This function is deprecated. Use 'gettimeofday' function for 64-bit precision.
  63. * This definition will be removed in a future release.
  64. */
  65. uint32_t system_get_time(void) __attribute__ ((deprecated));
  66. /**
  67. * @brief Get the size of available heap.
  68. *
  69. * Note that the returned value may be larger than the maximum contiguous block
  70. * which can be allocated.
  71. *
  72. * @return Available heap size, in bytes.
  73. */
  74. uint32_t esp_get_free_heap_size(void);
  75. /**
  76. * @brief Get the size of available heap.
  77. *
  78. * Function has been renamed to esp_get_free_heap_size.
  79. * This name will be removed in a future release.
  80. *
  81. * @return Available heap size, in bytes.
  82. */
  83. uint32_t system_get_free_heap_size(void) __attribute__ ((deprecated));
  84. /**
  85. * @brief Get the minimum heap that has ever been available
  86. *
  87. * @return Minimum free heap ever available
  88. */
  89. uint32_t esp_get_minimum_free_heap_size( void );
  90. /**
  91. * @brief Get one random 32-bit word from hardware RNG
  92. *
  93. * The hardware RNG is fully functional whenever an RF subsystem is running (ie Bluetooth or WiFi is enabled). For secure
  94. * random values, call this function after WiFi or Bluetooth are started.
  95. *
  96. * When the app is running without an RF subsystem enabled, it should be considered a PRNG. To help improve this
  97. * situation, the RNG is pre-seeded with entropy while the IDF bootloader is running. However no new entropy is
  98. * available during the window of time between when the bootloader exits and an RF subsystem starts. It may be possible
  99. * to discern a non-random pattern in a very large amount of output captured during this window of time.
  100. *
  101. * @return Random value between 0 and UINT32_MAX
  102. */
  103. uint32_t esp_random(void);
  104. /**
  105. * @brief Set base MAC address with the MAC address which is stored in BLK3 of EFUSE or
  106. * external storage e.g. flash and EEPROM.
  107. *
  108. * Base MAC address is used to generate the MAC addresses used by the networking interfaces.
  109. * If using base MAC address stored in BLK3 of EFUSE or external storage, call this API to set base MAC
  110. * address with the MAC address which is stored in BLK3 of EFUSE or external storage before initializing
  111. * WiFi/BT/Ethernet.
  112. *
  113. * @param mac base MAC address, length: 6 bytes.
  114. *
  115. * @return ESP_OK on success
  116. */
  117. esp_err_t esp_base_mac_addr_set(uint8_t *mac);
  118. /**
  119. * @brief Return base MAC address which is set using esp_base_mac_addr_set.
  120. *
  121. * @param mac base MAC address, length: 6 bytes.
  122. *
  123. * @return ESP_OK on success
  124. * ESP_ERR_INVALID_MAC base MAC address has not been set
  125. */
  126. esp_err_t esp_base_mac_addr_get(uint8_t *mac);
  127. /**
  128. * @brief Return base MAC address which was previously written to BLK3 of EFUSE.
  129. *
  130. * Base MAC address is used to generate the MAC addresses used by the networking interfaces.
  131. * This API returns the custom base MAC address which was previously written to BLK3 of EFUSE.
  132. * Writing this EFUSE allows setting of a different (non-Espressif) base MAC address. It is also
  133. * possible to store a custom base MAC address elsewhere, see esp_base_mac_addr_set() for details.
  134. *
  135. * @param mac base MAC address, length: 6 bytes.
  136. *
  137. * @return ESP_OK on success
  138. * ESP_ERR_INVALID_VERSION An invalid MAC version field was read from BLK3 of EFUSE
  139. * ESP_ERR_INVALID_CRC An invalid MAC CRC was read from BLK3 of EFUSE
  140. */
  141. esp_err_t esp_efuse_mac_get_custom(uint8_t *mac);
  142. /**
  143. * @brief Return base MAC address which is factory-programmed by Espressif in BLK0 of EFUSE.
  144. *
  145. * @param mac base MAC address, length: 6 bytes.
  146. *
  147. * @return ESP_OK on success
  148. */
  149. esp_err_t esp_efuse_mac_get_default(uint8_t *mac);
  150. /**
  151. * @brief Read hardware MAC address from efuse.
  152. *
  153. * Function has been renamed to esp_efuse_mac_get_default.
  154. * This name will be removed in a future release.
  155. *
  156. * @param mac hardware MAC address, length: 6 bytes.
  157. *
  158. * @return ESP_OK on success
  159. */
  160. esp_err_t esp_efuse_read_mac(uint8_t *mac) __attribute__ ((deprecated));
  161. /**
  162. * @brief Read hardware MAC address.
  163. *
  164. * Function has been renamed to esp_efuse_mac_get_default.
  165. * This name will be removed in a future release.
  166. *
  167. * @param mac hardware MAC address, length: 6 bytes.
  168. * @return ESP_OK on success
  169. */
  170. esp_err_t system_efuse_read_mac(uint8_t *mac) __attribute__ ((deprecated));
  171. /**
  172. * @brief Read base MAC address and set MAC address of the interface.
  173. *
  174. * This function first get base MAC address using esp_base_mac_addr_get or reads base MAC address
  175. * from BLK0 of EFUSE. Then set the MAC address of the interface including wifi station, wifi softap,
  176. * bluetooth and ethernet.
  177. *
  178. * @param mac MAC address of the interface, length: 6 bytes.
  179. * @param type type of MAC address, 0:wifi station, 1:wifi softap, 2:bluetooth, 3:ethernet.
  180. *
  181. * @return ESP_OK on success
  182. */
  183. esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type);
  184. /**
  185. * @brief Derive local MAC address from universal MAC address.
  186. *
  187. * This function derives a local MAC address from an universal MAC address.
  188. * A `definition of local vs universal MAC address can be found on Wikipedia
  189. * <https://en.wikipedia.org/wiki/MAC_address#Universal_vs._local>`.
  190. * In ESP32, universal MAC address is generated from base MAC address in EFUSE or other external storage.
  191. * Local MAC address is derived from the universal MAC address.
  192. *
  193. * @param local_mac Derived local MAC address, length: 6 bytes.
  194. * @param universal_mac Source universal MAC address, length: 6 bytes.
  195. *
  196. * @return ESP_OK on success
  197. */
  198. esp_err_t esp_derive_local_mac(uint8_t* local_mac, const uint8_t* universal_mac);
  199. /**
  200. * Get SDK version
  201. *
  202. * This function is deprecated and will be removed in a future release.
  203. *
  204. * @return constant string "master"
  205. */
  206. const char* system_get_sdk_version(void) __attribute__ ((deprecated));
  207. /**
  208. * Get IDF version
  209. *
  210. * @return constant string from IDF_VER
  211. */
  212. const char* esp_get_idf_version(void);
  213. /**
  214. * @brief Chip models
  215. */
  216. typedef enum {
  217. CHIP_ESP32 = 1, //!< ESP32
  218. } esp_chip_model_t;
  219. /**
  220. * Chip feature flags, used in esp_chip_info_t
  221. */
  222. #define CHIP_FEATURE_EMB_FLASH BIT(0)
  223. #define CHIP_FEATURE_WIFI_BGN BIT(1)
  224. #define CHIP_FEATURE_BLE BIT(4)
  225. #define CHIP_FEATURE_BT BIT(5)
  226. /**
  227. * @brief The structure represents information about the chip
  228. */
  229. typedef struct {
  230. esp_chip_model_t model; //!< chip model, one of esp_chip_model_t
  231. uint32_t features; //!< bit mask of CHIP_FEATURE_x feature flags
  232. uint8_t cores; //!< number of CPU cores
  233. uint8_t revision; //!< chip revision number
  234. } esp_chip_info_t;
  235. /**
  236. * @brief Fill an esp_chip_info_t structure with information about the chip
  237. * @param[out] out_info structure to be filled
  238. */
  239. void esp_chip_info(esp_chip_info_t* out_info);
  240. #ifdef __cplusplus
  241. }
  242. #endif
  243. #endif /* __ESP_SYSTEM_H__ */