122 lines
3.7 KiB
C++
Raw Normal View History

2023-08-01 17:27:01 +02:00
//
// FILE: CRC.cpp
// AUTHOR: Rob Tillaart
2023-10-19 12:13:06 +02:00
// VERSION: 1.0.2
2023-08-01 17:27:01 +02:00
// PURPOSE: Arduino library for CRC8, CRC12, CRC16, CRC32, CRC64
// URL: https://github.com/RobTillaart/CRC
2023-07-13 11:08:10 +02:00
#include "CRC.h"
uint8_t calcCRC8(
const uint8_t *array, crc_size_t length,
uint8_t polynome, uint8_t initial, uint8_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
CRC8 crc(polynome, initial, xorOut, reverseIn, reverseOut);
yieldPeriod == CRC_YIELD_DISABLED ?
crc.add(array, length) :
crc.add(array, length, yieldPeriod);
return crc.calc();
}
uint16_t calcCRC12(
const uint8_t *array, crc_size_t length,
uint16_t polynome, uint16_t initial, uint16_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
CRC12 crc(polynome, initial, xorOut, reverseIn, reverseOut);
yieldPeriod == CRC_YIELD_DISABLED ?
crc.add(array, length) :
crc.add(array, length, yieldPeriod);
return crc.calc();
}
uint16_t calcCRC16(
const uint8_t *array, crc_size_t length,
uint16_t polynome, uint16_t initial, uint16_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
CRC16 crc(polynome, initial, xorOut, reverseIn, reverseOut);
yieldPeriod == CRC_YIELD_DISABLED ?
crc.add(array, length) :
crc.add(array, length, yieldPeriod);
return crc.calc();
}
uint32_t calcCRC32(
const uint8_t *array, crc_size_t length,
uint32_t polynome, uint32_t initial, uint32_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
CRC32 crc(polynome, initial, xorOut, reverseIn, reverseOut);
yieldPeriod == CRC_YIELD_DISABLED ?
crc.add(array, length) :
crc.add(array, length, yieldPeriod);
return crc.calc();
}
uint64_t calcCRC64(
const uint8_t *array, crc_size_t length,
uint64_t polynome, uint64_t initial, uint64_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
CRC64 crc(polynome, initial, xorOut, reverseIn, reverseOut);
yieldPeriod == CRC_YIELD_DISABLED ?
crc.add(array, length) :
crc.add(array, length, yieldPeriod);
return crc.calc();
}
uint8_t crc8(
const uint8_t *array, crc_size_t length,
uint8_t polynome, uint8_t initial, uint8_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC8(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
uint16_t crc12(
const uint8_t *array, crc_size_t length,
uint16_t polynome, uint16_t initial, uint16_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC12(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
uint16_t crc16(
const uint8_t *array, crc_size_t length,
uint16_t polynome, uint16_t initial, uint16_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC16(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
uint16_t crc16_CCITT(
const uint8_t *array, crc_size_t length,
uint16_t polynome, uint16_t initial, uint16_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC16(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
uint32_t crc32(
const uint8_t *array, crc_size_t length,
uint32_t polynome, uint32_t initial, uint32_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC32(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
uint64_t crc64(
const uint8_t *array, crc_size_t length,
uint64_t polynome, uint64_t initial, uint64_t xorOut,
bool reverseIn, bool reverseOut, crc_size_t yieldPeriod)
{
return calcCRC64(array, length, polynome, initial, xorOut, reverseIn, reverseOut, yieldPeriod);
}
2023-08-01 17:27:01 +02:00
// -- END OF FILE