26/02/2013
/*=======================================================================*/
/* Function that calculates CRC-CCITT 16 bits
/* INPUT:
/* unsigned char *inbuffer : 8 bits input vector over which CRC checksum is calculated
/* must termined by 0x00
/* OUTPUT:
/* unsigned int: 16 bits return of crc_ccitt checksum
/*=======================================================================*/
/* OVERVIEW:
/*
Width = 16 bits
/*
Truncated polynomial = 0x1021
/*
Initial value = 0xFFFF
/*
No XOR is performed on the output CRC
/* DESCRIPTION:
/*
Computing a POLY number from the crc equation.
/*
Crc s are usually expressed as an polynomial expression such as:
/*
/*
x^16 + x^12 + x^5 + 1
/* CHECK
/*
0xE5CC This is the checksum for the ascii string "123456789"
/* EXAMPLE
/* http://www.zorc.breitbandkatze.de/crc.html
*=======================================================================*/
#define crc_poly 0x1021
// Polynome du CRC-CCITT-16Bits
unsigned int crc_ccitt16 (unsigned char *inbuffer) {
unsigned int crc_checksum = 0xffff;
unsigned char ch;
char i,xor_flag;
while ( *inbuffer!=0)
{
ch = *i+;
for(i=0; i<8; i++)
{
xor_flag=(crc_checksum & 0x8000)? 1:0;
crc_checksum = crc_checksum << 1;
if (ch & 0x80) crc_c+;
if (xor_flag) crc_checksum = crc_checksum ^ crc_poly;
ch = ch << 1;
}
}
for(i=0; i<16; i++)
{
xor_flag=(crc_checksum & 0x8000)? 1:0;
crc_checksum = crc_checksum << 1;
if (xor_flag) crc_checksum = crc_checksum ^ crc_poly;
}
return (crc_checksum);
}