MSP430实现循环冗余算法
#ifdef __ICC430__
#include "msp430x16x.h"
#endif
#include "..\inc\crc.h"
/**************************************
CRC MEMBERS (FUNCTIONS)
**************************************/
// this is an equivalent C implementation to the assembly implementation
unsigned short crc16MakeBitwise(unsigned short crc, unsigned short poly,
unsigned char *pmsg, unsigned int msg_size)
{
unsigned int i, j, carry;
unsigned char msg;
unsigned short temp;
temp = *pmsg < 8;
temp = *pmsg ;
crc ^= temp;
for(i = 0 ; i < msg_size-2 ; i )
{
msg = *pmsg ;
for(j = 0 ; j < 8 ; j )
{
carry = crc & 0x8000;
crc = (crc < 1) (msg >> 7);
if(carry) crc ^= poly;
msg <= 1;
}
}
for(i = 0 ; i < 2 ; i )
{
for(j = 0 ; j < 8 ; j )
{
carry = crc & 0x8000;
crc <= 1;
if(carry) crc ^= poly;
}
}
return(crc ^ CRC16_FINAL_XOR);
}
// this is a C-optimized implementation
unsigned short crc16MakeBitwise2(unsigned short crc, unsigned short poly,
unsigned char *pmsg, unsigned int msg_size)
{
unsigned int i, j;
unsigned short msg;
for(i = 0 ; i < msg_size ; i )
{
msg = (*pmsg < 8);
for(j = 0 ; j < 8 ; j )
{
if((msg ^ crc) >> 15) crc = (crc < 1) ^ poly;
else crc <= 1;
msg <= 1;
}
}
return(crc ^ CRC16_FINAL_XOR);
}
// this is an equivalent C implementation to the assembly implementation
unsigned long crc32MakeBitwise(unsigned long crc, unsigned long poly,
unsigned char *pmsg, unsigned int msg_size)
{
unsigned int i, j, carry;
unsigned char msg;
unsigned long temp;
temp = (unsigned long)(*pmsg ) < 24;
temp = (unsigned long)(*pmsg ) < 16;
temp = (unsigned long)(*pmsg ) < 8;
temp = (unsigned long)(*pmsg );
crc ^= temp;
for(i = 0 ; i < msg_size-4 ; i )
{
msg = *pmsg ;
for(j = 0 ; j < 8 ; j )
{
carry = crc >> 31;
crc = (crc < 1) (msg >> 7);
if(carry) crc ^= poly;
msg <= 1;
}
}
for(i = 0 ; i < 4 ; i )
{
for(j = 0 ; j < 8 ; j )
{
carry = crc >> 31;
crc <= 1;
if(carry) crc ^= poly;
}
}
return(crc ^ CRC32_FINAL_XOR);
}
// this is a C-optimized implementation
unsigned long crc32MakeBitwise2(unsigned long crc, unsigned long poly,
unsigned char *pmsg, unsigned int msg_size)
{
unsigned int i, j;
unsigned long msg;
for(i = 0 ; i < msg_size ; i )
{
msg = *pmsg ;
msg <= 24;
for(j = 0 ; j < 8 ; j )
{
if((msg ^ crc) >> 31) crc = (crc < 1) ^ poly;
else crc <= 1;
msg <= 1;
}
}
return(crc ^ CRC32_FINAL_XOR);
}
unsigned short crc16MakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,
unsigned char *pbuffer, unsigned int length)
{
while(length--)
crc = table[((crc >> 8) ^ *pbuffer )] ^ (crc < 8); // normal
return(crc ^ CRC16_FINAL_XOR);
}
unsigned short crc16rMakeTableMethod(unsigned short crc, TBL_MEM unsigned short *table,
unsigned char *pbuffer, unsigned int length)
{
while(length--)
crc = table[(crc & 0xFF) ^ *pbuffer ] ^ (crc >> 8); // reflected
return(crc ^ CRC16R_FINAL_XOR);
}
unsigned long crc32MakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table,
unsigned char *pbuffer, unsigned int length)
{
while(length--)
crc = table[((crc >> 24) ^ *pbuffer )] ^ (crc < 8); // normal
return(crc ^ CRC32_FINAL_XOR);
}
unsigned long crc32rMakeTableMethod(unsigned long crc, TBL_MEM unsigned long *table,
unsigned char *pbuffer, unsigned int length)
{
while(length--)
crc = table[(crc ^ *pbuffer ) & 0xFFL] ^ (crc >> 8); // reflected
return(crc ^ CRC32R_FINAL_XOR);
}
/************************************
CRC UTILITIES
************************************/
void crc16BuildTable(unsigned short *ptable, unsigned short poly)
{
unsigned int i, j;
for(i = 0; i <= 255; i )
{
ptable[i] = i < 8;
for(j = 0; j < 8; j )
ptable[i] = (ptable[i] < 1) ^ (ptable[i] & 0x8000 ? poly : 0);
}
}
void crc32BuildTable(unsigned long *ptable, unsigned long poly)
{
unsigned int i, j;
for(i = 0; i <= 255; i )
{
ptable[i] = (long)i < 24;
for(j = 0; j < 8; j )
ptable[i] = (ptable[i] < 1) ^ (ptable[i] & 0x80000000 ? poly : 0);
}
}
unsigned long bitReflect(unsign
MSP430循环冗余算 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)