efuse.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 _ROM_EFUSE_H_
  14. #define _ROM_EFUSE_H_
  15. #include <stdint.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /** \defgroup efuse_APIs efuse APIs
  20. * @brief ESP32 efuse read/write APIs
  21. * @attention
  22. *
  23. */
  24. /** @addtogroup efuse_APIs
  25. * @{
  26. */
  27. /**
  28. * @brief Do a efuse read operation, to update the efuse value to efuse read registers.
  29. *
  30. * @param null
  31. *
  32. * @return null
  33. */
  34. void ets_efuse_read_op(void);
  35. /**
  36. * @brief Do a efuse write operation, to update efuse write registers to efuse, then you need call ets_efuse_read_op again.
  37. *
  38. * @param null
  39. *
  40. * @return null
  41. */
  42. void ets_efuse_program_op(void);
  43. /**
  44. * @brief Read 8M Analog Clock value(8 bit) in efuse, the analog clock will not change with temperature.
  45. * It can be used to test the external xtal frequency, do not touch this efuse field.
  46. *
  47. * @param null
  48. *
  49. * @return u32: 1 for 100KHZ, range is 0 to 255.
  50. */
  51. uint32_t ets_efuse_get_8M_clock(void);
  52. /**
  53. * @brief Read spi flash pin configuration from Efuse
  54. *
  55. * @return
  56. * - 0 for default SPI pins.
  57. * - 1 for default HSPI pins.
  58. * - Other values define a custom pin configuration mask. Pins are encoded as per the EFUSE_SPICONFIG_RET_SPICLK,
  59. * EFUSE_SPICONFIG_RET_SPIQ, EFUSE_SPICONFIG_RET_SPID, EFUSE_SPICONFIG_RET_SPICS0, EFUSE_SPICONFIG_RET_SPIHD macros.
  60. * WP pin (for quad I/O modes) is not saved in efuse and not returned by this function.
  61. */
  62. uint32_t ets_efuse_get_spiconfig(void);
  63. #define EFUSE_SPICONFIG_SPI_DEFAULTS 0
  64. #define EFUSE_SPICONFIG_HSPI_DEFAULTS 1
  65. #define EFUSE_SPICONFIG_RET_SPICLK_MASK 0x3f
  66. #define EFUSE_SPICONFIG_RET_SPICLK_SHIFT 0
  67. #define EFUSE_SPICONFIG_RET_SPICLK(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPICLK_SHIFT) & EFUSE_SPICONFIG_RET_SPICLK_MASK)
  68. #define EFUSE_SPICONFIG_RET_SPIQ_MASK 0x3f
  69. #define EFUSE_SPICONFIG_RET_SPIQ_SHIFT 6
  70. #define EFUSE_SPICONFIG_RET_SPIQ(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPIQ_SHIFT) & EFUSE_SPICONFIG_RET_SPIQ_MASK)
  71. #define EFUSE_SPICONFIG_RET_SPID_MASK 0x3f
  72. #define EFUSE_SPICONFIG_RET_SPID_SHIFT 12
  73. #define EFUSE_SPICONFIG_RET_SPID(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPID_SHIFT) & EFUSE_SPICONFIG_RET_SPID_MASK)
  74. #define EFUSE_SPICONFIG_RET_SPICS0_MASK 0x3f
  75. #define EFUSE_SPICONFIG_RET_SPICS0_SHIFT 18
  76. #define EFUSE_SPICONFIG_RET_SPICS0(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPICS0_SHIFT) & EFUSE_SPICONFIG_RET_SPICS0_MASK)
  77. #define EFUSE_SPICONFIG_RET_SPIHD_MASK 0x3f
  78. #define EFUSE_SPICONFIG_RET_SPIHD_SHIFT 24
  79. #define EFUSE_SPICONFIG_RET_SPIHD(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPIHD_SHIFT) & EFUSE_SPICONFIG_RET_SPIHD_MASK)
  80. /**
  81. * @brief A crc8 algorithm used in efuse check.
  82. *
  83. * @param unsigned char const *p : Pointer to original data.
  84. *
  85. * @param unsigned int len : Data length in byte.
  86. *
  87. * @return unsigned char: Crc value.
  88. */
  89. unsigned char esp_crc8(unsigned char const *p, unsigned int len);
  90. /**
  91. * @}
  92. */
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif /* _ROM_EFUSE_H_ */