fsl_mecc.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * Copyright 2019-2021 NXP
  3. * All rights reserved.
  4. *
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_MECC_H_
  9. #define _FSL_MECC_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup mecc
  13. * @{
  14. */
  15. /******************************************************************************
  16. * Definitions.
  17. *****************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief Driver version 2.0.2. */
  21. #define FSL_MECC_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 2U))
  22. /*@}*/
  23. /*! @brief Error codes for the MECC driver. */
  24. enum
  25. {
  26. kStatus_MECC_BankMiss = MAKE_STATUS(kStatusGroup_MECC, 0), /*!< Ocram bank miss */
  27. };
  28. /*!
  29. * @brief MECC interrupt configuration structure, default settings all disabled.
  30. *
  31. * This structure contains the settings for all of the MECC interrupt configurations.
  32. */
  33. enum
  34. {
  35. kMECC_SingleError0InterruptEnable =
  36. MECC_ERR_SIG_EN_SINGLE_ERR0_SIG_EN_MASK, /*!< Single Bit Error On Ocram Bank0 interrupt enable.*/
  37. kMECC_SingleError1InterruptEnable =
  38. MECC_ERR_SIG_EN_SINGLE_ERR1_SIG_EN_MASK, /*!< Single Bit Error On Ocram Bank1 interrupt enable*/
  39. kMECC_SingleError2InterruptEnable =
  40. MECC_ERR_SIG_EN_SINGLE_ERR2_SIG_EN_MASK, /*!< Single Bit Error On Ocram Bank2 interrupt enable*/
  41. kMECC_SingleError3InterruptEnable =
  42. MECC_ERR_SIG_EN_SINGLE_ERR3_SIG_EN_MASK, /*!< Single Bit Error On Ocram Bank3 interrupt enable*/
  43. kMECC_MultiError0InterruptEnable =
  44. MECC_ERR_SIG_EN_MULTI_ERR0_SIG_EN_MASK, /*!< Multiple Bits Error On Ocram Bank0 interrupt enable*/
  45. kMECC_MultiError1InterruptEnable =
  46. MECC_ERR_SIG_EN_MULTI_ERR1_SIG_EN_MASK, /*!< Multiple Bits Error On Ocram Bank1 interrupt enable*/
  47. kMECC_MultiError2InterruptEnable =
  48. MECC_ERR_SIG_EN_MULTI_ERR2_SIG_EN_MASK, /*!< Multiple Bits Error On Ocram Bank2 interrupt enable*/
  49. kMECC_MultiError3InterruptEnable =
  50. MECC_ERR_SIG_EN_MULTI_ERR3_SIG_EN_MASK, /*!< Multiple Bits Error On Ocram Bank3 interrupt enable*/
  51. kMECC_StrobeError0InterruptEnable =
  52. MECC_ERR_SIG_EN_STRB_ERR0_SIG_EN_MASK, /*!< AXI Strobe Error On Ocram Bank0 interrupt enable*/
  53. kMECC_StrobeError1InterruptEnable =
  54. MECC_ERR_SIG_EN_STRB_ERR1_SIG_EN_MASK, /*!< AXI Strobe Error On Ocram Bank1 interrupt enable*/
  55. kMECC_StrobeError2InterruptEnable =
  56. MECC_ERR_SIG_EN_STRB_ERR2_SIG_EN_MASK, /*!< AXI Strobe Error On Ocram Bank2 interrupt enable*/
  57. kMECC_StrobeError3InterruptEnable =
  58. MECC_ERR_SIG_EN_STRB_ERR3_SIG_EN_MASK, /*!< AXI Strobe Error On Ocram Bank3 interrupt enable*/
  59. kMECC_AccessError0InterruptEnable =
  60. MECC_ERR_SIG_EN_ADDR_ERR0_SIG_EN_MASK, /*!< Ocram Access Error On Bank0 interrupt enable*/
  61. kMECC_AccessError1InterruptEnable =
  62. MECC_ERR_SIG_EN_ADDR_ERR1_SIG_EN_MASK, /*!< Ocram Access Error On Bank1 interrupt enable*/
  63. kMECC_AccessError2InterruptEnable =
  64. MECC_ERR_SIG_EN_ADDR_ERR2_SIG_EN_MASK, /*!< Ocram Access Error On Bank2 interrupt enable*/
  65. kMECC_AccessError3InterruptEnable =
  66. MECC_ERR_SIG_EN_ADDR_ERR3_SIG_EN_MASK, /*!< Ocram Access Error On Bank3 interrupt enable*/
  67. kMECC_AllInterruptsEnable = 0xFFFF, /*!< all interrupts enable */
  68. };
  69. /*!
  70. * @brief MECC interrupt status configuration structure, default settings all disabled.
  71. *
  72. * This structure contains the settings for all of the MECC interrupt status configurations.
  73. */
  74. enum
  75. {
  76. kMECC_SingleError0InterruptStatusEnable =
  77. MECC_ERR_STAT_EN_SINGLE_ERR0_STAT_EN_MASK, /*!< Single Bit Error On Ocram Bank0 interrupt status enable.*/
  78. kMECC_SingleError1InterruptStatusEnable =
  79. MECC_ERR_STAT_EN_SINGLE_ERR1_STAT_EN_MASK, /*!< Single Bit Error On Ocram Bank1 interrupt status enable*/
  80. kMECC_SingleError2InterruptStatusEnable =
  81. MECC_ERR_STAT_EN_SINGLE_ERR2_STAT_EN_MASK, /*!< Single Bit Error On Ocram Bank2 interrupt status enable*/
  82. kMECC_SingleError3InterruptStatusEnable =
  83. MECC_ERR_STAT_EN_SINGLE_ERR3_STAT_EN_MASK, /*!< Single Bit Error On Ocram Bank3 interrupt status enable*/
  84. kMECC_MultiError0InterruptStatusEnable =
  85. MECC_ERR_STAT_EN_MULTI_ERR0_STAT_EN_MASK, /*!< Multiple Bits Error On Ocram Bank0 interrupt status enable*/
  86. kMECC_MultiError1InterruptStatusEnable =
  87. MECC_ERR_STAT_EN_MULTI_ERR1_STAT_EN_MASK, /*!< Multiple Bits Error On Ocram Bank1 interrupt status enable*/
  88. kMECC_MultiError2InterruptStatusEnable =
  89. MECC_ERR_STAT_EN_MULTI_ERR2_STAT_EN_MASK, /*!< Multiple Bits Error On Ocram Bank2 interrupt status enable*/
  90. kMECC_MultiError3InterruptStatusEnable =
  91. MECC_ERR_STAT_EN_MULTI_ERR3_STAT_EN_MASK, /*!< Multiple Bits Error On Ocram Bank3 interrupt status enable*/
  92. kMECC_StrobeError0InterruptStatusEnable =
  93. MECC_ERR_STAT_EN_STRB_ERR0_STAT_EN_MASK, /*!< AXI Strobe Error On Ocram Bank0 interrupt status enable*/
  94. kMECC_StrobeError1InterruptStatusEnable =
  95. MECC_ERR_STAT_EN_STRB_ERR1_STAT_EN_MASK, /*!< AXI Strobe Error On Ocram Bank1 interrupt status enable*/
  96. kMECC_StrobeError2InterruptStatusEnable =
  97. MECC_ERR_STAT_EN_STRB_ERR2_STAT_EN_MASK, /*!< AXI Strobe Error On Ocram Bank2 interrupt status enable*/
  98. kMECC_StrobeError3InterruptStatusEnable =
  99. MECC_ERR_STAT_EN_STRB_ERR3_STAT_EN_MASK, /*!< AXI Strobe Error On Ocram Bank3 interrupt status enable*/
  100. kMECC_AccessError0InterruptStatusEnable =
  101. MECC_ERR_STAT_EN_ADDR_ERR0_STAT_EN_MASK, /*!< Ocram Access Error On Bank0 interrupt status enable*/
  102. kMECC_AccessError1InterruptStatusEnable =
  103. MECC_ERR_STAT_EN_ADDR_ERR1_STAT_EN_MASK, /*!< Ocram Access Error On Bank1 interrupt status enable*/
  104. kMECC_AccessError2InterruptStatusEnable =
  105. MECC_ERR_STAT_EN_ADDR_ERR2_STAT_EN_MASK, /*!< Ocram Access Error On Bank2 interrupt status enable*/
  106. kMECC_AccessError3InterruptStatusEnable =
  107. MECC_ERR_STAT_EN_ADDR_ERR3_STAT_EN_MASK, /*!< Ocram Access Error On Bank3 interrupt status enable*/
  108. kMECC_AllInterruptsStatusEnable = 0xFFFF, /*!< all interrupts enable */
  109. };
  110. /*!
  111. * @brief MECC status flags.
  112. *
  113. * This provides constants for the MECC status flags for use in the MECC functions.
  114. */
  115. enum
  116. {
  117. kMECC_SingleError0InterruptFlag =
  118. MECC_ERR_STATUS_SINGLE_ERR0_MASK, /*!< Single Bit Error On Ocram Bank0 interrupt flag*/
  119. kMECC_SingleError1InterruptFlag =
  120. MECC_ERR_STATUS_SINGLE_ERR1_MASK, /*!< Single Bit Error On Ocram Bank1 interrupt flag*/
  121. kMECC_SingleError2InterruptFlag =
  122. MECC_ERR_STATUS_SINGLE_ERR2_MASK, /*!< Single Bit Error On Ocram Bank2 interrupt flag*/
  123. kMECC_SingleError3InterruptFlag =
  124. MECC_ERR_STATUS_SINGLE_ERR3_MASK, /*!< Single Bit Error On Ocram Bank3 interrupt flag*/
  125. kMECC_MultiError0InterruptFlag =
  126. MECC_ERR_STATUS_MULTI_ERR0_MASK, /*!< Multiple Bits Error On Ocram Bank0 interrupt flag*/
  127. kMECC_MultiError1InterruptFlag =
  128. MECC_ERR_STATUS_MULTI_ERR1_MASK, /*!< Multiple Bits Error On Ocram Bank1 interrupt flag*/
  129. kMECC_MultiError2InterruptFlag =
  130. MECC_ERR_STATUS_MULTI_ERR2_MASK, /*!< Multiple Bits Error On Ocram Bank2 interrupt flag*/
  131. kMECC_MultiError3InterruptFlag =
  132. MECC_ERR_STATUS_MULTI_ERR3_MASK, /*!< Multiple Bits Error On Ocram Bank3 interrupt flag*/
  133. kMECC_StrobeError0InterruptFlag =
  134. MECC_ERR_STATUS_STRB_ERR0_MASK, /*!< AXI Strobe Error On Ocram Bank0 interrupt flag*/
  135. kMECC_StrobeError1InterruptFlag =
  136. MECC_ERR_STATUS_STRB_ERR1_MASK, /*!< AXI Strobe Error On Ocram Bank1 interrupt flag*/
  137. kMECC_StrobeError2InterruptFlag =
  138. MECC_ERR_STATUS_STRB_ERR2_MASK, /*!< AXI Strobe Error On Ocram Bank2 interrupt flag*/
  139. kMECC_StrobeError3InterruptFlag =
  140. MECC_ERR_STATUS_STRB_ERR3_MASK, /*!< AXI Strobe Error On Ocram Bank3 interrupt flag*/
  141. kMECC_AccessError0InterruptFlag = MECC_ERR_STATUS_ADDR_ERR0_MASK, /*!< Ocram Access Error On Bank0 interrupt flag*/
  142. kMECC_AccessError1InterruptFlag = MECC_ERR_STATUS_ADDR_ERR1_MASK, /*!< Ocram Access Error On Bank1 interrupt flag*/
  143. kMECC_AccessError2InterruptFlag = MECC_ERR_STATUS_ADDR_ERR2_MASK, /*!< Ocram Access Error On Bank2 interrupt flag*/
  144. kMECC_AccessError3InterruptFlag = MECC_ERR_STATUS_ADDR_ERR3_MASK, /*!< Ocram Access Error On Bank3 interrupt flag*/
  145. kMECC_AllInterruptsFlag = 0xFFFF, /*!< all interrupts interrupt flag */
  146. };
  147. /*! @brief MECC ocram bank number */
  148. enum
  149. {
  150. kMECC_OcramBank0 = 0U, /*!< ocram bank number 0: ocram_base_address+0x20*i */
  151. kMECC_OcramBank1 = 1U, /*!< ocram bank number 1: ocram_base_address+0x20*i+0x8 */
  152. kMECC_OcramBank2 = 2U, /*!< ocram bank number 2: ocram_base_address+0x20*i+0x10 */
  153. kMECC_OcramBank3 = 3U, /*!< ocram bank number 3: ocram_base_address+0x20*i+0x18 */
  154. };
  155. /*! @brief MECC instance */
  156. enum
  157. {
  158. kMECC_Instance0 = 0U, /*!< Peripheral MECC1 base */
  159. kMECC_Instance1 = 1U, /*!< Peripheral MECC2 base */
  160. };
  161. /*! @brief MECC user configuration.*/
  162. typedef struct _mecc_config
  163. {
  164. bool enableMecc; /*!< Enable the MECC function. */
  165. uint32_t Ocram1StartAddress; /*!< Ocram 1 start address. */
  166. uint32_t Ocram1EndAddress; /*!< Ocram 1 end address. */
  167. uint32_t Ocram2StartAddress; /*!< Ocram 2 start address. */
  168. uint32_t Ocram2EndAddress; /*!< Ocram 2 end address. */
  169. } mecc_config_t;
  170. /*! @brief MECC ocram single error information, including single error address, ECC code, error data and error bit
  171. * position */
  172. typedef struct _mecc_single_error_info
  173. {
  174. uint32_t singleErrorAddress; /*!< Single error address on Ocram bank n */
  175. uint32_t singleErrorDataLow; /*!< Single error low 32 bits uncorrected read data on Ocram bank n */
  176. uint32_t singleErrorDataHigh; /*!< Single error high 32 bits uncorrected read data on Ocram bank n */
  177. uint32_t singleErrorPosLow; /*!< Single error bit postion of low 32 bits read data on Ocram bank n */
  178. uint32_t singleErrorPosHigh; /*!< Single error bit postion of high 32 bits read data on Ocram bank n */
  179. uint8_t singleErrorEccCode; /*!< Single error ECC code on Ocram bank n */
  180. } mecc_single_error_info_t;
  181. /*! @brief MECC ocram multiple error information, including multiple error address, ECC code, error data */
  182. typedef struct _mecc_multi_error_info
  183. {
  184. uint32_t multiErrorAddress; /*!< Multiple error address on Ocram bank n */
  185. uint32_t multiErrorDataLow; /*!< Multiple error low 32 bits read data on Ocram bank n */
  186. uint32_t multiErrorDataHigh; /*!< Multiple error high 32 bits read data on Ocram bank n */
  187. uint8_t multiErrorEccCode; /*!< Multiple error ECC code on Ocram bank n */
  188. } mecc_multi_error_info_t;
  189. /*******************************************************************************
  190. * APIs
  191. ******************************************************************************/
  192. #if defined(__cplusplus)
  193. extern "C" {
  194. #endif
  195. /*!
  196. * @name Initialization and deinitialization
  197. * @{
  198. */
  199. /*!
  200. * @brief MECC module initialization function.
  201. *
  202. * @param base MECC base address.
  203. * @param config pointer to the MECC configuration structure.
  204. */
  205. void MECC_Init(MECC_Type *base, mecc_config_t *config);
  206. /*!
  207. * @brief Deinitializes the MECC.
  208. *
  209. * @param base MECC base address.
  210. */
  211. void MECC_Deinit(MECC_Type *base);
  212. /*!
  213. * @brief Sets the MECC configuration structure to default values.
  214. *
  215. * @param config pointer to the MECC configuration structure.
  216. */
  217. void MECC_GetDefaultConfig(mecc_config_t *config);
  218. /* @} */
  219. /*!
  220. * @name Status
  221. * @{
  222. */
  223. /*!
  224. * @brief Gets MECC status flags.
  225. *
  226. * @param base MECC peripheral base address.
  227. * @return MECC status flags.
  228. */
  229. static inline uint32_t MECC_GetStatusFlags(MECC_Type *base)
  230. {
  231. return base->ERR_STATUS & (uint32_t)kMECC_AllInterruptsFlag;
  232. }
  233. /*!
  234. * @brief MECC module clear interrupt status.
  235. *
  236. * @param base MECC base address.
  237. * @param mask status to clear.
  238. */
  239. static inline void MECC_ClearStatusFlags(MECC_Type *base, uint32_t mask)
  240. {
  241. base->ERR_STATUS = mask;
  242. }
  243. /*!
  244. * @brief MECC module enable interrupt status.
  245. *
  246. * @param base MECC base address.
  247. * @param mask status to enable.
  248. */
  249. static inline void MECC_EnableInterruptStatus(MECC_Type *base, uint32_t mask)
  250. {
  251. base->ERR_STAT_EN |= mask;
  252. }
  253. /*!
  254. * @brief MECC module disable interrupt status.
  255. *
  256. * @param base MECC base address.
  257. * @param mask status to disable.
  258. */
  259. static inline void MECC_DisableInterruptStatus(MECC_Type *base, uint32_t mask)
  260. {
  261. base->ERR_STAT_EN &= ~mask;
  262. }
  263. /* @} */
  264. /*!
  265. * @name Interrupts
  266. * @{
  267. */
  268. /*!
  269. * @brief MECC module enable interrupt.
  270. *
  271. * @param base MECC base address.
  272. * @param mask The interrupts to enable.
  273. */
  274. static inline void MECC_EnableInterrupts(MECC_Type *base, uint32_t mask)
  275. {
  276. base->ERR_SIG_EN |= mask;
  277. }
  278. /*!
  279. * @brief MECC module disable interrupt.
  280. *
  281. * @param base MECC base address.
  282. * @param mask The interrupts to disable.
  283. */
  284. static inline void MECC_DisableInterrupts(MECC_Type *base, uint32_t mask)
  285. {
  286. base->ERR_SIG_EN &= ~mask;
  287. }
  288. /* @} */
  289. /*!
  290. * @name functional
  291. * @{
  292. */
  293. /*!
  294. * @brief MECC module error injection.
  295. *
  296. * @param base MECC base address.
  297. * @param lowerrordata low 32 bits data.
  298. * @param higherrordata high 32 bits data.
  299. * @param eccdata ecc code.
  300. * @param banknumber ocram bank number.
  301. * @retval kStatus_Success.
  302. *
  303. * Bank0: ocram_base_address+0x20*i
  304. * Bank1: ocram_base_address+0x20*i+0x8
  305. * Bank2: ocram_base_address+0x20*i+0x10
  306. * Bank3: ocram_base_address+0x20*i+0x18
  307. * i = 0,1,2,3,4.....
  308. */
  309. status_t MECC_ErrorInjection(
  310. MECC_Type *base, uint32_t lowerrordata, uint32_t higherrordata, uint8_t eccdata, uint8_t banknumber);
  311. /*!
  312. * @brief MECC module get single error information.
  313. *
  314. * @param base MECC base address.
  315. * @param info single error information.
  316. * @param banknumber ocram bank number.
  317. * @retval kStatus_Success.
  318. * @retval kStatus_MECC_BankMiss.
  319. *
  320. * Bank0: ocram_base_address+0x20*i
  321. * Bank1: ocram_base_address+0x20*i+0x8
  322. * Bank2: ocram_base_address+0x20*i+0x10
  323. * Bank3: ocram_base_address+0x20*i+0x18
  324. * i = 0,1,2,3,4.....
  325. */
  326. status_t MECC_GetSingleErrorInfo(MECC_Type *base, mecc_single_error_info_t *info, uint8_t banknumber);
  327. /*!
  328. * @brief MECC module get multiple error information.
  329. *
  330. * @param base MECC base address.
  331. * @param info multiple error information.
  332. * @param banknumber ocram bank number.
  333. * @retval kStatus_Success.
  334. * @retval kStatus_MECC_BankMiss.
  335. *
  336. * Bank0: ocram_base_address+0x20*i
  337. * Bank1: ocram_base_address+0x20*i+0x8
  338. * Bank2: ocram_base_address+0x20*i+0x10
  339. * Bank3: ocram_base_address+0x20*i+0x18
  340. * i = 0,1,2,3,4.....
  341. */
  342. status_t MECC_GetMultiErrorInfo(MECC_Type *base, mecc_multi_error_info_t *info, uint8_t banknumber);
  343. /*! @}*/
  344. #if defined(__cplusplus)
  345. }
  346. #endif
  347. /*! @}*/
  348. #endif