Guard hardware related implementation into DEVICE_CRC

pull/7735/head
deepikabhavnani 2018-08-08 13:56:13 -05:00
parent 531a83ebd2
commit f593555cbb
1 changed files with 12 additions and 8 deletions

View File

@ -95,7 +95,14 @@ namespace mbed {
template <uint32_t polynomial = POLY_32BIT_ANSI, uint8_t width = 32> template <uint32_t polynomial = POLY_32BIT_ANSI, uint8_t width = 32>
class MbedCRC { class MbedCRC {
public: public:
enum CrcMode { HARDWARE = 0, TABLE, BITWISE }; enum CrcMode
{
#ifdef DEVICE_CRC
HARDWARE = 0,
#endif
TABLE = 1,
BITWISE
};
public: public:
typedef uint64_t crc_data_size_t; typedef uint64_t crc_data_size_t;
@ -170,12 +177,12 @@ public:
int32_t compute_partial(void *buffer, crc_data_size_t size, uint32_t *crc) int32_t compute_partial(void *buffer, crc_data_size_t size, uint32_t *crc)
{ {
switch (_mode) { switch (_mode) {
case HARDWARE:
#ifdef DEVICE_CRC #ifdef DEVICE_CRC
case HARDWARE:
hal_crc_compute_partial((uint8_t *)buffer, size); hal_crc_compute_partial((uint8_t *)buffer, size);
#endif // DEVICE_CRC
*crc = 0; *crc = 0;
return 0; return 0;
#endif
case TABLE: case TABLE:
return table_compute_partial(buffer, size, crc); return table_compute_partial(buffer, size, crc);
case BITWISE: case BITWISE:
@ -229,15 +236,12 @@ public:
{ {
MBED_ASSERT(crc != NULL); MBED_ASSERT(crc != NULL);
if (_mode == HARDWARE) {
#ifdef DEVICE_CRC #ifdef DEVICE_CRC
if (_mode == HARDWARE) {
*crc = hal_crc_get_result(); *crc = hal_crc_get_result();
return 0; return 0;
#else
return -1;
#endif
} }
#endif
uint32_t p_crc = *crc; uint32_t p_crc = *crc;
if ((width < 8) && (NULL == _crc_table)) { if ((width < 8) && (NULL == _crc_table)) {
p_crc = (uint32_t)(p_crc << (8 - width)); p_crc = (uint32_t)(p_crc << (8 - width));