esp_efuse_utility.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. #include_next "esp_efuse_utility.h"
  24. /**
  25. * @brief Structure range address by blocks
  26. */
  27. typedef struct {
  28. uint32_t start;
  29. uint32_t end;
  30. } esp_efuse_range_addr_t;
  31. /**
  32. * @brief This is type of function that will handle the efuse field register.
  33. *
  34. * @param[in] num_reg The register number in the block.
  35. * @param[in] efuse_block Block number.
  36. * @param[in] bit_start Start bit in the register.
  37. * @param[in] bit_count The number of bits used in the register.
  38. * @param[in/out] arr A pointer to an array or variable.
  39. * @param[in/out] bits_counter Counter bits.
  40. *
  41. * @return
  42. * - ESP_OK: The operation was successfully completed.
  43. * - other efuse component errors.
  44. */
  45. 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);
  46. /**
  47. * @brief This function processes the field by calling the passed function.
  48. *
  49. * This function selects the field, checks the length, and calls the register processing function.
  50. * @param[in] field A pointer to the structure describing the fields of efuse.
  51. * @param[in/out] ptr A pointer to an array that is used to read / write from / to the efuse field.
  52. * @param[in] ptr_size_bits The size of the data in bits for the efuse field. if = 0 then read all field bits.
  53. * @param[in] func_proc This is the function that will handle the efuse fields.
  54. *
  55. * @return
  56. * - ESP_OK: The operation was successfully completed.
  57. * - other efuse component errors.
  58. */
  59. 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);
  60. /**
  61. * @brief Write register with the required number of "1" bits.
  62. * @param[in/out] cnt The number of bits you need to set in the field.
  63. */
  64. 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);
  65. /**
  66. * @brief Fill registers from array for writing.
  67. * @param[in] arr_in A pointer to an array in which the data for the writing.
  68. */
  69. 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);
  70. /**
  71. * @brief Count a set bits in register.
  72. * @param[in/out] out_cnt A pointer to size_t variable which will contain the number of "1" bits.
  73. */
  74. 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);
  75. /**
  76. * @brief Read efuse register and write this value to array.
  77. * @param[out] arr_out A pointer to array that will contain the result of reading.
  78. */
  79. 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);
  80. /**
  81. * @brief Burn values written to the efuse write registers.
  82. *
  83. * If CONFIG_EFUSE_VIRTUAL is set, writing will not be performed.
  84. * After the function is completed, the writing registers are cleared.
  85. */
  86. void esp_efuse_utility_burn_efuses(void);
  87. /**
  88. * @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".
  89. */
  90. int esp_efuse_utility_get_number_of_items(int bits, int size_of_base);
  91. /**
  92. * @brief Reading efuse register.
  93. */
  94. uint32_t esp_efuse_utility_read_reg(esp_efuse_block_t blk, unsigned int num_reg);
  95. /**
  96. * @brief Writing efuse register with checking of repeated programming of programmed bits.
  97. */
  98. esp_err_t esp_efuse_utility_write_reg(unsigned int num_reg, esp_efuse_block_t efuse_block, uint32_t reg_to_write);
  99. /* @brief Reset efuse write registers
  100. *
  101. * Efuse write registers are written to zero, to negate
  102. * any changes that have been staged here.
  103. */
  104. void esp_efuse_utility_reset(void);
  105. /**
  106. * @brief Fills the virt_blocks array by values from efuse_Rdata.
  107. */
  108. void esp_efuse_utility_update_virt_blocks(void);
  109. /**
  110. * @brief Prints efuse values for all registers.
  111. */
  112. void esp_efuse_utility_debug_dump_blocks(void);
  113. /**
  114. * @brief Erase the virt_blocks array.
  115. */
  116. void esp_efuse_utility_erase_virt_blocks(void);
  117. /**
  118. * @brief Apply coding_scheme to write registers.
  119. *
  120. * @return
  121. * - ESP_OK: The operation was successfully completed.
  122. * - ESP_ERR_CODING: Error range of data does not match the coding scheme.
  123. */
  124. esp_err_t esp_efuse_utility_apply_new_coding_scheme(void);
  125. /**
  126. * @brief Efuse read operation: copies data from physical efuses to efuse read registers.
  127. */
  128. void esp_efuse_utility_clear_program_registers(void);
  129. #ifdef __cplusplus
  130. }
  131. #endif