Skip to content

Commit 0d0402d

Browse files
author
Cruz Monrreal
authored
Merge pull request #7793 from deepikabhavnani/crc_template_fix
Template specialization didnt work after addition of default constructor
2 parents fa4b2f0 + 7885edb commit 0d0402d

File tree

2 files changed

+23
-43
lines changed

2 files changed

+23
-43
lines changed

drivers/MbedCRC.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,46 +24,6 @@ namespace mbed {
2424

2525
/* Default values for different types of polynomials
2626
*/
27-
template<>
28-
MbedCRC<POLY_32BIT_ANSI, 32>::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),
30-
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
31-
{
32-
mbed_crc_ctor();
33-
}
34-
35-
template<>
36-
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
37-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
38-
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
39-
{
40-
mbed_crc_ctor();
41-
}
42-
43-
template<>
44-
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
45-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
46-
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
47-
{
48-
mbed_crc_ctor();
49-
}
50-
51-
template<>
52-
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
53-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
54-
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
55-
{
56-
mbed_crc_ctor();
57-
}
58-
59-
template<>
60-
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
61-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
62-
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
63-
{
64-
mbed_crc_ctor();
65-
}
66-
6727
template<>
6828
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
6929
_initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),

drivers/MbedCRC.h

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class MbedCRC {
124124
*/
125125
MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder) :
126126
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data),
127-
_reflect_remainder(reflect_remainder), _crc_table(NULL)
127+
_reflect_remainder(reflect_remainder)
128128
{
129129
mbed_crc_ctor();
130130
}
@@ -445,8 +445,6 @@ class MbedCRC {
445445
{
446446
MBED_STATIC_ASSERT(width <= 32, "Max 32-bit CRC supported");
447447

448-
_mode = (_crc_table != NULL) ? TABLE : BITWISE;
449-
450448
#ifdef DEVICE_CRC
451449
crc_mbed_config_t config;
452450
config.polynomial = polynomial;
@@ -458,8 +456,30 @@ class MbedCRC {
458456

459457
if (hal_crc_is_supported(&config)) {
460458
_mode = HARDWARE;
459+
return;
461460
}
462461
#endif
462+
switch (polynomial) {
463+
case POLY_32BIT_ANSI:
464+
_crc_table = (uint32_t *)Table_CRC_32bit_ANSI;
465+
break;
466+
case POLY_8BIT_CCITT:
467+
_crc_table = (uint32_t *)Table_CRC_8bit_CCITT;
468+
break;
469+
case POLY_7BIT_SD:
470+
_crc_table = (uint32_t *)Table_CRC_7Bit_SD;
471+
break;
472+
case POLY_16BIT_CCITT:
473+
_crc_table = (uint32_t *)Table_CRC_16bit_CCITT;
474+
break;
475+
case POLY_16BIT_IBM:
476+
_crc_table = (uint32_t *)Table_CRC_16bit_IBM;
477+
break;
478+
default:
479+
_crc_table = NULL;
480+
break;
481+
}
482+
_mode = (_crc_table != NULL) ? TABLE : BITWISE;
463483
}
464484
};
465485

0 commit comments

Comments
 (0)