📄 make_crc.c
字号:
#include "syscfg.h"#include "aos.h"#define CRC16_POLY 0x1021 /* CRC-CCITT 16 is based on the polynomial x^16+x^12+x^5+1, and the reference value is 0x1021 */U16 crc_tab[256]; U8 gucIsTableInit;extern VOID clear_watch_dog(VOID);VOID init_crc_tab( VOID ){ U16 i, j; U16 value; if ( gucIsTableInit ) return; for ( i=0; i<256; i++ ) { value = (U16)(i << 8); for ( j=0; j<8; j++ ) { if ( (value&0x8000) != 0 ) value = (U16)((value<<1) ^ CRC16_POLY); else value <<= 1; } crc_tab[i] = value; } gucIsTableInit = 1;}VOID make_crc( U8 *buffer, U32 count, U16 *crc ){ U16 temp; temp = *crc; while ( count-- != 0 ) { if (count % 10000 == 0) { clear_watch_dog(); } temp = (U16)(( temp<<8 ) ^ crc_tab[ ( temp>>8 ) ^ *buffer++ ]); } *crc = temp; return ;}U16 aos_CalCRC ( U8 *ptr, U32 count ) { U16 crc = 0; init_crc_tab(); make_crc( ptr, count, &crc ); return ( crc & 0xFFFF ) ;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -