Merged from git.drogon.net, SPI driver helpers, C++ wrappers, softPwm, piNes, gertboard, SPI
This commit is contained in:
committed by
Philip Howard
parent
21f0472265
commit
ae40bdaf6a
68
examples/delayTest.c
Normal file
68
examples/delayTest.c
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <wiringPi.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define CYCLES 1000
|
||||
#define DELAY 99
|
||||
|
||||
int main()
|
||||
{
|
||||
int x ;
|
||||
struct timeval t1, t2 ;
|
||||
long long t ;
|
||||
unsigned int max, min ;
|
||||
|
||||
unsigned int values [CYCLES] ;
|
||||
|
||||
max = 0 ;
|
||||
min = 1000000 ;
|
||||
|
||||
if (wiringPiSetup () == -1)
|
||||
return 1 ;
|
||||
|
||||
piHiPri (10) ;
|
||||
sleep (1) ;
|
||||
|
||||
// Baseline test
|
||||
|
||||
gettimeofday (&t1, NULL) ;
|
||||
gettimeofday (&t2, NULL) ;
|
||||
|
||||
t = t2.tv_usec - t1.tv_usec ;
|
||||
printf ("Baseline test: %lld\n", t);
|
||||
|
||||
for (x = 0 ; x < CYCLES ; ++x)
|
||||
{
|
||||
gettimeofday (&t1, NULL) ;
|
||||
delayMicroseconds (DELAY) ;
|
||||
gettimeofday (&t2, NULL) ;
|
||||
|
||||
t = t2.tv_usec - t1.tv_usec ;
|
||||
if (t > max) max = t ;
|
||||
if (t < min) min = t ;
|
||||
values [x] = t ;
|
||||
}
|
||||
|
||||
printf ("Done: Max: %d, min: %d\n", max, min) ;
|
||||
|
||||
for (x = 0 ; x < CYCLES ; ++x)
|
||||
{
|
||||
printf ("%4d", values [x]) ;
|
||||
if (values [x] > DELAY)
|
||||
printf (".") ;
|
||||
else if (values [x] < DELAY)
|
||||
printf ("-") ;
|
||||
else
|
||||
printf (" ") ;
|
||||
if (((x + 1) % 20) == 0)
|
||||
printf ("\n") ;
|
||||
}
|
||||
printf ("\n") ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
Reference in New Issue
Block a user