Преглед на файлове

Merge pull request #236 from WiringPi/master

release 3.4 - dev
example
mstroh76 преди 6 месеца
committed by GitHub
родител
ревизия
59f6c5ce07
No known key found for this signature in database GPG ключ ID: B5690EEEBB952194
променени са 11 файла, в които са добавени 353 реда и са изтрити 133 реда
  1. +1
    -1
      VERSION
  2. +2
    -2
      version.h
  3. +38
    -0
      wiringPi/test/Makefile
  4. +7
    -33
      wiringPi/test/wiringpi_test1_sysfs.c
  5. +7
    -33
      wiringPi/test/wiringpi_test2_sysfs.c
  6. +6
    -32
      wiringPi/test/wiringpi_test3_device_wpi.c
  7. +6
    -32
      wiringPi/test/wiringpi_test4_device_phys.c
  8. +57
    -0
      wiringPi/test/wiringpi_test5_default.c
  9. +170
    -0
      wiringPi/test/wiringpi_test6_isr.c
  10. +11
    -0
      wiringPi/test/wiringpi_test7_version.c
  11. +48
    -0
      wiringPi/test/wpi_test.h

+ 1
- 1
VERSION Целия файл

@@ -1 +1 @@
3.3
3.4

+ 2
- 2
version.h Целия файл

@@ -1,3 +1,3 @@
#define VERSION "3.3"
#define VERSION "3.4"
#define VERSION_MAJOR 3
#define VERSION_MINOR 3
#define VERSION_MINOR 4

+ 38
- 0
wiringPi/test/Makefile Целия файл

@@ -0,0 +1,38 @@
CC = gcc
CFLAGS = -Wall
LDFLAGS =

tests = wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_version

all: $(tests)

wiringpi_test1_sysfs:
${CC} ${CFLAGS} wiringpi_test1_sysfs.c -o wiringpi_test1_sysfs -lwiringPi

wiringpi_test2_sysfs:
${CC} ${CFLAGS} wiringpi_test2_sysfs.c -o wiringpi_test2_sysfs -lwiringPi

wiringpi_test3_device_wpi:
${CC} ${CFLAGS} wiringpi_test3_device_wpi.c -o wiringpi_test3_device_wpi -lwiringPi

wiringpi_test4_device_phys:
${CC} ${CFLAGS} wiringpi_test4_device_phys.c -o wiringpi_test4_device_phys -lwiringPi

wiringpi_test5_default:
${CC} ${CFLAGS} wiringpi_test5_default.c -o wiringpi_test5_default -lwiringPi

