Skip to content

Commit

Permalink
fix bug of pre-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyongzhong0 committed Jul 31, 2020
1 parent 703d75b commit f87d846
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
10 changes: 2 additions & 8 deletions src/crc16.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#ifdef CRCLIB_USING_CRC16

#ifdef CRC16_USING_CONST_TABLE

#if (CRC16_POLY == 0xA001)
#if (defined(CRC16_USING_CONST_TABLE) && (CRC16_POLY == 0xA001))
static const u16 crc16_table[] = {
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241,
0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440,
Expand Down Expand Up @@ -47,7 +45,7 @@ static const u16 crc16_table[] = {
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641,
0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040
};
#elif (CRC16_POLY == 0x8408)
#elif (defined(CRC16_USING_CONST_TABLE) && (CRC16_POLY == 0x8408))
const u16 crc16_table[] = {
0x0000, 0x1189, 0x2312, 0x329B, 0x4624, 0x57AD, 0x6536, 0x74BF,
0x8C48, 0x9DC1, 0xAF5A, 0xBED3, 0xCA6C, 0xDBE5, 0xE97E, 0xF8F7,
Expand Down Expand Up @@ -82,10 +80,7 @@ const u16 crc16_table[] = {
0xF78F, 0xE606, 0xD49D, 0xC514, 0xB1AB, 0xA022, 0x92B9, 0x8330,
0x7BC7, 0x6A4E, 0x58D5, 0x495C, 0x3DE3, 0x2C6A, 0x1EF1, 0x0F78
};
#endif

#else

static u16 crc16_table[256];
void crc16_table_init(void)
{
Expand All @@ -109,7 +104,6 @@ void crc16_table_init(void)
}
}
INIT_BOARD_EXPORT(crc16_table_init);

#endif

u16 crc16_cyc_cal(u16 init_val, u8 *pdata, u32 len)
Expand Down
10 changes: 2 additions & 8 deletions src/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#ifdef CRCLIB_USING_CRC32

#ifdef CRC32_USING_CONST_TABLE

#if (CRC32_POLY == 0xEDB88320)
#if (defined(CRC32_USING_CONST_TABLE) && (CRC32_POLY == 0xEDB88320))
const u32 crc32_table[] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
Expand Down Expand Up @@ -47,7 +45,7 @@ const u32 crc32_table[] = {
0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
#elif (CRC32_POLY == 0x82F63B78))
#elif (defined(CRC32_USING_CONST_TABLE) && (CRC32_POLY == 0x82F63B78))
const u32 crc32_table[] = {
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
Expand Down Expand Up @@ -82,10 +80,7 @@ const u32 crc32_table[] = {
0xF36E6F75, 0x0105EC76, 0x12551F82, 0xE03E9C81, 0x34F4F86A, 0xC69F7B69, 0xD5CF889D, 0x27A40B9E,
0x79B737BA, 0x8BDCB4B9, 0x988C474D, 0x6AE7C44E, 0xBE2DA0A5, 0x4C4623A6, 0x5F16D052, 0xAD7D5351
};
#endif

#else

static u32 crc32_table[256];
void crc32_table_init(void)
{
Expand All @@ -109,7 +104,6 @@ void crc32_table_init(void)
}
}
INIT_BOARD_EXPORT(crc32_table_init);

#endif

u32 crc32_cyc_cal(u32 init_val, u8 *pdata, u32 len)
Expand Down
12 changes: 3 additions & 9 deletions src/crc8.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@

#ifdef CRCLIB_USING_CRC8

#ifdef CRC8_USING_CONST_TABLE

#if (CRC8_POLY == 0x8C)
#if (defined(CRC8_USING_CONST_TABLE) && (CRC8_POLY == 0x8C))
const u8 crc8_table[] = {
0x00, 0x5E, 0xBC, 0xE2, 0x61, 0x3F, 0xDD, 0x83,
0xC2, 0x9C, 0x7E, 0x20, 0xA3, 0xFD, 0x1F, 0x41,
Expand Down Expand Up @@ -47,7 +45,7 @@ const u8 crc8_table[] = {
0x74, 0x2A, 0xC8, 0x96, 0x15, 0x4B, 0xA9, 0xF7,
0xB6, 0xE8, 0x0A, 0x54, 0xD7, 0x89, 0x6B, 0x35
};
#elif (CRC8_POLY == 0xD9)
#elif (defined(CRC8_USING_CONST_TABLE) && (CRC8_POLY == 0xD9))
const u8 crc8_table[] = {
0x00, 0xD0, 0x13, 0xC3, 0x26, 0xF6, 0x35, 0xE5,
0x4C, 0x9C, 0x5F, 0x8F, 0x6A, 0xBA, 0x79, 0xA9,
Expand Down Expand Up @@ -82,10 +80,7 @@ const u8 crc8_table[] = {
0x77, 0xA7, 0x64, 0xB4, 0x51, 0x81, 0x42, 0x92,
0x3B, 0xEB, 0x28, 0xF8, 0x1D, 0xCD, 0x0E, 0xDE
};
#endif

#else

static u8 crc8_table[256];
void crc8_table_init(void)
{
Expand All @@ -109,7 +104,6 @@ void crc8_table_init(void)
}
}
INIT_BOARD_EXPORT(crc8_table_init);

#endif

u8 crc8_cyc_cal(u8 init_val, u8 *pdata, u32 len)
Expand All @@ -128,7 +122,7 @@ u8 crc8_cyc_cal(u8 init_val, u8 *pdata, u32 len)
return(crc8);
}

u8 crc8_cal(u8 *pdata, u32 len)//计算长度Len数量数据的CRC校验值,返回计算出的校验值
u8 crc8_cal(u8 *pdata, u32 len)
{
return(crc8_cyc_cal(CRC8_INIT_VAL, pdata, len) ^ CRC8_INIT_VAL);
}
Expand Down

0 comments on commit f87d846

Please sign in to comment.