Przemysław Kozyra / Mbed 2 deprecated K64F_CRC_HW

Dependencies:   HW_CRC_K64F mbed

Fork of fastCRCperf by tom dunigan

Committer:
manitou
Date:
Fri Apr 22 09:55:23 2016 +0000
Revision:
0:d4f8f8fee9db
Child:
1:66996d5c4b7c
performance test of FastCRC lib

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manitou 0:d4f8f8fee9db 1 // test FastCRC performance, hardware vs avr softcrc
manitou 0:d4f8f8fee9db 2 //FastCRC
manitou 0:d4f8f8fee9db 3 //Benchmark
manitou 0:d4f8f8fee9db 4 //
manitou 0:d4f8f8fee9db 5 //(c) Frank Boesing 2014
manitou 0:d4f8f8fee9db 6
manitou 0:d4f8f8fee9db 7 #include "mbed.h"
manitou 0:d4f8f8fee9db 8 #include "FastCRC.h"
manitou 0:d4f8f8fee9db 9 #include "crc16.h"
manitou 0:d4f8f8fee9db 10
manitou 0:d4f8f8fee9db 11 Timer tmr;
manitou 0:d4f8f8fee9db 12 #define micros tmr.read_us
manitou 0:d4f8f8fee9db 13
manitou 0:d4f8f8fee9db 14 #define BUFSIZE 16384
manitou 0:d4f8f8fee9db 15
manitou 0:d4f8f8fee9db 16
manitou 0:d4f8f8fee9db 17 FastCRC8 CRC8;
manitou 0:d4f8f8fee9db 18 FastCRC16 CRC16;
manitou 0:d4f8f8fee9db 19 FastCRC32 CRC32;
manitou 0:d4f8f8fee9db 20
manitou 0:d4f8f8fee9db 21 uint8_t buf[BUFSIZE] __attribute__((aligned(4)));
manitou 0:d4f8f8fee9db 22
manitou 0:d4f8f8fee9db 23
manitou 0:d4f8f8fee9db 24 // Supporting functions for Software CRC
manitou 0:d4f8f8fee9db 25
manitou 0:d4f8f8fee9db 26 inline uint16_t softcrc(uint16_t seed, uint8_t *data, uint16_t datalen) {
manitou 0:d4f8f8fee9db 27 for (uint16_t i=0; i<datalen; i++) {
manitou 0:d4f8f8fee9db 28 seed = _crc16_update(seed, data[i]);
manitou 0:d4f8f8fee9db 29 }
manitou 0:d4f8f8fee9db 30 return seed;
manitou 0:d4f8f8fee9db 31 }
manitou 0:d4f8f8fee9db 32
manitou 0:d4f8f8fee9db 33 inline uint16_t softcrcIbutton(uint16_t seed, uint8_t *data, uint16_t datalen) {
manitou 0:d4f8f8fee9db 34 for (uint16_t i=0; i<datalen; i++) {
manitou 0:d4f8f8fee9db 35 seed = _crc_ibutton_update(seed, data[i]);
manitou 0:d4f8f8fee9db 36 }
manitou 0:d4f8f8fee9db 37 return seed;
manitou 0:d4f8f8fee9db 38 }
manitou 0:d4f8f8fee9db 39
manitou 0:d4f8f8fee9db 40 inline uint16_t softcrcCCIT(uint16_t seed, uint8_t *data, uint16_t datalen) {
manitou 0:d4f8f8fee9db 41 for (uint16_t i=0; i<datalen; i++) {
manitou 0:d4f8f8fee9db 42 seed = _crc_ccitt_update(seed, data[i]);
manitou 0:d4f8f8fee9db 43 }
manitou 0:d4f8f8fee9db 44 return seed;
manitou 0:d4f8f8fee9db 45 }
manitou 0:d4f8f8fee9db 46
manitou 0:d4f8f8fee9db 47 inline uint16_t softcrcXMODEM(uint16_t seed, uint8_t *data, uint16_t datalen) {
manitou 0:d4f8f8fee9db 48 for (uint16_t i=0; i<datalen; i++) {
manitou 0:d4f8f8fee9db 49 seed = _crc_xmodem_update(seed, data[i]);
manitou 0:d4f8f8fee9db 50 }
manitou 0:d4f8f8fee9db 51 return seed;
manitou 0:d4f8f8fee9db 52 }
manitou 0:d4f8f8fee9db 53
manitou 0:d4f8f8fee9db 54
manitou 0:d4f8f8fee9db 55 void printVals(char * name, uint32_t crc, uint32_t time) {
manitou 0:d4f8f8fee9db 56 printf("%s Value:0x%x, Time: %d us\n",name,crc,time);
manitou 0:d4f8f8fee9db 57 }
manitou 0:d4f8f8fee9db 58
manitou 0:d4f8f8fee9db 59 main() {
manitou 0:d4f8f8fee9db 60 uint32_t time;
manitou 0:d4f8f8fee9db 61 uint32_t crc;
manitou 0:d4f8f8fee9db 62
manitou 0:d4f8f8fee9db 63 tmr.start();
manitou 0:d4f8f8fee9db 64 printf("\nSystemCoreClock %d %s %s\n",SystemCoreClock,__TIME__,__DATE__);
manitou 0:d4f8f8fee9db 65 printf("CRC Benchmark %d bytes\n",sizeof(buf));
manitou 0:d4f8f8fee9db 66
manitou 0:d4f8f8fee9db 67 //Fill array with data
manitou 0:d4f8f8fee9db 68 for (int i=0; i<BUFSIZE; i++) {
manitou 0:d4f8f8fee9db 69 buf[i] = (i+1) & 0xff;
manitou 0:d4f8f8fee9db 70 }
manitou 0:d4f8f8fee9db 71
manitou 0:d4f8f8fee9db 72
manitou 0:d4f8f8fee9db 73 time = micros();
manitou 0:d4f8f8fee9db 74 crc = CRC8.maxim(buf, BUFSIZE);
manitou 0:d4f8f8fee9db 75 time = micros() - time;
manitou 0:d4f8f8fee9db 76 printVals("Maxim (iButton) FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 77
manitou 0:d4f8f8fee9db 78 time = micros();
manitou 0:d4f8f8fee9db 79 crc = softcrcIbutton(0, buf, BUFSIZE);
manitou 0:d4f8f8fee9db 80 time = micros() - time;
manitou 0:d4f8f8fee9db 81 printVals("Maxim (iButton) builtin:",crc,time);
manitou 0:d4f8f8fee9db 82
manitou 0:d4f8f8fee9db 83
manitou 0:d4f8f8fee9db 84 time = micros();
manitou 0:d4f8f8fee9db 85 crc = CRC16.modbus(buf, BUFSIZE);
manitou 0:d4f8f8fee9db 86 time = micros() - time;
manitou 0:d4f8f8fee9db 87 printVals("MODBUS FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 88
manitou 0:d4f8f8fee9db 89 time = micros();
manitou 0:d4f8f8fee9db 90 crc = softcrc(0xffff, buf, BUFSIZE);
manitou 0:d4f8f8fee9db 91 time = micros() - time;
manitou 0:d4f8f8fee9db 92 printVals("MODBUS builtin:",crc,time);
manitou 0:d4f8f8fee9db 93
manitou 0:d4f8f8fee9db 94
manitou 0:d4f8f8fee9db 95 time = micros();
manitou 0:d4f8f8fee9db 96 crc = CRC16.xmodem(buf, BUFSIZE);
manitou 0:d4f8f8fee9db 97 time = micros() - time;
manitou 0:d4f8f8fee9db 98 printVals("XMODEM FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 99
manitou 0:d4f8f8fee9db 100 time = micros();
manitou 0:d4f8f8fee9db 101 crc = softcrcXMODEM(0, buf, BUFSIZE);
manitou 0:d4f8f8fee9db 102 time = micros() - time;
manitou 0:d4f8f8fee9db 103 printVals("XMODEM builtin:",crc,time);
manitou 0:d4f8f8fee9db 104
manitou 0:d4f8f8fee9db 105 time = micros();
manitou 0:d4f8f8fee9db 106 crc = CRC16.mcrf4xx(buf,BUFSIZE);
manitou 0:d4f8f8fee9db 107 time = micros() - time;
manitou 0:d4f8f8fee9db 108 printVals("MCRF4XX FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 109
manitou 0:d4f8f8fee9db 110 time = micros();
manitou 0:d4f8f8fee9db 111 crc = softcrcCCIT(0xffff, buf, BUFSIZE);
manitou 0:d4f8f8fee9db 112 time = micros() - time;
manitou 0:d4f8f8fee9db 113 printVals("MCRF4XX builtin:",crc,time);
manitou 0:d4f8f8fee9db 114
manitou 0:d4f8f8fee9db 115
manitou 0:d4f8f8fee9db 116 time = micros();
manitou 0:d4f8f8fee9db 117 crc = CRC16.kermit(buf, BUFSIZE);
manitou 0:d4f8f8fee9db 118 time = micros() - time;
manitou 0:d4f8f8fee9db 119 printVals("KERMIT FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 120
manitou 0:d4f8f8fee9db 121 time = micros();
manitou 0:d4f8f8fee9db 122 crc = CRC32.crc32(buf, BUFSIZE);
manitou 0:d4f8f8fee9db 123 time = micros() - time;
manitou 0:d4f8f8fee9db 124 printVals("Ethernet FastCRC:",crc,time);
manitou 0:d4f8f8fee9db 125 }