Fix. Crc types changes.

This commit is contained in:
Dmitrii Leliuhin
2020-05-24 19:36:02 +03:00
parent 1437068bdf
commit 5121ed0ba9
3 changed files with 266 additions and 262 deletions
+7 -6
View File
@@ -47,18 +47,19 @@
#include <stdint.h> #include <stdint.h>
#include <QtGlobal>
// ================= 16-BIT CRC =================== // ================= 16-BIT CRC ===================
class FastCRC16 { class FastCRC16 {
public: public:
FastCRC16(uint16_t seed); FastCRC16(quint16 seed);
// change function name from mcrf4xx_upd to mcrf4xx // change function name from mcrf4xx_upd to mcrf4xx
uint16_t mcrf4xx_calc(const uint8_t *data,const uint16_t datalen); // Equivalent to _crc_ccitt_update() in crc16.h from avr_libc quint16 mcrf4xx_calc(const quint8 *data,const quint16 datalen); // Equivalent to _crc_ccitt_update() in crc16.h from avr_libc
private: private:
uint16_t seed_; quint16 seed_;
}; };
@@ -66,13 +67,13 @@ private:
class FastCRC32 { class FastCRC32 {
public: public:
FastCRC32(uint32_t seed); FastCRC32(quint32 seed);
// change function name from crc32_upd to crc32 // change function name from crc32_upd to crc32
uint32_t crc32_calc(const uint8_t *data, uint16_t len); // Call for subsequent calculations with previous seed quint32 crc32_calc(const quint8 *data, quint16 len); // Call for subsequent calculations with previous seed
private: private:
uint32_t seed_; quint32 seed_;
}; };
#endif // FASTCRC_FASTCRC_H_ #endif // FASTCRC_FASTCRC_H_
+4 -2
View File
@@ -36,8 +36,10 @@
#include <stdint.h> #include <stdint.h>
#include <QtGlobal>
// crc16 table // crc16 table
const uint16_t crc_table_mcrf4xx[1024] = { const quint16 crc_table_mcrf4xx[1024] = {
0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
@@ -169,7 +171,7 @@ const uint16_t crc_table_mcrf4xx[1024] = {
}; };
// crc32 table // crc32 table
const uint32_t crc_table_crc32[256] = { const quint32 crc_table_crc32[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba,
0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+22 -21
View File
@@ -41,7 +41,7 @@
// ================= 16-BIT CRC =================== // ================= 16-BIT CRC ===================
/** Constructor /** Constructor
*/ */
FastCRC16::FastCRC16(uint16_t seed) { FastCRC16::FastCRC16(quint16 seed) {
seed_ = seed; seed_ = seed;
} }
@@ -58,27 +58,28 @@ FastCRC16::FastCRC16(uint16_t seed) {
* @return CRC value * @return CRC value
*/ */
uint16_t FastCRC16::mcrf4xx_calc(const uint8_t *data, uint16_t len) { #include "vbyte_buffer.h"
uint16_t crc = seed_; quint16 FastCRC16::mcrf4xx_calc(const quint8 *data, quint16 len)
{
quint16 crc = seed_;
while (((uintptr_t)data & 3) && len) { while (((quintptr)data & 3) && len) {
crc = (crc >> 8) ^ crc_table_mcrf4xx[(crc & 0xff) ^ *data++]; crc = (crc >> 8) ^ crc_table_mcrf4xx[(crc & 0xff) ^ *data++];
len--; len--;
} }
while (len >= 16) { while (len >= 16) {
len -= 16; len -= 16;
crc_n4(crc, ((uint32_t *)data)[0], crc_table_mcrf4xx); crc_n4(crc, ((quint32 *)data)[0], crc_table_mcrf4xx);
crc_n4(crc, ((uint32_t *)data)[1], crc_table_mcrf4xx); crc_n4(crc, ((quint32 *)data)[1], crc_table_mcrf4xx);
crc_n4(crc, ((uint32_t *)data)[2], crc_table_mcrf4xx); crc_n4(crc, ((quint32 *)data)[2], crc_table_mcrf4xx);
crc_n4(crc, ((uint32_t *)data)[3], crc_table_mcrf4xx); crc_n4(crc, ((quint32 *)data)[3], crc_table_mcrf4xx);
data += 16; data += 16;
} }
while (len--) { while (len--)
crc = (crc >> 8) ^ crc_table_mcrf4xx[(crc & 0xff) ^ *data++]; crc = (crc >> 8) ^ crc_table_mcrf4xx[(crc & 0xff) ^ *data++];
}
//seed = crc; //seed = crc;
return crc; return crc;
@@ -88,7 +89,7 @@ uint16_t FastCRC16::mcrf4xx_calc(const uint8_t *data, uint16_t len) {
// ================= 32-BIT CRC =================== // ================= 32-BIT CRC ===================
/** Constructor /** Constructor
*/ */
FastCRC32::FastCRC32(uint32_t seed) { FastCRC32::FastCRC32(quint32 seed) {
seed_ = seed; seed_ = seed;
} }
@@ -116,28 +117,28 @@ FastCRC32::FastCRC32(uint32_t seed) {
#define CRC_TABLE_CRC32 crc_table_crc32 #define CRC_TABLE_CRC32 crc_table_crc32
#endif #endif
uint32_t FastCRC32::crc32_calc(const uint8_t *data, uint16_t len) { quint32 FastCRC32::crc32_calc(const quint8 *data, quint16 len) {
uint32_t crc = seed_^0xffffffff; quint32 crc = seed_^0xffffffff;
while (((uintptr_t)data & 3) && len) { while (((quintptr)data & 3) && len) {
crc = (crc >> 8) ^ CRC_TABLE_CRC32[(crc & 0xff) ^ *data++]; crc = (crc >> 8) ^ CRC_TABLE_CRC32[(crc & 0xff) ^ *data++];
len--; len--;
} }
while (len >= 16) { while (len >= 16) {
len -= 16; len -= 16;
#if CRC_BIGTABLES #if CRC_BIGTABLES
crc_n4d(crc, ((uint32_t *)data)[0], CRC_TABLE_CRC32); crc_n4d(crc, ((uint32_t *)data)[0], CRC_TABLE_CRC32);
crc_n4d(crc, ((uint32_t *)data)[1], CRC_TABLE_CRC32); crc_n4d(crc, ((uint32_t *)data)[1], CRC_TABLE_CRC32);
crc_n4d(crc, ((uint32_t *)data)[2], CRC_TABLE_CRC32); crc_n4d(crc, ((uint32_t *)data)[2], CRC_TABLE_CRC32);
crc_n4d(crc, ((uint32_t *)data)[3], CRC_TABLE_CRC32); crc_n4d(crc, ((uint32_t *)data)[3], CRC_TABLE_CRC32);
#else #else
crcsm_n4d(crc, ((uint32_t *)data)[0], CRC_TABLE_CRC32); crcsm_n4d(crc, ((quint32 *)data)[0], CRC_TABLE_CRC32);
crcsm_n4d(crc, ((uint32_t *)data)[1], CRC_TABLE_CRC32); crcsm_n4d(crc, ((quint32 *)data)[1], CRC_TABLE_CRC32);
crcsm_n4d(crc, ((uint32_t *)data)[2], CRC_TABLE_CRC32); crcsm_n4d(crc, ((quint32 *)data)[2], CRC_TABLE_CRC32);
crcsm_n4d(crc, ((uint32_t *)data)[3], CRC_TABLE_CRC32); crcsm_n4d(crc, ((quint32 *)data)[3], CRC_TABLE_CRC32);
#endif #endif
data += 16; data += 16;
} }