Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions drivers/MbedCRC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,46 +24,6 @@ namespace mbed {

/* Default values for different types of polynomials
*/
template<>
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
{
mbed_crc_ctor();
}

template<>
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
{
mbed_crc_ctor();
}

template<>
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
{
mbed_crc_ctor();
}

template<>
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
{
mbed_crc_ctor();
}

template<>
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
{
mbed_crc_ctor();
}

template<>
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
_initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
Expand Down
26 changes: 23 additions & 3 deletions drivers/MbedCRC.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class MbedCRC {
*/
MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder) :
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data),
_reflect_remainder(reflect_remainder), _crc_table(NULL)
_reflect_remainder(reflect_remainder)
{
mbed_crc_ctor();
}
Expand Down Expand Up @@ -445,8 +445,6 @@ class MbedCRC {
{
MBED_STATIC_ASSERT(width <= 32, "Max 32-bit CRC supported");

_mode = (_crc_table != NULL) ? TABLE : BITWISE;

#ifdef DEVICE_CRC
crc_mbed_config_t config;
config.polynomial = polynomial;
Expand All @@ -458,8 +456,30 @@ class MbedCRC {

if (hal_crc_is_supported(&config)) {
_mode = HARDWARE;
return;
}
#endif
switch (polynomial) {
case POLY_32BIT_ANSI:
_crc_table = (uint32_t *)Table_CRC_32bit_ANSI;
break;
case POLY_8BIT_CCITT:
_crc_table = (uint32_t *)Table_CRC_8bit_CCITT;
break;
case POLY_7BIT_SD:
_crc_table = (uint32_t *)Table_CRC_7Bit_SD;
break;
case POLY_16BIT_CCITT:
_crc_table = (uint32_t *)Table_CRC_16bit_CCITT;
break;
case POLY_16BIT_IBM:
_crc_table = (uint32_t *)Table_CRC_16bit_IBM;
break;
default:
_crc_table = NULL;
break;
}
_mode = (_crc_table != NULL) ? TABLE : BITWISE;
}
};

Expand Down