KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
checksum.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2013 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : checksum.h
11  * Created : 18 feb. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef CHECKSUM_H_
16 #define CHECKSUM_H_
17 
18 /**
19  * @file
20  *
21  * @ingroup util
22  *
23  * This module provides checksum functions.
24  */
25 
26 #include <stdint.h>
27 #include <stdbool.h>
28 
29 //! Value to which the Adler32 checksum should be initialized
30 #define ADLER32_INIT_VAL 1
31 //! Value to which the CRC32 checksum should be initialized
32 #define CRC32_INIT_VAL 0xFFFFFFFF
33 
34 /**
35  * Update the adler32 checkum with the new data. Adler32 is a very simple to implement checksum
36  * but still quite effective. Its much lighter than CRC32, since this required division. However
37  * CRC32 is capable of detecting more errors.
38  *
39  * @param adler Previous adler32 output, or ADLER32_INIT_VAL to start.
40  * @param buf A pointer to the buffer data to add
41  * @param len The length of the buffer
42  *
43  * @return The updated adler32 checksum
44  */
45 uint32_t adler32(uint32_t adler, const uint8_t * buf, int len);
46 
47 
48 /**
49  * Lightweight CRC32 algorithm, using Ethernet polynomial. Same as used everywhere.
50  *
51  * @param adler Previous crc32 output, or CRC32_INIT_VAL to start.
52  * @param buf A pointer to the buffer data to add
53  * @param len The length of the buffer
54  *
55  * @return The updated crc32 checksum
56  */
57 uint32_t crc32(uint32_t crc, const uint8_t *ptr, int cnt, bool dbg);
58 
59 #endif /* CHECKSUM_H_ */
uint32_t adler32(uint32_t adler, const uint8_t *buf, int len)
Update the adler32 checkum with the new data.
Definition: checksum.c:23
uint32_t crc32(uint32_t crc, const uint8_t *ptr, int cnt, bool dbg)
Lightweight CRC32 algorithm, using Ethernet polynomial.
Definition: checksum.c:57