Skip to content

Commit b60eb1d

Browse files
author
deepikabhavnani
committed
Updated table to be const and small fixes
1 parent af09822 commit b60eb1d

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

drivers/MbedCRC.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
#include "drivers/TableCRC.h"
2121
#include "platform/mbed_assert.h"
2222

23+
/* This is invalid warning from the compiler for below section of code
24+
if ((width < 8) && (NULL == _crc_table)) {
25+
p_crc = (uint32_t)(p_crc << (8 - width));
26+
}
27+
Compiler warns of the shift operation with width as it is width=(std::uint8_t),
28+
but we check for ( width < 8) before performing shift, so it should not be an issue.
29+
*/
2330
#if defined ( __CC_ARM )
2431
#pragma diag_suppress 62 // Shift count is negative
2532
#elif defined ( __GNUC__ )
@@ -57,7 +64,6 @@ typedef enum crc_polynomial {
5764
* @code
5865
*
5966
* #include "mbed.h"
60-
* #include "drivers/MbedCRC.h"
6167
*
6268
* int main() {
6369
* MbedCRC<POLY_32BIT_ANSI, 32> ct;
@@ -77,7 +83,6 @@ typedef enum crc_polynomial {
7783
* @code
7884
*
7985
* #include "mbed.h"
80-
* #include "drivers/MbedCRC.h"
8186
* int main() {
8287
* MbedCRC<POLY_32BIT_ANSI, 32> ct;
8388
*
@@ -263,7 +268,7 @@ class MbedCRC
263268
*/
264269
uint32_t get_crc_mask(void) const
265270
{
266-
return (width < 8 ? ((1u << 8)-1) : (uint32_t)((uint64_t)(1ull << width) - 1));
271+
return (width < 8 ? ((1u << 8) - 1) : (uint32_t)((uint64_t)(1ull << width) - 1));
267272
}
268273

269274
/** Final value of CRC is reflected

drivers/TableCRC.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
*/
1616

1717
#include <stdint.h>
18+
#include "drivers/TableCRC.h"
1819

1920
namespace mbed {
2021
/** \addtogroup drivers */
2122
/** @{*/
2223

23-
uint8_t Table_CRC_7Bit_SD[256] = {
24+
extern const uint8_t Table_CRC_7Bit_SD[MBED_CRC_TABLE_SIZE] = {
2425
0x0, 0x12, 0x24, 0x36, 0x48, 0x5a, 0x6c, 0x7e, 0x90, 0x82, 0xb4, 0xa6, 0xd8, 0xca, 0xfc, 0xee,
2526
0x32, 0x20, 0x16, 0x4, 0x7a, 0x68, 0x5e, 0x4c, 0xa2, 0xb0, 0x86, 0x94, 0xea, 0xf8, 0xce, 0xdc,
2627
0x64, 0x76, 0x40, 0x52, 0x2c, 0x3e, 0x8, 0x1a, 0xf4, 0xe6, 0xd0, 0xc2, 0xbc, 0xae, 0x98, 0x8a,
@@ -39,7 +40,7 @@ uint8_t Table_CRC_7Bit_SD[256] = {
3940
0x1c, 0xe, 0x38, 0x2a, 0x54, 0x46, 0x70, 0x62, 0x8c, 0x9e, 0xa8, 0xba, 0xc4, 0xd6, 0xe0, 0xf2
4041
};
4142

42-
uint8_t Table_CRC_8bit_CCITT[256] = {
43+
extern const uint8_t Table_CRC_8bit_CCITT[MBED_CRC_TABLE_SIZE] = {
4344
0x0, 0x7, 0xe, 0x9, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d,
4445
0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d,
4546
0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd,
@@ -58,7 +59,7 @@ uint8_t Table_CRC_8bit_CCITT[256] = {
5859
0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3
5960
};
6061

61-
uint16_t Table_CRC_16bit_CCITT[256] = {
62+
extern const uint16_t Table_CRC_16bit_CCITT[MBED_CRC_TABLE_SIZE] = {
6263
0x0, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b,
6364
0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
6465
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x420, 0x1401,
@@ -83,7 +84,7 @@ uint16_t Table_CRC_16bit_CCITT[256] = {
8384
0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
8485
};
8586

86-
uint16_t Table_CRC_16bit_IBM[256] = {
87+
extern const uint16_t Table_CRC_16bit_IBM[MBED_CRC_TABLE_SIZE] = {
8788
0x0, 0x8005, 0x800f, 0xa, 0x801b, 0x1e, 0x14, 0x8011, 0x8033, 0x36, 0x3c, 0x8039,
8889
0x28, 0x802d, 0x8027, 0x22, 0x8063, 0x66, 0x6c, 0x8069, 0x78, 0x807d, 0x8077, 0x72,
8990
0x50, 0x8055, 0x805f, 0x5a, 0x804b, 0x4e, 0x44, 0x8041, 0x80c3, 0xc6, 0xcc, 0x80c9,
@@ -107,7 +108,7 @@ uint16_t Table_CRC_16bit_IBM[256] = {
107108
0x220, 0x8225, 0x822f, 0x22a, 0x823b, 0x23e, 0x234, 0x8231, 0x8213, 0x216, 0x21c, 0x8219
108109
};
109110

110-
uint32_t Table_CRC_32bit_ANSI[256] = {
111+
extern const uint32_t Table_CRC_32bit_ANSI[MBED_CRC_TABLE_SIZE] = {
111112
0x0, 0x4c11db7, 0x9823b6e, 0xd4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
112113
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd,
113114
0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75,

drivers/TableCRC.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ namespace mbed {
2323
/** \addtogroup drivers */
2424
/** @{*/
2525

26-
extern uint8_t Table_CRC_7Bit_SD[256];
27-
extern uint8_t Table_CRC_8bit_CCITT[256];
28-
extern uint16_t Table_CRC_16bit_CCITT[256];
29-
extern uint16_t Table_CRC_16bit_IBM[256];
30-
extern uint32_t Table_CRC_32bit_ANSI[256];
26+
#define MBED_CRC_TABLE_SIZE 256
27+
28+
extern const uint8_t Table_CRC_7Bit_SD[MBED_CRC_TABLE_SIZE];
29+
extern const uint8_t Table_CRC_8bit_CCITT[MBED_CRC_TABLE_SIZE];
30+
extern const uint16_t Table_CRC_16bit_CCITT[MBED_CRC_TABLE_SIZE];
31+
extern const uint16_t Table_CRC_16bit_IBM[MBED_CRC_TABLE_SIZE];
32+
extern const uint32_t Table_CRC_32bit_ANSI[MBED_CRC_TABLE_SIZE];
3133

3234
/** @}*/
3335
} // namespace mbed

0 commit comments

Comments
 (0)