CRC16, CRC8 source code Algorithm = table-driven

源代码在线查看: crc.c

软件大小: 3 K
上传用户: zm250063191
关键词: table-driven Algorithm source CRC8
下载地址: 免注册下载 普通下载 VIP

相关代码

				/**
				 * \file crc.c
				 * Functions and types for CRC checks.
				 *
				 * Generated on Thu Oct 30 15:54:49 2008,
				 * by pycrc v0.6.6, http://www.tty1.net/pycrc/
				 * using the configuration:
				 *    Width        = 8
				 *    Poly         = 0x07
				 *    XorIn        = 0x00
				 *    ReflectIn    = False
				 *    XorOut       = 0x00
				 *    ReflectOut   = False
				 *    Algorithm    = table-driven
				 *****************************************************************************/
				#include "crc.h"
				
				/**
				 * Static table used for the table_driven implementation.
				 *****************************************************************************/
				uc8 crc8_table[16] =
				{
				  0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d
				};
				
				uc16 crc16_table[16] =
				{
				  0x0000, 0xcc01, 0xd801, 0x1400, 0xf001, 0x3c00, 0x2800, 0xe401,
				  0xa001, 0x6c00, 0x7800, 0xb401, 0x5000, 0x9c01, 0x8801, 0x4400
				};
				
				/**
				 * Update the crc value with new data.
				 *
				 * \param crc      The current crc value.
				 * \param data     Pointer to a buffer of \a data_len bytes.
				 * \param data_len Number of bytes in the \a data buffer.
				 * \return         The updated crc value.
				 *****************************************************************************/
				u8 crc8_update (u8 crc, u8 *data, u8 data_len)
				{
				  u8 tbl_idx;
				
				  while (data_len)
				  {
				    tbl_idx = (crc >> 4) ^ (*data >> 4);
				    crc = crc8_table[tbl_idx & 0x0f] ^ (crc 				    tbl_idx = (crc >> 4) ^ (*data >> 0);
				    crc = crc8_table[tbl_idx & 0x0f] ^ (crc 				
				    data++;
				    data_len--;
				  }
				  return crc & 0xff;
				}
				
				
				u16 crc16_update (u16 crc, u8 *data, u8 data_len)
				{
				  u8 tbl_idx;
				
				  while (data_len--)
				  {
				    tbl_idx = crc ^ (*data >> (0 * 4) );
				    crc = crc16_table[tbl_idx & 0x0f] ^ (crc >> 4);
				    tbl_idx = crc ^ (*data >> (1 * 4) );
				    crc = crc16_table[tbl_idx & 0x0f] ^ (crc >> 4);
				
				    data++;
				  }
				  return crc & 0xffff;
				}
							

相关资源