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_MAX78002_CRC_H_
27 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_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  * @return  Success/Fail, see \ref MXC_Error_Codes for a list of return codes.
87  */
88 // AI87-TODO: Changed because of redundancy in MXC_CRC_RevA_Handler?
89 void MXC_CRC_Handler(int ch, int error);
90 
91 /**
92  * @brief   Set the bit-order of CRC calculation
93  *
94  * @param   bitOrder  The direction to perform CRC calculation in
95  */
96 void MXC_CRC_SetDirection(mxc_crc_bitorder_t bitOrder);
97 
98 /**
99  * @brief   Set the bit-order of CRC calculation
100  *
101  * @return  The direction of calculation, 1 for MSB first, 0 for LSB first
102  */
103 mxc_crc_bitorder_t MXC_CRC_GetDirection(void);
104 
105 /**
106  * @brief   Byte Swap CRC Data Input
107  *
108  * @param   bitOrder  The direction to perform CRC calculation in
109  */
110 void MXC_CRC_SwapDataIn(mxc_crc_bitorder_t bitOrder);
111 
112 /**
113  * @brief   Byte Swap CRC Data output
114  *
115  * @param   bitOrder  The direction to perform CRC calculation in
116  */
117 void MXC_CRC_SwapDataOut(mxc_crc_bitorder_t bitOrder);
118 
119 /**
120  * @brief   Set the Polynomial for CRC calculation
121  *
122  * @param   poly  The polynomial to use for CRC calculation
123  */
124 void MXC_CRC_SetPoly(uint32_t poly);
125 
126 /**
127  * @brief   Get the polynomial for CRC calculation
128  *
129  * @return  The polynomial used in calculation
130  */
131 uint32_t MXC_CRC_GetPoly(void);
132 
133 /**
134  * @brief   Get the result of a CRC calculation
135  *
136  * @return  The calculated CRC value
137  */
138 uint32_t MXC_CRC_GetResult(void);
139 
140 /*******************************/
141 /* High Level Functions        */
142 /*******************************/
143 
144 /**
145  * @brief   Perform a CRC computation
146  * @note    The result of the CRC calculation will be placed in the
147  *          mxc_crc_req_t structure
148  *
149  * @param   req   Structure containing the data for calculation
150  *
151  * @return  see \ref MXC_Error_Codes for a list of return codes.
152  */
153 int MXC_CRC_Compute(mxc_crc_req_t *req);
154 
155 /**
156  * @brief   Perform a CRC computation using DMA
157  * @note    The result of the CRC calculation will be placed in the
158  *          mxc_crc_req_t structure. The user must call
159  *          MXC_DMA_Handler() in the ISR
160  *
161  * @param   req   Structure containing the data for calculation
162  *
163  * @return  see \ref MXC_Error_Codes for a list of return codes.
164  */
165 int MXC_CRC_ComputeAsync(mxc_crc_req_t *req);
166 
167 #ifdef __cplusplus
168 }
169 #endif
170 /**@} end of group crc */
171 
172 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX78002_CRC_H_
173