Use a precomputed CRC table for xmodem
[uccvend-snackrom.git] / ROM2 / gencrctab.c
diff --git a/ROM2/gencrctab.c b/ROM2/gencrctab.c
new file mode 100644 (file)
index 0000000..e9f9650
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+#define CRC16 0x1021           /* Generator polynomial (X^16 + X^12 + X^5 + 1) */
+int main() {
+       int val;
+       printf("const u16 crctab[] = {\n\t");
+       for (val = 0; val <= 255; val++) {
+               int i;
+               unsigned int crc;
+               crc = val << 8;
+               for (i = 0; i < 8; i++) {
+                       crc <<= 1;
+                       if (crc & 0x10000)
+                               crc ^= CRC16;
+               }
+               printf("0x%04x,", crc&0xffff);
+               if ((val+1)%8 == 0) printf("\n\t");
+    }
+       printf("};\n");
+       return 0;
+}

UCC git Repository :: git.ucc.asn.au