|
Open Model Railroad Network (OpenMRN)
|
#include <stdint.h>#include <stddef.h>Go to the source code of this file.
Classes | |
| class | Crc8DallasMaxim |
| Helper class for computing CRC-8 according to Dallas/Maxim specification for 1-wire protocol. More... | |
| class | Crc16CCITT |
| Helper class for computing CRC-16 according to the CCITT specification (polynomial = 0x1021, x^16 + x^12 + x^5 + 1, initial value = 0xFFFF). More... | |
Macros | |
| #define | CRC8DALLAS_TABLE_SIZE 16 |
| Use the smaller (slower) table by default. | |
| #define | CRC16CCITT_TABLE_SIZE 256 |
| Use the larger (faster) table by default. | |
Functions | |
| uint16_t | crc_16_ibm (const void *data, size_t length_bytes) |
| Computes the 16-bit CRC value over data using the CRC16-ANSI (aka CRC16-IBM) settings. | |
| void | crc3_crc16_ibm (const void *data, size_t length_bytes, uint16_t *checksum) |
| Computes the triple-CRC value over a chunk of data. | |
| static void | crc3_crc16_ccitt (const void *data, size_t length_bytes, uint16_t checksum[3]) |
| Computes the triple-CRC value over a chunk of data. | |
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Helper functions for computing checksums.
Definition in file Crc.hxx.
| #define CRC16CCITT_TABLE_SIZE 256 |
| #define CRC8DALLAS_TABLE_SIZE 16 |
|
inlinestatic |
Computes the triple-CRC value over a chunk of data.
checksum is an array of 3 halfwords. The first halfword will get the CRC of the data array, the second halfword the CRC of all even index bytes (starting with the first byte, index 0), the third halfword will get the CRC of all odd index bytes (starting with the the second byte, index 1).
This implementation has no requirements for starting alignment or size modulus. It will work on any number of bytes.
| data | what to compute the checksum over |
| length_bytes | how long data is |
| checksum | is the output buffer where to store the 48-bit checksum. |
| void crc3_crc16_ibm | ( | const void * | data, |
| size_t | length_bytes, | ||
| uint16_t * | checksum | ||
| ) |
Computes the triple-CRC value over a chunk of data.
checksum is an array of 3 halfwords. The first halfword will get the CRC of the data array, the second halfword the CRC of all odd bytes (starting with the first byte), the third halfword will get the CRC of all even bytes.
This routine is helpful, because a similar routine is part of the TIVA microcontroller ROM, thus needs no implementation on an actual part. It is important to note that the TIVA version takes the length in 4-byte words and allows only using data length divisible by 4.
| data | what to compute the checksum over |
| length_bytes | how long data is |
| checksum | is the output buffer where to store the 48-bit checksum. |
| uint16_t crc_16_ibm | ( | const void * | data, |
| size_t | length_bytes | ||
| ) |
Computes the 16-bit CRC value over data using the CRC16-ANSI (aka CRC16-IBM) settings.
This involves zero init value, zero terminating value, reversed polynomial 0xA001, reversing input bits and reversing output bits. The example CRC value of "123456789" is 0xbb3d.
| data | what to compute the checksum over |
| length_bytes | how long data is |