Chinaunix首页 | 论坛 | 博客
  • 博客访问: 548291
  • 博文数量: 105
  • 博客积分: 3274
  • 博客等级: 中校
  • 技术积分: 1161
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-21 12:14
文章分类

全部博文(105)

文章存档

2011年(1)

2010年(104)

分类: 嵌入式

2010-06-30 21:20:10

/*
**---------------------------------------------------------------------------
**
** Abstract: Calculate j1850 CRC 
**
** Parameters: Pointer to frame buffer, frame length
**
** Returns: CRC of frame
**
**---------------------------------------------------------------------------
*/
// calculate J1850 message CRC
u8 j1850_crc(u8 *msg_buf, u16 nbytes)
{
 u8 crc_reg=0xff,poly,bit_count;
 u16 byte_count;
 u8 *byte_point;
 u8 bit_point;
 for (byte_count=0, byte_point=msg_buf; byte_count {
  for (bit_count=0, bit_point=0x80 ; bit_count<8; ++bit_count, bit_point>>=1)
  {
   if (bit_point & *byte_point) // case for new bit = 1
   {
    if (crc_reg & 0x80)
     poly=1; // define the polynomial
    else
     poly=0x1c;
    crc_reg= ( (crc_reg << 1) | 1) ^ poly;
   }
   else  // case for new bit = 0
   {
    poly=0;
    if (crc_reg & 0x80)
     poly=0x1d;
    crc_reg= (crc_reg << 1) ^ poly;
   }
  }
 }
 return ~crc_reg; // Return CRC
}
阅读(3547) | 评论(0) | 转发(1) |
0

上一篇:linux 管理磁盘

下一篇:linux dd的使用

给主人留下些什么吧!~~