fsl_xecc.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /*
  2. * Copyright 2019-2020 NXP
  3. * All rights reserved.
  4. *
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_XECC_H_
  9. #define _FSL_XECC_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup xecc
  13. * @{
  14. */
  15. /******************************************************************************
  16. * Definitions.
  17. *****************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief Driver version 2.0.0. */
  21. #define FSL_XECC_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 0U))
  22. /*@}*/
  23. /*!
  24. * @brief XECC interrupt configuration structure, , xecc_interrupt_enable_t.
  25. *
  26. * This structure contains the settings for all of the XECC interrupt configurations.
  27. */
  28. enum
  29. {
  30. kXECC_SingleErrorInterruptEnable = XECC_ERR_SIG_EN_SINGLE_ERR_SIG_EN_MASK, /*!< Single bit error interrupt enable*/
  31. kXECC_MultiErrorInterruptEnable = XECC_ERR_SIG_EN_MULTI_ERR_SIG_EN_MASK, /*!< Multiple bit error interrupt enable*/
  32. kXECC_AllInterruptsEnable =
  33. XECC_ERR_SIG_EN_SINGLE_ERR_SIG_EN_MASK | XECC_ERR_SIG_EN_MULTI_ERR_SIG_EN_MASK, /*!< all interrupts enable */
  34. };
  35. /*!
  36. * @brief XECC interrupt status configuration structure, xecc_interrupt_status_enable_t.
  37. *
  38. * This structure contains the settings for all of the XECC interrupt status configurations.
  39. */
  40. enum
  41. {
  42. kXECC_SingleErrorInterruptStatusEnable =
  43. XECC_ERR_STAT_EN_SINGLE_ERR_STAT_EN_MASK, /*!< Single bit error interrupt status enable*/
  44. kXECC_MultiErrorInterruptStatusEnable =
  45. XECC_ERR_STAT_EN_MULIT_ERR_STAT_EN_MASK, /*!< Multiple bits error interrupt status enable*/
  46. kXECC_AllInterruptsStatusEnable = XECC_ERR_STAT_EN_SINGLE_ERR_STAT_EN_MASK |
  47. XECC_ERR_STAT_EN_MULIT_ERR_STAT_EN_MASK, /*!< all interrupts enable */
  48. };
  49. /*!
  50. * @brief XECC status flags, xecc_interrupt_status_t.
  51. *
  52. * This provides constants for the XECC status flags for use in the XECC functions.
  53. */
  54. enum
  55. {
  56. kXECC_SingleErrorInterruptFlag =
  57. XECC_ERR_STATUS_SINGLE_ERR_MASK, /*!< Single bit error interrupt happens on read data*/
  58. kXECC_MultiErrorInterruptFlag =
  59. XECC_ERR_STATUS_MULTI_ERR_MASK, /*!< Multiple bits error interrupt happens on read data*/
  60. kXECC_AllInterruptsFlag =
  61. XECC_ERR_STATUS_SINGLE_ERR_MASK | XECC_ERR_STATUS_MULTI_ERR_MASK, /*!< all interrupts happens on read data*/
  62. };
  63. /*! @brief XECC user configuration.*/
  64. typedef struct _xecc_config
  65. {
  66. bool enableXECC; /*!< Enable the XECC function. */
  67. bool enableWriteECC; /*!< Enable write ECC function. */
  68. bool enableReadECC; /*!< Enable read ECC function. */
  69. bool enableSwap; /*!< Enable swap function. */
  70. /*!< The minimum ECC region range is 4k, so the lower 12 bits of this register must be 0.*/
  71. uint32_t Region0BaseAddress; /*!< ECC region 0 base address. */
  72. uint32_t Region0EndAddress; /*!< ECC region 0 end address. */
  73. uint32_t Region1BaseAddress; /*!< ECC region 1 base address. */
  74. uint32_t Region1EndAddress; /*!< ECC region 1 end address. */
  75. uint32_t Region2BaseAddress; /*!< ECC region 2 base address. */
  76. uint32_t Region2EndAddress; /*!< ECC region 2 end address. */
  77. uint32_t Region3BaseAddress; /*!< ECC region 3 base address. */
  78. uint32_t Region3EndAddress; /*!< ECC region 3 end address. */
  79. } xecc_config_t;
  80. /*! @brief XECC single error information, including single error address, ECC code, error data, error bit
  81. * position and error bit field */
  82. typedef struct _xecc_single_error_info
  83. {
  84. uint32_t singleErrorAddress; /*!< Single error address */
  85. uint32_t singleErrorData; /*!< Single error read data */
  86. uint32_t singleErrorEccCode; /*!< Single error ECC code */
  87. uint32_t singleErrorBitPos; /*!< Single error bit postion */
  88. uint32_t singleErrorBitField; /*!< Single error bit field */
  89. } xecc_single_error_info_t;
  90. /*! @brief XECC multiple error information, including multiple error address, ECC code, error data and error bit field
  91. */
  92. typedef struct _xecc_multi_error_info
  93. {
  94. uint32_t multiErrorAddress; /*!< Multiple error address */
  95. uint32_t multiErrorData; /*!< Multiple error read data */
  96. uint32_t multiErrorEccCode; /*!< Multiple error ECC code */
  97. uint32_t multiErrorBitField; /*!< Single error bit field */
  98. } xecc_multi_error_info_t;
  99. /*******************************************************************************
  100. * APIs
  101. ******************************************************************************/
  102. #if defined(__cplusplus)
  103. extern "C" {
  104. #endif
  105. /*!
  106. * @name Initialization and deinitialization
  107. * @{
  108. */
  109. /*!
  110. * @brief XECC module initialization function.
  111. *
  112. * @param base XECC base address.
  113. * @param config pointer to the XECC configuration structure.
  114. */
  115. void XECC_Init(XECC_Type *base, const xecc_config_t *config);
  116. /*!
  117. * @brief Deinitializes the XECC.
  118. *
  119. * @param base XECC base address.
  120. */
  121. void XECC_Deinit(XECC_Type *base);
  122. /*!
  123. * @brief Sets the XECC configuration structure to default values.
  124. *
  125. * @param config pointer to the XECC configuration structure.
  126. */
  127. void XECC_GetDefaultConfig(xecc_config_t *config);
  128. /* @} */
  129. /*!
  130. * @name Status
  131. * @{
  132. */
  133. /*!
  134. * @brief Gets XECC status flags.
  135. *
  136. * @param base XECC peripheral base address.
  137. * @return XECC status flags.
  138. */
  139. static inline uint32_t XECC_GetStatusFlags(XECC_Type *base)
  140. {
  141. return base->ERR_STATUS & (uint32_t)kXECC_AllInterruptsFlag;
  142. }
  143. /*!
  144. * @brief XECC module clear interrupt status.
  145. *
  146. * @param base XECC base address.
  147. * @param mask status to clear from xecc_interrupt_status_t.
  148. */
  149. static inline void XECC_ClearStatusFlags(XECC_Type *base, uint32_t mask)
  150. {
  151. base->ERR_STATUS = mask;
  152. }
  153. /*!
  154. * @brief XECC module enable interrupt status.
  155. *
  156. * @param base XECC base address.
  157. * @param mask status to enable from xecc_interrupt_status_enable_t.
  158. */
  159. static inline void XECC_EnableInterruptStatus(XECC_Type *base, uint32_t mask)
  160. {
  161. base->ERR_STAT_EN |= mask;
  162. }
  163. /*!
  164. * @brief XECC module disable interrupt status.
  165. *
  166. * @param base XECC base address.
  167. * @param mask status to disable from xecc_interrupt_status_enable_t.
  168. */
  169. static inline void XECC_DisableInterruptStatus(XECC_Type *base, uint32_t mask)
  170. {
  171. base->ERR_STAT_EN &= ~mask;
  172. }
  173. /* @} */
  174. /*!
  175. * @name Interrupts
  176. * @{
  177. */
  178. /*!
  179. * @brief XECC module enable interrupt.
  180. *
  181. * @param base XECC base address.
  182. * @param mask The interrupts to enable from xecc_interrupt_enable_t.
  183. */
  184. static inline void XECC_EnableInterrupts(XECC_Type *base, uint32_t mask)
  185. {
  186. base->ERR_SIG_EN |= mask;
  187. }
  188. /*!
  189. * @brief XECC module disable interrupt.
  190. *
  191. * @param base XECC base address.
  192. * @param mask The interrupts to disable from xecc_interrupt_enable_t.
  193. */
  194. static inline void XECC_DisableInterrupts(XECC_Type *base, uint32_t mask)
  195. {
  196. base->ERR_SIG_EN &= ~mask;
  197. }
  198. /* @} */
  199. /*!
  200. * @name functional
  201. * @{
  202. */
  203. /*!
  204. * @brief XECC module write ECC function enable.
  205. *
  206. * @param base XECC base address.
  207. * @param enable enable or disable.
  208. */
  209. static inline void XECC_WriteECCEnable(XECC_Type *base, bool enable)
  210. {
  211. if (enable)
  212. {
  213. base->ECC_CTRL |= XECC_ECC_CTRL_WECC_EN(1);
  214. }
  215. else
  216. {
  217. base->ECC_CTRL |= XECC_ECC_CTRL_WECC_EN(0);
  218. }
  219. }
  220. /*!
  221. * @brief XECC module read ECC function enable.
  222. *
  223. * @param base XECC base address.
  224. * @param enable enable or disable.
  225. */
  226. static inline void XECC_ReadECCEnable(XECC_Type *base, bool enable)
  227. {
  228. if (enable)
  229. {
  230. base->ECC_CTRL |= XECC_ECC_CTRL_RECC_EN(1);
  231. }
  232. else
  233. {
  234. base->ECC_CTRL |= XECC_ECC_CTRL_RECC_EN(0);
  235. }
  236. }
  237. /*!
  238. * @brief XECC module swap data enable.
  239. *
  240. * @param base XECC base address.
  241. * @param enable enable or disable.
  242. */
  243. static inline void XECC_SwapECCEnable(XECC_Type *base, bool enable)
  244. {
  245. if (enable)
  246. {
  247. base->ECC_CTRL |= XECC_ECC_CTRL_SWAP_EN(1);
  248. }
  249. else
  250. {
  251. base->ECC_CTRL |= XECC_ECC_CTRL_SWAP_EN(0);
  252. }
  253. }
  254. /*!
  255. * @brief XECC module error injection.
  256. *
  257. * @param base XECC base address.
  258. * @param errordata error data.
  259. * @param erroreccdata ecc code.
  260. * @retval kStatus_Success.
  261. */
  262. status_t XECC_ErrorInjection(XECC_Type *base, uint32_t errordata, uint8_t erroreccdata);
  263. /*!
  264. * @brief XECC module get single error information.
  265. *
  266. * @param base XECC base address.
  267. * @param info single error information.
  268. */
  269. void XECC_GetSingleErrorInfo(XECC_Type *base, xecc_single_error_info_t *info);
  270. /*!
  271. * @brief XECC module get multiple error information.
  272. *
  273. * @param base XECC base address.
  274. * @param info multiple error information.
  275. */
  276. void XECC_GetMultiErrorInfo(XECC_Type *base, xecc_multi_error_info_t *info);
  277. /*! @}*/
  278. #if defined(__cplusplus)
  279. }
  280. #endif
  281. /*! @}*/
  282. #endif