esp_system.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_MAC_ADDRESS_FROM_EFUSE 2
  29. #define FOUR_MAC_ADDRESS_FROM_EFUSE 4
  30. #define NUM_MAC_ADDRESS_FROM_EFUSE CONFIG_NUMBER_OF_MAC_ADDRESS_GENERATED_FROM_EFUSE
  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 one random 32-bit word from hardware RNG
  86. *
  87. * @return random value between 0 and UINT32_MAX
  88. */
  89. uint32_t esp_random(void);
  90. /**
  91. * @brief Read hardware MAC address.
  92. *
  93. * In WiFi MAC, only ESP32 station MAC is the hardware MAC, ESP32 softAP MAC is a software MAC
  94. * calculated from ESP32 station MAC.
  95. * So users need to call esp_wifi_get_macaddr to query the ESP32 softAP MAC if ESP32 station MAC changed.
  96. *
  97. * @param mac hardware MAC address, length: 6 bytes.
  98. *
  99. * @return ESP_OK on success
  100. */
  101. esp_err_t esp_efuse_read_mac(uint8_t* mac);
  102. /**
  103. * @brief Read hardware MAC address.
  104. *
  105. * Function has been renamed to esp_efuse_read_mac.
  106. * This name will be removed in a future release.
  107. *
  108. * @param mac hardware MAC address, length: 6 bytes.
  109. * @return ESP_OK on success
  110. */
  111. esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__ ((deprecated));
  112. /**
  113. * @brief Read hardware MAC address and set MAC address of the interface.
  114. *
  115. * This function first reads hardware MAC address from efuse. Then set the MAC address of the interface
  116. * including wifi station, wifi softap, bluetooth and ethernet.
  117. *
  118. * @param mac MAC address of the interface, length: 6 bytes.
  119. * @param type type of MAC address, 0:wifi station, 1:wifi softap, 2:bluetooth, 3:ethernet.
  120. *
  121. * @return ESP_OK on success
  122. */
  123. esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type);
  124. /**
  125. * @brief Derive MAC address.
  126. *
  127. * This function derives a local MAC address from an universal MAC address.
  128. * Addresses can either be universally administered addresses or locally administered addresses.
  129. * A universally administered address is uniquely assigned to a device by its manufacturer.
  130. * The first three octets (in transmission order) identify the organization that issued the identifier
  131. * and are known as the Organizationally Unique Identifier (OUI).[4] The remainder of the address
  132. * (three octets for MAC-48 and EUI-48 or five for EUI-64) are assigned by that organization in nearly
  133. * any manner they please, subject to the constraint of uniqueness. A locally administered address is
  134. * assigned to a device by a network administrator, overriding the burned-in address.
  135. * Universally administered and locally administered addresses are distinguished by setting
  136. * the second-least-significant bit of the first octet of the address. This bit is also referred to
  137. * as the U/L bit, short for Universal/Local, which identifies how the address is administered.
  138. * If the bit is 0, the address is universally administered. If it is 1, the address is locally administered.
  139. * In the example address 06-00-00-00-00-00 the first octet is 06 (hex), the binary form of which is 00000110,
  140. * where the second-least-significant bit is 1. Therefore, it is a locally administered address.[7] Consequently,
  141. * this bit is 0 in all OUIs.
  142. * In ESP32, universal MAC address is generated from the hardware MAC address in efuse.
  143. * Local MAC address is derived from the universal MAC address.
  144. *
  145. * @param dst_mac Derived local MAC address, length: 6 bytes.
  146. * @param src_mac Source universal MAC address, length: 6 bytes.
  147. *
  148. * @return ESP_OK on success
  149. */
  150. esp_err_t esp_derive_mac(uint8_t* dst_mac, const uint8_t* src_mac);
  151. /**
  152. * Get SDK version
  153. *
  154. * This function is deprecated and will be removed in a future release.
  155. *
  156. * @return constant string "master"
  157. */
  158. const char* system_get_sdk_version(void) __attribute__ ((deprecated));
  159. /**
  160. * Get IDF version
  161. *
  162. * @return constant string from IDF_VER
  163. */
  164. const char* esp_get_idf_version(void);
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif /* __ESP_SYSTEM_H__ */