ENEL400 / crc

Dependents:   AlohaTransceiver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers crc.cpp Source File

crc.cpp

00001 #include "crc.h"
00002 
00003 uint8_t crc8(const uint8_t *data, int len)
00004 {
00005     unsigned int crc = 0;
00006 
00007     for (int j = len; j; j--, data++)
00008     {
00009         crc ^= (*data << 8);
00010         for (int i = 8; i; i--)
00011         {
00012             if (crc & 0x8000)
00013             {
00014                 crc ^= (CRC8_GEN << 3);
00015             }
00016             crc <<= 1;
00017         }
00018     }
00019 
00020     return (uint8_t)(crc >> 8);
00021 }