update for the v3+

This commit is contained in:
Gordon Henderson
2018-03-14 07:17:04 +00:00
parent 96344ff712
commit 8d188fa0e0
17 changed files with 281 additions and 154 deletions

61
examples/blink-thread.c Normal file
View File

@@ -0,0 +1,61 @@
/*
* blink-thread.c:
* Standard "blink" program in wiringPi. Blinks an LED connected
* to the first GPIO pin.
*
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <wiringPi.h>
// LED Pin - wiringPi pin 0 is BCM_GPIO 17.
#define LED 0
PI_THREAD (blinky)
{
for (;;)
{
digitalWrite (LED, HIGH) ; // On
delay (500) ; // mS
digitalWrite (LED, LOW) ; // Off
delay (500) ;
}
}
int main (void)
{
printf ("Raspberry Pi blink\n") ;
wiringPiSetup () ;
pinMode (LED, OUTPUT) ;
piThreadCreate (blinky) ;
for (;;)
{
printf ("Hello, world\n") ;
delay (600) ;
}
return 0 ;
}

View File

@@ -25,7 +25,6 @@
#include <stdio.h>
#include <unistd.h>
#include <wiringPi.h>
#include <sys/time.h>
@@ -34,17 +33,13 @@
int main()
{
int x ;
struct timeval t1, t2 ;
struct timeval t1, t2, t3 ;
int t ;
int max, min ;
int del ;
int underRuns, overRuns, exactRuns, total ;
int underRuns, overRuns, exactRuns, bogusRuns, total ;
int descheds ;
if (wiringPiSetup () == -1)
return 1 ;
piHiPri (10) ; sleep (1) ;
// Baseline test
@@ -58,21 +53,22 @@ int main()
{
underRuns = overRuns = exactRuns = total = 0 ;
descheds = 0 ;
max = del ;
min = del ;
max = 0 ;
min = 999 ;
for (x = 0 ; x < CYCLES ; ++x)
{
for (;;) // Repeat this if we get a delay over 999uS
{ // -> High probability Linux has deschedulled us
gettimeofday (&t1, NULL) ;
delayMicroseconds (del) ;
usleep (del) ;
// delayMicroseconds (del) ;
gettimeofday (&t2, NULL) ;
if (t2.tv_usec < t1.tv_usec) // Counter wrapped
t = (1000000 + t2.tv_usec) - t1.tv_usec;
else
t = t2.tv_usec - t1.tv_usec ;
timersub (&t2, &t1, &t3) ;
t = t3.tv_usec ;
if (t > 999)
{
++descheds ;
@@ -82,25 +78,24 @@ int main()
break ;
}
if (t > max)
{
max = t ;
++overRuns ;
}
else if (t < min)
{
min = t ;
++underRuns ;
}
else
if (t == del)
++exactRuns ;
else if (t < del)
++underRuns ;
else if (t > del)
++overRuns ;
if (t > max)
max = t ;
else if (t < min)
min = t ;
total += t ;
}
printf ("Delay: %3d. Min: %3d, Max: %3d, Unders: %3d, Overs: %3d, Exacts: %3d, Average: %3d, Descheds: %2d\n",
del, min, max, underRuns, overRuns, exactRuns, total / CYCLES, descheds) ;
fflush (stdout) ;
delay (1) ;
usleep (1000) ;
}
return 0 ;