Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

106 строки
2.2 KiB

  1. /*
  2. * speed.c:
  3. * Simple program to measure the speed of the various GPIO
  4. * access mechanisms.
  5. */
  6. #include <wiringPi.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <stdint.h>
  10. #define FAST_COUNT 10000000
  11. #define SLOW_COUNT 1000000
  12. int main (void)
  13. {
  14. int i ;
  15. uint32_t start, end, count, sum, perSec ;
  16. printf ("Raspberry Pi wiringPi speed test program\n") ;
  17. // Start the standard way
  18. if (wiringPiSetup () == -1)
  19. exit (1) ;
  20. printf ("Native wiringPi method: (%8d iterations)\n", FAST_COUNT) ;
  21. pinMode (0, OUTPUT) ;
  22. sum = 0 ;
  23. for (i = 0 ; i < 3 ; ++i)
  24. {
  25. printf (" Pass: %d: ", i) ;
  26. fflush (stdout) ;
  27. start = millis () ;
  28. for (count = 0 ; count < FAST_COUNT ; ++count)
  29. digitalWrite (0, 1) ;
  30. end = millis () ;
  31. printf (" %8dmS\n", end - start) ;
  32. sum += (end - start) ;
  33. }
  34. digitalWrite (0, 0) ;
  35. printf (" Average: %8dmS", sum / 3) ;
  36. perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
  37. printf (": %6d/sec\n", perSec) ;
  38. printf ("Native GPIO method: (%8d iterations)\n", FAST_COUNT) ;
  39. if (wiringPiSetupGpio () == -1)
  40. exit (1) ;
  41. pinMode (17, OUTPUT) ;
  42. sum = 0 ;
  43. for (i = 0 ; i < 3 ; ++i)
  44. {
  45. printf (" Pass: %d: ", i) ;
  46. fflush (stdout) ;
  47. start = millis () ;
  48. for (count = 0 ; count < 10000000 ; ++count)
  49. digitalWrite (17, 1) ;
  50. end = millis () ;
  51. printf (" %8dmS\n", end - start) ;
  52. sum += (end - start) ;
  53. }
  54. digitalWrite (17, 0) ;
  55. printf (" Average: %8dmS", sum / 3) ;
  56. perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
  57. printf (": %6d/sec\n", perSec) ;
  58. // Switch to SYS mode:
  59. if (wiringPiSetupSys () == -1)
  60. exit (1) ;
  61. printf ("/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
  62. sum = 0 ;
  63. for (i = 0 ; i < 3 ; ++i)
  64. {
  65. printf (" Pass: %d: ", i) ;
  66. fflush (stdout) ;
  67. start = millis () ;
  68. for (count = 0 ; count < SLOW_COUNT ; ++count)
  69. digitalWrite (17, 1) ;
  70. end = millis () ;
  71. printf (" %8dmS\n", end - start) ;
  72. sum += (end - start) ;
  73. }
  74. digitalWrite (17, 0) ;
  75. printf (" Average: %8dmS", sum / 3) ;
  76. perSec = (int)(double)SLOW_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
  77. printf (": %6d/sec\n", perSec) ;
  78. return 0 ;
  79. }