libbase: crc16: commit smaller version of crc16
authorSean Cross <sean@xobs.io>
Sun, 20 Jan 2019 23:25:01 +0000 (12:25 +1300)
committerTim 'mithro' Ansell <me@mith.ro>
Mon, 2 Sep 2019 21:44:18 +0000 (14:44 -0700)
Signed-off-by: Sean Cross <sean@xobs.io>
litex/soc/software/libbase/crc16.c

index a1222e861101602c4c281bf8cb765e16f26faf67..df9ed09eb5bee3a91385b8b0d15912dcc69f43f4 100644 (file)
@@ -1,5 +1,5 @@
 #include <crc.h>
-
+#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