]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/crc32.c
commit 9f316c246baafa15c542a5aea81a94f26e3d6507
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / crc32.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v3_10_00_09 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2014, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
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.
20  *
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.
24  *
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.
36  * --/COPYRIGHT--*/
37 #include "crc32.h"
38 #include <msp.h>
39 #include <debug.h>
40 #include <hw_memmap.h>
41
42 void CRC32_setSeed(uint32_t seed, uint_fast8_t crcType)
43 {
44     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
45
46     if (CRC16_MODE == crcType)
47         CRC32->INIRES16 = seed;
48     else
49     {
50         CRC32->INIRES32_HI = ((seed & 0xFFFF0000) >> 16);
51         CRC32->INIRES32_LO = (seed & 0xFFFF);
52     }
53 }
54
55 void CRC32_set8BitData(uint8_t dataIn, uint_fast8_t crcType)
56 {
57     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
58
59     if (CRC16_MODE == crcType)
60         HWREG8(&(CRC32->DI16)) = dataIn;
61     else
62         HWREG8(&(CRC32->DI32)) = dataIn;
63 }
64
65 void CRC32_set16BitData(uint16_t dataIn, uint_fast8_t crcType)
66 {
67     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
68
69     if (CRC16_MODE == crcType)
70         CRC32->DI16 = dataIn;
71     else
72         CRC32->DI32 = dataIn;
73 }
74
75 void CRC32_set32BitData(uint32_t dataIn)
76 {
77     //CRC32->DI32 = dataIn & 0xFFFF;
78     //CRC32->DI32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
79
80     HWREG16(&(CRC32->DI32)) = dataIn & 0xFFFF;
81     HWREG16(&(CRC32->DI32)) = (uint16_t)(
82             (dataIn & 0xFFFF0000) >> 16);
83 }
84
85 void CRC32_set8BitDataReversed(uint8_t dataIn, uint_fast8_t crcType)
86 {
87     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
88
89     if (CRC16_MODE == crcType)
90         HWREG8(&(CRC32->DIRB16)) = dataIn;
91     else
92         HWREG8(&(CRC32->DIRB32)) = dataIn;
93 }
94
95 void CRC32_set16BitDataReversed(uint16_t dataIn, uint_fast8_t crcType)
96 {
97     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
98
99     if (CRC16_MODE == crcType)
100         CRC32->DIRB16 = dataIn;
101     else
102         CRC32->DIRB32 = dataIn;
103 }
104
105 void CRC32_set32BitDataReversed(uint32_t dataIn)
106 {
107     //CRC32->DIRB32 = dataIn & 0xFFFF;
108     //CRC32->DIRB32 = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
109
110     HWREG16(&(CRC32->DIRB32)) = dataIn & 0xFFFF;
111     HWREG16(&(CRC32->DIRB32)) = (uint16_t)(
112             (dataIn & 0xFFFF0000) >> 16);
113
114 }
115
116 uint32_t CRC32_getResult(uint_fast8_t crcType)
117 {
118     uint32_t result;
119     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
120
121     if (CRC16_MODE == crcType)
122         return CRC32->INIRES16;
123     else
124     {
125         result = CRC32->INIRES32_HI;
126         result = (result << 16);
127         result |= CRC32->INIRES32_LO;
128         return (result);
129     }
130 }
131
132 uint32_t CRC32_getResultReversed(uint_fast8_t crcType)
133 {
134     uint32_t result;
135     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
136
137     if (CRC16_MODE == crcType)
138         return CRC32->RESR16;
139     else
140     {
141         result = CRC32->RESR32_HI;
142         result = (result << 16);
143         result |= CRC32->RESR32_LO;
144         return (result);
145     }
146 }
147