MSPM0L111X Driver Library  2.05.01.00
dl_crcp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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_crcp.h
34  * @brief Cyclic Redundancy Check with Configurable Polynomial (CRCP) Driver Library
35  * @defgroup CRCP Cyclic Redundancy Check with Configurable Polynomial (CRCP)
36  *
37  * @anchor ti_dl_dl_crcp_Overview
38  * # Overview
39  *
40  * The CRCP DriverLib allows full configuration of the MSPM0 CRCP module.
41  * The cyclic redundancy check (CRC) accelerator generates signatures for a
42  * given data sequence based on a user-configured polynomial, allowing for
43  * support of any 16-bit or 32-bit polynomial including but not limited to:
44  * * CRC32-IS03309
45  * * CRC16-ITT
46  * * CRC-32C
47  * * CRC-32K
48  * * CRC-16-Profibus
49  *
50  * <hr>
51  ******************************************************************************
52  */
56 #ifndef ti_dl_dl_crcp__include
57 #define ti_dl_dl_crcp__include
58 
59 #include <stdbool.h>
60 #include <stdint.h>
61 
62 #include <ti/devices/msp/msp.h>
63 #include <ti/driverlib/dl_common.h>
64 
65 #ifdef __MSPM0_HAS_CRCP__
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 /* clang-format off */
72 
77 #define DL_CRC_POLYNOMIAL_SIZE_16 DL_CRCP_POLYNOMIAL_SIZE_16
78 
83 #define DL_CRC_POLYNOMIAL_SIZE_32 DL_CRCP_POLYNOMIAL_SIZE_32
84 
89 #define DL_CRC_BIT_REVERSED DL_CRCP_BIT_REVERSED
90 
95 #define DL_CRC_BIT_NOT_REVERSED DL_CRCP_BIT_NOT_REVERSED
96 
101 #define DL_CRC_INPUT_ENDIANESS_LITTLE_ENDIAN \
102  DL_CRCP_INPUT_ENDIANESS_LITTLE_ENDIAN
103 
108 #define DL_CRC_INPUT_ENDIANESS_BIG_ENDIAN DL_CRCP_INPUT_ENDIANESS_BIG_ENDIAN
109 
114 #define DL_CRC_OUTPUT_BYTESWAP_ENABLED DL_CRCP_OUTPUT_BYTESWAP_ENABLED
115 
120 #define DL_CRC_OUTPUT_BYTESWAP_DISABLED DL_CRCP_OUTPUT_BYTESWAP_DISABLED
121 
126 #define DL_CRC_CRCPOLY_POLYNOMIAL_32_MPEG2 DL_CRCP_CRCPOLY_POLYNOMIAL_32_MPEG2
127 
132 #define DL_CRC_CRCPOLY_POLYNOMIAL_32_Q DL_CRCP_CRCPOLY_POLYNOMIAL_32_Q
133 
138 #define DL_CRC_CRCPOLY_POLYNOMIAL_32_JAMCRC \
139  DL_CRCP_CRCPOLY_POLYNOMIAL_32_JAMCRC
140 
145 #define DL_CRC_CRCPOLY_POLYNOMIAL_32_XFER \
146  DL_CRCP_CRCPOLY_POLYNOMIAL_32_XFER
147 
152 #define DL_CRC_CRCPOLY_POLYNOMIAL_32_MPEG2 DL_CRCP_CRCPOLY_POLYNOMIAL_32_MPEG2
153 
158 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_CCIT_ZERO \
159  DL_CRCP_CRCPOLY_POLYNOMIAL_16_CCIT_ZERO
160 
165 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_ARC \
166  DL_CRCP_CRCPOLY_POLYNOMIAL_16_ARC
167 
172 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_AUG_CCIT \
173  DL_CRCP_CRCPOLY_POLYNOMIAL_16_AUG_CCIT
174 
179 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_BUYPASS \
180  DL_CRCP_CRCPOLY_POLYNOMIAL_16_BUYPASS
181 
186 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_CCIT_FALSE \
187  DL_CRCP_CRCPOLY_POLYNOMIAL_16_CCIT_FALSE
188 
193 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_CDMA2000 \
194  DL_CRCP_CRCPOLY_POLYNOMIAL_16_CDMA2000
195 
200 #define DL_CRC_CRCPOLY_POLYNOMIAL_16_MODBUS \
201  DL_CRCP_CRCPOLY_POLYNOMIAL_16_MODBUS
202 
207 #define DL_CRC_CRCSEED_SEED_32_MPEG2 DL_CRCP_CRCSEED_SEED_32_MPEG2
208 
213 #define DL_CRC_CRCSEED_SEED_32_Q DL_CRCP_CRCSEED_SEED_32_Q
214 
219 #define DL_CRC_CRCSEED_SEED_32_JAMCRC DL_CRCP_CRCSEED_SEED_32_JAMCRC
220 
225 #define DL_CRC_CRCSEED_SEED_32_XFER DL_CRCP_CRCSEED_SEED_32_XFER
226 
231 #define DL_CRC_CRCSEED_SEED_32_MPEG2 DL_CRCP_CRCSEED_SEED_32_MPEG2
232 
237 #define DL_CRC_CRCSEED_SEED_16_AUG_CCIT DL_CRCP_CRCSEED_SEED_16_AUG_CCIT
238 
243 #define DL_CRC_CRCSEED_SEED_16_BUYPASS DL_CRCP_CRCSEED_SEED_16_BUYPASS
244 
249 #define DL_CRC_CRCSEED_SEED_16_CCIT_FALSE DL_CRCP_CRCSEED_SEED_16_CCIT_FALSE
250 
255 #define DL_CRC_CRCSEED_SEED_16_CDMA2000 DL_CRCP_CRCSEED_SEED_16_CDMA2000
256 
261 #define DL_CRC_CRCSEED_SEED_16_MODBUS DL_CRCP_CRCSEED_SEED_16_MODBUS
262 
267 #define DL_CRC_enablePower DL_CRCP_enablePower
268 
273 #define DL_CRC_isPowerEnabled DL_CRCP_isPowerEnabled
274 
279 #define DL_CRC_reset DL_CRCP_reset
280 
285 #define DL_CRC_isReset DL_CRCP_isReset
286 
291 #define DL_CRC_init DL_CRCP_init
292 
297 #define DL_CRC_setSeed16 DL_CRCP_setSeed16
298 
303 #define DL_CRC_setSeed32 DL_CRCP_setSeed32
304 
309 #define DL_CRC_feedData8 DL_CRCP_feedData8
310 
315 #define DL_CRC_feedData16 DL_CRCP_feedData16
316 
321 #define DL_CRC_feedData32 DL_CRCP_feedData32
322 
327 #define DL_CRC_getResult16 DL_CRCP_getResult16
328 
333 #define DL_CRC_getResult32 DL_CRCP_getResult32
334 
339 #define DL_CRC_setPolynomial DL_CRCP_setPolynomial
340 
345 #define DL_CRC_getPolynomial DL_CRCP_getPolynomial
346 
351 #define DL_CRC_calculateBlock32 DL_CRCP_calculateBlock32
352 
357 #define DL_CRC_calculateMemoryRange32 DL_CRCP_calculateMemoryRange32
358 
363 #define DL_CRC_calculateBlock16 DL_CRCP_calculateBlock16
364 
369 #define DL_CRC_calculateMemoryRange16 DL_CRCP_calculateMemoryRange16
370 
375 #define DL_CRC_getCRCINAddr DL_CRCP_getCRCINAddr
376 
377 /* clang-format on */
378 
380 typedef enum {
384  DL_CRCP_POLYNOMIAL_SIZE_16 = CRCP_CRCCTRL_POLYSIZE_CRC16,
387  DL_CRCP_POLYNOMIAL_SIZE_32 = CRCP_CRCCTRL_POLYSIZE_CRC32
389 
391 typedef enum {
393  DL_CRCP_BIT_REVERSED = CRCP_CRCCTRL_BITREVERSE_REVERSED,
395  DL_CRCP_BIT_NOT_REVERSED = CRCP_CRCCTRL_BITREVERSE_NOT_REVERSED
396 } DL_CRCP_BIT;
397 
399 typedef enum {
403  CRCP_CRCCTRL_INPUT_ENDIANNESS_LITTLE_ENDIAN,
407  CRCP_CRCCTRL_INPUT_ENDIANNESS_BIG_ENDIAN
409 
411 typedef enum {
413  DL_CRCP_OUTPUT_BYTESWAP_ENABLED = CRCP_CRCCTRL_OUTPUT_BYTESWAP_ENABLE,
415  DL_CRCP_OUTPUT_BYTESWAP_DISABLED = CRCP_CRCCTRL_OUTPUT_BYTESWAP_DISABLE
417 
425 typedef enum {
426 
460 
462 
470 typedef enum {
471 
505 
507 
517 __STATIC_INLINE void DL_CRCP_enablePower(CRCP_Regs *crcp)
518 {
519  crcp->GPRCM.PWREN = (CRCP_PWREN_KEY_UNLOCK_W | CRCP_PWREN_ENABLE_ENABLE);
520 }
521 
532 __STATIC_INLINE void DL_CRCP_disablePower(CRCP_Regs *crcp)
533 {
534  crcp->GPRCM.PWREN = (CRCP_PWREN_KEY_UNLOCK_W | CRCP_PWREN_ENABLE_DISABLE);
535 }
536 
554 __STATIC_INLINE bool DL_CRCP_isPowerEnabled(const CRCP_Regs *crcp)
555 {
556  return ((crcp->GPRCM.PWREN & CRCP_PWREN_ENABLE_MASK) ==
557  CRCP_PWREN_ENABLE_ENABLE);
558 }
559 
565 __STATIC_INLINE void DL_CRCP_reset(CRCP_Regs *crcp)
566 {
567  crcp->GPRCM.RSTCTL =
568  (CRCP_RSTCTL_KEY_UNLOCK_W | CRCP_RSTCTL_RESETSTKYCLR_CLR |
569  CRCP_RSTCTL_RESETASSERT_ASSERT);
570 }
571 
581 __STATIC_INLINE bool DL_CRCP_isReset(const CRCP_Regs *crcp)
582 {
583  return ((crcp->GPRCM.STAT & CRCP_STAT_RESETSTKY_MASK) ==
584  CRCP_STAT_RESETSTKY_RESET);
585 }
586 
600 __STATIC_INLINE void DL_CRCP_init(CRCP_Regs *crcp,
601  DL_CRCP_POLYNOMIAL_SIZE polySize, DL_CRCP_BIT bitOrd,
602  DL_CRCP_INPUT_ENDIANESS inEndianness, DL_CRCP_OUTPUT_BYTESWAP outByteSwap)
603 {
604  crcp->CRCCTRL = ((uint32_t) polySize | (uint32_t) bitOrd |
605  (uint32_t) inEndianness | (uint32_t) outByteSwap);
606 }
607 
623 __STATIC_INLINE void DL_CRCP_setSeed16(CRCP_Regs *crcp, uint16_t seed)
624 {
625  volatile uintptr_t addr;
626  volatile uint16_t *pRef;
627 
628  addr = (uintptr_t)((volatile uintptr_t *) &crcp->CRCSEED);
629  pRef = (volatile uint16_t *) addr;
630 
631  *pRef = seed;
632 }
633 
649 __STATIC_INLINE void DL_CRCP_setSeed32(CRCP_Regs *crcp, uint32_t seed)
650 {
651  crcp->CRCSEED = seed;
652 }
653 
662 __STATIC_INLINE void DL_CRCP_feedData8(CRCP_Regs *crcp, uint8_t dataIn)
663 {
664  volatile uint8_t *pRef = (volatile uint8_t *) &crcp->CRCIN;
665  *pRef = dataIn;
666 }
667 
676 __STATIC_INLINE void DL_CRCP_feedData16(CRCP_Regs *crcp, uint16_t dataIn)
677 {
678  volatile uintptr_t addr;
679  volatile uint16_t *pRef;
680 
681  addr = (uintptr_t)((volatile uintptr_t *) &crcp->CRCIN);
682  pRef = (volatile uint16_t *) addr;
683 
684  *pRef = dataIn;
685 }
686 
698 __STATIC_INLINE void DL_CRCP_feedData32(CRCP_Regs *crcp, uint32_t dataIn)
699 {
700  crcp->CRCIN = dataIn;
701 }
702 
715 __STATIC_INLINE uint16_t DL_CRCP_getResult16(const CRCP_Regs *crcp)
716 {
717  return ((uint16_t) crcp->CRCOUT);
718 }
719 
735 __STATIC_INLINE uint32_t DL_CRCP_getResult32(const CRCP_Regs *crcp)
736 {
737  return (crcp->CRCOUT);
738 }
739 
754 __STATIC_INLINE void DL_CRCP_setPolynomial(CRCP_Regs *crcp, uint32_t poly)
755 {
756  crcp->CRCPOLY = poly;
757 }
758 
772 __STATIC_INLINE uint32_t DL_CRCP_getPolynomial(const CRCP_Regs *crcp)
773 {
774  return (crcp->CRCPOLY);
775 }
776 
790 extern uint32_t DL_CRCP_calculateBlock32(
791  CRCP_Regs *crcp, uint32_t seed, const uint32_t *ptr, uint32_t size);
792 
808 extern uint32_t DL_CRCP_calculateMemoryRange32(CRCP_Regs *crcp, uint32_t seed,
809  uint32_t *ptrStart, const uint32_t *ptrEnd);
810 
824 extern uint16_t DL_CRCP_calculateBlock16(
825  CRCP_Regs *crcp, uint16_t seed, const uint16_t *ptr, uint16_t size);
826 
842 extern uint16_t DL_CRCP_calculateMemoryRange16(CRCP_Regs *crcp, uint16_t seed,
843  uint16_t *ptrStart, const uint16_t *ptrEnd);
844 
855 __STATIC_INLINE uintptr_t DL_CRCP_getCRCINAddr(const CRCP_Regs *crcp)
856 {
857  return ((uintptr_t) &crcp->CRCIN);
858 }
859 #ifdef __cplusplus
860 }
861 #endif
862 
863 #endif /* __MSPM0_HAS_CRCP__ */
864 
865 #endif /* ti_dl_DL_CRCP__include */
866 
DL_CRCP_POLYNOMIAL_SIZE
Definition: dl_crcp.h:380
Definition: dl_crcp.h:444
__STATIC_INLINE uint32_t DL_CRCP_getResult32(const CRCP_Regs *crcp)
Returns the result from the 32-bit polynomial calculation.
Definition: dl_crcp.h:735
DL_CRCP_OUTPUT_BYTESWAP
Definition: dl_crcp.h:411
Definition: dl_crcp.h:495
__STATIC_INLINE void DL_CRCP_setSeed16(CRCP_Regs *crcp, uint16_t seed)
Initializes the seed for a 16-bit polynomial CRC calculation.
Definition: dl_crcp.h:623
__STATIC_INLINE uint16_t DL_CRCP_getResult16(const CRCP_Regs *crcp)
Returns the result from the 16-bit polynomial calculation.
Definition: dl_crcp.h:715
Definition: dl_crcp.h:384
Definition: dl_crcp.h:498
__STATIC_INLINE void DL_CRCP_disablePower(CRCP_Regs *crcp)
Disables the Peripheral Write Enable (PWREN) register for the CRCP.
Definition: dl_crcp.h:532
Definition: dl_crcp.h:413
Definition: dl_crcp.h:406
__STATIC_INLINE void DL_CRCP_setSeed32(CRCP_Regs *crcp, uint32_t seed)
Initializes the seed for a 32-bit polynomial CRC calculation.
Definition: dl_crcp.h:649
__STATIC_INLINE void DL_CRCP_setPolynomial(CRCP_Regs *crcp, uint32_t poly)
Sets the active polynomial terms for the CRC calculation.
Definition: dl_crcp.h:754
DL_CRCP_CRCSEED_SEED
seeds for commonly used pre-defined polynomials to be used by CRCP as mentioned by the website http:/...
Definition: dl_crcp.h:470
Definition: dl_crcp.h:459
Definition: dl_crcp.h:387
__STATIC_INLINE void DL_CRCP_feedData32(CRCP_Regs *crcp, uint32_t dataIn)
Feeds 32-bit data into the CRC calculation.
Definition: dl_crcp.h:698
DriverLib Common APIs.
__STATIC_INLINE void DL_CRCP_reset(CRCP_Regs *crcp)
Resets CRCP peripheral.
Definition: dl_crcp.h:565
DL_CRCP_CRCPOLY_POLYNOMIAL
commonly used pre-defined polynomials to be used by CRCP as mentioned by the website http://www...
Definition: dl_crcp.h:425
__STATIC_INLINE void DL_CRCP_enablePower(CRCP_Regs *crcp)
Enables the Peripheral Write Enable (PWREN) register for the CRCP.
Definition: dl_crcp.h:517
__STATIC_INLINE void DL_CRCP_init(CRCP_Regs *crcp, DL_CRCP_POLYNOMIAL_SIZE polySize, DL_CRCP_BIT bitOrd, DL_CRCP_INPUT_ENDIANESS inEndianness, DL_CRCP_OUTPUT_BYTESWAP outByteSwap)
Initializes the CRCP peripheral.
Definition: dl_crcp.h:600
Definition: dl_crcp.h:486
Definition: dl_crcp.h:429
uint32_t DL_CRCP_calculateMemoryRange32(CRCP_Regs *crcp, uint32_t seed, uint32_t *ptrStart, const uint32_t *ptrEnd)
Calculates the CRC over a memory range.
Definition: dl_crcp.h:477
uint16_t DL_CRCP_calculateBlock16(CRCP_Regs *crcp, uint16_t seed, const uint16_t *ptr, uint16_t size)
Calculates the CRC over a range of 16-bit values.
Definition: dl_crcp.h:415
__STATIC_INLINE uint32_t DL_CRCP_getPolynomial(const CRCP_Regs *crcp)
Gets the active polynomial terms for the CRC calculation.
Definition: dl_crcp.h:772
__STATIC_INLINE void DL_CRCP_feedData16(CRCP_Regs *crcp, uint16_t dataIn)
Feeds 16-bit data into the CRC calculation.
Definition: dl_crcp.h:676
Definition: dl_crcp.h:492
__STATIC_INLINE void DL_CRCP_feedData8(CRCP_Regs *crcp, uint8_t dataIn)
Feeds 8-bit data into the CRC calculation.
Definition: dl_crcp.h:662
DL_CRCP_BIT
Definition: dl_crcp.h:391
__STATIC_INLINE bool DL_CRCP_isPowerEnabled(const CRCP_Regs *crcp)
Returns if the Peripheral Write Enable (PWREN) register for the CRCP is enabled.
Definition: dl_crcp.h:554
Definition: dl_crcp.h:438
Definition: dl_crcp.h:393
Definition: dl_crcp.h:395
Definition: dl_crcp.h:450
Definition: dl_crcp.h:504
__STATIC_INLINE bool DL_CRCP_isReset(const CRCP_Regs *crcp)
Returns if CRCP module has been reset.
Definition: dl_crcp.h:581
uint32_t DL_CRCP_calculateBlock32(CRCP_Regs *crcp, uint32_t seed, const uint32_t *ptr, uint32_t size)
Calculates the CRC over a range of 32-bit values.
Definition: dl_crcp.h:501
Definition: dl_crcp.h:435
Definition: dl_crcp.h:480
__STATIC_INLINE uintptr_t DL_CRCP_getCRCINAddr(const CRCP_Regs *crcp)
Returns the address of the CRC input data register.
Definition: dl_crcp.h:855
Definition: dl_crcp.h:489
Definition: dl_crcp.h:402
Definition: dl_crcp.h:432
uint16_t DL_CRCP_calculateMemoryRange16(CRCP_Regs *crcp, uint16_t seed, uint16_t *ptrStart, const uint16_t *ptrEnd)
Calculates the CRC over a memory range.
Definition: dl_crcp.h:483
Definition: dl_crcp.h:474
DL_CRCP_INPUT_ENDIANESS
Definition: dl_crcp.h:399
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale