Just tried to verify the FastCRC_example and got this.
D:\Arduino\libraries\FastCRC\FastCRC.cpp: In member function 'uint8_t FastCRC8::smbus(const uint8_t*, uint16_t)':
D:\Arduino\libraries\FastCRC\FastCRC.cpp:78:27: error: 'CRC_FLAG_NOREFLECT_8' was not declared in this scope
Using Arduino 1.0.6 and Teensy 3.1
edit.
I get the same error with FastCRC_validate.
#define CRC_FLAG_NOREFLECT_8 (0) //For 8-Bit CRC
Hm, i think somehow this line got lost:
Code:#define CRC_FLAG_NOREFLECT_8 (0) //For 8-Bit CRC
Can't test this at the moment !
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::cksum_upd(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:72: multiple definition of `FastCRC8::FastCRC8()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:68: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::cksum_upd(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:72: multiple definition of `FastCRC8::FastCRC8()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:68: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC8::smbus(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:106: multiple definition of `FastCRC8::update(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:101: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC8::generic(unsigned char, unsigned char, unsigned long, unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:139: multiple definition of `FastCRC8::generic(unsigned char, unsigned char, unsigned long, unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:134: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC8::maxim(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:94: multiple definition of `FastCRC8::maxim(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:89: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC8::smbus(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:82: multiple definition of `FastCRC8::smbus(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:78: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::FastCRC16()':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:157: multiple definition of `FastCRC16::FastCRC16()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:150: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::FastCRC16()':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:157: multiple definition of `FastCRC16::FastCRC16()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:150: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::update(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:240: multiple definition of `FastCRC16::update(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:233: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::generic(unsigned short, unsigned short, unsigned long, unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:272: multiple definition of `FastCRC16::generic(unsigned short, unsigned short, unsigned long, unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:265: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::x25(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:228: multiple definition of `FastCRC16::x25(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:221: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::xmodem(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:216: multiple definition of `FastCRC16::xmodem(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:209: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::kermit(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:203: multiple definition of `FastCRC16::kermit(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:196: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::modbus(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:191: multiple definition of `FastCRC16::modbus(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:184: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::mcrf4xx(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:179: multiple definition of `FastCRC16::mcrf4xx(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:172: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC16::ccitt(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:167: multiple definition of `FastCRC16::ccitt(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:160: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::FastCRC32()':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:297: multiple definition of `FastCRC32::FastCRC32()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:284: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::FastCRC32()':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:297: multiple definition of `FastCRC32::FastCRC32()'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:284: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::update(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:332: multiple definition of `FastCRC32::update(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:319: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::generic(unsigned long, unsigned long, unsigned long, unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:362: multiple definition of `FastCRC32::generic(unsigned long, unsigned long, unsigned long, unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:349: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::cksum(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:319: multiple definition of `FastCRC32::cksum(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:306: first defined here
FastCRC\FastCRChw.cpp.o: In function `FastCRC32::crc32(unsigned char const*, unsigned short)':
D:\Arduino\libraries\FastCRC/FastCRChw.cpp:307: multiple definition of `FastCRC32::crc32(unsigned char const*, unsigned short)'
FastCRC\FastCRC.cpp.o:D:\Arduino\libraries\FastCRC/FastCRC.cpp:294: first defined here
collect2.exe: error: ld returned 1 exit status
Ah.. i see.
please delete FastCRC.cpp from the FastCRC directory and insert the define from above bewteen the other defines in the .h file.
That's it.
I'll ask Paul to update the Lib with the next beta.
Regards, Frank.
CRC Benchmark
Length: 16384 Bytes
Maxim (iButton) 8-Bit CRC:
FastCRC : Value 0xF6 in 350us
Software: Value 0xF6 in 12482us
MODBUS 16-Bit CRC:
FastCRC: Value 0x7029 in 350us
Software: Value 0x7029 in 18123us
XMODEM 16-Bit CRC:
FastCRC: Value 0x98D9 in 348us
Software: Value 0x98D9 in 13678us
MCRF4XX 16-Bit CRC:
FastCRC: Value 0x4A29 in 351us
Software: Value 0x4A29 in 2397us
KERMIT 16-Bit CRC:
FastCRC: Value 0xB259 in 351us
Ethernet 32-Bit CRC:
FastCRC: Value 0x1271457F in 348us
//FastCRC
//Quick'n dirty Benchmark
//
//(c) Frank Boesing 2014
#include <util/crc16.h>
#include <FastCRC.h>
#define Ser Serial
#define BUFSIZE 16384
FastCRC8 CRC8;
FastCRC16 CRC16;
FastCRC32 CRC32;
uint8_t buf[BUFSIZE];
// Supporting functions for Software CRC
inline uint16_t softcrc(uint16_t seed, uint8_t *data, uint16_t datalen) {
for (uint16_t i=0; i<datalen; i++) {
seed = _crc16_update(seed, data[i]);
}
return seed;
}
inline uint16_t softcrcIbutton(uint16_t seed, uint8_t *data, uint16_t datalen) {
for (uint16_t i=0; i<datalen; i++) {
seed = _crc_ibutton_update(seed, data[i]);
}
return seed;
}
inline uint16_t softcrcCCIT(uint16_t seed, uint8_t *data, uint16_t datalen) {
for (uint16_t i=0; i<datalen; i++) {
seed = _crc_ccitt_update(seed, data[i]);
}
return seed;
}
inline uint16_t softcrcXMODEM(uint16_t seed, uint8_t *data, uint16_t datalen) {
for (uint16_t i=0; i<datalen; i++) {
seed = _crc_xmodem_update(seed, data[i]);
}
return seed;
}
void setup() {
Ser.begin(115200);
}
void loop() {
int time;
uint32_t crc;
delay(1000);
Ser.printf("\r\n\r\nCRC Benchmark\r\n");
Ser.printf("Length: %u Bytes\r\n\r\n", sizeof(buf));
//Fill array with data
for (int i=0; i<BUFSIZE; i++) {
buf[i] = (i+1) & 0xff;
}
Ser.printf("\r\nMaxim (iButton) 8-Bit CRC:\r\n");
Ser.flush();
time = micros();
crc = CRC8.maxim(buf, BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC : Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
time = micros();
crc = softcrcIbutton(0, buf, BUFSIZE);
time = micros() - time;
Ser.printf("Software: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
Ser.println("\r\nMODBUS 16-Bit CRC:");
Ser.flush();
time = micros();
crc = CRC16.modbus(buf, BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
time = micros();
crc = softcrc(0xffff, buf, BUFSIZE);
time = micros() - time;
Ser.printf("Software: Value 0x%X in %uus\r\n", crc, time);
Ser.println("\r\nXMODEM 16-Bit CRC:");
Ser.flush();
time = micros();
crc = CRC16.xmodem(buf, BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
time = micros();
crc = softcrcXMODEM(0, buf, BUFSIZE);
time = micros() - time;
Ser.printf("Software: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
Ser.println("\r\nMCRF4XX 16-Bit CRC:");
Ser.flush();
time = micros();
crc = CRC16.mcrf4xx(buf,BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
time = micros();
crc = softcrcCCIT(0xffff, buf, BUFSIZE);
time = micros() - time;
Ser.printf("Software: Value 0x%X in %uus\r\n", crc, time);
Ser.flush();
Ser.println("\r\nKERMIT 16-Bit CRC:");
Ser.flush();
time = micros();
crc = CRC16.kermit(buf, BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC: Value 0x%X in %uus\r\n", crc, time);
Ser.println("\r\nEthernet 32-Bit CRC:");
Ser.flush();
time = micros();
crc = CRC32.crc32(buf, BUFSIZE);
time = micros() - time;
Ser.printf("FastCRC: Value 0x%X in %uus\r\n", crc, time);
}
Teensy 3.2 @120MHz mbed K64F @120MHz
hardware CRC hardware CRC
Maxim (iButton) FastCRC: Value:0xF6, Time: 275 us. Maxim (iButton) FastCRC: Value:0xf6, Time: 275 us
Maxim (iButton) builtin: Value:0xF6, Time: 9994 us. Maxim (iButton) builtin: Value:0xf6, Time: 7100 us
MODBUS FastCRC: Value:0x7029, Time: 275 us. MODBUS FastCRC: Value:0x7029, Time: 275 us
MODBUS builtin: Value:0x7029, Time: 9584 us. MODBUS builtin: Value:0x7029, Time: 7100 us
XMODEM FastCRC: Value:0x98D9, Time: 275 us. XMODEM FastCRC: Value:0x98d9, Time: 275 us
XMODEM builtin: Value:0x98D9, Time: 10542 us. XMODEM builtin: Value:0x98d9, Time: 8193 us
MCRF4XX FastCRC: Value:0x4A29, Time: 275 us. MCRF4XX FastCRC: Value:0x4a29, Time: 275 us
MCRF4XX builtin: Value:0x4A29, Time: 1783 us. MCRF4XX builtin: Value:0x4a29, Time: 1639 us
KERMIT FastCRC: Value:0xB259, Time: 279 us. KERMIT FastCRC: Value:0xb259, Time: 275 us
Ethernet FastCRC: Value:0x1271457F, Time: 275 us. Ethernet FastCRC: Value:0x1271457f, Time: 275 us
table-driven CRC table-driven CRC
Maxim (iButton) FastCRC: Value:0xF6, Time: 1329 us. Maxim (iButton) FastCRC: Value:0xf6, Time: 997 us
Maxim (iButton) builtin: Value:0xF6, Time: 9994 us. Maxim (iButton) builtin: Value:0xf6, Time: 7101 us
MODBUS FastCRC: Value:0x7029, Time: 2226 us. MODBUS FastCRC: Value:0x7029, Time: 1623 us
MODBUS builtin: Value:0x7029, Time: 9584 us. MODBUS builtin: Value:0x7029, Time: 7101 us
XMODEM FastCRC: Value:0x98D9, Time: 2102 us. XMODEM FastCRC: Value:0x98d9, Time: 1608 us
XMODEM builtin: Value:0x98D9, Time: 10542 us. XMODEM builtin: Value:0x98d9, Time: 8193 us
MCRF4XX FastCRC: Value:0x4A29, Time: 2185 us. MCRF4XX FastCRC: Value:0x4a29, Time: 1664 us
MCRF4XX builtin: Value:0x4A29, Time: 1782 us. MCRF4XX builtin: Value:0x4a29, Time: 1639 us
KERMIT FastCRC: Value:0xB259, Time: 2190 us. KERMIT FastCRC: Value:0xb259, Time: 1650 us
Ethernet FastCRC: Value:0x38D32145, Time: 2090 us. Ethernet FastCRC: Value:0x38d32145, Time: 1702 us
FYI,
I ported the FastCRC library to mbed K64F (Freescale/NXP Cortex M4F @120MHz , floating point, think teensy++3.1). The CRC implementation is the same as the teensy 3, so there was no problem porting. To compare hardware, builtin (Arduino crc16.h), and table-driven CRCs, I mangled the __MK... conditionals in the library so the IDE was forced to build the table-driven implementation.
can you make a pullrequest, pls ?
I had fits getting the ARM hardware CRC32 fixed poly to match a software equivalent running on an x86 - two ends of a data link.
CRC->CR = 1; //reset
while(CRC->DR != ~0); // wait for reset
CRC->DR = __RBIT(0x41414141); // AAAA ;
result = ~__RBIT(CRC->DR);
Added PROGMEM...
It would be great if somebody could test it with an AVR (mine are collecting dust.. too much trouble to reactivate them)
It may not be worth adding conditional compilation for each CRC type and its associated tables, but as the library is now (about 23K of tables), none of the AVR engines can compile the FastCRC library. A user can cut and paste out the needed pieces for a particular algorithm thanks to your building such a comprehensive library.
Suggestion: I don't think you want noInterrupts() in your benchmark example. For the AVR-based processors, you will block the millisecond tick interrupt and possibly lose milliseconds in your elapsed-time calculation! I was surprised that noInterrupts() had no effect on teensy 3 sysTick timer interrupts ( I guess because it's not an NVIC maskable interrupt).
They can't compile ? Thanks for the info.. i try it..
#ifdef ARDUINO
#error asap: buy teensy
#endif
Suggestion: I don't think you want noInterrupts() in your benchmark example. For the AVR-based processors, you will block the millisecond tick interrupt and possibly lose milliseconds in your elapsed-time calculation! I was surprised that noInterrupts() had no effect on teensy 3 sysTick timer interrupts ( I guess because it's not an NVIC maskable interrupt).
Ok, that's because of the large array in the benchmark-example. It is 16 KB. reducing to 2 or 4 KB should work for the LC.
manitou: do have have an arduino ? could you please test a single crc ? perhaps one 8-, one 16- and a 32-bit.. the validation skec
th uses an 9-byte array so it should work to comment-out the unused CRCs
CRC Validation
SMBUS is ok
Maxim is ok
CCITT is ok
MCRF4XX is NOT ok
MODBUS is NOT ok
KERMIT is NOT ok
XMODEM is NOT ok
X.25 is NOT ok
CRC32 is ok
CKSUM is NOT ok
On the ARMs, the interrupts are called when the interrupts are re-enabled. Are they lost on AVR ?
I don't want the interrupts because they lead to not-constant values (us)..
Is it ok to reduce the bufsize in the benchmark dramatically ? Perhaps from 16 KB to 512 bytes ?
CRC Benchmark
Length: 4096 Bytes
Maxim (iButton) FastCRC: Value:0x18, Time: 3904 us 8.39 mbs
Maxim (iButton) builtin: Value:0x18, Time: 15320 us 2.14 mbs
MODBUS FastCRC: Value:0x47A, Time: 5084 us 6.45 mbs
MODBUS builtin: Value:0x47A, Time: 8304 us 3.95 mbs
XMODEM FastCRC: Value:0x4B2E, Time: 5084 us 6.45 mbs
XMODEM builtin: Value:0x4B2E, Time: 8832 us 3.71 mbs
MCRF4XX FastCRC: Value:0x492A, Time: 5084 us 6.45 mbs
MCRF4XX builtin: Value:0x492A, Time: 6752 us 4.85 mbs
KERMIT FastCRC: Value:0xB2DD, Time: 5084 us 6.45 mbs
Ethernet FastCRC: Value:0xAE7F4FCF, Time: 8820 us 3.72 mbs
CRC Benchmark
Length: 16384 Bytes
Maxim (iButton) FastCRC: Value:0xF6, Time: 275 us 476.63 mbs
Maxim (iButton) builtin: Value:0xF6, Time: 9993 us 13.12 mbs
MODBUS FastCRC: Value:0x7029, Time: 275 us 476.63 mbs
MODBUS builtin: Value:0x7029, Time: 9584 us 13.68 mbs
XMODEM FastCRC: Value:0x98D9, Time: 275 us 476.63 mbs
XMODEM builtin: Value:0x98D9, Time: 10539 us 12.44 mbs
MCRF4XX FastCRC: Value:0x4A29, Time: 274 us 478.36 mbs
MCRF4XX builtin: Value:0x4A29, Time: 1782 us 73.55 mbs
KERMIT FastCRC: Value:0xB259, Time: 278 us 471.48 mbs
Ethernet FastCRC: Value:0x1271457F, Time: 279 us 469.79 mbs
Length: 4096 Bytes
Maxim (iButton) FastCRC: Value:0x18, Time: 772 us 42.45 mbs
Maxim (iButton) builtin: Value:0x18, Time: 772 us 42.45 mbs
MODBUS FastCRC: Value:0x47A, Time: 924 us 35.46 mbs
MODBUS builtin: Value:0x47A, Time: 1024 us 32.00 mbs
XMODEM FastCRC: Value:0x4B2E, Time: 924 us 35.46 mbs
XMODEM builtin: Value:0x4B2E, Time: 516 us 63.50 mbs
MCRF4XX FastCRC: Value:0x492A, Time: 924 us 35.46 mbs
MCRF4XX builtin: Value:0x492A, Time: 1536 us 21.33 mbs
KERMIT FastCRC: Value:0xB2DD, Time: 924 us 35.46 mbs
Ethernet FastCRC: Value:0xAE7F4FCF, Time: 1532 us 21.39 mbs