2 * @brief Cyclic Redundancy Check (CRC) registers and driver functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #ifndef __CRC_001_H_
\r
33 #define __CRC_001_H_
\r
35 #include "sys_config.h"
\r
42 /** @defgroup IP_CRC_001 IP: CRC register block and driver
\r
43 * @ingroup IP_Drivers
\r
48 * @brief CRC register block structure
\r
50 typedef struct { /*!< CRC Structure */
\r
51 __IO uint32_t MODE; /*!< CRC Mode Register */
\r
52 __IO uint32_t SEED; /*!< CRC SEED Register */
\r
54 __I uint32_t SUM; /*!< CRC Checksum Register. */
\r
55 __O uint32_t WRDATA32; /*!< CRC Data Register: write size 32-bit*/
\r
56 __O uint16_t WRDATA16; /*!< CRC Data Register: write size 16-bit*/
\r
57 __O uint8_t WRDATA8; /*!< CRC Data Register: write size 8-bit*/
\r
63 * @brief CRC MODE register description
\r
65 #define CRC_MODE_POLY_BITMASK ((0x03)) /** CRC polynomial Bit mask */
\r
66 #define CRC_MODE_POLY_CCITT (0x00) /** Select CRC-CCITT polynomial */
\r
67 #define CRC_MODE_POLY_CRC16 (0x01) /** Select CRC-16 polynomial */
\r
68 #define CRC_MODE_POLY_CRC32 (0x02) /** Select CRC-32 polynomial */
\r
69 #define CRC_MODE_WRDATA_BITMASK (0x03 << 2) /** CRC WR_Data Config Bit mask */
\r
70 #define CRC_MODE_WRDATA_BIT_RVS (1 << 2) /** Select Bit order reverse for WR_DATA (per byte) */
\r
71 #define CRC_MODE_WRDATA_CMPL (1 << 3) /** Select One's complement for WR_DATA */
\r
72 #define CRC_MODE_SUM_BITMASK (0x03 << 4) /** CRC Sum Config Bit mask */
\r
73 #define CRC_MODE_SUM_BIT_RVS (1 << 4) /** Select Bit order reverse for CRC_SUM */
\r
74 #define CRC_MODE_SUM_CMPL (1 << 5) /** Select One's complement for CRC_SUM */
\r
76 #define MODE_CFG_CCITT (0x00) /** Pre-defined mode word for default CCITT setup */
\r
77 #define MODE_CFG_CRC16 (0x15) /** Pre-defined mode word for default CRC16 setup */
\r
78 #define MODE_CFG_CRC32 (0x36) /** Pre-defined mode word for default CRC32 setup */
\r
80 #define CRC_SEED_CCITT (0x0000FFFF)/** Initial seed value for CCITT mode */
\r
81 #define CRC_SEED_CRC16 (0x00000000)/** Initial seed value for CRC16 mode */
\r
82 #define CRC_SEED_CRC32 (0xFFFFFFFF)/** Initial seed value for CRC32 mode */
\r
85 * @brief CRC polynomial
\r
87 typedef enum IP_CRC_001_POLY {
\r
88 CRC_POLY_CCITT = CRC_MODE_POLY_CCITT, /**< CRC-CCIT polynomial */
\r
89 CRC_POLY_CRC16 = CRC_MODE_POLY_CRC16, /**< CRC-16 polynomial */
\r
90 CRC_POLY_CRC32 = CRC_MODE_POLY_CRC32, /**< CRC-32 polynomial */
\r
92 } IP_CRC_001_POLY_T;
\r
95 * @brief Initializes the CRC Engine
\r
96 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
99 STATIC INLINE void IP_CRC_Init(IP_CRC_001_T *pCRC) {}
\r
102 * @brief De-initializes the CRC Engine
\r
103 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
106 STATIC INLINE void IP_CRC_DeInit(IP_CRC_001_T *pCRC) {}
\r
109 * @brief Select polynomial for CRC Engine
\r
110 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
111 * @param poly : CRC polynomial selection
\r
112 * @param flags : An Or'ed value of flags that setup the mode
\r
114 * @note Flags for setting up the mode word include CRC_MODE_WRDATA_BIT_RVS,
\r
115 * CRC_MODE_WRDATA_CMPL, CRC_MODE_SUM_BIT_RVS, and CRC_MODE_SUM_CMPL.
\r
117 STATIC INLINE void IP_CRC_SetPoly(IP_CRC_001_T *pCRC, IP_CRC_001_POLY_T poly,
\r
120 pCRC->MODE = (uint32_t) poly | flags;
\r
124 * @brief Sets up the CRC engine with defaults based on the polynomial to be used
\r
125 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
126 * @param poly : The enumerated polynomial to be used
\r
129 void IP_CRC_UseDefaultConfig(IP_CRC_001_T *pCRC, IP_CRC_001_POLY_T poly);
\r
132 * @brief Get mode register of CRC Engine
\r
133 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
134 * @return Current CRC Mode register (Or-ed bits value of CRC_MODE_*)
\r
136 STATIC INLINE uint32_t IP_CRC_GetMode(IP_CRC_001_T *pCRC)
\r
142 * @brief Set mode register of CRC Engine
\r
143 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
144 * @param mode : mode value to be set in mode register
\r
147 STATIC INLINE void IP_CRC_SetMode(IP_CRC_001_T *pCRC, uint32_t mode)
\r
153 * @brief Set Seed value
\r
154 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
155 * @param Seed : selected seed value
\r
158 STATIC INLINE void IP_CRC_SetSeed(IP_CRC_001_T *pCRC, uint32_t Seed)
\r
164 * @brief Get Seed value.
\r
165 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
166 * @return current seed value
\r
168 STATIC INLINE uint32_t IP_CRC_GetSeed(IP_CRC_001_T *pCRC)
\r
174 * @brief Write 8-bit data to CRC WR Data register.
\r
175 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
176 * @param data : data to be written
\r
179 STATIC INLINE void IP_CRC_Write8(IP_CRC_001_T *pCRC, uint8_t data)
\r
181 pCRC->WRDATA8 = data;
\r
185 * @brief Write 16-bit data to CRC WR Data register.
\r
186 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
187 * @param data : data to be written
\r
190 STATIC INLINE void IP_CRC_Write16(IP_CRC_001_T *pCRC, uint16_t data)
\r
192 pCRC->WRDATA16 = (uint32_t) data;
\r
196 * @brief Write 32-bit data to CRC WR Data register.
\r
197 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
198 * @param data : data to be written
\r
201 STATIC INLINE void IP_CRC_Write32(IP_CRC_001_T *pCRC, uint32_t data)
\r
203 pCRC->WRDATA32 = data;
\r
207 * @brief Read current calculated checksum from CRC Engine
\r
208 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
209 * @return Check sum value
\r
211 STATIC INLINE uint32_t IP_CRC_ReadSum(IP_CRC_001_T *pCRC)
\r
217 * @brief Convenience function for computing a standard CCITT checksum from an 8-bit data block
\r
218 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
219 * @param data : Pointer to the block of 8 bit data
\r
220 * @param bytes : The number of bytes pointed to by data
\r
221 * @return Computed checksum for the block
\r
223 uint32_t IP_CRC_CRC8(IP_CRC_001_T *pCRC, const uint8_t *data, uint32_t bytes);
\r
226 * @brief Convenience function for computing a standard CRC16 checksum from 16-bit data block
\r
227 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
228 * @param data : Pointer to the block of 16-bit data
\r
229 * @param hwords : The number of halfword entries pointed to by data
\r
230 * @return Computed checksum for the block
\r
232 uint32_t IP_CRC_CRC16(IP_CRC_001_T *pCRC, const uint16_t *data, uint32_t hwords);
\r
235 * @brief Convenience function for computing a standard CRC32 checksum from 32-bit data block
\r
236 * @param pCRC : Pointer to selected CRC Engine register block structure
\r
237 * @param data : Pointer to the block of 32-bit data
\r
238 * @param words : The number of 32-bit entries pointed to by data
\r
239 * @return Computed checksum for the block
\r
241 uint32_t IP_CRC_CRC32(IP_CRC_001_T *pCRC, const uint32_t *data, uint32_t words);
\r
251 #endif /* __CRC_001_H_ */
\r