diff options
Diffstat (limited to 'firmware/common/crc32-mi4.c')
-rw-r--r-- | firmware/common/crc32-mi4.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/firmware/common/crc32-mi4.c b/firmware/common/crc32-mi4.c new file mode 100644 index 0000000000..8956364f10 --- /dev/null +++ b/firmware/common/crc32-mi4.c | |||
@@ -0,0 +1,93 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: crc32.c 10464 2006-08-05 20:19:10Z miipekk $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Barry Wardell | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | /* | ||
21 | * We can't use the CRC32 implementation in the firmware library as it uses a | ||
22 | * different polynomial. The polynomial needed is 0xEDB88320L | ||
23 | * | ||
24 | * CRC32 implementation taken from: | ||
25 | * | ||
26 | * efone - Distributed internet phone system. | ||
27 | * | ||
28 | * (c) 1999,2000 Krzysztof Dabrowski | ||
29 | * (c) 1999,2000 ElysiuM deeZine | ||
30 | * | ||
31 | * This program is free software; you can redistribute it and/or | ||
32 | * modify it under the terms of the GNU General Public License | ||
33 | * as published by the Free Software Foundation; either version | ||
34 | * 2 of the License, or (at your option) any later version. | ||
35 | * | ||
36 | */ | ||
37 | |||
38 | /* based on implementation by Finn Yannick Jacobs */ | ||
39 | |||
40 | |||
41 | |||
42 | /* crc_tab[] -- this crcTable is being build by chksum_crc32GenTab(). | ||
43 | * so make sure, you call it before using the other | ||
44 | * functions! | ||
45 | */ | ||
46 | static unsigned int crc_tab[256]; | ||
47 | |||
48 | /* chksum_crc() -- to a given block, this one calculates the | ||
49 | * crc32-checksum until the length is | ||
50 | * reached. the crc32-checksum will be | ||
51 | * the result. | ||
52 | */ | ||
53 | unsigned int chksum_crc32 (unsigned char *block, unsigned int length) | ||
54 | { | ||
55 | register unsigned long crc; | ||
56 | unsigned long i; | ||
57 | |||
58 | crc = 0; | ||
59 | for (i = 0; i < length; i++) | ||
60 | { | ||
61 | crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_tab[(crc ^ *block++) & 0xFF]; | ||
62 | } | ||
63 | return (crc); | ||
64 | } | ||
65 | |||
66 | /* chksum_crc32gentab() -- to a global crc_tab[256], this one will | ||
67 | * calculate the crcTable for crc32-checksums. | ||
68 | * it is generated to the polynom [..] | ||
69 | */ | ||
70 | |||
71 | void chksum_crc32gentab (void) | ||
72 | { | ||
73 | unsigned long crc, poly; | ||
74 | int i, j; | ||
75 | |||
76 | poly = 0xEDB88320L; | ||
77 | for (i = 0; i < 256; i++) | ||
78 | { | ||
79 | crc = i; | ||
80 | for (j = 8; j > 0; j--) | ||
81 | { | ||
82 | if (crc & 1) | ||
83 | { | ||
84 | crc = (crc >> 1) ^ poly; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | crc >>= 1; | ||
89 | } | ||
90 | } | ||
91 | crc_tab[i] = crc; | ||
92 | } | ||
93 | } | ||