1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 #ifndef _CRC_32_H
33 
34 //*****************************************************************************
35 //
36 //! \addtogroup crc32_api
37 //! @{
38 //
39 //*****************************************************************************
40 
41 #include <stdint.h>
42 
43 #define CRC16_MODE 0x00
44 #define CRC32_MODE 0x01
45 
46 //*****************************************************************************
47 //
48 //! Sets the seed for the CRC.
49 //!
50 //! \param seed is the seed for the CRC to start generating a signature from.
51 //!        Modified bits are \b CRC16INIRESL0 of \b CRC16INIRESL0 register.
52 //!            \b CRC32INIRESL0 of \b CRC32INIRESL0 register
53 //! \param crcType selects between CRC32 and CRC16
54 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
55 //!
56 //! This function sets the seed for the CRC to begin generating a signature with
57 //! the given seed and all passed data. Using this function resets the CRC32
58 //! signature.
59 //!
60 //! \return NONE
61 //
62 //*****************************************************************************
63 extern void CRC32_setSeed(uint32_t seed, uint_fast8_t crcType);
64 
65 //*****************************************************************************
66 //
67 //! Sets the 8 Bit data to add into the CRC module to generate a new signature.
68 //!
69 //! \param dataIn is the data to be added, through the CRC module, to the
70 //!       signature.
71 //!        Modified bits are \b CRC16DIB0 of \b CRC16DIB0 register.
72 //!                            \b CRC32DIB0 of \b CRC32DIB0 register.
73 //! \param crcType selects between CRC32 and CRC16
74 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
75 //!
76 //! This function sets the given data into the CRC module to generate the new
77 //! signature from the current signature and new data. Bit 0 is
78 //!    treated as LSB.
79 //!
80 //! \return NONE
81 //
82 //*****************************************************************************
83 extern void CRC32_set8BitData(uint8_t dataIn, uint_fast8_t crcType);
84 
85 //*****************************************************************************
86 //
87 //! Sets the 16 Bit data to add into the CRC module to generate a new signature.
88 //!
89 //! \param dataIn is the data to be added, through the CRC module, to the
90 //!       signature.
91 //!        Modified bits are \b CRC16DIW0 of \b CRC16DIW0 register.
92 //!                          \b CRC32DIW0 of \b CRC32DIW0 register.
93 //! \param crcType selects between CRC32 and CRC16
94 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
95 //!
96 //! This function sets the given data into the CRC module to generate the new
97 //! signature from the current signature and new data. Bit 0 is
98 //!    treated as LSB
99 //!
100 //! \return NONE
101 //
102 //*****************************************************************************
103 extern void CRC32_set16BitData(uint16_t dataIn, uint_fast8_t crcType);
104 
105 //*****************************************************************************
106 //
107 //! Sets the 32 Bit data to add into the CRC module to generate a new signature.
108 //!    Available only for CRC32_MODE and not for CRC16_MODE
109 //! \param dataIn is the data to be added, through the CRC module, to the
110 //!       signature.
111 //!        Modified bits are \b CRC32DIL0 of \b CRC32DIL0 register.
112 //!
113 //! This function sets the given data into the CRC module to generate the new
114 //! signature from the current signature and new data. Bit 0 is
115 //!    treated as LSB
116 //!
117 //! \return NONE
118 //
119 //*****************************************************************************
120 extern void CRC32_set32BitData(uint32_t dataIn);
121 
122 //*****************************************************************************
123 //
124 //! Translates the data by reversing the bits in each 8 bit data and then sets
125 //! this data to add into the CRC module to generate a new signature.
126 //!
127 //! \param dataIn is the data to be added, through the CRC module, to the
128 //!       signature.
129 //!        Modified bits are \b CRC16DIRBB0 of \b CRC16DIRBB0 register.
130 //!                             \b CRC32DIRBB0 of \b CRC32DIRBB0 register.
131 //! \param crcType selects between CRC32 and CRC16
132 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
133 //!
134 //! This function first reverses the bits in each byte of the data and then
135 //! generates the new signature from the current signature and new translated
136 //! data. Bit 0 is treated as MSB.
137 //!
138 //! \return NONE
139 //
140 //*****************************************************************************
141 extern void CRC32_set8BitDataReversed(uint8_t dataIn, uint_fast8_t crcType);
142 
143 //*****************************************************************************
144 //
145 //! Translates the data by reversing the bits in each 16 bit data and then
146 //!    sets this data to add into the CRC module to generate a new signature.
147 //!
148 //! \param dataIn is the data to be added, through the CRC module, to the
149 //!       signature.
150 //!        Modified bits are \b CRC16DIRBW0 of \b CRC16DIRBW0 register.
151 //!                             \b CRC32DIRBW0 of \b CRC32DIRBW0 register.
152 //! \param crcType selects between CRC32 and CRC16
153 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
154 //!
155 //! This function first reverses the bits in each byte of the data and then
156 //! generates the new signature from the current signature and new translated
157 //! data.  Bit 0 is treated as MSB.
158 //!
159 //! \return NONE
160 //
161 //*****************************************************************************
162 extern void CRC32_set16BitDataReversed(uint16_t dataIn, uint_fast8_t crcType);
163 
164 //*****************************************************************************
165 //
166 //! Translates the data by reversing the bits in each 32 Bit Data and then
167 //!    sets this data to add into the CRC module to generate a new signature.
168 //!    Available only for CRC32 mode and not for CRC16 mode
169 //! \param dataIn is the data to be added, through the CRC module, to the
170 //!       signature.
171 //!        Modified bits are \b CRC32DIRBL0 of \b CRC32DIRBL0 register.
172 //!
173 //! This function first reverses the bits in each byte of the data and then
174 //! generates the new signature from the current signature and new translated
175 //! data.  Bit 0 is treated as MSB.
176 //!
177 //! \return NONE
178 //
179 //*****************************************************************************
180 extern void CRC32_set32BitDataReversed(uint32_t dataIn);
181 
182 //*****************************************************************************
183 //
184 //! Returns the value of CRC Signature Result.
185 //!
186 //! \param crcType selects between CRC32 and CRC16
187 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
188 //!
189 //! This function returns the value of the signature result generated by the CRC.
190 //! Bit 0 is treated as LSB.
191 //! \return uint32_t Result
192 //
193 //*****************************************************************************
194 extern uint32_t CRC32_getResult(uint_fast8_t crcType);
195 
196 //*****************************************************************************
197 //
198 //! Returns the bit-wise reversed format of the 32 bit Signature Result.
199 //!
200 //! \param crcType selects between CRC32 and CRC16
201 //!            Valid values are \b CRC16_MODE and \b CRC32_MODE
202 //!
203 //! This function returns the bit-wise reversed format of the Signature Result.
204 //! Bit 0 is treated as MSB.
205 //!
206 //! \return uint32_t Result
207 //
208 //*****************************************************************************
209 extern uint32_t CRC32_getResultReversed(uint_fast8_t crcType);
210 
211 /* Defines for future devices that might have multiple instances */
212 #define CRC32_setSeedMultipleInstance(a,b,c) CRC32_setSeed(b,c)
213 #define CRC32_set8BitDataMultipleInstance(a,b,c)  CRC32_set8BitData(b,c)
214 #define CRC32_set16BitDataMultipleInstance(a,b,c) CRC32_set16BitData(b,c)
215 #define CRC32_set32BitDataMultipleInstance(a,b) CRC32_set32BitData(b)
216 #define CRC32_set8BitDataReversedMultipleInstance(a,b,c) CRC32_set8BitDataReversed(b,c)
217 #define CRC32_set16BitDataReversedMultipleInstance(a,b,c) CRC32_set16BitDataReversed(b,c)
218 #define CRC32_set32BitDataReversedMultipleInstance(a,b) CRC32_set32BitDataReversed(b)
219 #define CRC32_getResultMultipleInstance(a,b) CRC32_getResult()
220 #define CRC32_getResultReversedMultipleInstance(a,b) CRC32_getResultReversed(b)
221 
222 //*****************************************************************************
223 //
224 // Close the Doxygen group.
225 //! @}
226 //
227 //*****************************************************************************
228 
229 
230 #endif
231