crc library used in layer 2 and layer 3 implementation

Dependents:   AlohaTransceiver

Files at this revision

API Documentation at this revision

Comitter:
rba90
Date:
Tue Jul 12 13:10:24 2016 +0000
Commit message:
init;

Changed in this revision

crc.cpp Show annotated file Show diff for this revision Revisions of this file
crc.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 70b7787124e0 crc.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/crc.cpp	Tue Jul 12 13:10:24 2016 +0000
@@ -0,0 +1,21 @@
+#include "crc.h"
+
+uint8_t crc8(const uint8_t *data, int len)
+{
+    unsigned int crc = 0;
+
+    for (int j = len; j; j--, data++)
+    {
+        crc ^= (*data << 8);
+        for (int i = 8; i; i--)
+        {
+            if (crc & 0x8000)
+            {
+                crc ^= (CRC8_GEN << 3);
+            }
+            crc <<= 1;
+        }
+    }
+
+    return (uint8_t)(crc >> 8);
+}
\ No newline at end of file
diff -r 000000000000 -r 70b7787124e0 crc.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/crc.h	Tue Jul 12 13:10:24 2016 +0000
@@ -0,0 +1,11 @@
+#ifndef crc_h_
+#define crc_h_
+
+#include <stdint.h>
+
+// x^8 + x^2 + x + 1 polynomial
+#define CRC8_GEN 0x1070 
+
+uint8_t crc8(const uint8_t *data, int len);
+
+#endif
\ No newline at end of file