代码拉取完成,页面将自动刷新
#include "stdio.h"
#include "stdint.h"
#include "DevicesCRC.h"
uint8_t ucCRC7_MMC(uint8_t *pucInitCRC, void *pvDataBuff, int32_t iLength)
{
uint8_t ucPolynomial = 0x12, ucInputCRC = 0, *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pucInitCRC != NULL)
ucInputCRC = *pucInitCRC;
while((iLength--) > 0)
{
ucInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (ucInputCRC & 0x80)
ucInputCRC = (ucInputCRC << 1) ^ ucPolynomial;
else
ucInputCRC <<= 1;
}
}
return ucInputCRC >> 1;
}
uint8_t ucCRC8(uint8_t *pucInitCRC, void *pvDataBuff, int32_t iLength)
{
uint8_t ucPolynomial = 0x07, ucInputCRC = 0, *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pucInitCRC != NULL)
ucInputCRC = *pucInitCRC;
while((iLength--) > 0)
{
ucInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (ucInputCRC & 0x80)
ucInputCRC = (ucInputCRC << 1) ^ ucPolynomial;
else
ucInputCRC <<= 1;
}
}
return ucInputCRC;
}
uint8_t ucCRC8_ITU(uint8_t *pucInitCRC, void *pvDataBuff, int32_t iLength)
{
uint8_t ucPolynomial = 0x07, ucInputCRC = 0, *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pucInitCRC != NULL)
ucInputCRC = *pucInitCRC;
while((iLength--) > 0)
{
ucInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (ucInputCRC & 0x80)
ucInputCRC = (ucInputCRC << 1) ^ ucPolynomial;
else
ucInputCRC <<= 1;
}
}
return ucInputCRC ^ 0x55;
}
uint8_t ucCRC8_ROHC(uint8_t *pucInitCRC, void *pvDataBuff, int32_t iLength)
{
uint8_t ucPolynomial = 0xE0, ucInputCRC = 0xFF, *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pucInitCRC != NULL)
ucInputCRC = *pucInitCRC;
while((iLength--) > 0)
{
ucInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (ucInputCRC & 1)
ucInputCRC = (ucInputCRC >> 1) ^ ucPolynomial;
else
ucInputCRC >>= 1;
}
}
return ucInputCRC;
}
uint8_t ucCRC8_MAXIM(uint8_t *pucInitCRC, void *pvDataBuff, int32_t iLength)
{
uint8_t ucPolynomial = 0x8C, ucInputCRC = 0, *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pucInitCRC != NULL)
ucInputCRC = *pucInitCRC;
while((iLength--) > 0)
{
ucInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (ucInputCRC & 1)
ucInputCRC = (ucInputCRC >> 1) ^ ucPolynomial;
else
ucInputCRC >>= 1;
}
}
return ucInputCRC;
}
uint16_t usCRC16_IBM(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0xA001, usInputCRC = 0xFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return usInputCRC;
}
uint16_t usCRC16_MAXIM(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0xA001, usInputCRC = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return ~usInputCRC;
}
uint16_t usCRC16_USB(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0xA001, usInputCRC = 0xFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return ~usInputCRC;
}
uint16_t usCRC16_MODBUS(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0xA001, usInputCRC = 0xFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return usInputCRC;
}
uint16_t usCRC16_CCITT(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0x8408, usInputCRC = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return usInputCRC;
}
uint16_t usCRC16_CCITT_FALSE(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0x1021, usInputCRC = 0xFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= (uint16_t)(*pucDataBuff++) << 8;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 0x8000)
usInputCRC = (usInputCRC << 1) ^ usPolynomial;
else
usInputCRC <<= 1;
}
}
return usInputCRC;
}
uint16_t usCRC16_X25(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0x8408, usInputCRC = 0xFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return ~usInputCRC;
}
uint16_t usCRC16_XMODEM(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0x1021, usInputCRC = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= (uint16_t)(*pucDataBuff++) << 8;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 0x8000)
usInputCRC = (usInputCRC << 1) ^ usPolynomial;
else
usInputCRC <<= 1;
}
}
return usInputCRC;
}
uint16_t usCRC16_DNP(uint16_t *pusInitCRC, void *pvDataBuff, int32_t iLength)
{
uint16_t usPolynomial = 0xA6BC, usInputCRC = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(pusInitCRC != NULL)
usInputCRC = *pusInitCRC;
while((iLength--) > 0)
{
usInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if (usInputCRC & 1)
usInputCRC = (usInputCRC >> 1) ^ usPolynomial;
else
usInputCRC >>= 1;
}
}
return ~usInputCRC;
}
uint32_t uiReflect(uint32_t uiData, uint8_t ucLength)
{
uint32_t uiMask = 1 << (ucLength - 1), uiMaskRef = 1, uiDataReturn = 0;
for(; uiMask; uiMask >>= 1)
{
if(uiData & uiMask)
uiDataReturn |= uiMaskRef;
uiMaskRef <<= 1;
}
return uiDataReturn;
}
uint32_t uiCRC32(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
uiPolynomial = uiReflect(uiPolynomial, 32);
while((iLength--) > 0)
{
uiInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 1)
uiInputCRC = (uiInputCRC >> 1) ^ uiPolynomial;
else
uiInputCRC >>= 1;
}
}
return ~uiInputCRC;
}
uint32_t uiCRC32_BZIP2(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
while((iLength--) > 0)
{
uiInputCRC ^= (uint32_t)(*pucDataBuff++) << 24;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 0x80000000)
uiInputCRC = (uiInputCRC << 1) ^ uiPolynomial;
else
uiInputCRC <<= 1;
}
}
return ~uiInputCRC;
}
uint32_t uiCRC32_MPEG2(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
while((iLength--) > 0)
{
uiInputCRC ^= (uint32_t)(*pucDataBuff++) << 24;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 0x80000000)
uiInputCRC = (uiInputCRC << 1) ^ uiPolynomial;
else
uiInputCRC <<= 1;
}
}
return uiInputCRC;
}
uint32_t uiCRC32_POSIX(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
while((iLength--) > 0)
{
uiInputCRC ^= (uint32_t)(*pucDataBuff++) << 24;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 0x80000000)
uiInputCRC = (uiInputCRC << 1) ^ uiPolynomial;
else
uiInputCRC <<= 1;
}
}
return ~uiInputCRC;
}
uint32_t uiCRC32_JAMCRC(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
uiPolynomial = uiReflect(uiPolynomial, 32);
while((iLength--) > 0)
{
uiInputCRC ^= *pucDataBuff++;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 1)
uiInputCRC = (uiInputCRC >> 1) ^ uiPolynomial;
else
uiInputCRC >>= 1;
}
}
return uiInputCRC;
}
uint32_t uiCRC32_STM32(uint32_t *puiInitCRC, void *pvDataBuff, int32_t iLength)
{
uint32_t uiPolynomial = 0x04C11DB7, uiInputCRC = 0xFFFFFFFF, xbit = 0x80000000, uiDataTemp = 0;
uint8_t *pucDataBuff = pvDataBuff;
int8_t i = 0;
if(pucDataBuff == NULL)
return 0;
if(puiInitCRC != NULL)
uiInputCRC = *puiInitCRC;
while((iLength--) > 0)
{
uiDataTemp = *pucDataBuff++;
xbit = 0x80000000;
for(i = 0; i < 8; ++i)
{
if(uiInputCRC & 0x80000000)
uiInputCRC = (uiInputCRC << 1) ^ uiPolynomial;
else
uiInputCRC <<= 1;
if(uiDataTemp & xbit)
uiInputCRC ^= uiPolynomial;
xbit >>= 1;
}
}
return uiInputCRC;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。