Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:02

0001 /*
0002  * Copyright 2019-2020 NXP
0003  * All rights reserved.
0004  *
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 
0009 #ifndef _FSL_XECC_H_
0010 #define _FSL_XECC_H_
0011 
0012 #include "fsl_common.h"
0013 
0014 /*!
0015  * @addtogroup xecc
0016  * @{
0017  */
0018 
0019 /******************************************************************************
0020  * Definitions.
0021  *****************************************************************************/
0022 
0023 /*! @name Driver version */
0024 /*@{*/
0025 /*! @brief Driver version 2.0.0. */
0026 #define FSL_XECC_DRIVER_VERSION (MAKE_VERSION(2U, 0U, 0U))
0027 /*@}*/
0028 
0029 /*!
0030  * @brief XECC interrupt configuration structure, , xecc_interrupt_enable_t.
0031  *
0032  * This structure contains the settings for all of the XECC interrupt configurations.
0033  */
0034 enum
0035 {
0036     kXECC_SingleErrorInterruptEnable = XECC_ERR_SIG_EN_SINGLE_ERR_SIG_EN_MASK, /*!< Single bit error interrupt enable*/
0037     kXECC_MultiErrorInterruptEnable  = XECC_ERR_SIG_EN_MULTI_ERR_SIG_EN_MASK, /*!< Multiple bit error interrupt enable*/
0038 
0039     kXECC_AllInterruptsEnable =
0040         XECC_ERR_SIG_EN_SINGLE_ERR_SIG_EN_MASK | XECC_ERR_SIG_EN_MULTI_ERR_SIG_EN_MASK, /*!< all interrupts enable */
0041 };
0042 
0043 /*!
0044  * @brief XECC interrupt status configuration structure, xecc_interrupt_status_enable_t.
0045  *
0046  * This structure contains the settings for all of the XECC interrupt status configurations.
0047  */
0048 enum
0049 {
0050     kXECC_SingleErrorInterruptStatusEnable =
0051         XECC_ERR_STAT_EN_SINGLE_ERR_STAT_EN_MASK, /*!< Single bit error interrupt status enable*/
0052     kXECC_MultiErrorInterruptStatusEnable =
0053         XECC_ERR_STAT_EN_MULIT_ERR_STAT_EN_MASK, /*!< Multiple bits error interrupt status enable*/
0054 
0055     kXECC_AllInterruptsStatusEnable = XECC_ERR_STAT_EN_SINGLE_ERR_STAT_EN_MASK |
0056                                       XECC_ERR_STAT_EN_MULIT_ERR_STAT_EN_MASK, /*!< all interrupts enable */
0057 };
0058 
0059 /*!
0060  * @brief XECC status flags, xecc_interrupt_status_t.
0061  *
0062  * This provides constants for the XECC status flags for use in the XECC functions.
0063  */
0064 enum
0065 {
0066     kXECC_SingleErrorInterruptFlag =
0067         XECC_ERR_STATUS_SINGLE_ERR_MASK, /*!< Single bit error interrupt happens on read data*/
0068     kXECC_MultiErrorInterruptFlag =
0069         XECC_ERR_STATUS_MULTI_ERR_MASK, /*!< Multiple bits error interrupt happens on read data*/
0070 
0071     kXECC_AllInterruptsFlag =
0072         XECC_ERR_STATUS_SINGLE_ERR_MASK | XECC_ERR_STATUS_MULTI_ERR_MASK, /*!< all interrupts happens on read data*/
0073 };
0074 
0075 /*! @brief XECC user configuration.*/
0076 typedef struct _xecc_config
0077 {
0078     bool enableXECC;     /*!< Enable the XECC function. */
0079     bool enableWriteECC; /*!< Enable write ECC function. */
0080     bool enableReadECC;  /*!< Enable read ECC function. */
0081     bool enableSwap;     /*!< Enable swap function. */
0082 
0083     /*!< The minimum ECC region range is 4k, so the lower 12 bits of this register must be 0.*/
0084     uint32_t Region0BaseAddress; /*!< ECC region 0 base address. */
0085     uint32_t Region0EndAddress;  /*!< ECC region 0 end address. */
0086     uint32_t Region1BaseAddress; /*!< ECC region 1 base address. */
0087     uint32_t Region1EndAddress;  /*!< ECC region 1 end address. */
0088     uint32_t Region2BaseAddress; /*!< ECC region 2 base address. */
0089     uint32_t Region2EndAddress;  /*!< ECC region 2 end address. */
0090     uint32_t Region3BaseAddress; /*!< ECC region 3 base address. */
0091     uint32_t Region3EndAddress;  /*!< ECC region 3 end address. */
0092 } xecc_config_t;
0093 
0094 /*! @brief XECC single error information, including single error address, ECC code, error data, error bit
0095  * position and error bit field */
0096 typedef struct _xecc_single_error_info
0097 {
0098     uint32_t singleErrorAddress;  /*!< Single error address */
0099     uint32_t singleErrorData;     /*!< Single error read data */
0100     uint32_t singleErrorEccCode;  /*!< Single error ECC code */
0101     uint32_t singleErrorBitPos;   /*!< Single error bit postion */
0102     uint32_t singleErrorBitField; /*!< Single error bit field */
0103 } xecc_single_error_info_t;
0104 
0105 /*! @brief XECC multiple error information, including multiple error address, ECC code, error data and error bit field
0106  */
0107 typedef struct _xecc_multi_error_info
0108 {
0109     uint32_t multiErrorAddress;  /*!< Multiple error address */
0110     uint32_t multiErrorData;     /*!< Multiple error read data */
0111     uint32_t multiErrorEccCode;  /*!< Multiple error ECC code */
0112     uint32_t multiErrorBitField; /*!< Single error bit field */
0113 } xecc_multi_error_info_t;
0114 
0115 /*******************************************************************************
0116  * APIs
0117  ******************************************************************************/
0118 
0119 #if defined(__cplusplus)
0120 extern "C" {
0121 #endif
0122 
0123 /*!
0124  * @name Initialization and deinitialization
0125  * @{
0126  */
0127 
0128 /*!
0129  * @brief XECC module initialization function.
0130  *
0131  * @param base XECC base address.
0132  * @param config pointer to the XECC configuration structure.
0133  */
0134 void XECC_Init(XECC_Type *base, const xecc_config_t *config);
0135 
0136 /*!
0137  * @brief Deinitializes the XECC.
0138  *
0139  * @param base XECC base address.
0140  */
0141 void XECC_Deinit(XECC_Type *base);
0142 
0143 /*!
0144  * @brief Sets the XECC configuration structure to default values.
0145  *
0146  * @param config pointer to the XECC configuration structure.
0147  */
0148 void XECC_GetDefaultConfig(xecc_config_t *config);
0149 
0150 /* @} */
0151 
0152 /*!
0153  * @name Status
0154  * @{
0155  */
0156 /*!
0157  * @brief Gets XECC status flags.
0158  *
0159  * @param base XECC peripheral base address.
0160  * @return XECC status flags.
0161  */
0162 static inline uint32_t XECC_GetStatusFlags(XECC_Type *base)
0163 {
0164     return base->ERR_STATUS & (uint32_t)kXECC_AllInterruptsFlag;
0165 }
0166 
0167 /*!
0168  * @brief XECC module clear interrupt status.
0169  *
0170  * @param base XECC base address.
0171  * @param mask status to clear from xecc_interrupt_status_t.
0172  */
0173 static inline void XECC_ClearStatusFlags(XECC_Type *base, uint32_t mask)
0174 {
0175     base->ERR_STATUS = mask;
0176 }
0177 
0178 /*!
0179  * @brief XECC module enable interrupt status.
0180  *
0181  * @param base XECC base address.
0182  * @param mask status to enable from xecc_interrupt_status_enable_t.
0183  */
0184 static inline void XECC_EnableInterruptStatus(XECC_Type *base, uint32_t mask)
0185 {
0186     base->ERR_STAT_EN |= mask;
0187 }
0188 
0189 /*!
0190  * @brief XECC module disable interrupt status.
0191  *
0192  * @param base XECC base address.
0193  * @param mask status to disable from xecc_interrupt_status_enable_t.
0194  */
0195 static inline void XECC_DisableInterruptStatus(XECC_Type *base, uint32_t mask)
0196 {
0197     base->ERR_STAT_EN &= ~mask;
0198 }
0199 
0200 /* @} */
0201 
0202 /*!
0203  * @name Interrupts
0204  * @{
0205  */
0206 
0207 /*!
0208  * @brief XECC module enable interrupt.
0209  *
0210  * @param base XECC base address.
0211  * @param mask The interrupts to enable from xecc_interrupt_enable_t.
0212  */
0213 static inline void XECC_EnableInterrupts(XECC_Type *base, uint32_t mask)
0214 {
0215     base->ERR_SIG_EN |= mask;
0216 }
0217 
0218 /*!
0219  * @brief XECC module disable interrupt.
0220  *
0221  * @param base XECC base address.
0222  * @param mask The interrupts to disable from xecc_interrupt_enable_t.
0223  */
0224 static inline void XECC_DisableInterrupts(XECC_Type *base, uint32_t mask)
0225 {
0226     base->ERR_SIG_EN &= ~mask;
0227 }
0228 /* @} */
0229 
0230 /*!
0231  * @name functional
0232  * @{
0233  */
0234 /*!
0235  * @brief XECC module write ECC function enable.
0236  *
0237  * @param base XECC base address.
0238  * @param enable enable or disable.
0239  */
0240 static inline void XECC_WriteECCEnable(XECC_Type *base, bool enable)
0241 {
0242     if (enable)
0243     {
0244         base->ECC_CTRL |= XECC_ECC_CTRL_WECC_EN(1);
0245     }
0246     else
0247     {
0248         base->ECC_CTRL |= XECC_ECC_CTRL_WECC_EN(0);
0249     }
0250 }
0251 
0252 /*!
0253  * @brief XECC module read ECC function enable.
0254  *
0255  * @param base XECC base address.
0256  * @param enable enable or disable.
0257  */
0258 static inline void XECC_ReadECCEnable(XECC_Type *base, bool enable)
0259 {
0260     if (enable)
0261     {
0262         base->ECC_CTRL |= XECC_ECC_CTRL_RECC_EN(1);
0263     }
0264     else
0265     {
0266         base->ECC_CTRL |= XECC_ECC_CTRL_RECC_EN(0);
0267     }
0268 }
0269 
0270 /*!
0271  * @brief XECC module swap data enable.
0272  *
0273  * @param base XECC base address.
0274  * @param enable enable or disable.
0275  */
0276 static inline void XECC_SwapECCEnable(XECC_Type *base, bool enable)
0277 {
0278     if (enable)
0279     {
0280         base->ECC_CTRL |= XECC_ECC_CTRL_SWAP_EN(1);
0281     }
0282     else
0283     {
0284         base->ECC_CTRL |= XECC_ECC_CTRL_SWAP_EN(0);
0285     }
0286 }
0287 
0288 /*!
0289  * @brief XECC module error injection.
0290  *
0291  * @param base XECC base address.
0292  * @param errordata error data.
0293  * @param erroreccdata ecc code.
0294  * @retval kStatus_Success.
0295  */
0296 status_t XECC_ErrorInjection(XECC_Type *base, uint32_t errordata, uint8_t erroreccdata);
0297 
0298 /*!
0299  * @brief XECC module get single error information.
0300  *
0301  * @param base XECC base address.
0302  * @param info single error information.
0303  */
0304 void XECC_GetSingleErrorInfo(XECC_Type *base, xecc_single_error_info_t *info);
0305 
0306 /*!
0307  * @brief XECC module get multiple error information.
0308  *
0309  * @param base XECC base address.
0310  * @param info multiple error information.
0311  */
0312 void XECC_GetMultiErrorInfo(XECC_Type *base, xecc_multi_error_info_t *info);
0313 
0314 /*! @}*/
0315 
0316 #if defined(__cplusplus)
0317 }
0318 #endif
0319 
0320 /*! @}*/
0321 
0322 #endif