annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 INT16U cal_crc_half(INT8U far *pin, INT8U len)
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 {
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 INT16U crc;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 INT8U da;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 INT8U far *ptr;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8 INT8U bCRCHign;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 INT8U bCRCLow;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 INT16U crc_ta[16]=
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 {
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7,
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1ef
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 };
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 ptr=pin;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18 crc=0;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 while(len--!=0)
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 {
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22 da=((INT8U)(crc>>8))>>4;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 crc<<=4;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 crc^=crc_ta[da^(*ptr>>4)];
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 da=((INT8U)(crc>>8))>>4;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30 crc<<=4;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32 crc^=crc_ta[da^(*ptr&0x0f)];
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 ptr++;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 }
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 bCRCLow = crc;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 bCRCHign= (INT8U)(crc>>8);
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 if(bCRCLow==0x28||bCRCLow==0x0d||bCRCLow==0x0a)
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42 {
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
43 bCRCLow++;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
44 }
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
45 if(bCRCHign==0x28||bCRCHign==0x0d||bCRCHign==0x0a)
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
46
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
47 {
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
48 bCRCHign++;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
49 }
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
50 crc = ((INT16U)bCRCHign)<<8;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
51 crc += bCRCLow;
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
52 return(crc);
1f3c12ba927d Rework code for USB interface
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
53 }