CMSIS2000  0.0.7
 Указатель Структуры данных Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Макросы Группы Страницы
crc32.h
См. документацию.
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 /** Begin CRC calculation.
34  * \return CRC calc start value
35 */
36 
37 #define crc32_init() ((uint32_t)0xffffffff)
38 /*----------------------------------------------------------------------------*/
39 /** Finish CRC calculation
40  * \par crc current CRC value
41  * \return end CRC value
42  */
43 #define crc32_end(crc) (((uint32_t)(crc)) ^ ((uint32_t)0xffffffff))
44 /*----------------------------------------------------------------------------*/
45 /***\brief crc32_update
46  Calculate CRC value one at a time
47  the CRC area, and passing value to get the CRC
48  \par crc previous CRC
49  \par val8 curr data
50  \return new CRC
51 */
53 /*----------------------------------------------------------------------------*/
54 /***\brief crc32_no_comp
55  Calculate CRC for array of bytes without complement to ones.
56 
57  \par crc previous CRC (if no previous set is to 0!)
58  \par data curr data ptr
59  \par len curr data length
60 
61  \return returned value calculated CRC
62 */
63 uint32_t crc32_no_comp (uint32_t curr_crc, const uint8_t *data8, size_t len);
64 
65 /*----------------------------------------------------------------------------*/
66 /***\brief crc32
67  Calculate CRC for array of bytes
68 
69  \par crc previous CRC (if no previous set is to 0!)
70  \par data curr data ptr
71  \par len curr data length
72 
73  \return returned value calculated CRC
74 */
75 static inline uint32_t crc32 (uint32_t curr_crc, const uint8_t *data, size_t len)
76 {
77 return (crc32_end(
78  crc32_no_comp( curr_crc ^ crc32_init(),
79  data,len)
80  )
81  );
82 }
83