uint16_t UpdateCRC16(uint16_t crcIn, uint8_t byte)
{
uint32_t crc = crcIn; //crcIn =0;
uint32_t in = byte|0x100; //??????2»¶® °Ñμúèyλ(±£Ö¤μúèyλÎa 1 )
do
{
crc <<= 1;
in <<= 1; //êy¾Y×óòÆò»Î»
if(in&0x100) //
{
++crc;
}
if(crc&0x10000)
{
crc ^= 0x1021;
}
} while(!(in&0x10000));
return (crc&0xffffu); //ÎT·ûoÅêy¾YààDí
}
/**
* @brief Cal CRC16 for YModem Packet
* @param data
* @param length
* @retval CRC value
*/
uint16_t Cal_CRC16(const uint8_t* data, uint32_t size)
{
uint32_t crc = 0;
const uint8_t* dataEnd = data+size; //Ö¸Ïò*data μÄÄ©Î2
while(data<dataEnd)
{
crc = UpdateCRC16(crc,*data++); //Ïè*data oó*(data+1)
}
crc = UpdateCRC16(crc,0);
crc = UpdateCRC16(crc,0);
return (crc&0xffffu);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>