48 lines
724 B
C
48 lines
724 B
C
#include "stdafx.h"
|
|
#include "crc.h"
|
|
/*
|
|
static u16 crc16(unsigned char *buf,unsigned short length)
|
|
{
|
|
int i = 0;
|
|
int j = 0;
|
|
int crc16 = 0xffff;
|
|
for (i = 0;i < length;i++)
|
|
{
|
|
crc16 = crc16 ^ buf[i];
|
|
for (j = 0;j < 8;j++)
|
|
{
|
|
if (crc16 & 0x01)
|
|
{
|
|
crc16 = (crc16 >> 1) ^ 0xa001;
|
|
}
|
|
else
|
|
{
|
|
crc16 = crc16 >> 1;
|
|
}
|
|
}
|
|
}
|
|
return (u16)crc16;
|
|
}
|
|
*/
|
|
|
|
static unsigned int cal_crc16(unsigned char *ptr, unsigned int len)
|
|
{
|
|
unsigned int crc;
|
|
unsigned char i;
|
|
crc=0xffff;
|
|
while(len--!=0) {
|
|
crc = crc^(*ptr);
|
|
for(i=0; i<8; i++) {
|
|
if((crc&0x0001)==0x0001) {crc>>=1;crc^=0xA001;}
|
|
else crc>>=1;
|
|
}
|
|
ptr++;
|
|
}
|
|
return(crc);
|
|
}
|
|
u16 get_crc(u8 * val,u16 len)
|
|
{
|
|
return cal_crc16(val,len);
|
|
}
|
|
|