1 /**
2  * @file    crc.h
3  * @brief   cyclic redundancy check driver.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_CRC_H_
27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_CRC_H_
28 
29 /***** Includes *****/
30 #include "crc_regs.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /**
37  * @defgroup crc CRC
38  * @ingroup periphlibs
39  * @{
40  */
41 
42 /***** CRC Definitions *****/
43 /**
44   * @brief  Structure used to set up CRC request
45   *
46   */
47 typedef struct _mxc_crc_req_t {
48     uint32_t *dataBuffer; ///< Pointer to the data
49     uint32_t dataLen; ///< Length of the data
50     uint32_t resultCRC; ///< Calculated CRC value
51 } mxc_crc_req_t;
52 
53 /**
54  * @brief CRC data bit order
55  *
56  */
57 typedef enum { CRC_LSB_FIRST, CRC_MSB_FIRST } mxc_crc_bitorder_t;
58 
59 /***** Function Prototypes *****/
60 
61 /* ************************************************************************* */
62 /* Global Control/Configuration functions                                    */
63 /* ************************************************************************* */
64 
65 /**
66  * @brief   Enable portions of the CRC
67  *
68  *
69  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
70  */
71 int MXC_CRC_Init(void);
72 
73 /**
74  * @brief   Disable and reset portions of the CRC
75  *
76  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
77  */
78 int MXC_CRC_Shutdown(void);
79 
80 /**
81  * @brief   This function should be called from the CRC ISR Handler
82  *          when using Async functions
83  * @param   ch      DMA channel
84  * @param   error   error
85  */
86 void MXC_CRC_Handler(int ch, int error);
87 
88 /**
89  * @brief   Set the bit-order of CRC calculation
90  *
91  * @param   bitOrder  The direction to perform CRC calculation in
92  */
93 void MXC_CRC_SetDirection(mxc_crc_bitorder_t bitOrder);
94 
95 /**
96  * @brief   Set the bit-order of CRC calculation
97  *
98  * @return  The direction of calculation, 1 for MSB first, 0 for LSB first
99  */
100 mxc_crc_bitorder_t MXC_CRC_GetDirection(void);
101 
102 /**
103  * @brief   Byte Swap CRC Data Input
104  *
105  * @param   bitOrder  The direction to perform CRC calculation in
106  */
107 void MXC_CRC_SwapDataIn(mxc_crc_bitorder_t bitOrder);
108 
109 /**
110  * @brief   Byte Swap CRC Data output
111  *
112  * @param   bitOrder  The direction to perform CRC calculation in
113  */
114 void MXC_CRC_SwapDataOut(mxc_crc_bitorder_t bitOrder);
115 
116 /**
117  * @brief   Set the Polynomial for CRC calculation
118  *
119  * @param   poly  The polynomial to use for CRC calculation
120  */
121 void MXC_CRC_SetPoly(uint32_t poly);
122 
123 /**
124  * @brief   Get the polynomial for CRC calculation
125  *
126  * @return  The polynomial used in calculation
127  */
128 uint32_t MXC_CRC_GetPoly(void);
129 
130 /**
131  * @brief   Get the result of a CRC calculation
132  *
133  * @return  The calculated CRC value
134  */
135 uint32_t MXC_CRC_GetResult(void);
136 
137 /*******************************/
138 /* High Level Functions        */
139 /*******************************/
140 
141 /**
142  * @brief   Perform a CRC computation
143  * @note    The result of the CRC calculation will be placed in the
144  *          mxc_crc_req_t structure
145  *
146  * @param   req   Structure containing the data for calculation
147  *
148  * @return  see \ref MXC_Error_Codes for a list of return codes.
149  */
150 int MXC_CRC_Compute(mxc_crc_req_t *req);
151 
152 /**
153  * @brief   Perform a CRC computation using DMA
154  * @note    The result of the CRC calculation will be placed in the
155  *          mxc_crc_req_t structure. The user must call
156  *          MXC_DMA_Handler() in the ISR
157  *
158  * @param   req   Structure containing the data for calculation
159  *
160  * @return  see \ref MXC_Error_Codes for a list of return codes.
161  */
162 int MXC_CRC_ComputeAsync(mxc_crc_req_t *req);
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 /**@} end of group crc */
168 
169 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32662_CRC_H_
170