]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_driver/include/drv_crc.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / csi / csi_driver / include / drv_crc.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /******************************************************************************
18  * @file     drv_crc.h
19  * @brief    Header File for CRC Driver
20  * @version  V1.0
21  * @date     02. June 2017
22  ******************************************************************************/
23 #ifndef _CSI_CRC_H_
24 #define _CSI_CRC_H_
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 #include <stdint.h>
31 #include <drv_errno.h>
32 #include <drv_common.h>
33
34
35 /****** CRC specific error codes *****/
36 #define CRC_ERROR_MODE                (EDRV_SPECIFIC + 1)     ///< Specified Mode not supported
37
38 /// definition for crc handle.
39 typedef void *crc_handle_t;
40
41 /*----- CRC Control Codes: Mode -----*/
42 typedef enum {
43     CRC_MODE_CRC8                   = 0,   ///< Mode CRC8
44     CRC_MODE_CRC16                     ,   ///< Mode CRC16
45     CRC_MODE_CRC32                         ///< Mode CRC32
46 } crc_mode_e;
47
48 /*----- CRC Control Codes: Mode Parameters: Key length -----*/
49 typedef enum {
50     CRC_STANDARD_CRC_ROHC         = 0,    ///< Standard CRC RHOC
51     CRC_STANDARD_CRC_MAXIM           ,    ///< Standard CRC MAXIAM
52     CRC_STANDARD_CRC_X25             ,    ///< Standard CRC X25
53     CRC_STANDARD_CRC_CCITT           ,    ///< Standard CRC CCITT
54     CRC_STANDARD_CRC_USB             ,    ///< Standard CRC USB
55     CRC_STANDARD_CRC_IBM             ,    ///< Standard CRC IBM
56     CRC_STANDARD_CRC_MODBUS               ///< Standard CRC MODBUS
57 } crc_standard_crc_e;
58
59 /**
60 \brief CRC Status
61 */
62 typedef struct {
63     uint32_t busy             : 1;        ///< busy flag
64 } crc_status_t;
65
66 /****** CRC Event *****/
67 typedef enum {
68     CRC_EVENT_CALCULATE_COMPLETE  = 0,  ///< Calculate completed
69 } crc_event_e;
70
71 typedef void (*crc_event_cb_t)(crc_event_e event);   ///< Pointer to \ref crc_event_cb_t : CRC Event call back.
72
73 /**
74 \brief CRC Device Driver Capabilities.
75 */
76 typedef struct {
77     uint32_t ROHC               : 1;      ///< supports ROHC mode
78     uint32_t MAXIM              : 1;      ///< supports MAXIM mode
79     uint32_t X25                : 1;      ///< supports X25 mode
80     uint32_t CCITT              : 1;      ///< supports CCITT mode
81     uint32_t USB                : 1;      ///< supports USB mode
82     uint32_t IBM                : 1;      ///< supports IBM mode
83     uint32_t MODBUS             : 1;      ///< supports MODBUS mode
84 } crc_capabilities_t;
85
86 // Function documentation
87
88 /**
89   \brief       get crc handle count.
90   \return      crc handle count
91 */
92 int32_t csi_crc_get_instance_count(void);
93
94 /**
95   \brief       Initialize CRC Interface. 1. Initializes the resources needed for the CRC interface 2.registers event callback function
96   \param[in]   idx must not exceed return value of csi_crc_get_handle_count()
97   \param[in]   cb_event  Pointer to \ref crc_event_cb_t
98   \return      return crc handle if success
99 */
100 crc_handle_t csi_crc_initialize(int32_t idx, crc_event_cb_t cb_event);
101
102 /**
103   \brief       De-initialize CRC Interface. stops operation and releases the software resources used by the interface
104   \param[in]   handle  crc handle to operate.
105   \return      error code
106 */
107 int32_t csi_crc_uninitialize(crc_handle_t handle);
108
109 /**
110   \brief       Get driver capabilities.
111   \param[in]   handle crc handle to operate.
112   \return      \ref crc_capabilities_t
113 */
114 crc_capabilities_t csi_crc_get_capabilities(crc_handle_t handle);
115
116 /**
117   \brief       config crc mode.
118   \param[in]   handle  crc handle to operate.
119   \param[in]   mode      \ref crc_mode_e
120   \param[in]   standard  \ref crc_standard_crc_e
121   \return      error code
122 */
123 int32_t csi_crc_config(crc_handle_t handle,
124                        crc_mode_e mode,
125                        crc_standard_crc_e standard
126                       );
127
128 /**
129   \brief       calculate crc.
130   \param[in]   handle  crc handle to operate.
131   \param[in]   in      Pointer to the input data
132   \param[out]  out     Pointer to the result.
133   \param[in]   len     intpu data len.
134   \return      error code
135 */
136 int32_t csi_crc_calculate(crc_handle_t handle, const void *in, void *out, uint32_t len);
137
138 /**
139   \brief       Get CRC status.
140   \param[in]   handle  crc handle to operate.
141   \return      CRC status \ref crc_status_t
142 */
143 crc_status_t csi_crc_get_status(crc_handle_t handle);
144
145
146 #ifdef __cplusplus
147 }
148 #endif
149
150 #endif /* _CSI_CRC_H_ */