13 struct timeval t1, t2 ;
17 int underRuns, overRuns, exactRuns, total ;
20 if (wiringPiSetup () == -1)
23 piHiPri (10) ; sleep (1) ;
27 gettimeofday (&t1, NULL) ;
28 gettimeofday (&t2, NULL) ;
30 t = t2.tv_usec - t1.tv_usec ;
31 printf ("Baseline test: %d\n", t);
33 for (del = 1 ; del < 200 ; ++del)
35 underRuns = overRuns = exactRuns = total = 0 ;
40 for (x = 0 ; x < CYCLES ; ++x)
42 for (;;) // Repeat this if we get a delay over 999uS
43 { // -> High probability Linux has deschedulled us
44 gettimeofday (&t1, NULL) ;
45 delayMicroseconds (del) ;
46 gettimeofday (&t2, NULL) ;
48 if (t2.tv_usec < t1.tv_usec) // Counter wrapped
49 t = (1000000 + t2.tv_usec) - t1.tv_usec;
51 t = t2.tv_usec - t1.tv_usec ;
76 printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
77 del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;