1 /*
2  * Copyright (C) 2017-2019 Alibaba Group Holding Limited
3  */
4 
5 
6 /******************************************************************************
7  * @file     drv_crc.h
8  * @brief    Header File for CRC Driver
9  * @version  V1.0
10  * @date     02. June 2017
11  * @model    crc
12  ******************************************************************************/
13 #ifndef _CSI_CRC_H_
14 #define _CSI_CRC_H_
15 
16 
17 #include <stdint.h>
18 #include <drv_errno.h>
19 #include <drv_common.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 /****** CRC specific error codes *****/
26 #define CRC_ERROR_MODE                (DRV_ERROR_SPECIFIC + 1)     ///< Specified Mode not supported
27 
28 /// definition for crc handle.
29 typedef void *crc_handle_t;
30 
31 /*----- CRC Control Codes: Mode -----*/
32 typedef enum {
33     CRC_MODE_CRC8                   = 0,   ///< Mode CRC8
34     CRC_MODE_CRC16,                        ///< Mode CRC16
35     CRC_MODE_CRC32                         ///< Mode CRC32
36 } crc_mode_e;
37 
38 /*----- CRC Control Codes: Mode Parameters: Key length -----*/
39 typedef enum {
40     CRC_STANDARD_CRC_ROHC         = 0,    ///< Standard CRC RHOC
41     CRC_STANDARD_CRC_MAXIM,               ///< Standard CRC MAXIAM
42     CRC_STANDARD_CRC_X25,                 ///< Standard CRC X25
43     CRC_STANDARD_CRC_CCITT,               ///< Standard CRC CCITT
44     CRC_STANDARD_CRC_CCITT_FALSE,         ///< Standard CRC CCITT-FALSE
45     CRC_STANDARD_CRC_USB,                 ///< Standard CRC USB
46     CRC_STANDARD_CRC_IBM,                 ///< Standard CRC IBM
47     CRC_STANDARD_CRC_MODBUS,              ///< Standard CRC MODBUS
48     CRC_STANDARD_CRC_ITU,                 ///< Standard CRC ITU
49     CRC_STANDARD_CRC_PMEQ_2,              ///< Standard CRC PMEQ_2
50     CRC_STANDARD_CRC_XMODEM,              ///< Standard CRC XMODEM
51     CRC_STANDARD_CRC_DNP,                 ///< Standard CRC DNP
52     CRC_STANDARD_CRC_NONE,                ///< Standard CRC NONE
53 } crc_standard_crc_e;
54 
55 /**
56 \brief CRC Status
57 */
58 typedef struct {
59     uint32_t busy             : 1;        ///< busy flag
60 } crc_status_t;
61 
62 /****** CRC Event *****/
63 typedef enum {
64     CRC_EVENT_CALCULATE_COMPLETE  = 0,  ///< Calculate completed
65 } crc_event_e;
66 
67 typedef void (*crc_event_cb_t)(int32_t idx, crc_event_e event);   ///< Pointer to \ref crc_event_cb_t : CRC Event call back.
68 
69 /**
70 \brief CRC Device Driver Capabilities.
71 */
72 typedef struct {
73     uint32_t ROHC               : 1;      ///< supports ROHC mode
74     uint32_t MAXIM              : 1;      ///< supports MAXIM mode
75     uint32_t X25                : 1;      ///< supports X25 mode
76     uint32_t CCITT              : 1;      ///< supports CCITT mode
77     uint32_t CCITT_FALSE        : 1;      ///< supports CCITT-FALSE mode
78     uint32_t USB                : 1;      ///< supports USB mode
79     uint32_t IBM                : 1;      ///< supports IBM mode
80     uint32_t MODBUS             : 1;      ///< supports MODBUS mode
81     uint32_t ITU                : 1;      ///< supports ITU mode
82     uint32_t PMEQ_2             : 1;      ///< supports PMEQ_2 mode
83     uint32_t XMODEM             : 1;      ///< supports XMODEM mode
84     uint32_t DNP                : 1;      ///< supports DNP mode
85     uint32_t NONE               : 1;      ///< supports NONE mode
86 } crc_capabilities_t;
87 
88 // Function documentation
89 
90 /**
91   \brief       Initialize CRC Interface. 1. Initializes the resources needed for the CRC interface 2.registers event callback function
92   \param[in]   idx  device id
93   \param[in]   cb_event event callback function \ref crc_event_cb_t
94   \return      return crc handle if success
95 */
96 crc_handle_t csi_crc_initialize(int32_t idx, crc_event_cb_t cb_event);
97 
98 /**
99   \brief       De-initialize CRC Interface. stops operation and releases the software resources used by the interface
100   \param[in]   handle  crc handle to operate.
101   \return      error code
102 */
103 int32_t csi_crc_uninitialize(crc_handle_t handle);
104 
105 /**
106   \brief       control crc power.
107   \param[in]   handle  crc handle to operate.
108   \param[in]   state   power state.\ref csi_power_stat_e.
109   \return      error code
110 */
111 int32_t csi_crc_power_control(crc_handle_t handle, csi_power_stat_e state);
112 
113 /**
114   \brief       Get driver capabilities.
115   \param[in]   idx  device id
116   \return      \ref crc_capabilities_t
117 */
118 crc_capabilities_t csi_crc_get_capabilities(int32_t idx);
119 
120 /**
121   \brief       config crc mode.
122   \param[in]   handle  crc handle to operate.
123   \param[in]   mode      \ref crc_mode_e
124   \param[in]   standard  \ref crc_standard_crc_e
125   \return      error code
126 */
127 int32_t csi_crc_config(crc_handle_t handle,
128                        crc_mode_e mode,
129                        crc_standard_crc_e standard
130                       );
131 
132 /**
133   \brief       calculate crc. this function will pad zero if input data is not word aligned
134   \param[in]   handle  crc handle to operate.
135   \param[in]   in      Pointer to the input data
136   \param[out]  out     Pointer to the result.
137   \param[in]   len     intput data len.
138   \return      error code
139 */
140 int32_t csi_crc_calculate(crc_handle_t handle, const void *in, void *out, uint32_t len);
141 
142 /**
143   \brief       Get CRC status.
144   \param[in]   handle  crc handle to operate.
145   \return      CRC status \ref crc_status_t
146 */
147 crc_status_t csi_crc_get_status(crc_handle_t handle);
148 
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* _CSI_CRC_H_ */
155