Mercurial > ~darius > hgwebdir.cgi > giant
comparison docs/CRC.c @ 0:1f3c12ba927d default tip
Rework code for USB interface
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sun, 19 Nov 2017 18:10:23 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f3c12ba927d |
---|---|
1 INT16U cal_crc_half(INT8U far *pin, INT8U len) | |
2 { | |
3 | |
4 INT16U crc; | |
5 | |
6 INT8U da; | |
7 INT8U far *ptr; | |
8 INT8U bCRCHign; | |
9 INT8U bCRCLow; | |
10 | |
11 INT16U crc_ta[16]= | |
12 { | |
13 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7, | |
14 | |
15 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef | |
16 }; | |
17 ptr=pin; | |
18 crc=0; | |
19 | |
20 while(len--!=0) | |
21 { | |
22 da=((INT8U)(crc>>8))>>4; | |
23 | |
24 crc<<=4; | |
25 | |
26 crc^=crc_ta[da^(*ptr>>4)]; | |
27 | |
28 da=((INT8U)(crc>>8))>>4; | |
29 | |
30 crc<<=4; | |
31 | |
32 crc^=crc_ta[da^(*ptr&0x0f)]; | |
33 | |
34 ptr++; | |
35 } | |
36 bCRCLow = crc; | |
37 | |
38 bCRCHign= (INT8U)(crc>>8); | |
39 | |
40 if(bCRCLow==0x28||bCRCLow==0x0d||bCRCLow==0x0a) | |
41 | |
42 { | |
43 bCRCLow++; | |
44 } | |
45 if(bCRCHign==0x28||bCRCHign==0x0d||bCRCHign==0x0a) | |
46 | |
47 { | |
48 bCRCHign++; | |
49 } | |
50 crc = ((INT16U)bCRCHign)<<8; | |
51 crc += bCRCLow; | |
52 return(crc); | |
53 } |