esp_efuse_utility.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Copyright 2017-2018 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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include <string.h>
  19. #include "esp_types.h"
  20. #include "esp_err.h"
  21. #include "esp_efuse.h"
  22. #include "sdkconfig.h"
  23. #if CONFIG_IDF_TARGET_ESP32
  24. #include "esp32/esp_efuse_utility.h"
  25. #elif CONFIG_IDF_TARGET_ESP32S2
  26. #include "esp32s2/esp_efuse_utility.h"
  27. #endif
  28. /**
  29. * @brief Structure range address by blocks
  30. */
  31. typedef struct {
  32. uint32_t start;
  33. uint32_t end;
  34. } esp_efuse_range_addr_t;
  35. /**
  36. * @brief This is type of function that will handle the efuse field register.
  37. *
  38. * @param[in] num_reg The register number in the block.
  39. * @param[in] efuse_block Block number.
  40. * @param[in] bit_start Start bit in the register.
  41. * @param[in] bit_count The number of bits used in the register.
  42. * @param[in/out] arr A pointer to an array or variable.
  43. * @param[in/out] bits_counter Counter bits.
  44. *
  45. * @return
  46. * - ESP_OK: The operation was successfully completed.
  47. * - other efuse component errors.
  48. */
  49. typedef esp_err_t (*efuse_func_proc_t) (unsigned int num_reg, esp_efuse_block_t efuse_block, int starting_bit_num_in_reg, int num_bits_used_in_reg, void* arr, int* bits_counter);
  50. /**
  51. * @brief This function processes the field by calling the passed function.
  52. *
  53. * This function selects the field, checks the length, and calls the register processing function.
  54. * @param[in] field A pointer to the structure describing the fields of efuse.
  55. * @param[in/out] ptr A pointer to an array that is used to read / write from / to the efuse field.
  56. * @param[in] ptr_size_bits The size of the data in bits for the efuse field. if = 0 then read all field bits.
  57. * @param[in] func_proc This is the function that will handle the efuse fields.
  58. *
  59. * @return
  60. * - ESP_OK: The operation was successfully completed.
  61. * - other efuse component errors.
  62. */
  63. esp_err_t esp_efuse_utility_process(const esp_efuse_desc_t* field[], void* ptr, size_t ptr_size_bits, efuse_func_proc_t func_proc);
  64. /**
  65. * @brief Write register with the required number of "1" bits.
  66. * @param[in/out] cnt The number of bits you need to set in the field.
  67. */
  68. esp_err_t esp_efuse_utility_write_cnt(unsigned int num_reg, esp_efuse_block_t efuse_block, int bit_start, int bit_count, void* cnt, int* bits_counter);
  69. /**
  70. * @brief Fill registers from array for writing.
  71. * @param[in] arr_in A pointer to an array in which the data for the writing.
  72. */
  73. esp_err_t esp_efuse_utility_write_blob(unsigned int num_reg, esp_efuse_block_t efuse_block, int bit_start, int bit_count, void* arr_in, int* bits_counter);
  74. /**
  75. * @brief Count a set bits in register.
  76. * @param[in/out] out_cnt A pointer to size_t variable which will contain the number of "1" bits.
  77. */
  78. esp_err_t esp_efuse_utility_count_once(unsigned int num_reg, esp_efuse_block_t efuse_block, int bit_start, int bit_count, void* out_cnt, int* bits_counter);
  79. /**
  80. * @brief Read efuse register and write this value to array.
  81. * @param[out] arr_out A pointer to array that will contain the result of reading.
  82. */
  83. esp_err_t esp_efuse_utility_fill_buff(unsigned int num_reg, esp_efuse_block_t efuse_block, int bit_start, int bit_count, void* arr_out, int* bits_counter);
  84. /**
  85. * @brief Burn values written to the efuse write registers.
  86. *
  87. * If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed.
  88. * After the function is completed, the writing registers are cleared.
  89. */
  90. void esp_efuse_utility_burn_efuses(void);
  91. /**
  92. * @brief Returns the number of array elements for placing these "bits" in an array with the length of each element equal to "size_of_base".
  93. */
  94. int esp_efuse_utility_get_number_of_items(int bits, int size_of_base);
  95. /**
  96. * @brief Reading efuse register.
  97. */
  98. uint32_t esp_efuse_utility_read_reg(esp_efuse_block_t blk, unsigned int num_reg);
  99. /**
  100. * @brief Writing efuse register with checking of repeated programming of programmed bits.
  101. */
  102. esp_err_t esp_efuse_utility_write_reg(unsigned int num_reg, esp_efuse_block_t efuse_block, uint32_t reg_to_write);
  103. /* @brief Reset efuse write registers
  104. *
  105. * Efuse write registers are written to zero, to negate
  106. * any changes that have been staged here.
  107. */
  108. void esp_efuse_utility_reset(void);
  109. /**
  110. * @brief Fills the virt_blocks array by values from efuse_Rdata.
  111. */
  112. void esp_efuse_utility_update_virt_blocks(void);
  113. /**
  114. * @brief Prints efuse values for all registers.
  115. */
  116. void esp_efuse_utility_debug_dump_blocks(void);
  117. /**
  118. * @brief Erase the virt_blocks array.
  119. */
  120. void esp_efuse_utility_erase_virt_blocks(void);
  121. /**
  122. * @brief Apply coding_scheme to write registers.
  123. *
  124. * @return
  125. * - ESP_OK: The operation was successfully completed.
  126. * - ESP_ERR_CODING: Error range of data does not match the coding scheme.
  127. */
  128. esp_err_t esp_efuse_utility_apply_new_coding_scheme(void);
  129. /**
  130. * @brief Efuse read operation: copies data from physical efuses to efuse read registers.
  131. */
  132. void esp_efuse_utility_clear_program_registers(void);
  133. #ifdef __cplusplus
  134. }
  135. #endif