]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/crc32.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / crc32.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, 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
41 void CRC32_setSeed(uint32_t seed, uint_fast8_t crcType)
42 {
43     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
44
45     if (CRC16_MODE == crcType)
46         CRC32->rCRC16INIRES = seed;
47     else
48     {
49         CRC32->rCRC32INIRES_HI = ((seed & 0xFFFF0000) >> 16);
50         CRC32->rCRC32INIRES_LO = (seed & 0xFFFF);
51     }
52 }
53
54 void CRC32_set8BitData(uint8_t dataIn, uint_fast8_t crcType)
55 {
56     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
57
58     if (CRC16_MODE == crcType)
59         HWREG8(CRC32_BASE + OFS_CRC16DI) = dataIn;
60     else
61         HWREG8(CRC32_BASE + OFS_CRC32DI) = dataIn;
62 }
63
64 void CRC32_set16BitData(uint16_t dataIn, uint_fast8_t crcType)
65 {
66     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
67
68     if (CRC16_MODE == crcType)
69         CRC32->rCRC16DI = dataIn;
70     else
71         CRC32->rCRC32DI = dataIn;
72 }
73
74 void CRC32_set32BitData(uint32_t dataIn)
75 {
76     //CRC32->rCRC32DI = dataIn & 0xFFFF;
77     //CRC32->rCRC32DI = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
78
79     HWREG16(CRC32_BASE + OFS_CRC32DI) = dataIn & 0xFFFF;
80     HWREG16(CRC32_BASE + OFS_CRC32DI) = (uint16_t)(
81             (dataIn & 0xFFFF0000) >> 16);
82 }
83
84 void CRC32_set8BitDataReversed(uint8_t dataIn, uint_fast8_t crcType)
85 {
86     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
87
88     if (CRC16_MODE == crcType)
89         HWREG8(CRC32_BASE + OFS_CRC16DIRB) = dataIn;
90     else
91         HWREG8(CRC32_BASE + OFS_CRC32DIRB) = dataIn;
92 }
93
94 void CRC32_set16BitDataReversed(uint16_t dataIn, uint_fast8_t crcType)
95 {
96     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
97
98     if (CRC16_MODE == crcType)
99         CRC32->rCRC16DIRB = dataIn;
100     else
101         CRC32->rCRC32DIRB = dataIn;
102 }
103
104 void CRC32_set32BitDataReversed(uint32_t dataIn)
105 {
106     HWREG16(CRC32_BASE + OFS_CRC32DIRB) = dataIn & 0xFFFF;
107     HWREG16(CRC32_BASE + OFS_CRC32DIRB) = (uint16_t)(
108             (dataIn & 0xFFFF0000) >> 16);
109     //CRC32->rCRC32DIRB = dataIn & 0xFFFF;
110     //CRC32->rCRC32DIRB = (uint16_t) ((dataIn & 0xFFFF0000) >> 16);
111 }
112
113 uint32_t CRC32_getResult(uint_fast8_t crcType)
114 {
115     uint32_t result;
116     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
117
118     if (CRC16_MODE == crcType)
119         return CRC32->rCRC16INIRES;
120     else
121     {
122         result = CRC32->rCRC32INIRES_HI;
123         result = (result << 16);
124         result |= CRC32->rCRC32INIRES_LO;
125         return (result);
126     }
127 }
128
129 uint32_t CRC32_getResultReversed(uint_fast8_t crcType)
130 {
131     uint32_t result;
132     ASSERT((CRC16_MODE == crcType) || (CRC32_MODE == crcType));
133
134     if (CRC16_MODE == crcType)
135         return CRC32->rCRC16RESR;
136     else
137     {
138         result = CRC32->rCRC32RESR_HI;
139         result = (result << 16);
140         result |= CRC32->rCRC32RESR_LO;
141         return (result);
142     }
143 }
144