選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

84 行
1.5 KiB

  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <wiringPi.h>
  4. #include <sys/time.h>
  5. #define CYCLES 1000
  6. int main()
  7. {
  8. int x ;
  9. struct timeval t1, t2 ;
  10. int t ;
  11. int max, min ;
  12. int del ;
  13. int underRuns, overRuns, exactRuns, total ;
  14. int descheds ;
  15. if (wiringPiSetup () == -1)
  16. return 1 ;
  17. piHiPri (10) ; sleep (1) ;
  18. // Baseline test
  19. gettimeofday (&t1, NULL) ;
  20. gettimeofday (&t2, NULL) ;
  21. t = t2.tv_usec - t1.tv_usec ;
  22. printf ("Baseline test: %d\n", t);
  23. for (del = 1 ; del < 200 ; ++del)
  24. {
  25. underRuns = overRuns = exactRuns = total = 0 ;
  26. descheds = 0 ;
  27. max = del ;
  28. min = del ;
  29. for (x = 0 ; x < CYCLES ; ++x)
  30. {
  31. for (;;) // Repeat this if we get a delay over 999uS
  32. { // -> High probability Linux has deschedulled us
  33. gettimeofday (&t1, NULL) ;
  34. delayMicroseconds (del) ;
  35. gettimeofday (&t2, NULL) ;
  36. if (t2.tv_usec < t1.tv_usec) // Counter wrapped
  37. t = (1000000 + t2.tv_usec) - t1.tv_usec;
  38. else
  39. t = t2.tv_usec - t1.tv_usec ;
  40. if (t > 999)
  41. {
  42. ++descheds ;
  43. continue ;
  44. }
  45. else
  46. break ;
  47. }
  48. if (t > max)
  49. {
  50. max = t ;
  51. ++overRuns ;
  52. }
  53. else if (t < min)
  54. {
  55. min = t ;
  56. ++underRuns ;
  57. }
  58. else
  59. ++exactRuns ;
  60. total += t ;
  61. }
  62. printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
  63. del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;
  64. fflush (stdout) ;
  65. delay (1) ;
  66. }
  67. return 0 ;
  68. }