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 #include <ti/devices/msp432p4xx/driverlib/crc32.h>
33 #include <ti/devices/msp432p4xx/inc/msp.h>
34 #include <ti/devices/msp432p4xx/driverlib/debug.h>
35
36
CRC32_setSeed(uint32_t seed,uint_fast8_t crcType)37 void CRC32_setSeed(uint32_t seed, uint_fast8_t crcType)
38 {
39 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
40
41 if (CRC16_MODE == crcType)
42 CRC32->INIRES16 = seed;
43 else
44 {
45 CRC32->INIRES32_HI = ((seed & 0xFFFF0000) >> 16);
46 CRC32->INIRES32_LO = (seed & 0xFFFF);
47 }
48 }
49
CRC32_set8BitData(uint8_t dataIn,uint_fast8_t crcType)50 void CRC32_set8BitData(uint8_t dataIn, uint_fast8_t crcType)
51 {
52 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
53
54 if (CRC16_MODE == crcType)
55 HWREG8(&(CRC32->DI16)) = dataIn;
56 else
57 HWREG8(&(CRC32->DI32)) = dataIn;
58 }
59
CRC32_set16BitData(uint16_t dataIn,uint_fast8_t crcType)60 void CRC32_set16BitData(uint16_t dataIn, uint_fast8_t crcType)
61 {
62 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
63
64 if (CRC16_MODE == crcType)
65 CRC32->DI16 = dataIn;
66 else
67 CRC32->DI32 = dataIn;
68 }
69
CRC32_set32BitData(uint32_t dataIn)70 void CRC32_set32BitData(uint32_t dataIn)
71 {
72 //CRC32->DI32 = dataIn & 0xFFFF;
73 //CRC32->DI32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
74
75 HWREG16(&(CRC32->DI32)) = dataIn & 0xFFFF;
76 HWREG16(&(CRC32->DI32)) = (uint16_t)(
77 (dataIn & 0xFFFF0000) >> 16);
78 }
79
CRC32_set8BitDataReversed(uint8_t dataIn,uint_fast8_t crcType)80 void CRC32_set8BitDataReversed(uint8_t dataIn, uint_fast8_t crcType)
81 {
82 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
83
84 if (CRC16_MODE == crcType)
85 HWREG8(&(CRC32->DIRB16)) = dataIn;
86 else
87 HWREG8(&(CRC32->DIRB32)) = dataIn;
88 }
89
CRC32_set16BitDataReversed(uint16_t dataIn,uint_fast8_t crcType)90 void CRC32_set16BitDataReversed(uint16_t dataIn, uint_fast8_t crcType)
91 {
92 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
93
94 if (CRC16_MODE == crcType)
95 CRC32->DIRB16 = dataIn;
96 else
97 CRC32->DIRB32 = dataIn;
98 }
99
CRC32_set32BitDataReversed(uint32_t dataIn)100 void CRC32_set32BitDataReversed(uint32_t dataIn)
101 {
102 //CRC32->DIRB32 = dataIn & 0xFFFF;
103 //CRC32->DIRB32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
104
105 HWREG16(&(CRC32->DIRB32)) = dataIn & 0xFFFF;
106 HWREG16(&(CRC32->DIRB32)) = (uint16_t)(
107 (dataIn & 0xFFFF0000) >> 16);
108
109 }
110
CRC32_getResult(uint_fast8_t crcType)111 uint32_t CRC32_getResult(uint_fast8_t crcType)
112 {
113 uint32_t result;
114 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
115
116 if (CRC16_MODE == crcType)
117 return CRC32->INIRES16;
118 else
119 {
120 result = CRC32->INIRES32_HI;
121 result = (result << 16);
122 result |= CRC32->INIRES32_LO;
123 return (result);
124 }
125 }
126
CRC32_getResultReversed(uint_fast8_t crcType)127 uint32_t CRC32_getResultReversed(uint_fast8_t crcType)
128 {
129 uint32_t result;
130 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
131
132 if (CRC16_MODE == crcType)
133 return CRC32->RESR16;
134 else
135 {
136 result = CRC32->RESR32_HI;
137 result = (result << 16);
138 result |= CRC32->RESR32_LO;
139 return (result);
140 }
141 }
142
143