wiringpi_test6_isr:
${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi

wiringpi_test7_version:
${CC} ${CFLAGS} wiringpi_test7_version.c -o wiringpi_test7_version -lwiringPi

test:
for t in $(tests) ; do \
echo === unit test: $${t} === ; \
time ./$${t} ; \
echo ; echo ; \
done

clean:
for t in $(tests) ; do rm -fv $${t} ; done

wiringPi/test/wiringpi_test1_device.c → wiringPi/test/wiringpi_test1_sysfs.c Целия файл

@@ -1,8 +1,7 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi

#include <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -12,33 +11,8 @@

const int GPIO = 19;
const int GPIOIN = 26;
const int ToggleValue = 4;
const int ToggleValue = 4;

void CheckGPIO(int out) {
int in = digitalRead(GPIOIN);
int read = digitalRead(GPIO);

int pass = 0;
if (out==in && in==read) {
pass = 1;
}
printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" );
}

void digitalWriteEx(int pin, int mode) {
digitalWrite(pin, mode);
printf("out = %d ", mode);
delayMicroseconds(5000);
CheckGPIO(mode);
}

void pullUpDnControlEx (int pin ,int mode) {
pullUpDnControl (pin, mode);
int out = mode==PUD_UP ? 1:0;
printf("in = %4s ", mode==PUD_UP ? "up":"down");
delayMicroseconds(5000);
CheckGPIO(out);
}

int main (void) {

@@ -46,7 +20,7 @@ int main (void) {
printf(" testing digitalWrite, digitalRead and pullUpDnControl\n");

if (wiringPiSetupSys() == -1) {
printf("wiringPiSetupGpioDevice failed\n\n");
printf("wiringPiSetupSys failed\n\n");
exit(EXIT_FAILURE);
}
pinMode(GPIOIN, INPUT);
@@ -54,9 +28,9 @@ int main (void) {

printf("toggle %d times ...\n", ToggleValue);
for (int loop=1; loop<ToggleValue; loop++) {
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);
digitalWriteEx(GPIO, HIGH);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
}

@@ -69,9 +43,9 @@ int main (void) {
pullUpDnControl (GPIOIN, PUD_OFF);

for (int loop=1; loop<ToggleValue; loop++) {
pullUpDnControlEx (GPIO, PUD_DOWN);
pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
delayMicroseconds(600000);
pullUpDnControlEx (GPIO, PUD_UP);
pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
delayMicroseconds(600000);
}


wiringPi/test/wiringpi_test2_device.c → wiringPi/test/wiringpi_test2_sysfs.c Целия файл

@@ -1,8 +1,7 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test2_device.c -o wiringpi_test2_device -lwiringPi

#include <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -12,33 +11,8 @@

const int GPIO = 19;
const int GPIOIN = 26;
const int ToggleValue = 4;
const int ToggleValue = 4;

void CheckGPIO(int out) {
int in = digitalRead(GPIOIN);
int read = digitalRead(GPIO);

int pass = 0;
if (out==in && in==read) {
pass = 1;
}
printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" );
}

void digitalWriteEx(int pin, int mode) {
digitalWrite(pin, mode);
printf("out = %d ", mode);
delayMicroseconds(5000);
CheckGPIO(mode);
}

void pullUpDnControlEx (int pin ,int mode) {
pullUpDnControl (pin, mode);
int out = mode==PUD_UP ? 1:0;
printf("in = %4s ", mode==PUD_UP ? "up":"down");
delayMicroseconds(5000);
CheckGPIO(out);
}

int main (void) {

@@ -53,19 +27,19 @@ int main (void) {
pinMode(GPIO, OUTPUT);

printf("\nTest output\n");
digitalWriteEx(GPIO, HIGH);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

printf("\nTest output off with pull up\n");
pinMode(GPIO, OUTPUT);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
pullUpDnControl (GPIO, PUD_UP);
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(HIGH);
CheckGPIO(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);

printf("\nTest output off with pull down\n");
@@ -73,7 +47,7 @@ int main (void) {
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(LOW);
CheckGPIO(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

return(EXIT_SUCCESS);

wiringPi/test/wiringpi_test3_device.c → wiringPi/test/wiringpi_test3_device_wpi.c Целия файл

@@ -1,8 +1,7 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test3_device.c -o wiringpi_test3_device -lwiringPi

#include <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -14,31 +13,6 @@ const int GPIO = 24; //BCM 19
const int GPIOIN = 25; //BCM 26;
const int ToggleValue = 4;

void CheckGPIO(int out) {
int in = digitalRead(GPIOIN);
int read = digitalRead(GPIO);

int pass = 0;
if (out==in && in==read) {
pass = 1;
}
printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" );
}

void digitalWriteEx(int pin, int mode) {
digitalWrite(pin, mode);
printf("out = %d ", mode);
delayMicroseconds(5000);
CheckGPIO(mode);
}

void pullUpDnControlEx (int pin ,int mode) {
pullUpDnControl (pin, mode);
int out = mode==PUD_UP ? 1:0;
printf("in = %4s ", mode==PUD_UP ? "up":"down");
delayMicroseconds(5000);
CheckGPIO(out);
}

int main (void) {

@@ -53,19 +27,19 @@ int main (void) {
pinMode(GPIO, OUTPUT);

printf("\nTest output\n");
digitalWriteEx(GPIO, HIGH);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

printf("\nTest output off with pull up\n");
pinMode(GPIO, OUTPUT);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
pullUpDnControl (GPIO, PUD_UP);
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(HIGH);
CheckGPIO(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);

printf("\nTest output off with pull down\n");
@@ -73,7 +47,7 @@ int main (void) {
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(LOW);
CheckGPIO(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

return(EXIT_SUCCESS);

wiringPi/test/wiringpi_test4_device.c → wiringPi/test/wiringpi_test4_device_phys.c Целия файл

@@ -1,8 +1,7 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test4_device.c -o wiringpi_test4_device -lwiringPi

#include <wiringPi.h>
#include <stdio.h>
#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
@@ -14,31 +13,6 @@ const int GPIO = 35; //BCM 19
const int GPIOIN = 37; //BCM 26;
const int ToggleValue = 4;

void CheckGPIO(int out) {
int in = digitalRead(GPIOIN);
int read = digitalRead(GPIO);

int pass = 0;
if (out==in && in==read) {
pass = 1;
}
printf("GPIO%d = %d (GPIO%d = %d) -> %s\n", GPIOIN, in, GPIO, read, pass ? "passed":"failed" );
}

void digitalWriteEx(int pin, int mode) {
digitalWrite(pin, mode);
printf("out = %d ", mode);
delayMicroseconds(5000);
CheckGPIO(mode);
}

void pullUpDnControlEx (int pin ,int mode) {
pullUpDnControl (pin, mode);
int out = mode==PUD_UP ? 1:0;
printf("in = %4s ", mode==PUD_UP ? "up":"down");
delayMicroseconds(5000);
CheckGPIO(out);
}

int main (void) {

@@ -53,19 +27,19 @@ int main (void) {
pinMode(GPIO, OUTPUT);

printf("\nTest output\n");
digitalWriteEx(GPIO, HIGH);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

printf("\nTest output off with pull up\n");
pinMode(GPIO, OUTPUT);
digitalWriteEx(GPIO, LOW);
digitalWriteEx(GPIO, GPIOIN, LOW);
pullUpDnControl (GPIO, PUD_UP);
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(HIGH);
CheckGPIO(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);

printf("\nTest output off with pull down\n");
@@ -73,7 +47,7 @@ int main (void) {
pinMode(GPIO, PM_OFF);
delayMicroseconds(600000);
printf("out = off ");
CheckGPIO(LOW);
CheckGPIO(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);

return(EXIT_SUCCESS);

+ 57
- 0
wiringPi/test/wiringpi_test5_default.c Целия файл

@@ -0,0 +1,57 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi

#include "wpi_test.h"
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>


const int GPIO = 19;
const int GPIOIN = 26;
const int ToggleValue = 4;


int main (void) {

printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
printf(" testing digitalWrite, digitalRead and pullUpDnControl\n");

if (wiringPiSetupGpio() == -1) {
printf("wiringPiSetupGpio failed\n\n");
exit(EXIT_FAILURE);
}
pinMode(GPIOIN, INPUT);
pinMode(GPIO, OUTPUT);

printf("toggle %d times ...\n", ToggleValue);
for (int loop=1; loop<ToggleValue; loop++) {
digitalWriteEx(GPIO, GPIOIN, LOW);
delayMicroseconds(600000);
digitalWriteEx(GPIO, GPIOIN, HIGH);
delayMicroseconds(600000);
}

digitalWrite(GPIO, LOW);

printf("\nWiringPi GPIO test program (using GPIO%d (input pull up/down) and GPIO%d (input))\n", GPIO, GPIOIN);
pullUpDnControl (GPIO, PUD_UP);
pinMode(GPIO, INPUT);
delayMicroseconds(3000000);
pullUpDnControl (GPIOIN, PUD_OFF);

for (int loop=1; loop<ToggleValue; loop++) {
pullUpDnControlEx (GPIO, GPIOIN, PUD_DOWN);
delayMicroseconds(600000);
pullUpDnControlEx (GPIO, GPIOIN, PUD_UP);
delayMicroseconds(600000);
}

//Error wrong direction - only for fun
digitalWrite(GPIO, LOW);

return(EXIT_SUCCESS);
}


+ 170
- 0
wiringPi/test/wiringpi_test6_isr.c Целия файл

@@ -0,0 +1,170 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test1_device.c -o wiringpi_test1_device -lwiringPi

#include "wpi_test.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>


const int GPIO = 19;
const int GPIOIN = 26;
const int ToggleValue = 4;


static volatile int globalCounter;
volatile long long gStartTime, gEndTime;


static void wfi (void) {
struct timeval now;

gettimeofday(&now, 0);
if (0==gStartTime) {
gStartTime = now.tv_sec*1000000LL + now.tv_usec;
} else {
gEndTime = now.tv_sec*1000000LL + now.tv_usec;
}
globalCounter++;
}


double StartSequence (int Enge, int OUTpin) {
int expected;
double timeExpected;

gStartTime = 0;
gEndTime = 0;
globalCounter = 0;
printf("Start\n");
digitalWrite(OUTpin, HIGH);
delay(200);
digitalWrite(OUTpin, LOW);
delay(100);
digitalWrite(OUTpin, HIGH);
delay(200);
digitalWrite(OUTpin, LOW);
delay(100);
printf("Stop\n");
int globalCounterCopy = globalCounter;

if (INT_EDGE_BOTH == Enge) {
expected = 4;
timeExpected = 500;
} else {
expected = 2;
timeExpected = 300;
}

if (globalCounter==expected) {
double fTime = (gEndTime - gStartTime) / 1000000.0;
printf("IRQ worked %g sec (~%gs expected)", fTime, timeExpected/1000.0);
double diff = fTime-(timeExpected/1000.0);
if(diff<0.05 && diff>0) {
printf(" -> %spassed%s\n", COLORGRN, COLORDEF);
} else {
printf(" -> %sfailed%s\n", COLORRED, COLORDEF);
}

return fTime;
} else {
printf("IRQ not worked got %d iterations (%d exprected)\n\n", globalCounterCopy, expected);
return 0;
}
}


double DurationTime(int Enge, int OUTpin, int IRQpin) {
struct timeval now;
double fTime = 0.0;

gStartTime = 0;
gEndTime = 0;
globalCounter = 0;
printf("Start\n");

if (INT_EDGE_RISING == Enge) {
digitalWrite(OUTpin, LOW);
wiringPiISR (IRQpin, INT_EDGE_RISING, &wfi) ;
sleep(1);
gettimeofday(&now, 0);
gStartTime = now.tv_sec*1000000LL + now.tv_usec;
digitalWrite(OUTpin, HIGH);
delay(20);
digitalWrite(OUTpin, LOW);
} else if (INT_EDGE_FALLING == Enge) {
digitalWrite(OUTpin, HIGH);
wiringPiISR (IRQpin, INT_EDGE_FALLING, &wfi) ;
sleep(1);
gettimeofday(&now, 0);
gStartTime = now.tv_sec*1000000LL + now.tv_usec;
digitalWrite(OUTpin, LOW);
}

sleep(1);
fTime = (gEndTime - gStartTime);
printf("IRQ detect time %g usec", fTime);
if (fTime<2000 && fTime>0) {
printf(" -> %spassed%s\n", COLORGRN, COLORDEF);
} else {
printf(" -> %sfailed%s\n", COLORRED, COLORDEF);
}
wiringPiISRStop (IRQpin) ;

return fTime;
}

int main (void) {
const int IRQpin = GPIOIN ;
const int OUTpin = GPIO ;
int major, minor;

wiringPiVersion(&major, &minor);

printf("WiringPi GPIO test program 1 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
printf(" testing irq\n");

printf("\nISR test (WiringPi %d.%d)\n", major, minor);

wiringPiSetupGpio() ;

pinMode(IRQpin, INPUT);
pinMode(OUTpin, OUTPUT);
digitalWrite (OUTpin, LOW) ;


printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin);
wiringPiISR (IRQpin, INT_EDGE_RISING, &wfi) ;
sleep(1);
StartSequence (INT_EDGE_RISING, OUTpin);
printf("Testing close\n");
wiringPiISRStop (IRQpin) ;

printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin);
wiringPiISR (IRQpin, INT_EDGE_FALLING, &wfi) ;
sleep(1);
StartSequence (INT_EDGE_FALLING, OUTpin);
printf("Testing close\n");
wiringPiISRStop (IRQpin) ;

printf("Testing IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin);
wiringPiISR (IRQpin, INT_EDGE_BOTH, &wfi) ;
sleep(1);
StartSequence (INT_EDGE_BOTH, OUTpin);
printf("Testing close\n");
wiringPiISRStop (IRQpin) ;

for (int count=0; count<2; count++) {
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin);
DurationTime(INT_EDGE_RISING, OUTpin, IRQpin);

printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin);
DurationTime(INT_EDGE_FALLING, OUTpin, IRQpin);
}
pinMode(OUTpin, INPUT);

return 0 ;
}

+ 11
- 0
wiringPi/test/wiringpi_test7_version.c Целия файл

@@ -0,0 +1,11 @@
#include "wpi_test.h"
#include "../../version.h"

int main (void) {
int major, minor;

wiringPiVersion(&major, &minor);

CheckSame("version major", major, VERSION_MAJOR);
CheckSame("version minor", minor, VERSION_MINOR);
}

+ 48
- 0
wiringPi/test/wpi_test.h Целия файл

@@ -0,0 +1,48 @@

#include <wiringPi.h>
#include <stdio.h>

#define COLORDEF "\x1B[0m"
#define COLORRED "\x1B[31m"
#define COLORGRN "\x1B[32m"

void CheckGPIO(int GPIO, int GPIOIN, int out) {
int in = digitalRead(GPIOIN);
int read = digitalRead(GPIO);

int pass = 0;
if (out==in && in==read) {
pass = 1;
}
if (pass) {
printf("GPIO%d = %d (GPIO%d = %d) -> %spassed%s\n", GPIOIN, in, GPIO, read, COLORGRN, COLORDEF );
} else {
printf("GPIO%d = %d (GPIO%d = %d) -> %sfailed%s\n", GPIOIN, in, GPIO, read, COLORRED, COLORDEF );
}
}


void digitalWriteEx(int GPIO, int GPIOIN, int mode) {
digitalWrite(GPIO, mode);
printf("out = %d ", mode);
delayMicroseconds(5000);
CheckGPIO(GPIO, GPIOIN, mode);
}


void pullUpDnControlEx (int GPIO, int GPIOIN, int mode) {
pullUpDnControl (GPIO, mode);
int out = mode==PUD_UP ? 1:0;
printf("in = %4s ", mode==PUD_UP ? "up":"down");
delayMicroseconds(5000);
CheckGPIO(GPIO, GPIOIN, out);
}


void CheckSame(const char* msg, int value, int expect) {
if (value==expect) {
printf("%s -> %spassed%s\n", msg, COLORGRN, COLORDEF );
} else {
printf("%s -> %sfailed%s\n", msg, COLORRED, COLORDEF );
}
}

Зареждане…
Отказ
Запис