PX4 Firmware
PX4 Autopilot Software http://px4.io
crc.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2015 PX4 Development Team. All rights reserved.
4  * Author: Ben Dyer <ben_dyer@mac.com>
5  * Pavel Kirienko <pavel.kirienko@zubax.com>
6  * David Sidrane <david_s5@nscdg.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  * 3. Neither the name PX4 nor the names of its contributors may be
19  * used to endorse or promote products derived from this software
20  * without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  ****************************************************************************/
36 
37 #pragma once
38 
39 /****************************************************************************
40  * Included Files
41  ****************************************************************************/
42 /****************************************************************************
43  * Pre-processor Definitions
44  ****************************************************************************/
45 #define CRC16_INITIAL 0xFFFFu
46 #define CRC16_OUTPUT_XOR 0x0000u
47 #define CRC64_INITIAL 0xFFFFFFFFFFFFFFFFull
48 #define CRC64_OUTPUT_XOR 0xFFFFFFFFFFFFFFFFull
49 
50 /****************************************************************************
51  * Public Type Definitions
52  ****************************************************************************/
53 
54 /****************************************************************************
55  * Global Variables
56  ****************************************************************************/
57 
58 /****************************************************************************
59  * Public Function Prototypes
60  ****************************************************************************/
61 /****************************************************************************
62  * Name: crc16_add
63  *
64  * Description:
65  * Use to calculates a CRC-16-CCITT using the polynomial of
66  * 0x1021 by adding a value successive values.
67  *
68  * Input Parameters:
69  * crc - The running total of the crc 16
70  * value - The value to add
71  *
72  * Returned Value:
73  * The current crc16 with the value processed.
74  *
75  ****************************************************************************/
76 
77 uint16_t crc16_add(uint16_t crc, uint8_t value);
78 
79 /****************************************************************************
80  * Name: crc16_signature
81  *
82  * Description:
83  * Calculates a CRC-16-CCITT using the crc16_add
84  * function
85  *
86  * Input Parameters:
87  * initial - The Initial value to uses as the crc's starting point
88  * length - The number of bytes to add to the crc
89  * bytes - A pointer to any array of length bytes
90  *
91  * Returned Value:
92  * The crc16 of the array of bytes
93  *
94  ****************************************************************************/
95 
96 uint16_t crc16_signature(uint16_t initial, size_t length,
97  const uint8_t *bytes);
98 
99 /****************************************************************************
100  * Name: crc64_add_word
101  *
102  * Description:
103  * Calculates a CRC-64-WE using the polynomial of 0x42F0E1EBA9EA3693
104  * See http://reveng.sourceforge.net/crc-catalogue/17plus.htm#crc.cat-bits.64
105  * Check: 0x62EC59E3F1A4F00A
106  *
107  * Input Parameters:
108  * crc - The running total of the crc 64
109  * value - The value to add
110  *
111  * Returned Value:
112  * The current crc64 with the value processed.
113  *
114  ****************************************************************************/
115 
116 uint64_t crc64_add_word(uint64_t crc, uint32_t value);
uint16_t crc16_signature(uint16_t initial, size_t length, const uint8_t *bytes)
Definition: crc.c:124
uint64_t crc64_add_word(uint64_t crc, uint32_t value)
Definition: crc.c:152
uint16_t crc16_add(uint16_t crc, uint8_t value)
Definition: crc.c:89