1 /**
2   *******************************************************************************************************
3   * @file    fm33lc0xx_fl_crc.h
4   * @author  FMSH Application Team
5   * @brief   Head file of CRC FL Module
6   *******************************************************************************************************
7   * @attention
8   *
9   * Copyright (c) [2021] [Fudan Microelectronics]
10   * THIS SOFTWARE is licensed under Mulan PSL v2.
11   * You can use this software according to the terms and conditions of the Mulan PSL v2.
12   * You may obtain a copy of Mulan PSL v2 at:
13   *          http://license.coscl.org.cn/MulanPSL2
14   * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
15   * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
16   * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
17   * See the Mulan PSL v2 for more details.
18   *
19   *******************************************************************************************************
20   */
21 
22 
23 /* Define to prevent recursive inclusion---------------------------------------------------------------*/
24 #ifndef __FM33LC0XX_FL_CRC_H
25 #define __FM33LC0XX_FL_CRC_H
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 /* Includes -------------------------------------------------------------------------------------------*/
31 #include "fm33lc0xx_fl_def.h"
32 /** @addtogroup FM33LC0XX_FL_Driver
33   * @{
34   */
35 
36 /** @defgroup CRC CRC
37   * @brief CRC FL driver
38   * @{
39   */
40 
41 /* Exported types -------------------------------------------------------------------------------------*/
42 /** @defgroup CRC_FL_ES_INIT CRC Exported Init structures
43   * @{
44   */
45 
46 /**
47   * @brief FL CRC Init Sturcture definition
48   */
49 typedef struct
50 {
51     /** CRC初值 */
52     uint32_t initVal;
53 
54     /** 计算数据宽度 */
55     uint32_t dataWidth;
56 
57     /** 输入数据翻转 */
58     uint32_t reflectIn;
59 
60     /** 输出数据翻转 */
61     uint32_t reflectOut;
62 
63     /** 输出结果异或寄存器 */
64     uint32_t xorReg;
65 
66     /** 输出结果异或使能 */
67     uint32_t xorRegState;
68 
69     /** CRC多项式宽 */
70     uint32_t polynomialWidth;
71 
72     /** CRC多项式 */
73     uint32_t polynomial;
74 
75     /** 计算模式串行或并行 */
76     uint32_t calculatMode;
77 
78 } FL_CRC_InitTypeDef;
79 
80 /**
81   * @}
82   */
83 /* Exported constants ---------------------------------------------------------------------------------*/
84 /** @defgroup CRC_FL_Exported_Constants CRC Exported Constants
85   * @{
86   */
87 
88 #define    CRC_CR_OPWD_Pos                                        (9U)
89 #define    CRC_CR_OPWD_Msk                                        (0x1U << CRC_CR_OPWD_Pos)
90 #define    CRC_CR_OPWD                                            CRC_CR_OPWD_Msk
91 
92 #define    CRC_CR_PARA_Pos                                        (8U)
93 #define    CRC_CR_PARA_Msk                                        (0x1U << CRC_CR_PARA_Pos)
94 #define    CRC_CR_PARA                                            CRC_CR_PARA_Msk
95 
96 #define    CRC_CR_RFLTIN_Pos                                      (6U)
97 #define    CRC_CR_RFLTIN_Msk                                      (0x3U << CRC_CR_RFLTIN_Pos)
98 #define    CRC_CR_RFLTIN                                          CRC_CR_RFLTIN_Msk
99 
100 #define    CRC_CR_RFLTO_Pos                                       (5U)
101 #define    CRC_CR_RFLTO_Msk                                       (0x1U << CRC_CR_RFLTO_Pos)
102 #define    CRC_CR_RFLTO                                           CRC_CR_RFLTO_Msk
103 
104 #define    CRC_CR_RES_Pos                                         (4U)
105 #define    CRC_CR_RES_Msk                                         (0x1U << CRC_CR_RES_Pos)
106 #define    CRC_CR_RES                                             CRC_CR_RES_Msk
107 
108 #define    CRC_CR_BUSY_Pos                                        (3U)
109 #define    CRC_CR_BUSY_Msk                                        (0x1U << CRC_CR_BUSY_Pos)
110 #define    CRC_CR_BUSY                                            CRC_CR_BUSY_Msk
111 
112 #define    CRC_CR_XOR_Pos                                         (2U)
113 #define    CRC_CR_XOR_Msk                                         (0x1U << CRC_CR_XOR_Pos)
114 #define    CRC_CR_XOR                                             CRC_CR_XOR_Msk
115 
116 #define    CRC_CR_SEL_Pos                                         (0U)
117 #define    CRC_CR_SEL_Msk                                         (0x3U << CRC_CR_SEL_Pos)
118 #define    CRC_CR_SEL                                             CRC_CR_SEL_Msk
119 
120 
121 #define    FL_CRC_DATA_WIDTH_8B                                   (0x0U << CRC_CR_OPWD_Pos)
122 #define    FL_CRC_DATA_WIDTH_32B                                  (0x1U << CRC_CR_OPWD_Pos)
123 
124 
125 #define    FL_CRC_CALCULATE_SERIAL                                (0x0U << CRC_CR_PARA_Pos)
126 #define    FL_CRC_CALCULATE_PARALLEL                              (0x1U << CRC_CR_PARA_Pos)
127 
128 
129 #define    FL_CRC_INPUT_INVERT_NONE                               (0x0U << CRC_CR_RFLTIN_Pos)
130 #define    FL_CRC_INPUT_INVERT_BYTE                               (0x1U << CRC_CR_RFLTIN_Pos)
131 #define    FL_CRC_INPUT_INVERT_HALF_WORD                          (0x2U << CRC_CR_RFLTIN_Pos)
132 #define    FL_CRC_INPUT_INVERT_WORD                               (0x3U << CRC_CR_RFLTIN_Pos)
133 
134 
135 #define    FL_CRC_OUPUT_INVERT_NONE                               (0x0U << CRC_CR_RFLTO_Pos)
136 #define    FL_CRC_OUPUT_INVERT_BYTE                               (0x1U << CRC_CR_RFLTO_Pos)
137 
138 
139 #define    FL_CRC_POLYNOMIAL_32B                                  (0x0U << CRC_CR_SEL_Pos)
140 #define    FL_CRC_POLYNOMIAL_16B                                  (0x1U << CRC_CR_SEL_Pos)
141 #define    FL_CRC_POLYNOMIAL_8B                                   (0x2U << CRC_CR_SEL_Pos)
142 #define    FL_CRC_POLYNOMIAL_7B                                   (0x3U << CRC_CR_SEL_Pos)
143 
144 
145 /**
146   * @}
147   */
148 /* Exported functions ---------------------------------------------------------------------------------*/
149 /** @defgroup CRC_FL_Exported_Functions CRC Exported Functions
150   * @{
151   */
152 
153 /**
154   * @brief    Set CRC data register
155   * @rmtoll   DR        FL_CRC_WriteData
156   * @param    CRCx CRC instance
157   * @param    data
158   * @retval   None
159   */
FL_CRC_WriteData(CRC_Type * CRCx,uint32_t data)160 __STATIC_INLINE void FL_CRC_WriteData(CRC_Type *CRCx, uint32_t data)
161 {
162     MODIFY_REG(CRCx->DR, (0xffffffffU << 0U), (data << 0U));
163 }
164 
165 /**
166   * @brief    Get CRC data register value
167   * @rmtoll   DR        FL_CRC_ReadData
168   * @param    CRCx CRC instance
169   * @retval
170   */
FL_CRC_ReadData(CRC_Type * CRCx)171 __STATIC_INLINE uint32_t FL_CRC_ReadData(CRC_Type *CRCx)
172 {
173     return (uint32_t)(READ_BIT(CRCx->DR, (0xffffffffU << 0U)) >> 0U);
174 }
175 
176 /**
177   * @brief    Set CRC calculate operation width
178   * @rmtoll   CR    OPWD    FL_CRC_SetDataWidth
179   * @param    CRCx CRC instance
180   * @param    dataWidth This parameter can be one of the following values:
181   *           @arg @ref FL_CRC_DATA_WIDTH_8B
182   *           @arg @ref FL_CRC_DATA_WIDTH_32B
183   * @retval   None
184   */
FL_CRC_SetDataWidth(CRC_Type * CRCx,uint32_t dataWidth)185 __STATIC_INLINE void FL_CRC_SetDataWidth(CRC_Type *CRCx, uint32_t dataWidth)
186 {
187     MODIFY_REG(CRCx->CR, CRC_CR_OPWD_Msk, dataWidth);
188 }
189 
190 /**
191   * @brief    Get CRC calculate operation width
192   * @rmtoll   CR    OPWD    FL_CRC_GetDataWidth
193   * @param    CRCx CRC instance
194   * @retval   Returned value can be one of the following values:
195   *           @arg @ref FL_CRC_DATA_WIDTH_8B
196   *           @arg @ref FL_CRC_DATA_WIDTH_32B
197   */
FL_CRC_GetDataWidth(CRC_Type * CRCx)198 __STATIC_INLINE uint32_t FL_CRC_GetDataWidth(CRC_Type *CRCx)
199 {
200     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_OPWD_Msk));
201 }
202 
203 /**
204   * @brief    Set CRC parallel calculation mode
205   * @rmtoll   CR    PARA    FL_CRC_SetCalculateMode
206   * @param    CRCx CRC instance
207   * @param    mode This parameter can be one of the following values:
208   *           @arg @ref FL_CRC_CALCULATE_SERIAL
209   *           @arg @ref FL_CRC_CALCULATE_PARALLEL
210   * @retval   None
211   */
FL_CRC_SetCalculateMode(CRC_Type * CRCx,uint32_t mode)212 __STATIC_INLINE void FL_CRC_SetCalculateMode(CRC_Type *CRCx, uint32_t mode)
213 {
214     MODIFY_REG(CRCx->CR, CRC_CR_PARA_Msk, mode);
215 }
216 
217 /**
218   * @brief    Get CRC parallel calculation mode
219   * @rmtoll   CR    PARA    FL_CRC_GetCalculateMode
220   * @param    CRCx CRC instance
221   * @retval   Returned value can be one of the following values:
222   *           @arg @ref FL_CRC_CALCULATE_SERIAL
223   *           @arg @ref FL_CRC_CALCULATE_PARALLEL
224   */
FL_CRC_GetCalculateMode(CRC_Type * CRCx)225 __STATIC_INLINE uint32_t FL_CRC_GetCalculateMode(CRC_Type *CRCx)
226 {
227     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_PARA_Msk));
228 }
229 
230 /**
231   * @brief    Set CRC reflected input
232   * @rmtoll   CR    RFLTIN    FL_CRC_SetInputInvertMode
233   * @param    CRCx CRC instance
234   * @param    mode This parameter can be one of the following values:
235   *           @arg @ref FL_CRC_INPUT_INVERT_NONE
236   *           @arg @ref FL_CRC_INPUT_INVERT_BYTE
237   *           @arg @ref FL_CRC_INPUT_INVERT_HALF_WORD
238   *           @arg @ref FL_CRC_INPUT_INVERT_WORD
239   * @retval   None
240   */
FL_CRC_SetInputInvertMode(CRC_Type * CRCx,uint32_t mode)241 __STATIC_INLINE void FL_CRC_SetInputInvertMode(CRC_Type *CRCx, uint32_t mode)
242 {
243     MODIFY_REG(CRCx->CR, CRC_CR_RFLTIN_Msk, mode);
244 }
245 
246 /**
247   * @brief    Get CRC reflected input status
248   * @rmtoll   CR    RFLTIN    FL_CRC_GetInputInvertMode
249   * @param    CRCx CRC instance
250   * @retval   Returned value can be one of the following values:
251   *           @arg @ref FL_CRC_INPUT_INVERT_NONE
252   *           @arg @ref FL_CRC_INPUT_INVERT_BYTE
253   *           @arg @ref FL_CRC_INPUT_INVERT_HALF_WORD
254   *           @arg @ref FL_CRC_INPUT_INVERT_WORD
255   */
FL_CRC_GetInputInvertMode(CRC_Type * CRCx)256 __STATIC_INLINE uint32_t FL_CRC_GetInputInvertMode(CRC_Type *CRCx)
257 {
258     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_RFLTIN_Msk));
259 }
260 
261 /**
262   * @brief    Set CRC reflected output
263   * @rmtoll   CR    RFLTO    FL_CRC_SetOutputInvertMode
264   * @param    CRCx CRC instance
265   * @param    mode This parameter can be one of the following values:
266   *           @arg @ref FL_CRC_OUPUT_INVERT_NONE
267   *           @arg @ref FL_CRC_OUPUT_INVERT_BYTE
268   * @retval   None
269   */
FL_CRC_SetOutputInvertMode(CRC_Type * CRCx,uint32_t mode)270 __STATIC_INLINE void FL_CRC_SetOutputInvertMode(CRC_Type *CRCx, uint32_t mode)
271 {
272     MODIFY_REG(CRCx->CR, CRC_CR_RFLTO_Msk, mode);
273 }
274 
275 /**
276   * @brief    Get CRC feflected output status
277   * @rmtoll   CR    RFLTO    FL_CRC_GetOutputInvertMode
278   * @param    CRCx CRC instance
279   * @retval   Returned value can be one of the following values:
280   *           @arg @ref FL_CRC_OUPUT_INVERT_NONE
281   *           @arg @ref FL_CRC_OUPUT_INVERT_BYTE
282   */
FL_CRC_GetOutputInvertMode(CRC_Type * CRCx)283 __STATIC_INLINE uint32_t FL_CRC_GetOutputInvertMode(CRC_Type *CRCx)
284 {
285     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_RFLTO_Msk));
286 }
287 
288 /**
289   * @brief    Get CRC result flag
290   * @rmtoll   CR    RES    FL_CRC_IsActiveFlag_Zero
291   * @param    CRCx CRC instance
292   * @retval   State of bit (1 or 0).
293   */
FL_CRC_IsActiveFlag_Zero(CRC_Type * CRCx)294 __STATIC_INLINE uint32_t FL_CRC_IsActiveFlag_Zero(CRC_Type *CRCx)
295 {
296     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_RES_Msk) == (CRC_CR_RES_Msk));
297 }
298 
299 /**
300   * @brief    Get CRC operational flag
301   * @rmtoll   CR    BUSY    FL_CRC_IsActiveFlag_Busy
302   * @param    CRCx CRC instance
303   * @retval   State of bit (1 or 0).
304   */
FL_CRC_IsActiveFlag_Busy(CRC_Type * CRCx)305 __STATIC_INLINE uint32_t FL_CRC_IsActiveFlag_Busy(CRC_Type *CRCx)
306 {
307     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_BUSY_Msk) == (CRC_CR_BUSY_Msk));
308 }
309 
310 /**
311   * @brief    Output XORed with CRC_XOR register enable
312   * @rmtoll   CR    XOR    FL_CRC_EnableOutputXOR
313   * @param    CRCx CRC instance
314   * @retval   None
315   */
FL_CRC_EnableOutputXOR(CRC_Type * CRCx)316 __STATIC_INLINE void FL_CRC_EnableOutputXOR(CRC_Type *CRCx)
317 {
318     SET_BIT(CRCx->CR, CRC_CR_XOR_Msk);
319 }
320 
321 /**
322   * @brief    Get output XORed with CRC_XOR register enable status
323   * @rmtoll   CR    XOR    FL_CRC_IsEnabledOutputXOR
324   * @param    CRCx CRC instance
325   * @retval   State of bit (1 or 0).
326   */
FL_CRC_IsEnabledOutputXOR(CRC_Type * CRCx)327 __STATIC_INLINE uint32_t FL_CRC_IsEnabledOutputXOR(CRC_Type *CRCx)
328 {
329     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_XOR_Msk) == CRC_CR_XOR_Msk);
330 }
331 
332 /**
333   * @brief    Output XORed with CRC_XOR register disable
334   * @rmtoll   CR    XOR    FL_CRC_DisableOutputXOR
335   * @param    CRCx CRC instance
336   * @retval   None
337   */
FL_CRC_DisableOutputXOR(CRC_Type * CRCx)338 __STATIC_INLINE void FL_CRC_DisableOutputXOR(CRC_Type *CRCx)
339 {
340     CLEAR_BIT(CRCx->CR, CRC_CR_XOR_Msk);
341 }
342 
343 /**
344   * @brief    Polynomial width selection
345   * @rmtoll   CR    SEL    FL_CRC_SetPolynomialWidth
346   * @param    CRCx CRC instance
347   * @param    width This parameter can be one of the following values:
348   *           @arg @ref FL_CRC_POLYNOMIAL_32B
349   *           @arg @ref FL_CRC_POLYNOMIAL_16B
350   *           @arg @ref FL_CRC_POLYNOMIAL_8B
351   *           @arg @ref FL_CRC_POLYNOMIAL_7B
352   * @retval   None
353   */
FL_CRC_SetPolynomialWidth(CRC_Type * CRCx,uint32_t width)354 __STATIC_INLINE void FL_CRC_SetPolynomialWidth(CRC_Type *CRCx, uint32_t width)
355 {
356     MODIFY_REG(CRCx->CR, CRC_CR_SEL_Msk, width);
357 }
358 
359 /**
360   * @brief    Get Polynomial width Selection status
361   * @rmtoll   CR    SEL    FL_CRC_GetPolynomialWidth
362   * @param    CRCx CRC instance
363   * @retval   Returned value can be one of the following values:
364   *           @arg @ref FL_CRC_POLYNOMIAL_32B
365   *           @arg @ref FL_CRC_POLYNOMIAL_16B
366   *           @arg @ref FL_CRC_POLYNOMIAL_8B
367   *           @arg @ref FL_CRC_POLYNOMIAL_7B
368   */
FL_CRC_GetPolynomialWidth(CRC_Type * CRCx)369 __STATIC_INLINE uint32_t FL_CRC_GetPolynomialWidth(CRC_Type *CRCx)
370 {
371     return (uint32_t)(READ_BIT(CRCx->CR, CRC_CR_SEL_Msk));
372 }
373 
374 /**
375   * @brief    Set linear feedback shift register
376   * @rmtoll   LFSR        FL_CRC_WriteInitialValue
377   * @param    CRCx CRC instance
378   * @param    data
379   * @retval   None
380   */
FL_CRC_WriteInitialValue(CRC_Type * CRCx,uint32_t data)381 __STATIC_INLINE void FL_CRC_WriteInitialValue(CRC_Type *CRCx, uint32_t data)
382 {
383     MODIFY_REG(CRCx->LFSR, (0xffffffffU << 0U), (data << 0U));
384 }
385 
386 /**
387   * @brief    Get linear feedback shift register value
388   * @rmtoll   LFSR        FL_CRC_ReadInitialValue
389   * @param    CRCx CRC instance
390   * @retval
391   */
FL_CRC_ReadInitialValue(CRC_Type * CRCx)392 __STATIC_INLINE uint32_t FL_CRC_ReadInitialValue(CRC_Type *CRCx)
393 {
394     return (uint32_t)(READ_BIT(CRCx->LFSR, (0xffffffffU << 0U)) >> 0U);
395 }
396 
397 /**
398   * @brief    Set eXclusive XOR register
399   * @rmtoll   XOR        FL_CRC_WriteXORValue
400   * @param    CRCx CRC instance
401   * @param    data
402   * @retval   None
403   */
FL_CRC_WriteXORValue(CRC_Type * CRCx,uint32_t data)404 __STATIC_INLINE void FL_CRC_WriteXORValue(CRC_Type *CRCx, uint32_t data)
405 {
406     MODIFY_REG(CRCx->XOR, (0xffffffffU << 0U), (data << 0U));
407 }
408 
409 /**
410   * @brief    Get eXclusive XOR register value
411   * @rmtoll   XOR        FL_CRC_ReadXORValue
412   * @param    CRCx CRC instance
413   * @retval
414   */
FL_CRC_ReadXORValue(CRC_Type * CRCx)415 __STATIC_INLINE uint32_t FL_CRC_ReadXORValue(CRC_Type *CRCx)
416 {
417     return (uint32_t)(READ_BIT(CRCx->XOR, (0xffffffffU << 0U)) >> 0U);
418 }
419 
420 /**
421   * @brief    Set CRC Polynominals
422   * @rmtoll   POLY        FL_CRC_WritePolynominalParam
423   * @param    CRCx CRC instance
424   * @param    data
425   * @retval   None
426   */
FL_CRC_WritePolynominalParam(CRC_Type * CRCx,uint32_t data)427 __STATIC_INLINE void FL_CRC_WritePolynominalParam(CRC_Type *CRCx, uint32_t data)
428 {
429     MODIFY_REG(CRCx->POLY, (0xffffffffU << 0U), (data << 0U));
430 }
431 
432 /**
433   * @brief    Get CRC Polynominals
434   * @rmtoll   POLY        FL_CRC_ReadPolynominalParam
435   * @param    CRCx CRC instance
436   * @retval
437   */
FL_CRC_ReadPolynominalParam(CRC_Type * CRCx)438 __STATIC_INLINE uint32_t FL_CRC_ReadPolynominalParam(CRC_Type *CRCx)
439 {
440     return (uint32_t)(READ_BIT(CRCx->POLY, (0xffffffffU << 0U)) >> 0U);
441 }
442 
443 /**
444   * @}
445   */
446 
447 /** @defgroup CRC_FL_EF_Init Initialization and de-initialization functions
448   * @{
449   */
450 FL_ErrorStatus FL_CRC_DeInit(CRC_Type *CRCx);
451 void FL_CRC_StructInit(FL_CRC_InitTypeDef *CRC_InitStruct);
452 FL_ErrorStatus FL_CRC_Init(CRC_Type *CRCx, FL_CRC_InitTypeDef *CRC_InitStruct);
453 
454 /**
455   * @}
456   */
457 
458 /**
459   * @}
460   */
461 
462 
463 /**
464   * @}
465   */
466 
467 #ifdef __cplusplus
468 }
469 #endif
470 
471 #endif /* __FM33LC0XX_FL_CRC_H*/
472 
473 /*************************Py_Code_Generator Version: 0.1-0.11-0.2 @ 2020-09-23*************************/
474 /********************** (C) COPYRIGHT Fudan Microelectronics **** END OF FILE ***********************/
475