efuse_hal.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_chip_revision(void)
  15. {
  16. return efuse_ll_get_chip_revision();
  17. }
  18. /******************* eFuse control functions *************************/
  19. void efuse_hal_set_timing(uint32_t apb_freq_hz)
  20. {
  21. ets_efuse_set_timing(apb_freq_hz);
  22. }
  23. void efuse_hal_read(void)
  24. {
  25. ets_efuse_read();
  26. }
  27. void efuse_hal_clear_program_registers(void)
  28. {
  29. ets_efuse_clear_program_registers();
  30. }
  31. void efuse_hal_program(uint32_t block)
  32. {
  33. ets_efuse_program(block);
  34. }
  35. void efuse_hal_rs_calculate(const void *data, void *rs_values)
  36. {
  37. ets_efuse_rs_calculate(data, rs_values);
  38. }
  39. /******************* eFuse control functions *************************/
  40. bool efuse_hal_is_coding_error_in_block(unsigned block)
  41. {
  42. if (block == 0) {
  43. for (unsigned i = 0; i < 5; i++) {
  44. if (REG_READ(EFUSE_RD_REPEAT_ERR0_REG + i * 4)) {
  45. return true;
  46. }
  47. }
  48. } else if (block <= 10) {
  49. // EFUSE_RD_RS_ERR0_REG: (hi) BLOCK8, BLOCK7, BLOCK6, BLOCK5, BLOCK4, BLOCK3, BLOCK2, BLOCK1 (low)
  50. // EFUSE_RD_RS_ERR1_REG: BLOCK10, BLOCK9
  51. block--;
  52. uint32_t error_reg = REG_READ(EFUSE_RD_RS_ERR0_REG + (block / 8) * 4);
  53. return ESP_EFUSE_BLOCK_ERROR_BITS(error_reg, block % 8) != 0;
  54. }
  55. return false;
  56. }