cMicroOrp  1.0.0
C code for microcontrollers - provides ORP remote interface
crcccitt.h
Go to the documentation of this file.
1 /*
2  * Library: libcrc
3  * File: include/checksum.h
4  * Author: Lammert Bies
5  *
6  * This file is licensed under the MIT License as stated below
7  *
8  * Copyright (c) 1999-2018 Lammert Bies
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 deal
12  * in the Software without restriction, including without limitation the rights
13  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14  * 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 all
18  * 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 FROM,
25  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26  * SOFTWARE.
27  *
28  * Description
29  * -----------
30  * The headerfile include/checksum.h contains the definitions and prototypes
31  * for routines that can be used to calculate several kinds of checksums.
32  */
33 
34 #ifndef DEF_LIBCRC_CHECKSUM_H
35 #define DEF_LIBCRC_CHECKSUM_H
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 // #include <stddef.h>
42 // #include <stdint.h>
43 #include "orp.h"
44 
45 /*
46  * #define CRC_POLY_xxxx
47  *
48  * The constants of the form CRC_POLY_xxxx define the polynomials for some well
49  * known CRC calculations.
50  */
51 
52 #define CRC_POLY_16 0xA001
53 #define CRC_POLY_32 0xEDB88320ul
54 #define CRC_POLY_64 0x42F0E1EBA9EA3693ull
55 #define CRC_POLY_CCITT 0x1021
56 #define CRC_POLY_DNP 0xA6BC
57 #define CRC_POLY_KERMIT 0x8408
58 #define CRC_POLY_SICK 0x8005
59 
60 /*
61  * #define CRC_START_xxxx
62  *
63  * The constants of the form CRC_START_xxxx define the values that are used for
64  * initialization of a CRC value for common used calculation methods.
65  */
66 
67 #define CRC_START_8 0x00
68 #define CRC_START_16 0x0000
69 #define CRC_START_MODBUS 0xFFFF
70 #define CRC_START_XMODEM 0x0000
71 #define CRC_START_CCITT_1D0F 0x1D0F
72 #define CRC_START_CCITT_FFFF 0xFFFF
73 #define CRC_START_KERMIT 0x0000
74 #define CRC_START_SICK 0x0000
75 #define CRC_START_DNP 0x0000
76 #define CRC_START_32 0xFFFFFFFFul
77 #define CRC_START_64_ECMA 0x0000000000000000ull
78 #define CRC_START_64_WE 0xFFFFFFFFFFFFFFFFull
79 
80 /*
81  * Prototype list of global functions
82  */
83 
84 unsigned char * checksum_NMEA( const unsigned char *input_str, unsigned char *result );
85 uint8_t crc_8( const unsigned char *input_str, size_t num_bytes );
86 uint16_t crc_16( const unsigned char *input_str, size_t num_bytes );
87 uint32_t crc_32( const unsigned char *input_str, size_t num_bytes );
88 uint64_t crc_64_ecma( const unsigned char *input_str, size_t num_bytes );
89 uint64_t crc_64_we( const unsigned char *input_str, size_t num_bytes );
90 uint16_t crc_ccitt_1d0f( const unsigned char *input_str, size_t num_bytes );
91 uint16_t crc_ccitt_ffff( const unsigned char *input_str, size_t num_bytes );
92 uint16_t crc_dnp( const unsigned char *input_str, size_t num_bytes );
93 uint16_t crc_kermit( const unsigned char *input_str, size_t num_bytes );
94 uint16_t crc_modbus( const unsigned char *input_str, size_t num_bytes );
95 uint16_t crc_sick( const unsigned char *input_str, size_t num_bytes );
96 uint16_t crc_xmodem( const unsigned char *input_str, size_t num_bytes );
97 uint8_t update_crc_8( uint8_t crc, unsigned char c );
98 uint16_t update_crc_16( uint16_t crc, unsigned char c );
99 uint32_t update_crc_32( uint32_t crc, unsigned char c );
100 uint64_t update_crc_64_ecma( uint64_t crc, unsigned char c );
101 uint16_t update_crc_ccitt( uint16_t crc, unsigned char c );
102 uint16_t update_crc_dnp( uint16_t crc, unsigned char c );
103 uint16_t update_crc_kermit( uint16_t crc, unsigned char c );
104 uint16_t update_crc_sick( uint16_t crc, unsigned char c, unsigned char prev_byte );
105 
106 /*
107  * Global CRC lookup tables
108  */
109 
110 extern const uint32_t crc_tab32[];
111 extern const uint64_t crc_tab64[];
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif // DEF_LIBCRC_CHECKSUM_H
crc_8
uint8_t crc_8(const unsigned char *input_str, size_t num_bytes)
update_crc_ccitt
uint16_t update_crc_ccitt(uint16_t crc, unsigned char c)
Definition: crcccitt.c:126
crc_modbus
uint16_t crc_modbus(const unsigned char *input_str, size_t num_bytes)
crc_64_ecma
uint64_t crc_64_ecma(const unsigned char *input_str, size_t num_bytes)
crc_xmodem
uint16_t crc_xmodem(const unsigned char *input_str, size_t num_bytes)
Definition: crcccitt.c:53
crc_16
uint16_t crc_16(const unsigned char *input_str, size_t num_bytes)
crc_64_we
uint64_t crc_64_we(const unsigned char *input_str, size_t num_bytes)
update_crc_16
uint16_t update_crc_16(uint16_t crc, unsigned char c)
update_crc_sick
uint16_t update_crc_sick(uint16_t crc, unsigned char c, unsigned char prev_byte)
update_crc_32
uint32_t update_crc_32(uint32_t crc, unsigned char c)
update_crc_kermit
uint16_t update_crc_kermit(uint16_t crc, unsigned char c)
update_crc_dnp
uint16_t update_crc_dnp(uint16_t crc, unsigned char c)
checksum_NMEA
unsigned char * checksum_NMEA(const unsigned char *input_str, unsigned char *result)
orp.h
crc_tab64
const uint64_t crc_tab64[]
crc_tab32
const uint32_t crc_tab32[]
crc_dnp
uint16_t crc_dnp(const unsigned char *input_str, size_t num_bytes)
crc_ccitt_1d0f
uint16_t crc_ccitt_1d0f(const unsigned char *input_str, size_t num_bytes)
Definition: crcccitt.c:67
update_crc_8
uint8_t update_crc_8(uint8_t crc, unsigned char c)
crc_kermit
uint16_t crc_kermit(const unsigned char *input_str, size_t num_bytes)
crc_ccitt_ffff
uint16_t crc_ccitt_ffff(const unsigned char *input_str, size_t num_bytes)
Definition: crcccitt.c:81
crc_32
uint32_t crc_32(const unsigned char *input_str, size_t num_bytes)
crc_sick
uint16_t crc_sick(const unsigned char *input_str, size_t num_bytes)
update_crc_64_ecma
uint64_t update_crc_64_ecma(uint64_t crc, unsigned char c)