From c0e723868ecb9313626b823abf922acb611ba3c5 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Mon, 21 Jan 2019 12:25:01 +1300 Subject: [PATCH] libbase: crc16: commit smaller version of crc16 Signed-off-by: Sean Cross --- litex/soc/software/libbase/crc16.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/litex/soc/software/libbase/crc16.c b/litex/soc/software/libbase/crc16.c index a1222e861..df9ed09eb 100644 --- a/litex/soc/software/libbase/crc16.c +++ b/litex/soc/software/libbase/crc16.c @@ -1,5 +1,5 @@ #include - +#ifdef CRC16_FAST static const unsigned int crc16_table[256] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, @@ -45,3 +45,16 @@ unsigned short crc16(const unsigned char *buffer, int len) return crc; } +#else +unsigned short crc16(const unsigned char* data_p, int length) { + unsigned char x; + unsigned short crc = 0; + + while (length--){ + x = crc >> 8 ^ *data_p++; + x ^= x>>4; + crc = (crc << 8) ^ ((unsigned short)(x << 12)) ^ ((unsigned short)(x <<5)) ^ ((unsigned short)x); + } + return crc; +} +#endif \ No newline at end of file