MSPM0C110X Driver Library  2.05.01.00
dl_crc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, 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  */
32 /*!****************************************************************************
33  * @file dl_crc.h
34  * @brief Cyclic Redundancy Check (CRC) Driver Library
35  * @defgroup CRC Cyclic Redundancy Check (CRC)
36  *
37  * @anchor ti_dl_dl_crc_Overview
38  * # Overview
39  *
40  * The CRC DriverLib allows full configuration of the MSPM0 CRC module.
41  * The cyclic redundancy check (CRC) accelerator generates signatures for a
42  * given data sequence based on the CRC16-CCITT polynomial or the
43  * CRC32-ISO3309 polynomial.
44  *
45  * <hr>
46  ******************************************************************************
47  */
51 #ifndef ti_dl_dl_crc__include
52 #define ti_dl_dl_crc__include
53 
54 #include <stdbool.h>
55 #include <stdint.h>
56 
57 #include <ti/devices/msp/msp.h>
58 #include <ti/driverlib/dl_common.h>
59 
60 #ifdef __MSPM0_HAS_CRC__
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #if (CRC_SYS_CRC32_ENABLE == 1)
67 
70 #define DEVICE_HAS_CRC_32_BIT_POLYNOMIAL
71 #endif
72 
74 typedef enum {
77  DL_CRC_16_POLYNOMIAL = CRC_CRCCTRL_POLYSIZE_CRC16,
78 #ifdef DEVICE_HAS_CRC_32_BIT_POLYNOMIAL
79 
81  DL_CRC_32_POLYNOMIAL = CRC_CRCCTRL_POLYSIZE_CRC32
82 #endif /* DEVICE_HAS_CRC_32_BIT_POLYNOMIAL */
84 
86 typedef enum {
88  DL_CRC_BIT_REVERSED = CRC_CRCCTRL_BITREVERSE_REVERSED,
90  DL_CRC_BIT_NOT_REVERSED = CRC_CRCCTRL_BITREVERSE_NOT_REVERSED
91 } DL_CRC_BIT;
92 
94 typedef enum {
98  CRC_CRCCTRL_INPUT_ENDIANNESS_LITTLE_ENDIAN,
101  DL_CRC_INPUT_ENDIANESS_BIG_ENDIAN = CRC_CRCCTRL_INPUT_ENDIANNESS_BIG_ENDIAN
103 
105 typedef enum {
107  DL_CRC_OUTPUT_BYTESWAP_ENABLED = CRC_CRCCTRL_OUTPUT_BYTESWAP_ENABLE,
109  DL_CRC_OUTPUT_BYTESWAP_DISABLED = CRC_CRCCTRL_OUTPUT_BYTESWAP_DISABLE
111 
121 __STATIC_INLINE void DL_CRC_enablePower(CRC_Regs *crc)
122 {
123  crc->GPRCM.PWREN = (CRC_PWREN_KEY_UNLOCK_W | CRC_PWREN_ENABLE_ENABLE);
124 }
125 
136 __STATIC_INLINE void DL_CRC_disablePower(CRC_Regs *crc)
137 {
138  crc->GPRCM.PWREN = (CRC_PWREN_KEY_UNLOCK_W | CRC_PWREN_ENABLE_DISABLE);
139 }
140 
158 __STATIC_INLINE bool DL_CRC_isPowerEnabled(const CRC_Regs *crc)
159 {
160  return (
161  (crc->GPRCM.PWREN & CRC_PWREN_ENABLE_MASK) == CRC_PWREN_ENABLE_ENABLE);
162 }
163 
169 __STATIC_INLINE void DL_CRC_reset(CRC_Regs *crc)
170 {
171  crc->GPRCM.RSTCTL =
172  (CRC_RSTCTL_KEY_UNLOCK_W | CRC_RSTCTL_RESETSTKYCLR_CLR |
173  CRC_RSTCTL_RESETASSERT_ASSERT);
174 }
175 
185 __STATIC_INLINE bool DL_CRC_isReset(const CRC_Regs *crc)
186 {
187  return ((crc->GPRCM.STAT & CRC_STAT_RESETSTKY_MASK) ==
188  CRC_STAT_RESETSTKY_RESET);
189 }
190 
203 __STATIC_INLINE void DL_CRC_init(CRC_Regs *crc, DL_CRC_POLYNOMIAL poly,
204  DL_CRC_BIT bitOrd, DL_CRC_INPUT_ENDIANESS inEndianness,
205  DL_CRC_OUTPUT_BYTESWAP outByteSwap)
206 {
207  crc->CRCCTRL = ((uint32_t) poly | (uint32_t) bitOrd |
208  (uint32_t) inEndianness | (uint32_t) outByteSwap);
209 }
210 
223 __STATIC_INLINE void DL_CRC_setSeed16(CRC_Regs *crc, uint16_t seed)
224 {
225  volatile uintptr_t addr;
226  volatile uint16_t *pRef;
227 
228  addr = (uintptr_t)((volatile uintptr_t *) &crc->CRCSEED);
229  pRef = (volatile uint16_t *) addr;
230 
231  *pRef = seed;
232 }
233 
246 __STATIC_INLINE void DL_CRC_setSeed32(CRC_Regs *crc, uint32_t seed)
247 {
248  crc->CRCSEED = seed;
249 }
250 
259 __STATIC_INLINE void DL_CRC_feedData8(CRC_Regs *crc, uint8_t dataIn)
260 {
261  volatile uint8_t *pRef = (volatile uint8_t *) &crc->CRCIN;
262  *pRef = dataIn;
263 }
264 
273 __STATIC_INLINE void DL_CRC_feedData16(CRC_Regs *crc, uint16_t dataIn)
274 {
275  volatile uintptr_t addr;
276  volatile uint16_t *pRef;
277 
278  addr = (uintptr_t)((volatile uintptr_t *) &crc->CRCIN);
279  pRef = (volatile uint16_t *) addr;
280 
281  *pRef = dataIn;
282 }
283 
295 __STATIC_INLINE void DL_CRC_feedData32(CRC_Regs *crc, uint32_t dataIn)
296 {
297  crc->CRCIN = dataIn;
298 }
299 
307 __STATIC_INLINE uint16_t DL_CRC_getResult16(const CRC_Regs *crc)
308 {
309  return ((uint16_t) crc->CRCOUT);
310 }
311 
319 __STATIC_INLINE uint32_t DL_CRC_getResult32(const CRC_Regs *crc)
320 {
321  return (crc->CRCOUT);
322 }
323 
337 extern uint32_t DL_CRC_calculateBlock32(
338  CRC_Regs *crc, uint32_t seed, const uint32_t *ptr, uint32_t size);
339 
355 extern uint32_t DL_CRC_calculateMemoryRange32(
356  CRC_Regs *crc, uint32_t seed, uint32_t *ptrStart, const uint32_t *ptrEnd);
357 
371 extern uint16_t DL_CRC_calculateBlock16(
372  CRC_Regs *crc, uint16_t seed, const uint16_t *ptr, uint16_t size);
373 
389 extern uint16_t DL_CRC_calculateMemoryRange16(
390  CRC_Regs *crc, uint16_t seed, uint16_t *ptrStart, const uint16_t *ptrEnd);
391 
402 __STATIC_INLINE uintptr_t DL_CRC_getCRCINAddr(const CRC_Regs *crc)
403 {
404  return ((uintptr_t) &crc->CRCIN);
405 }
406 #ifdef __cplusplus
407 }
408 #endif
409 
410 #endif /* __MSPM0_HAS_CRC__ */
411 
412 #endif /* ti_dl_dl_crc__include */
413 
__STATIC_INLINE void DL_CRC_disablePower(CRC_Regs *crc)
Disables the Peripheral Write Enable (PWREN) register for the CRC.
Definition: dl_crc.h:136
__STATIC_INLINE void DL_CRC_feedData32(CRC_Regs *crc, uint32_t dataIn)
Feeds 32-bit data into the CRC calculation.
Definition: dl_crc.h:295
__STATIC_INLINE uint16_t DL_CRC_getResult16(const CRC_Regs *crc)
Returns the result from the 16-bit polynomial calculation.
Definition: dl_crc.h:307
__STATIC_INLINE void DL_CRC_setSeed16(CRC_Regs *crc, uint16_t seed)
Initializes the seed for a 16-bit polynomial CRC calculation.
Definition: dl_crc.h:223
DL_CRC_BIT
Definition: dl_crc.h:86
uint32_t DL_CRC_calculateMemoryRange32(CRC_Regs *crc, uint32_t seed, uint32_t *ptrStart, const uint32_t *ptrEnd)
Calculates the CRC over a memory range.
__STATIC_INLINE void DL_CRC_feedData16(CRC_Regs *crc, uint16_t dataIn)
Feeds 16-bit data into the CRC calculation.
Definition: dl_crc.h:273
__STATIC_INLINE void DL_CRC_feedData8(CRC_Regs *crc, uint8_t dataIn)
Feeds 8-bit data into the CRC calculation.
Definition: dl_crc.h:259
Definition: dl_crc.h:90
DriverLib Common APIs.
__STATIC_INLINE void DL_CRC_setSeed32(CRC_Regs *crc, uint32_t seed)
Initializes the seed for a 32-bit polynomial CRC calculation.
Definition: dl_crc.h:246
__STATIC_INLINE uint32_t DL_CRC_getResult32(const CRC_Regs *crc)
Returns the result from the 32-bit polynomial calculation.
Definition: dl_crc.h:319
Definition: dl_crc.h:88
__STATIC_INLINE void DL_CRC_reset(CRC_Regs *crc)
Resets crc peripheral.
Definition: dl_crc.h:169
DL_CRC_OUTPUT_BYTESWAP
Definition: dl_crc.h:105
Definition: dl_crc.h:101
__STATIC_INLINE uintptr_t DL_CRC_getCRCINAddr(const CRC_Regs *crc)
Returns the address of the CRC input data register.
Definition: dl_crc.h:402
__STATIC_INLINE void DL_CRC_init(CRC_Regs *crc, DL_CRC_POLYNOMIAL poly, DL_CRC_BIT bitOrd, DL_CRC_INPUT_ENDIANESS inEndianness, DL_CRC_OUTPUT_BYTESWAP outByteSwap)
Initializes CRC.
Definition: dl_crc.h:203
Definition: dl_crc.h:107
DL_CRC_POLYNOMIAL
Definition: dl_crc.h:74
uint16_t DL_CRC_calculateBlock16(CRC_Regs *crc, uint16_t seed, const uint16_t *ptr, uint16_t size)
Calculates the CRC over a range of 16-bit values.
uint16_t DL_CRC_calculateMemoryRange16(CRC_Regs *crc, uint16_t seed, uint16_t *ptrStart, const uint16_t *ptrEnd)
Calculates the CRC over a memory range.
__STATIC_INLINE void DL_CRC_enablePower(CRC_Regs *crc)
Enables the Peripheral Write Enable (PWREN) register for the CRC.
Definition: dl_crc.h:121
DL_CRC_INPUT_ENDIANESS
Definition: dl_crc.h:94
Definition: dl_crc.h:77
uint32_t DL_CRC_calculateBlock32(CRC_Regs *crc, uint32_t seed, const uint32_t *ptr, uint32_t size)
Calculates the CRC over a range of 32-bit values.
__STATIC_INLINE bool DL_CRC_isPowerEnabled(const CRC_Regs *crc)
Returns if the Peripheral Write Enable (PWREN) register for the CRC is enabled.
Definition: dl_crc.h:158
Definition: dl_crc.h:109
__STATIC_INLINE bool DL_CRC_isReset(const CRC_Regs *crc)
Returns if crc module has been reset.
Definition: dl_crc.h:185
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale