uint8_t crc4_itu(uint8_t *data, uint_len length);
uint8_t crc5_epc(uint8_t *data, uint_len length);
uint8_t crc5_itu(uint8_t *data, uint_len length);
uint8_t crc5_usb(uint8_t *data, uint_len length);
uint8_t crc6_itu(uint8_t *data, uint_len length);
uint8_t crc7_mmc(uint8_t *data, uint_len length);
uint8_t crc8(uint8_t *data, uint_len length);
uint8_t crc8_itu(uint8_t *data, uint_len length);
uint8_t crc8_rohc(uint8_t *data, uint_len length);
uint8_t crc8_maxim(uint8_t *data, uint_len length);//DS18B20
uint16_t crc16_ibm(uint8_t *data, uint_len length);
uint16_t crc16_maxim(uint8_t *data, uint_len length);
uint16_t crc16_usb(uint8_t *data, uint_len length);
uint16_t crc16_modbus(uint8_t *data, uint_len length);
uint16_t crc16_ccitt(uint8_t *data, uint_len length);
uint16_t crc16_ccitt_false(uint8_t *data, uint_len length);
uint16_t crc16_x25(uint8_t *data, uint_len length);
uint16_t crc16_xmodem(uint8_t *data, uint_len length);
uint16_t crc16_dnp(uint8_t *data, uint_len length);
uint32_t crc32(uint8_t *data, uint_len length);
uint32_t crc32_mpeg_2(uint8_t *data, uint_len length);
/******************************************************************************
* Name: CRC-4/ITU x4+x+1
* Poly: 0x03
* Init: 0x00
* Refin: True
* Refout: True
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc4_itu(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for (i = 0; i < 8; ++i)
{
if (crc & 1)
crc = (crc >> 1) ^ 0x0C;// 0x0C = (reverse 0x03)>>(8-4)
else
crc = (crc >> 1);
}
}
return crc;
}
/******************************************************************************
* Name: CRC-5/EPC x5+x3+1
* Poly: 0x09
* Init: 0x09
* Refin: False
* Refout: False
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc5_epc(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0x48; // Initial value: 0x48 = 0x09<<(8-5)
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for ( i = 0; i < 8; i++ )
{
if ( crc & 0x80 )
crc = (crc << 1) ^ 0x48; // 0x48 = 0x09<<(8-5)
else
crc <<= 1;
}
}
return crc >> 3;
}
/******************************************************************************
* Name: CRC-5/ITU x5+x4+x2+1
* Poly: 0x15
* Init: 0x00
* Refin: True
* Refout: True
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc5_itu(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for (i = 0; i < 8; ++i)
{
if (crc & 1)
crc = (crc >> 1) ^ 0x15;// 0x15 = (reverse 0x15)>>(8-5)
else
crc = (crc >> 1);
}
}
return crc;
}
/******************************************************************************
* Name: CRC-5/USB x5+x2+1
* Poly: 0x05
* Init: 0x1F
* Refin: True
* Refout: True
* Xorout: 0x1F
* Note:
*****************************************************************************/
uint8_t crc5_usb(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0x1F; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for (i = 0; i < 8; ++i)
{
if (crc & 1)
crc = (crc >> 1) ^ 0x14;// 0x14 = (reverse 0x05)>>(8-5)
else
crc = (crc >> 1);
}
}
return crc ^ 0x1F;
}
/******************************************************************************
* Name: CRC-6/ITU x6+x+1
* Poly: 0x03
* Init: 0x00
* Refin: True
* Refout: True
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc6_itu(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for (i = 0; i < 8; ++i)
{
if (crc & 1)
crc = (crc >> 1) ^ 0x30;// 0x30 = (reverse 0x03)>>(8-6)
else
crc = (crc >> 1);
}
}
return crc;
}
/******************************************************************************
* Name: CRC-7/MMC x7+x3+1
* Poly: 0x09
* Init: 0x00
* Refin: False
* Refout: False
* Xorout: 0x00
* Use: MultiMediaCard,SD,ect.
*****************************************************************************/
uint8_t crc7_mmc(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for ( i = 0; i < 8; i++ )
{
if ( crc & 0x80 )
crc = (crc << 1) ^ 0x12; // 0x12 = 0x09<<(8-7)
else
crc <<= 1;
}
}
return crc >> 1;
}
/******************************************************************************
* Name: CRC-8 x8+x2+x+1
* Poly: 0x07
* Init: 0x00
* Refin: False
* Refout: False
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc8(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for ( i = 0; i < 8; i++ )
{
if ( crc & 0x80 )
crc = (crc << 1) ^ 0x07;
else
crc <<= 1;
}
}
return crc;
}
/******************************************************************************
* Name: CRC-8/ITU x8+x2+x+1
* Poly: 0x07
* Init: 0x00
* Refin: False
* Refout: False
* Xorout: 0x55
* Alias: CRC-8/ATM
*****************************************************************************/
uint8_t crc8_itu(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0; // Initial value
while(length--)
{
crc ^= *data++; // crc ^= *data; data++;
for ( i = 0; i < 8; i++ )
{
if ( crc & 0x80 )
crc = (crc << 1) ^ 0x07;
else
crc <<= 1;
}
}
return crc ^ 0x55;
}
/******************************************************************************
* Name: CRC-8/ROHC x8+x2+x+1
* Poly: 0x07
* Init: 0xFF
* Refin: True
* Refout: True
* Xorout: 0x00
* Note:
*****************************************************************************/
uint8_t crc8_rohc(uint8_t *data, uint_len length)
{
uint8_t i;
uint8_t crc = 0xFF; // Initial value
while(length--)
{