Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

111 lines
2.6KB

  1. // Simple performance test for Teensy 3.5/3.6 SDHC.
  2. // Demonstrates yield() efficiency.
  3. #include "SdFat.h"
  4. // 32 KiB buffer.
  5. const size_t BUF_DIM = 32768;
  6. // 8 MiB file.
  7. const uint32_t FILE_SIZE = 256UL*BUF_DIM;
  8. SdFatSdio sd;
  9. File file;
  10. uint8_t buf[BUF_DIM];
  11. // buffer as uint32_t
  12. uint32_t* buf32 = (uint32_t*)buf;
  13. // Total usec in read/write calls.
  14. uint32_t totalMicros = 0;
  15. // Time in yield() function.
  16. uint32_t yieldMicros = 0;
  17. // Number of yield calls.
  18. uint32_t yieldCalls = 0;
  19. // Max busy time for single yield call.
  20. uint32_t yieldMaxUsec = 0;
  21. //-----------------------------------------------------------------------------
  22. // Replace "weak" system yield() function.
  23. void yield() {
  24. // Only count cardBusy time.
  25. if (!sd.card()->dmaBusy()) {
  26. return;
  27. }
  28. uint32_t m = micros();
  29. yieldCalls++;
  30. while (sd.card()->dmaBusy()) {
  31. // Do something here.
  32. }
  33. m = micros() - m;
  34. if (m > yieldMaxUsec) {
  35. yieldMaxUsec = m;
  36. }
  37. yieldMicros += m;
  38. }
  39. //-----------------------------------------------------------------------------
  40. void setup() {
  41. Serial.begin(9600);
  42. while (!Serial) {
  43. }
  44. Serial.println("Type any character to begin");
  45. while (!Serial.available()) {
  46. }
  47. if (!sd.begin()) {
  48. sd.initErrorHalt();
  49. }
  50. if (!file.open("TeensyDemo.bin", O_RDWR | O_CREAT)) {
  51. sd.errorHalt("open failed");
  52. }
  53. Serial.println("\nsize,write,read");
  54. Serial.println("bytes,KB/sec,KB/sec");
  55. for (size_t nb = 512; nb <= BUF_DIM; nb *= 2) {
  56. file.truncate(0);
  57. uint32_t nRdWr = FILE_SIZE/nb;
  58. Serial.print(nb);
  59. Serial.print(',');
  60. uint32_t t = micros();
  61. for (uint32_t n = 0; n < nRdWr; n++) {
  62. // Set start and end of buffer.
  63. buf32[0] = n;
  64. buf32[nb/4 - 1] = n;
  65. if (nb != file.write(buf, nb)) {
  66. sd.errorHalt("write failed");
  67. }
  68. }
  69. t = micros() - t;
  70. totalMicros += t;
  71. Serial.print(1000.0*FILE_SIZE/t);
  72. Serial.print(',');
  73. file.rewind();
  74. t = micros();
  75. for (uint32_t n = 0; n < nRdWr; n++) {
  76. if ((int)nb != file.read(buf, nb)) {
  77. sd.errorHalt("read failed");
  78. }
  79. // crude check of data.
  80. if (buf32[0] != n || buf32[nb/4 - 1] != n) {
  81. sd.errorHalt("data check");
  82. }
  83. }
  84. t = micros() - t;
  85. totalMicros += t;
  86. Serial.println(1000.0*FILE_SIZE/t);
  87. }
  88. file.close();
  89. Serial.print("\ntotalMicros ");
  90. Serial.println(totalMicros);
  91. Serial.print("yieldMicros ");
  92. Serial.println(yieldMicros);
  93. Serial.print("yieldCalls ");
  94. Serial.println(yieldCalls);
  95. Serial.print("yieldMaxUsec ");
  96. Serial.println(yieldMaxUsec);
  97. Serial.println("Done");
  98. }
  99. void loop() {
  100. }