tao_z
2022-06-11 d8a5f3225d105585a4f181ed884adb2a861e0d13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
  ******************************************************************************
  * @file     xl_CRC.h
  * @author   software group
  * @brief    This file contains all the functions prototypes for the CRC
  *           firmware library.
  ******************************************************************************
  * @attention
    *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
#ifndef XL_CRC_H__
#define XL_CRC_H__
 
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ---------------------------------------------------------------*/
#include "XL6600.h"
 
/* Register define ------------------------------------------------------------*/
/* CTRL Bit Fields */
#define CRC_CTRL_CALC_MASK                       0x1u
#define CRC_CTRL_CALC_SHIFT                      0
#define CRC_CTRL_INIT_MASK                       0x2u
#define CRC_CTRL_INIT_SHIFT                      1
#define CRC_CTRL_TCRC_MASK                       0x4u
#define CRC_CTRL_TCRC_SHIFT                      2
#define CRC_CTRL_TOT_MASK                        0x300u
#define CRC_CTRL_TOT_SHIFT                       8
#define CRC_CTRL_INV_MASK                        0x800u
#define CRC_CTRL_INV_SHIFT                       11
#define CRC_CTRL_T16_MASK                        0x1000u
#define CRC_CTRL_T16_SHIFT                       12
 
/* GPOLY Bit Fields */
#define CRC_GPOLY_LOW_MASK                       0xFFFFu
#define CRC_GPOLY_LOW_SHIFT                      0
#define CRC_GPOLY_HIGH_MASK                      0xFFFF0000u
#define CRC_GPOLY_HIGH_SHIFT                     16
 
/* INIT Bit Fields */
#define CRC_INIT_LOW_MASK                        0xFFFFu
#define CRC_INIT_LOW_SHIFT                       0
#define CRC_INIT_HIGH_MASK                       0xFFFF0000u
#define CRC_INIT_HIGH_SHIFT                      16
 
/* DATAIN Bit Fields */
#define CRC_DATAIN_MASK                          0xFFu
#define CRC_DATAIN_SHIFT                         0
 
/* DATAOUT Bit Fields */
#define CRC_DATAOUT_LOW_MASK                     0xFFFFu
#define CRC_DATAOUT_LOW_SHIFT                    0
#define CRC_DATAOUT_HIGH_MASK                    0xFFFF0000u
#define CRC_DATAOUT_HIGH_SHIFT                   16
 
    
#define CRC_InitStatus_Failed                           ((uint8_t)0x00)       /*!< CRC³õʼ»¯Ê§°Ü */
#define CRC_InitStatus_Success                          ((uint8_t)0x01)          /*!< CRC³õʼ»¯³É¹¦ */
 
/** CRC - Register Layout Typedef */
typedef struct {
  __IO uint32_t CTRL;                              /*!< CRCÅäÖüĴæÆ÷, offset: 0x0 */
  __IO uint32_t GPOLY;                             /*!< CRC¶àÏîʽ¼Ä´æÆ÷, offset: 0x4 */     
  __IO uint32_t INIT;                              /*!< CRC³õʼֵ¼Ä´æÆ÷, offset: 0x8 */
  __O  uint32_t DATAIN;                            /*!< CRCÊý¾ÝÊäÈë¼Ä´æÆ÷, offset: 0x0C */
  __I  uint32_t DATAOUT;                           /*!< CRCÊý¾ÝÊä³ö¼Ä´æÆ÷, offset: 0x10 */
     
} CRC_Type;
extern CRC_Type* CRC;    
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @addtogroup CRC 
  * @{
  */
 
/* Exported types ------------------------------------------------------------*/ 
 
/**
  * @brief  CRC ³õʼ»¯½á¹¹Ì嶨Òå
  */
typedef struct
{
    uint32_t  CRC_PolyData;                                        /*!< CRC¼ÆËãËùÐèµÄ¶àÏîʽֵ */
    uint8_t   CRC_DataWidth;                                      /*!< CRCЭÒé¿í¶È£¬0£º16λCRCЭÒé ,1£º32λCRCЭÒé */
    uint8_t   CRC_WriteTranspose;                               /*!< Ð´×ªÖà*/
    uint8_t     CRC_Transpose16Only;                                  /*!< ½öÔÚ16λÊý¾ÝÄÚתÖà*/
    uint8_t   CRC_DataOutInvert;                                  /*!< CRC¼ÆËã½á¹ûÈ¡·´ */
 
}CRC_InitTypeDef;
 
/* Exported constants --------------------------------------------------------*/
/** @defgroup CRC_Exported_Constants CRCÄ£¿éʹÓòÎÊý¶¨Òå
  * @{
  */
 
/**
    * @defgroup CRC_Mode_Select CRCУÑéģʽѡÔñ
    * @{
    */
#define    CRC16_TRANSPOSE_IN32                   0              /*!< CRC16¼ÆËã½á¹ûÔÚ32λÊý¾ÝÄÚתÖà*/
#define    CRC16_TRANSPOSE_IN16                   1              /*!< CRC16¼ÆËã½á¹û½öÔÚ16λÊý¾ÝÄÚתÖà*/
/**
  * @}
  */
 
/**
    * @defgroup CRC_OutData_Invert CRCÊä³ö½á¹ûתÖÃ
    * @{
    */
#define    CRC_DATAOUT_NoInvert                   0              /*!< CRC¼ÆËã½á¹û²»È¡·´ */
#define    CRC_DATAOUT_Invert                     1              /*!< CRC¼ÆËã½á¹ûÈ¡·´ */
/**
  * @}
  */
    
/**
    * @defgroup CRC_Data_Transpose CRCÊý¾Ý·­×ª
    * @{
    */
#define    CRC_NoTranspose                              0                    /*!< Õý³£Êä³öCRC½á¹û£¬²»½øÐÐתÖà*/
#define    CRC_TransposeBytes                           1                    /*!< ½ö×Ö½ÚתÖã»×Ö½ÚÖеÄλ²»×ªÖà*/
#define    CRC_TransposeBits                            2                    /*!< ×Ö½ÚÖеÄλתÖã»×Ö½Ú²»×ªÖà*/
#define    CRC_TransposeBoth                            3                    /*!< ×Ö½ÚÖеÄλºÍ×Ö½Ú¾ùתÖà*/
/**
  * @}
  */
    
/**
    * @defgroup CRC_Data_Width CRCÊý¾ÝУÑé¿í¶È
    * @{
    */
#define    CRC_Width16Bits                              0u                   /*!< 16λCRCЭÒé */
#define    CRC_Width32Bits                           1u                   /*!< 32λCRCЭÒé */
/**
  * @}
  */
 
/**
  * @}
  */
 
/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/ 
void CRC_Deinit(void);
void CRC_Init(const CRC_InitTypeDef * CRC_InitStruct);
uint16_t CRC_Cal16(uint32_t InitValue, const uint8_t *msg, uint32_t SizeBytes);
uint16_t CRC_Cal16_Fast(uint32_t InitValue, const uint8_t *msg, uint32_t SizeBytes);
uint32_t CRC_Cal32(uint32_t InitValue, const uint8_t *msg, uint32_t SizeBytes);
uint32_t CRC_Cal32Fast(uint32_t InitValue, const uint8_t *msg, uint32_t SizeBytes);
    
#ifdef __cplusplus
}
#endif
 
#endif /*__XL_CRC_H__ */    
/**
  * @}
  */
 
/**
  * @}
  */