CMSIS2000  0.0.7
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
crc32.c
Go to the documentation of this file.
1 /*
2  * CMSIS2000
3  * CMSIS-like sources for LPC2xxx series MCUs
4  *
5  * (C) Copyright 2011-2012, Dmitriy Cherepanov, All Rights Reserved
6  *
7  * Version: 0.0.7
8  * Date of the Last Update: 2013-03-04
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining a copy
11  * of this software and associated documentation files (the "Software"), to
12  * deal in the Software without restriction, including without limitation the
13  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
14  * sell copies of the Software, and to permit persons to whom the Software is
15  * furnished to do so, subject to the following conditions:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26  * IN THE SOFTWARE.
27  *
28  * Do not be lasy! For the latest version see http://irtos.sourceforge.net .
29  *
30  *
31 #*/
32 /*----------------------------------------------------------------------------*/
33 
34 /* three strategies
35 #include "2000/compiller/strategies.h"
36 -Os
37 -03 static
38 -03 dynamic
39 */
40 
41 #include <stdint.h>
42 #include <stddef.h>
43 #include "../crc32.h"
44 
45 
47 {
48  uint_fast8_t i;
49  uint32_t entry;
50  uint32_t poly = 0xEDB88320L;
51 
52  entry = (crc_in ^ ((uint32_t) val8)) & 0xFF;
53  for (i = 0; i < 8; i++) {
54  if (entry & 1)
55  entry = (entry >> 1) ^ poly;
56  else
57  entry >>= 1;
58  }
59  return ( ((crc_in>>8) & 0x00FFFFFF) ^ entry);
60 }
61 
62 /*----------------------------------------------------------------------------*/
63 uint32_t crc32_no_comp (uint32_t curr_crc, const uint8_t *data8, size_t len)
64 {
65  while (len-- > 0) {
66  curr_crc = crc32_update(curr_crc, *data8);
67  data8++ ;
68  }
69 return ( curr_crc );
70 }
71 /*----------------------------------------------------------------------------*/
72 uint32_t crc32_copy (uint32_t curr_crc, const uint8_t *data8, size_t len)
73 {
74  while (len-- != 0) {
75  curr_crc = crc32_update(curr_crc, *data8);
76  data8++ ;
77  }
78 return ( curr_crc );
79 }