25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

104 satır
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. wiringPiGpioMode (WPI_MODE_GPIO) ;
  40. pinMode (17, OUTPUT) ;
  41. sum = 0 ;
  42. for (i = 0 ; i < 3 ; ++i)
  43. {
  44. printf (" Pass: %d: ", i) ;
  45. fflush (stdout) ;
  46. start = millis () ;
  47. for (count = 0 ; count < 10000000 ; ++count)
  48. digitalWrite (17, 1) ;
  49. end = millis () ;
  50. printf (" %8dmS\n", end - start) ;
  51. sum += (end - start) ;
  52. }
  53. digitalWrite (17, 0) ;
  54. printf (" Average: %8dmS", sum / 3) ;
  55. perSec = (int)(double)FAST_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
  56. printf (": %6d/sec\n", perSec) ;
  57. // Switch to SYS mode:
  58. wiringPiSetupSys () ;
  59. printf ("/sys/class/gpio method: (%8d iterations)\n", SLOW_COUNT) ;
  60. sum = 0 ;
  61. for (i = 0 ; i < 3 ; ++i)
  62. {
  63. printf (" Pass: %d: ", i) ;
  64. fflush (stdout) ;
  65. start = millis () ;
  66. for (count = 0 ; count < SLOW_COUNT ; ++count)
  67. digitalWrite (17, 1) ;
  68. end = millis () ;
  69. printf (" %8dmS\n", end - start) ;
  70. sum += (end - start) ;
  71. }
  72. digitalWrite (17, 0) ;
  73. printf (" Average: %8dmS", sum / 3) ;
  74. perSec = (int)(double)SLOW_COUNT / (double)((double)sum / 3.0) * 1000.0 ;
  75. printf (": %6d/sec\n", perSec) ;
  76. return 0 ;
  77. }