efuse_hal.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include "sdkconfig.h"
  7. #include <sys/param.h>
  8. #include "soc/soc_caps.h"
  9. #include "hal/assert.h"
  10. #include "hal/efuse_hal.h"
  11. #include "hal/efuse_ll.h"
  12. #include "esp32s2/rom/efuse.h"
  13. #define ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block) ((error_reg) & (0x0F << (4 * (block))))
  14. uint32_t efuse_hal_get_major_chip_version(void)
  15. {
  16. return efuse_ll_get_chip_wafer_version_major();
  17. }
  18. uint32_t efuse_hal_get_minor_chip_version(void)
  19. {
  20. return efuse_ll_get_chip_wafer_version_minor();
  21. }
  22. /******************* eFuse control functions *************************/
  23. void efuse_hal_set_timing(uint32_t apb_freq_hz)
  24. {
  25. ets_efuse_set_timing(apb_freq_hz);
  26. }
  27. void efuse_hal_read(void)
  28. {
  29. ets_efuse_read();
  30. }
  31. void efuse_hal_clear_program_registers(void)
  32. {
  33. ets_efuse_clear_program_registers();
  34. }
  35. void efuse_hal_program(uint32_t block)
  36. {
  37. ets_efuse_program(block);
  38. }
  39. void efuse_hal_rs_calculate(const void *data, void *rs_values)
  40. {
  41. ets_efuse_rs_calculate(data, rs_values);
  42. }
  43. /******************* eFuse control functions *************************/
  44. bool efuse_hal_is_coding_error_in_block(unsigned block)
  45. {
  46. if (block == 0) {
  47. for (unsigned i = 0; i < 5; i++) {
  48. if (REG_READ(EFUSE_RD_REPEAT_ERR0_REG + i * 4)) {
  49. return true;
  50. }
  51. }
  52. } else if (block <= 10) {
  53. // EFUSE_RD_RS_ERR0_REG: (hi) BLOCK8, BLOCK7, BLOCK6, BLOCK5, BLOCK4, BLOCK3, BLOCK2, BLOCK1 (low)
  54. // EFUSE_RD_RS_ERR1_REG: BLOCK10, BLOCK9
  55. block--;
  56. uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
  57. return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
  58. }
  59. return false;
  60. }