Gordon Henderson | bf0ad86 | 2012-08-16 15:04:43 +0100 | [diff] [blame] | 1 | |
| 2 | #include <stdio.h> |
| 3 | #include <unistd.h> |
| 4 | #include <wiringPi.h> |
| 5 | |
| 6 | #include <time.h> |
| 7 | #include <sys/types.h> |
| 8 | #include <sys/time.h> |
| 9 | |
| 10 | #define CYCLES 1000 |
| 11 | #define DELAY 99 |
| 12 | |
| 13 | int main() |
| 14 | { |
| 15 | int x ; |
| 16 | struct timeval t1, t2 ; |
| 17 | long long t ; |
| 18 | unsigned int max, min ; |
| 19 | |
| 20 | unsigned int values [CYCLES] ; |
| 21 | |
| 22 | max = 0 ; |
| 23 | min = 1000000 ; |
| 24 | |
| 25 | if (wiringPiSetup () == -1) |
| 26 | return 1 ; |
| 27 | |
| 28 | piHiPri (10) ; |
| 29 | sleep (1) ; |
| 30 | |
| 31 | // Baseline test |
| 32 | |
| 33 | gettimeofday (&t1, NULL) ; |
| 34 | gettimeofday (&t2, NULL) ; |
| 35 | |
| 36 | t = t2.tv_usec - t1.tv_usec ; |
| 37 | printf ("Baseline test: %lld\n", t); |
| 38 | |
| 39 | for (x = 0 ; x < CYCLES ; ++x) |
| 40 | { |
| 41 | gettimeofday (&t1, NULL) ; |
| 42 | delayMicroseconds (DELAY) ; |
| 43 | gettimeofday (&t2, NULL) ; |
| 44 | |
| 45 | t = t2.tv_usec - t1.tv_usec ; |
| 46 | if (t > max) max = t ; |
| 47 | if (t < min) min = t ; |
| 48 | values [x] = t ; |
| 49 | } |
| 50 | |
| 51 | printf ("Done: Max: %d, min: %d\n", max, min) ; |
| 52 | |
| 53 | for (x = 0 ; x < CYCLES ; ++x) |
| 54 | { |
| 55 | printf ("%4d", values [x]) ; |
| 56 | if (values [x] > DELAY) |
| 57 | printf (".") ; |
| 58 | else if (values [x] < DELAY) |
| 59 | printf ("-") ; |
| 60 | else |
| 61 | printf (" ") ; |
| 62 | if (((x + 1) % 20) == 0) |
| 63 | printf ("\n") ; |
| 64 | } |
| 65 | printf ("\n") ; |
| 66 | |
| 67 | return 0 ; |
| 68 | } |