hpm_otp_drv.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_OTP_DRV_H
  8. #define HPM_OTP_DRV_H
  9. /**
  10. * @brief OTP APIs
  11. * @defgroup otp_interface OTP driver APIs
  12. * @{
  13. */
  14. #include "hpm_common.h"
  15. /***********************************************************************************************************************
  16. * Definitions
  17. **********************************************************************************************************************/
  18. /**
  19. * @brief OTP region definitions
  20. */
  21. typedef enum {
  22. otp_region0_mask = 1U, /*!< Address range: [0, 7] */
  23. otp_region1_mask = 2U, /*!< Address range: [8, 15] */
  24. otp_region2_mask = 4U, /*!< Address range: [16, 127] */
  25. otp_region3_mask = 8U, /*!< Address range: user defined */
  26. } otp_region_t;
  27. /**
  28. * @brief OTP lock options
  29. */
  30. typedef enum {
  31. otp_no_lock = 0,
  32. otp_read_only = 1,
  33. otp_permanent_no_lock = 2,
  34. otp_disable_access = 3,
  35. otp_lock_option_max = otp_disable_access,
  36. } otp_lock_option_t;
  37. enum {
  38. otp_write_disallowed = MAKE_STATUS(status_group_otp, 0),
  39. };
  40. /***********************************************************************************************************************
  41. * Prototypes
  42. **********************************************************************************************************************/
  43. #ifdef __cpluscplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @brief Initialize OTP controller
  48. */
  49. void otp_init(void);
  50. /**
  51. * @brief De-initialize OTP controller
  52. */
  53. void otp_deinit(void);
  54. /**
  55. * @brief Read the OTP word from shadow register
  56. * @param [in] addr OTP word index
  57. * @retval OTP word value
  58. */
  59. uint32_t otp_read_from_shadow(uint32_t addr);
  60. /**
  61. * @brief Read the specified OTP word from OTP IP bus
  62. * @param [in] addr OTP word index
  63. * @retval OTP word value
  64. */
  65. uint32_t otp_read_from_ip(uint32_t addr);
  66. /**
  67. * @brief Program a word to specified OTP field
  68. * @param [in] addr OTP word index
  69. * @param [in] src Pointer to the data to be programmed
  70. * @param [in] num_of_words Number of words to be programmed, only 1 is allowed
  71. * @return API execution status
  72. */
  73. hpm_stat_t otp_program(uint32_t addr, const uint32_t *src, uint32_t num_of_words);
  74. /**
  75. * @brief Reload a OTP region
  76. * @param [in] region OTP region option
  77. * @return API execution status
  78. */
  79. hpm_stat_t otp_reload(otp_region_t region);
  80. /**
  81. * @brief Change the Software lock permission
  82. * @param [in] addr OTP word index
  83. * @param [in] lock_option OTP lcok option
  84. * @return API execution status
  85. */
  86. hpm_stat_t otp_lock_otp(uint32_t addr, otp_lock_option_t lock_option);
  87. /**
  88. * @brief OTP lock shadow
  89. * @param [in] addr OTP word index
  90. * @param [in] lock_option OTP lock option
  91. * @return API execution status
  92. */
  93. hpm_stat_t otp_lock_shadow(uint32_t addr, otp_lock_option_t lock_option);
  94. /**
  95. * @brief Set the configurable region range
  96. * @param [in] start OTP word start index
  97. * @param [in] num_of_words Number of words in configuration region
  98. * @retval status_out_of_range Invalid range
  99. * @retval status_success Operation is successful
  100. */
  101. hpm_stat_t otp_set_configurable_region(uint32_t start, uint32_t num_of_words);
  102. /**
  103. * @return Write data to OTP shadow register
  104. * @param [in] addr OTP word index
  105. * @param [val] val Data to be written
  106. * @return API execution status
  107. */
  108. hpm_stat_t otp_write_shadow_register(uint32_t addr, uint32_t val);
  109. #ifdef __cpluscplus
  110. }
  111. #endif
  112. /**
  113. * @}
  114. */
  115. #endif