crc library used in layer 2 and layer 3 implementation

Dependents:   AlohaTransceiver

crc.cpp

Committer:
rba90
Date:
2016-07-12
Revision:
0:70b7787124e0

File content as of revision 0:70b7787124e0:

#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);
}