PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

164 rindas
3.6KB

  1. /*
  2. FastCRC
  3. Benchmark
  4. (c) Frank Boesing 2014-2016
  5. Edit FastCRC.h for smaller Tables (#define CRC_BIGTABLES 1) - not needed for Teensy 3.x
  6. */
  7. #include <util/crc16.h>
  8. #include <FastCRC.h>
  9. //#define LOFLASH // <- Uncomment this for devices with small flashmemory
  10. //Determince the max. possible size for the data:
  11. #if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)
  12. #define BUFSIZE (56 * 1024) // 56KB for Teensy 3.x
  13. #elif defined(__MK20DX128__)
  14. #define BUFSIZE (10 * 1024) // 10KB for Teensy 3.0
  15. #elif defined(__MKL26Z64__)
  16. #define BUFSIZE (4 * 1024) // 4KB for Teensy LC
  17. #else
  18. #define BUFSIZE (1 * 1024) // 1KB for Teensy 2.0 / others...(use max. possible!)
  19. #endif
  20. uint8_t buf[BUFSIZE];
  21. FastCRC8 CRC8;
  22. FastCRC16 CRC16;
  23. FastCRC32 CRC32;
  24. // Supporting functions for Software CRC
  25. inline uint16_t softcrc(uint16_t seed, uint8_t *data, uint16_t datalen) {
  26. for (uint16_t i = 0; i < datalen; i++) {
  27. seed = _crc16_update(seed, data[i]);
  28. }
  29. return seed;
  30. }
  31. inline uint16_t softcrcIbutton(uint16_t seed, uint8_t *data, uint16_t datalen) {
  32. for (uint16_t i = 0; i < datalen; i++) {
  33. seed = _crc_ibutton_update(seed, data[i]);
  34. }
  35. return seed;
  36. }
  37. inline uint16_t softcrcCCIT(uint16_t seed, uint8_t *data, uint16_t datalen) {
  38. for (uint16_t i = 0; i < datalen; i++) {
  39. seed = _crc_ccitt_update(seed, data[i]);
  40. }
  41. return seed;
  42. }
  43. inline uint16_t softcrcXMODEM(uint16_t seed, uint8_t *data, uint16_t datalen) {
  44. for (uint16_t i = 0; i < datalen; i++) {
  45. seed = _crc_xmodem_update(seed, data[i]);
  46. }
  47. return seed;
  48. }
  49. void printVals(const char * name, const uint32_t crc, const uint32_t time) {
  50. Serial.print(name);
  51. Serial.print("\tValue:0x");
  52. Serial.print(crc, HEX);
  53. Serial.print(", Time: ");
  54. Serial.print(time);
  55. Serial.print(" us (");
  56. Serial.print((8.*BUFSIZE) / time);
  57. Serial.println(" mbs)");
  58. }
  59. void setup() {
  60. int time;
  61. uint32_t crc;
  62. delay(1500);
  63. Serial.begin(115200);
  64. Serial.println("CRC Benchmark");
  65. Serial.print("F_CPU: ");
  66. Serial.print((int) (F_CPU / 1E6));
  67. Serial.print(" MHz, length: ");
  68. Serial.print(BUFSIZE);
  69. Serial.println(" Bytes.");
  70. Serial.println();
  71. //Fill array with testdata
  72. for (uint16_t i = 0; i < BUFSIZE; i++) {
  73. buf[i] = (i + 1) & 0xff;
  74. }
  75. /* 8 BIT */
  76. time = micros();
  77. crc = CRC8.maxim(buf, BUFSIZE);
  78. time = micros() - time;
  79. printVals("Maxim (iButton) FastCRC:", crc, time);
  80. time = micros();
  81. crc = softcrcIbutton(0, buf, BUFSIZE);
  82. time = micros() - time;
  83. printVals("Maxim (iButton) builtin:", crc, time);
  84. #if !defined(LOFLASH)
  85. time = micros();
  86. crc = CRC16.modbus(buf, BUFSIZE);
  87. time = micros() - time;
  88. printVals("MODBUS FastCRC:", crc, time);
  89. time = micros();
  90. crc = softcrc(0xffff, buf, BUFSIZE);
  91. time = micros() - time;
  92. printVals("MODBUS builtin: ", crc, time);
  93. time = micros();
  94. crc = CRC16.xmodem(buf, BUFSIZE);
  95. time = micros() - time;
  96. printVals("XMODEM FastCRC:", crc, time);
  97. time = micros();
  98. crc = softcrcXMODEM(0, buf, BUFSIZE);
  99. time = micros() - time;
  100. printVals("XMODEM builtin: ", crc, time);
  101. #endif
  102. /* 16 BIT */
  103. time = micros();
  104. crc = CRC16.mcrf4xx(buf, BUFSIZE);
  105. time = micros() - time;
  106. printVals("MCRF4XX FastCRC:", crc, time);
  107. time = micros();
  108. crc = softcrcCCIT(0xffff, buf, BUFSIZE);
  109. time = micros() - time;
  110. printVals("MCRF4XX builtin:", crc, time);
  111. #if !defined(LOFLASH)
  112. time = micros();
  113. crc = CRC16.kermit(buf, BUFSIZE);
  114. time = micros() - time;
  115. printVals("KERMIT FastCRC:", crc, time);
  116. #endif
  117. /* 32 BIT */
  118. #if !defined(LOFLASH)
  119. time = micros();
  120. crc = CRC32.crc32(buf, BUFSIZE);
  121. time = micros() - time;
  122. printVals("Ethernet FastCRC:", crc, time);
  123. #endif
  124. }
  125. void loop() {
  126. }