efuse.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 pad configuration, show gpio number of flash pad, includes 5 pads.
  54. *
  55. * @param null
  56. *
  57. * @return uint32_t: 0, invalid, flash pad decided by strapping
  58. * else, bit[5:0] spiclk, bit[11:6] spiq, bit[17:12] spid, bit[23:18] spics0, bit[29:24] spihd
  59. */
  60. uint32_t ets_efuse_get_spiconfig(void);
  61. #define EFUSE_SPICONFIG_RET_SPICLK_MASK 0x3f
  62. #define EFUSE_SPICONFIG_RET_SPICLK_SHIFT 0
  63. #define EFUSE_SPICONFIG_RET_SPICLK(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPICLK_SHIFT) & EFUSE_SPICONFIG_RET_SPICLK_MASK)
  64. #define EFUSE_SPICONFIG_RET_SPIQ_MASK 0x3f
  65. #define EFUSE_SPICONFIG_RET_SPIQ_SHIFT 6
  66. #define EFUSE_SPICONFIG_RET_SPIQ(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPIQ_SHIFT) & EFUSE_SPICONFIG_RET_SPIQ_MASK)
  67. #define EFUSE_SPICONFIG_RET_SPID_MASK 0x3f
  68. #define EFUSE_SPICONFIG_RET_SPID_SHIFT 12
  69. #define EFUSE_SPICONFIG_RET_SPID(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPID_SHIFT) & EFUSE_SPICONFIG_RET_SPID_MASK)
  70. #define EFUSE_SPICONFIG_RET_SPICS0_MASK 0x3f
  71. #define EFUSE_SPICONFIG_RET_SPICS0_SHIFT 18
  72. #define EFUSE_SPICONFIG_RET_SPICS0(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPICS0_SHIFT) & EFUSE_SPICONFIG_RET_SPICS0_MASK)
  73. #define EFUSE_SPICONFIG_RET_SPIHD_MASK 0x3f
  74. #define EFUSE_SPICONFIG_RET_SPIHD_SHIFT 24
  75. #define EFUSE_SPICONFIG_RET_SPIHD(ret) (((ret) >> EFUSE_SPICONFIG_RET_SPIHD_SHIFT) & EFUSE_SPICONFIG_RET_SPIHD_MASK)
  76. /**
  77. * @brief A crc8 algorithm used in efuse check.
  78. *
  79. * @param unsigned char const *p : Pointer to original data.
  80. *
  81. * @param unsigned int len : Data length in byte.
  82. *
  83. * @return unsigned char: Crc value.
  84. */
  85. unsigned char esp_crc8(unsigned char const *p, unsigned int len);
  86. /**
  87. * @}
  88. */
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* _ROM_EFUSE_H_ */