Very small and fast CRC16 for embedded processors
I used this in an embedded PPP/IP/TCP/UDP stack I wrote in the mid 90's on the PC. But very useful for AVR's, PIC's and other 8bitters.
typedef unsigned short U16;
//(c)1996 www.mycal.com - attribution if used
//---------------------------------------------------------------------------
// Simple and fast CRC16 routine for embedded processors.
// Just slightly slower than the table lookup method but consumes
// almost no space. Much faster and smaller than the loop and
// shift method that is widely used in the embedded space.
// Can be optimized even more in .ASM
//
// data = (crcvalue ^ inputchar) & 0xff;
// data = (data ^ (data << 4)) & 0xff;
// crc = (crc >> 8) ^ ((data << 8) ^ (data <<3) ^ (data >> 4))
//---------------------------------------------------------------------------
U16
crcadd(U16 crcvalue, U8 c)
{
U16 b;
b = (crcvalue ^ c) & 0xFF;
b = (b ^ (b << 4)) & 0xFF;
b = (b << 8) ^ (b << 3) ^ (b >> 4);
return((crcvalue >> 8) ^ b);
}
|