Skip to content

Commit 2c97d03

Browse files
authoredMar 26, 2025
Merge pull request #801 from sdb4/feat_support_rolling_crc
support for rolling crc16
2 parents 6fbdb92 + 99fc451 commit 2c97d03

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎util/crc.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,17 @@ const unsigned short crc16_tab[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084,
5353
0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
5454
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 };
5555

56-
unsigned short crc16(unsigned char *buf, unsigned int len) {
57-
unsigned short cksum = 0;
56+
unsigned short crc16_rolling(unsigned short cksum, unsigned char *buf, unsigned int len) {
5857
for (unsigned int i = 0; i < len; i++) {
5958
cksum = crc16_tab[(((cksum >> 8) ^ *buf++) & 0xFF)] ^ (cksum << 8);
6059
}
6160
return cksum;
6261
}
6362

63+
unsigned short crc16(unsigned char *buf, unsigned int len) {
64+
return crc16_rolling(0, buf, len);
65+
}
66+
6467
#ifndef NO_STM32
6568
/**
6669
* @brief Computes the 32-bit CRC of a given buffer of data word(32-bit) using

‎util/crc.h

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/*
2626
* Functions
2727
*/
28+
unsigned short crc16_rolling(unsigned short cksum, unsigned char *buf, unsigned int len);
2829
unsigned short crc16(unsigned char *buf, unsigned int len);
2930
uint32_t crc32(uint32_t *buf, uint32_t len);
3031
void crc32_reset(void);

0 commit comments

Comments
 (0)