--- libelwix/inc/elwix/acrc.h 2019/12/18 20:00:18 1.6.28.1 +++ libelwix/inc/elwix/acrc.h 2024/10/12 16:02:23 1.8.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: acrc.h,v 1.6.28.1 2019/12/18 20:00:18 misho Exp $ +* $Id: acrc.h,v 1.8.2.1 2024/10/12 16:02:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2019 +Copyright 2004 - 2024 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -81,16 +81,29 @@ unsigned int crcReflect(unsigned int crcNum, unsigned unsigned int crcCalc(unsigned char * __restrict psBuf, unsigned int bufLen, unsigned char crcBits, unsigned char RevOpts, unsigned int initCRC, unsigned int xorCRC); +#define crc_32(x, l) crcCalc((x), (l), 32, REVOPTS_REVERTBYTE|REVOPTS_REVERTCRC, 0xFFFFFFFF, 0xFFFFFFFF) +#define crc_16(x, l) crcCalc((x), (l), 16, REVOPTS_REVERTBYTE|REVOPTS_REVERTCRC, 0x0, 0x0) +#define crc_16_ccitt(x, l) crcCalc((x), (l), 161, 0, 0x0, 0x0) +#define crc_16_xmodem(x, l) crcCalc((x), (l), 162, REVOPTS_REVERTBYTE|REVOPTS_REVERTCRC, 0x0, 0x0) +#define crc_8(x, l) crcCalc((x), (l), 8, 0, 0x0, 0x0) /* - * crc16() - Checksum in X/Y modem communication + * crc16_ccitt() - Checksum calculation * * @buf = Data for calculation * @bufLen = Length of data * return: Checksum */ -unsigned short crc16(unsigned char * __restrict buf, int bufLen); +unsigned short crc16_ccitt(unsigned char * __restrict buf, int bufLen); /* + * crc16_xy() - Checksum calculation in X/Y modem communication + * + * @buf = Data for calculation + * @bufLen = Length of data + * return: Checksum + */ +unsigned short crc16_xy(unsigned char * __restrict buf, int bufLen); +/* * crcIP() - Checksum in IP communication * * @buf = Data for calculation @@ -154,14 +167,23 @@ unsigned int crcAdler(unsigned char * __restrict psBuf #define crcEther(psBuf, bufLen) crcCalc((psBuf), (bufLen), 32, 3, 0xFFFFFFFF, 0xFFFFFFFF) /* - * crc_32() - CRC32 calculation from table + * crc8tbl() - CRC8 calculation from table * * @crc = Initial crc value * @buf = Data for calculation * @len = Length of data + * return: calculated CRC8 + */ +uint8_t crc8tbl(unsigned char crc, const unsigned char * __restrict buf, unsigned int len); +/* + * crc32tbl() - CRC32 calculation from table + * + * @crc = Initial crc value + * @buf = Data for calculation + * @len = Length of data * return: calculated CRC32 */ -unsigned int crc_32(unsigned int crc, const unsigned char * __restrict buf, unsigned int len); +unsigned int crc32tbl(unsigned int crc, const unsigned char * __restrict buf, unsigned int len); /* * crcPelco() - Calculate Pelco D/P CRC