Skip to content

Commit 3d1174a

Browse files
authored
Merge pull request #5911 from deepikabhavnani/common_crc
CRC class implementation
2 parents eaf6f81 + b60eb1d commit 3d1174a

File tree

5 files changed

+720
-0
lines changed

5 files changed

+720
-0
lines changed

drivers/MbedCRC.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <stddef.h>
18+
#include "drivers/TableCRC.h"
19+
#include "drivers/MbedCRC.h"
20+
21+
namespace mbed {
22+
/** \addtogroup drivers */
23+
/** @{*/
24+
25+
/* Default values for different types of polynomials
26+
*/
27+
template <uint32_t polynomial, uint8_t width>
28+
MbedCRC<polynomial, width>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
29+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder), _crc_table(NULL)
30+
{
31+
mbed_crc_ctor();
32+
}
33+
34+
template<>
35+
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
36+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
37+
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
38+
{
39+
mbed_crc_ctor();
40+
}
41+
42+
template<>
43+
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
44+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
45+
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
46+
{
47+
mbed_crc_ctor();
48+
}
49+
50+
template<>
51+
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
52+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
53+
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
54+
{
55+
mbed_crc_ctor();
56+
}
57+
58+
template<>
59+
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
60+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
61+
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
62+
{
63+
}
64+
65+
template<>
66+
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
67+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
68+
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
69+
{
70+
mbed_crc_ctor();
71+
}
72+
73+
template<>
74+
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
75+
_initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
76+
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
77+
{
78+
mbed_crc_ctor();
79+
}
80+
81+
template<>
82+
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC():
83+
_initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true),
84+
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
85+
{
86+
mbed_crc_ctor();
87+
}
88+
89+
template<>
90+
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC():
91+
_initial_value(~(0x0)), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
92+
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
93+
{
94+
mbed_crc_ctor();
95+
}
96+
97+
template<>
98+
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC():
99+
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
100+
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
101+
{
102+
mbed_crc_ctor();
103+
}
104+
105+
template<>
106+
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC():
107+
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
108+
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
109+
{
110+
mbed_crc_ctor();
111+
}
112+
113+
/** @}*/
114+
} // namespace mbed
115+

0 commit comments

Comments
 (0)