2 * -------------------------------------------
3 * MSP432 DriverLib - v3_10_00_09
4 * -------------------------------------------
6 * --COPYRIGHT--,BSD,BSD
7 * Copyright (c) 2014, Texas Instruments Incorporated
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * * Neither the name of Texas Instruments Incorporated nor the names of
22 * its contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #include <hw_memmap.h>
42 void CRC32_setSeed(uint32_t seed, uint_fast8_t crcType)
44 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
46 if (CRC16_MODE == crcType)
47 CRC32->INIRES16 = seed;
50 CRC32->INIRES32_HI = ((seed & 0xFFFF0000) >> 16);
51 CRC32->INIRES32_LO = (seed & 0xFFFF);
55 void CRC32_set8BitData(uint8_t dataIn, uint_fast8_t crcType)
57 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
59 if (CRC16_MODE == crcType)
60 HWREG8(&(CRC32->DI16)) = dataIn;
62 HWREG8(&(CRC32->DI32)) = dataIn;
65 void CRC32_set16BitData(uint16_t dataIn, uint_fast8_t crcType)
67 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
69 if (CRC16_MODE == crcType)
75 void CRC32_set32BitData(uint32_t dataIn)
77 //CRC32->DI32 = dataIn & 0xFFFF;
78 //CRC32->DI32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
80 HWREG16(&(CRC32->DI32)) = dataIn & 0xFFFF;
81 HWREG16(&(CRC32->DI32)) = (uint16_t)(
82 (dataIn & 0xFFFF0000) >> 16);
85 void CRC32_set8BitDataReversed(uint8_t dataIn, uint_fast8_t crcType)
87 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
89 if (CRC16_MODE == crcType)
90 HWREG8(&(CRC32->DIRB16)) = dataIn;
92 HWREG8(&(CRC32->DIRB32)) = dataIn;
95 void CRC32_set16BitDataReversed(uint16_t dataIn, uint_fast8_t crcType)
97 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
99 if (CRC16_MODE == crcType)
100 CRC32->DIRB16 = dataIn;
102 CRC32->DIRB32 = dataIn;
105 void CRC32_set32BitDataReversed(uint32_t dataIn)
107 //CRC32->DIRB32 = dataIn & 0xFFFF;
108 //CRC32->DIRB32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
110 HWREG16(&(CRC32->DIRB32)) = dataIn & 0xFFFF;
111 HWREG16(&(CRC32->DIRB32)) = (uint16_t)(
112 (dataIn & 0xFFFF0000) >> 16);
116 uint32_t CRC32_getResult(uint_fast8_t crcType)
119 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
121 if (CRC16_MODE == crcType)
122 return CRC32->INIRES16;
125 result = CRC32->INIRES32_HI;
126 result = (result << 16);
127 result |= CRC32->INIRES32_LO;
132 uint32_t CRC32_getResultReversed(uint_fast8_t crcType)
135 ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
137 if (CRC16_MODE == crcType)
138 return CRC32->RESR16;
141 result = CRC32->RESR32_HI;
142 result = (result << 16);
143 result |= CRC32->RESR32_LO;