1 /*!
2  * @file        apm32f0xx_crc.h
3  *
4  * @brief       This file contains all the functions prototypes for the CRC firmware library
5  *
6  * @version     V1.0.3
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 /* Define to prevent recursive inclusion */
27 #ifndef __APM32F0XX_CRC_H
28 #define __APM32F0XX_CRC_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /* Includes */
35 #include "apm32f0xx.h"
36 
37 /** @addtogroup APM32F0xx_StdPeriphDriver
38   @{
39 */
40 
41 /** @addtogroup CRC_Driver
42   @{
43 */
44 
45 /** @defgroup CRC_Macros Macros
46   @{
47 */
48 
49 /**@} end of group CRC_Macros */
50 
51 /** @defgroup CRC_Enumerations Enumerations
52   @{
53 */
54 
55 /**
56  * @brief   CRC Reverse Input Data
57  */
58 typedef enum
59 {
60     CRC_REVERSE_INPUT_DATA_NO   = ((uint8_t)0x00), /*!< Bit order not affected */
61     CRC_REVERSE_INPUT_DATA_8B   = ((uint8_t)0x01), /*!< Bit reversal done by byte */
62     CRC_REVERSE_INPUT_DATA_16B  = ((uint8_t)0x02), /*!< Bit reversal done by half-word */
63     CRC_REVERSE_INPUT_DATA_32B  = ((uint8_t)0x03), /*!< Bit reversal done by word */
64 } CRC_REVERSE_INPUT_DATA_T;
65 
66 /**
67  * @brief   CRC Polynomial Size
68  */
69 typedef enum
70 {
71     CRC_POLYNOMIAL_SIZE_7   = ((uint8_t)0x03), /*!< 7-bit polynomial for CRC calculation */
72     CRC_POLYNOMIAL_SIZE_8   = ((uint8_t)0x02), /*!< 8-bit polynomial for CRC calculation */
73     CRC_POLYNOMIAL_SIZE_16  = ((uint8_t)0x01), /*!< 16-bit polynomial for CRC calculation */
74     CRC_POLYNOMIAL_SIZE_32  = ((uint8_t)0x00), /*!< 32-bit polynomial for CRC calculation */
75 } CRC_POLYNOMIAL_SIZE_T;
76 
77 /**@} end of group CRC_Enumerations*/
78 
79 /** @defgroup CRC_Structures Structures
80   @{
81 */
82 
83 /**@} end of group CRC_Structures */
84 
85 /** @defgroup CRC_Variables Variables
86   @{
87 */
88 
89 /**@} end of group CRC_Variables */
90 
91 /** @defgroup CRC_Functions Functions
92   @{
93 */
94 
95 /* Reset CRC */
96 void CRC_Reset(void);
97 
98 /* Reset DATA */
99 void CRC_ResetDATA(void);
100 
101 /* CRC Polynomial Size */
102 void CRC_SetPolynomialSize(CRC_POLYNOMIAL_SIZE_T polynomialSize); /*!< Only for APM32F072 and APM32F091 devices */
103 void CRC_SetPolynomialValue(uint32_t polynomialValue); /*!< Only for APM32F072 and APM32F091 devices */
104 
105 /* Performed on input data */
106 void CRC_SelectReverseInputData(CRC_REVERSE_INPUT_DATA_T revInData);
107 
108 /* Enable and Disable Reverse Output Data */
109 void CRC_EnableReverseOutputData(void);
110 void CRC_DisableReverseOutputData(void);
111 
112 /* Write INITVAL register */
113 void CRC_WriteInitRegister(uint32_t initValue);
114 
115 /* Calculate CRC */
116 uint32_t CRC_CalculateCRC(uint32_t data);
117 uint32_t CRC_CalculateCRC8bits(uint8_t data);   /*!< Only for APM32F072 and APM32F091 devices */
118 uint32_t CRC_CalculateCRC16bits(uint16_t data); /*!< Only for APM32F072 and APM32F091 devices */
119 uint32_t CRC_CalculateBlockCRC(uint32_t pBuffer[], uint32_t bufferLength);
120 
121 /* Read CRC */
122 uint32_t CRC_ReadCRC(void);
123 
124 /* Independent Data(ID) */
125 void CRC_WriteIDRegister(uint8_t IDValue);
126 uint8_t CRC_ReadIDRegister(void);
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* __APM32F0XX_CRC_H */
133 
134 /**@} end of group CRC_Functions */
135 /**@} end of group CRC_Driver */
136 /**@} end of group APM32F0xx_StdPeriphDriver */
137