fsl_ocotp.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Copyright 2019-2020 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_OCOTP_H_
  8. #define _FSL_OCOTP_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup ocotp
  12. * @{
  13. */
  14. /*******************************************************************************
  15. * Definitions
  16. *******************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. /*! @brief OCOTP driver version. */
  20. #define FSL_OCOTP_DRIVER_VERSION (MAKE_VERSION(2, 1, 3))
  21. /*@}*/
  22. #ifndef OCOTP_READ_FUSE_DATA_COUNT
  23. #define OCOTP_READ_FUSE_DATA_COUNT (1U)
  24. #endif
  25. /*! @brief _ocotp_status Error codes for the OCOTP driver. */
  26. enum
  27. {
  28. kStatus_OCOTP_AccessError = MAKE_STATUS(kStatusGroup_SDK_OCOTP, 0), /*!< eFuse and shadow register access error. */
  29. kStatus_OCOTP_CrcFail = MAKE_STATUS(kStatusGroup_SDK_OCOTP, 1), /*!< CRC check failed. */
  30. kStatus_OCOTP_ReloadError =
  31. MAKE_STATUS(kStatusGroup_SDK_OCOTP, 2), /*!< Error happens during reload shadow register. */
  32. kStatus_OCOTP_ProgramFail = MAKE_STATUS(kStatusGroup_SDK_OCOTP, 3), /*!< Fuse programming failed. */
  33. kStatus_OCOTP_Locked = MAKE_STATUS(kStatusGroup_SDK_OCOTP, 4), /*!< Fuse is locked and cannot be programmed. */
  34. };
  35. #if (defined(FSL_FEATURE_OCOTP_HAS_TIMING_CTRL) && FSL_FEATURE_OCOTP_HAS_TIMING_CTRL)
  36. /*! @brief OCOTP timing structure.
  37. * Note that, these value are used for calcalating the read/write timings.
  38. * And the values should statisfy below rules:
  39. *
  40. * Tsp_rd=(WAIT+1)/ipg_clk_freq should be >= 150ns;
  41. * Tsp_pgm=(RELAX+1)/ipg_clk_freq should be >= 100ns;
  42. * Trd = ((STROBE_READ+1)- 2*(RELAX_READ+1)) /ipg_clk_freq,
  43. * The Trd is required to be larger than 40 ns.
  44. * Tpgm = ((STROBE_PROG+1)- 2*(RELAX_PROG+1)) /ipg_clk_freq;
  45. * The Tpgm should be configured within the range of 9000 ns < Tpgm < 11000 ns;
  46. */
  47. typedef struct _ocotp_timing
  48. {
  49. uint32_t wait; /*!< Wait time value to fill in the TIMING register. */
  50. uint32_t relax; /*!< Relax time value to fill in the TIMING register. */
  51. uint32_t strobe_prog; /*!< Storbe program time value to fill in the TIMING register. */
  52. uint32_t strobe_read; /*!< Storbe read time value to fill in the TIMING register. */
  53. } ocotp_timing_t;
  54. #endif /* FSL_FEATURE_OCOTP_HAS_TIMING_CTRL */
  55. /*******************************************************************************
  56. * API
  57. *******************************************************************************/
  58. #if defined(__cplusplus)
  59. extern "C" {
  60. #endif
  61. /*!
  62. * @brief Initializes OCOTP controller.
  63. *
  64. * @param base OCOTP peripheral base address.
  65. * @param srcClock_Hz source clock frequency in unit of Hz. When the macro
  66. * FSL_FEATURE_OCOTP_HAS_TIMING_CTRL is defined as 0, this parameter is not used,
  67. * application could pass in 0 in this case.
  68. */
  69. void OCOTP_Init(OCOTP_Type *base, uint32_t srcClock_Hz);
  70. /*!
  71. * @brief De-initializes OCOTP controller.
  72. *
  73. * @retval kStatus_Success upon successful execution, error status otherwise.
  74. */
  75. void OCOTP_Deinit(OCOTP_Type *base);
  76. /*!
  77. * @brief Checking the BUSY bit in CTRL register.
  78. * Checking this BUSY bit will help confirm if the OCOTP controller is ready for access.
  79. *
  80. * @param base OCOTP peripheral base address.
  81. * @retval true for bit set and false for cleared.
  82. */
  83. static inline bool OCOTP_CheckBusyStatus(OCOTP_Type *base)
  84. {
  85. return ((OCOTP_CTRL_BUSY_MASK == (base->CTRL & OCOTP_CTRL_BUSY_MASK)) ? (true) : (false));
  86. }
  87. /*!
  88. * @brief Checking the ERROR bit in CTRL register.
  89. *
  90. * @param base OCOTP peripheral base address.
  91. * @retval true for bit set and false for cleared.
  92. */
  93. static inline bool OCOTP_CheckErrorStatus(OCOTP_Type *base)
  94. {
  95. return ((OCOTP_CTRL_ERROR_MASK == (base->CTRL & OCOTP_CTRL_ERROR_MASK)) ? (true) : (false));
  96. }
  97. /*!
  98. * @brief Clear the error bit if this bit is set.
  99. *
  100. * @param base OCOTP peripheral base address.
  101. */
  102. static inline void OCOTP_ClearErrorStatus(OCOTP_Type *base)
  103. {
  104. base->CTRL_CLR = OCOTP_CTRL_CLR_ERROR_MASK;
  105. }
  106. /*!
  107. * @brief Reload the shadow register.
  108. * This function will help reload the shadow register without reseting the OCOTP module.
  109. * Please make sure the OCOTP has been initialized before calling this API.
  110. *
  111. * @param base OCOTP peripheral base addess.
  112. * @retval kStatus_Success Reload success.
  113. * @retval kStatus_OCOTP_ReloadError Reload failed.
  114. */
  115. status_t OCOTP_ReloadShadowRegister(OCOTP_Type *base);
  116. /*!
  117. * @brief Read the fuse shadow register with the fuse addess.
  118. *
  119. * @deprecated Use @ref OCOTP_ReadFuseShadowRegisterExt instead of this function.
  120. *
  121. * @param base OCOTP peripheral base address.
  122. * @param address the fuse address to be read from.
  123. * @return The read out data.
  124. */
  125. uint32_t OCOTP_ReadFuseShadowRegister(OCOTP_Type *base, uint32_t address);
  126. /*!
  127. * @brief Read the fuse shadow register from the fuse addess.
  128. *
  129. * This function reads fuse from @p address, how many words to read is specified
  130. * by the parameter @p fuseWords. This function could read at most
  131. * OCOTP_READ_FUSE_DATA_COUNT fuse word one time.
  132. *
  133. * @param base OCOTP peripheral base address.
  134. * @param address the fuse address to be read from.
  135. * @param data Data array to save the readout fuse value.
  136. * @param fuseWords How many words to read.
  137. * @retval kStatus_Success Read success.
  138. * @retval kStatus_Fail Error occurs during read.
  139. */
  140. status_t OCOTP_ReadFuseShadowRegisterExt(OCOTP_Type *base, uint32_t address, uint32_t *data, uint8_t fuseWords);
  141. /*!
  142. * @brief Write the fuse shadow register with the fuse addess and data.
  143. * Please make sure the wrtie address is not locked while calling this API.
  144. *
  145. * @param base OCOTP peripheral base address.
  146. * @param address the fuse address to be written.
  147. * @param data the value will be writen to fuse address.
  148. * @retval write status, kStatus_Success for success and kStatus_Fail for failed.
  149. */
  150. status_t OCOTP_WriteFuseShadowRegister(OCOTP_Type *base, uint32_t address, uint32_t data);
  151. /*!
  152. * @brief Write the fuse shadow register and lock it.
  153. *
  154. * Please make sure the wrtie address is not locked while calling this API.
  155. *
  156. * Some OCOTP controller supports ECC mode and redundancy mode (see reference mananual
  157. * for more details). OCOTP controller will auto select ECC or redundancy
  158. * mode to program the fuse word according to fuse map definition. In ECC mode, the
  159. * 32 fuse bits in one word can only be written once. In redundancy mode, the word can
  160. * be written more than once as long as they are different fuse bits. Set parameter
  161. * @p lock as true to force use ECC mode.
  162. *
  163. * @param base OCOTP peripheral base address.
  164. * @param address The fuse address to be written.
  165. * @param data The value will be writen to fuse address.
  166. * @param lock Lock or unlock write fuse shadow register operation.
  167. * @retval kStatus_Success Program and reload success.
  168. * @retval kStatus_OCOTP_Locked The eFuse word is locked and cannot be programmed.
  169. * @retval kStatus_OCOTP_ProgramFail eFuse word programming failed.
  170. * @retval kStatus_OCOTP_ReloadError eFuse word programming success, but
  171. * error happens during reload the values.
  172. * @retval kStatus_OCOTP_AccessError Cannot access eFuse word.
  173. */
  174. status_t OCOTP_WriteFuseShadowRegisterWithLock(OCOTP_Type *base, uint32_t address, uint32_t data, bool lock);
  175. /*!
  176. * @brief Get the OCOTP controller version from the register.
  177. *
  178. * @param base OCOTP peripheral base address.
  179. * @retval return the version value.
  180. */
  181. static inline uint32_t OCOTP_GetVersion(OCOTP_Type *base)
  182. {
  183. return (base->VERSION);
  184. }
  185. #if defined(__cplusplus)
  186. }
  187. #endif
  188. /*! @}*/
  189. #endif /* _FSL_OCOTP_H_ */