Mercurial > nand-ecoscentric
comparison packages/services/crc/current/src/crc16.c @ 395:9f81d6e38c3d
Fixed 32-bit reliance.
| author | asl |
|---|---|
| date | Tue, 29 Oct 2002 08:18:17 +0000 |
| parents | 544b77bfb6d5 |
| children | 74dbf4c3f2e1 |
comparison
equal
deleted
inserted
replaced
| 394:7ca632b46393 | 395:9f81d6e38c3d |
|---|---|
| 54 //========================================================================== | 54 //========================================================================== |
| 55 | 55 |
| 56 #include <cyg/crc/crc.h> | 56 #include <cyg/crc/crc.h> |
| 57 | 57 |
| 58 // Table of CRC constants - implements x^16+x^12+x^5+1 | 58 // Table of CRC constants - implements x^16+x^12+x^5+1 |
| 59 static const unsigned short crc16_tab[] = { | 59 static const cyg_uint16 crc16_tab[] = { |
| 60 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, | 60 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, |
| 61 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, | 61 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, |
| 62 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, | 62 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, |
| 63 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, | 63 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, |
| 64 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, | 64 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, |
| 89 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, | 89 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, |
| 90 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, | 90 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, |
| 91 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, | 91 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0, |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 unsigned short | 94 cyg_uint16 |
| 95 cyg_crc16(unsigned char *buf, int len) | 95 cyg_crc16(unsigned char *buf, int len) |
| 96 { | 96 { |
| 97 int i; | 97 int i; |
| 98 unsigned short cksum; | 98 cyg_uint16 cksum; |
| 99 | 99 |
| 100 cksum = 0; | 100 cksum = 0; |
| 101 for (i = 0; i < len; i++) { | 101 for (i = 0; i < len; i++) { |
| 102 cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8); | 102 cksum = crc16_tab[((cksum>>8) ^ *buf++) & 0xFF] ^ (cksum << 8); |
| 103 } | 103 } |
