Merge branch 'develop' into cleanup

This commit is contained in:
Manfred Wallner
2025-06-05 13:21:55 +02:00
committed by GitHub
18 changed files with 2194 additions and 561 deletions

246
wiringPi/WiringpiV1.c Normal file
View File

@@ -0,0 +1,246 @@
#include "Wiringpi.h"
int requestLineV1(int pin, unsigned int lineRequestFlags) {
struct gpiohandle_request rq;
if (lineFds[pin]>=0) {
if (lineRequestFlags == lineFlags[pin]) {
//already requested
return lineFds[pin];
} else {
//different request -> rerequest
releaseLine(pin);
}
}
//requested line
if (wiringPiGpioDeviceGetFd()<0) {
return -1; // error
}
rq.lineoffsets[0] = pin;
rq.lines = 1;
rq.flags = 0;
// MAP to V1 Flag
if (lineRequestFlags & WPI_FLAG_INPUT) {
rq.flags |= GPIOHANDLE_REQUEST_INPUT;
}
if (lineRequestFlags & WPI_FLAG_OUTPUT) {
rq.flags |= GPIOHANDLE_REQUEST_OUTPUT;
}
if (lineRequestFlags & WPI_FLAG_BIAS_OFF) {
rq.flags |= GPIOHANDLE_REQUEST_BIAS_DISABLE;
}
if (lineRequestFlags & WPI_FLAG_BIAS_UP) {
rq.flags |= GPIOHANDLE_REQUEST_BIAS_PULL_UP;
}
if (lineRequestFlags & WPI_FLAG_BIAS_DOWN) {
rq.flags |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN;
}
int ret = ioctl(chipFd, GPIO_GET_LINEHANDLE_IOCTL, &rq);
if (ret || rq.fd<0) {
ReportDeviceError("get line handle", pin, "RequestLineV1", ret);
return -1; // error
}
lineFlags[pin] = lineRequestFlags;
lineFds[pin] = rq.fd;
if (wiringPiDebug)
printf ("requestLine succeeded: pin:%d, flags: %u, fd :%d\n", pin, lineRequestFlags, lineFds[pin]) ;
return lineFds[pin];
}
int digitalReadDeviceV1(int pin) { // INPUT and OUTPUT should work
if (lineFds[pin]<0) {
// line not requested - auto request on first read as input
pinModeDevice(pin, INPUT);
}
if (lineFds[pin]>=0) {
struct gpiohandle_data data;
int ret = ioctl(lineFds[pin], GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data);
if (ret) {
ReportDeviceError("get line values", pin, "digitalRead", ret);
return LOW; // error
}
return data.values[0];
}
return LOW; // error , need to request line before
}
void digitalWriteDeviceV1(int pin, int value) {
if (wiringPiDebug)
printf ("digitalWriteDevice: ioctl pin:%d value: %d\n", pin, value) ;
if (lineFds[pin]<0) {
// line not requested - auto request on first write as output
pinModeDevice(pin, OUTPUT);
}
if (lineFds[pin]>=0 && (lineFlags[pin] & GPIOHANDLE_REQUEST_OUTPUT)>0) {
struct gpiohandle_data data;
data.values[0] = value;
if (wiringPiDebug)
printf ("digitalWriteDevice: ioctl pin:%d cmd: GPIOHANDLE_SET_LINE_VALUES_IOCTL, value: %d\n", pin, value) ;
int ret = ioctl(lineFds[pin], GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
if (ret) {
ReportDeviceError("set line values", pin, "digitalWrite", ret);
return; // error
}
} else {
fprintf(stderr, "digitalWrite: no output (%d)\n", lineFlags[pin]);
}
return; // error
}
/*
* waitForInterrupt:
* Pi Specific.
* Wait for Interrupt on a GPIO pin.
* This is actually done via the /dev/gpiochip interface regardless of
* the wiringPi access mode in-use. Maybe sometime it might get a better
* way for a bit more efficiency.
*********************************************************************************
*/
int waitForInterruptV1(int pin, int mS)
{
int fd, ret;
struct pollfd polls ;
struct gpioevent_data evdata;
//struct gpio_v2_line_request req2;
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio [pin] ;
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio [pin] ;
if ((fd = isrFds [pin]) == -1)
return -2 ;
// Setup poll structure
polls.fd = fd;
polls.events = POLLIN | POLLERR ;
polls.revents = 0;
// Wait for it ...
ret = poll(&polls, 1, mS);
if (ret <= 0) {
fprintf(stderr, "wiringPi: ERROR: poll returned=%d\n", ret);
} else {
//if (polls.revents & POLLIN)
if (wiringPiDebug) {
printf ("wiringPi: IRQ line %d received %d, fd=%d\n", pin, ret, isrFds[pin]) ;
}
/* read event data */
int readret = read(isrFds [pin], &evdata, sizeof(evdata));
if (readret == sizeof(evdata)) {
if (wiringPiDebug) {
printf ("wiringPi: IRQ data id: %d, timestamp: %lld\n", evdata.id, evdata.timestamp) ;
}
ret = evdata.id;
} else {
ret = 0;
}
}
return ret;
}
int waitForInterruptInitV1(int pin, int mode)
{
const char* strmode = "";
if (wiringPiMode == WPI_MODE_PINS) {
pin = pinToGpio [pin] ;
} else if (wiringPiMode == WPI_MODE_PHYS) {
pin = physToGpio [pin] ;
}
/* open gpio */
sleep(1);
if (wiringPiGpioDeviceGetFd()<0) {
return -1;
}
struct gpioevent_request req;
req.lineoffset = pin;
req.handleflags = GPIOHANDLE_REQUEST_INPUT;
switch(mode) {
default:
case INT_EDGE_SETUP:
if (wiringPiDebug) {
printf ("wiringPi: waitForInterruptMode mode INT_EDGE_SETUP - exiting\n") ;
}
return -1;
case INT_EDGE_FALLING:
req.eventflags = GPIOEVENT_REQUEST_FALLING_EDGE;
strmode = "falling";
break;
case INT_EDGE_RISING:
req.eventflags = GPIOEVENT_REQUEST_RISING_EDGE;
strmode = "rising";
break;
case INT_EDGE_BOTH:
req.eventflags = GPIOEVENT_REQUEST_BOTH_EDGES;
strmode = "both";
break;
}
strncpy(req.consumer_label, "wiringpi_gpio_irq", sizeof(req.consumer_label) - 1);
//later implement GPIO_V2_GET_LINE_IOCTL req2
int ret = ioctl(chipFd, GPIO_GET_LINEEVENT_IOCTL, &req);
if (ret) {
ReportDeviceError("get line event", pin , strmode, ret);
return -1;
}
if (wiringPiDebug) {
printf ("wiringPi: GPIO get line %d , mode %s succeded, fd=%d\n", pin, strmode, req.fd) ;
}
/* set event fd nonbloack read */
int fd_line = req.fd;
isrFds [pin] = fd_line;
int flags = fcntl(fd_line, F_GETFL);
flags |= O_NONBLOCK;
ret = fcntl(fd_line, F_SETFL, flags);
if (ret) {
fprintf(stderr, "wiringPi: ERROR: fcntl set nonblock return=%d\n", ret);
return -1;
}
return 0;
}
int waitForInterruptClose (int pin) {
if (isrFds[pin]>0) {
if (wiringPiDebug) {
printf ("wiringPi: waitForInterruptClose close thread 0x%lX\n", (unsigned long)isrThreads[pin]) ;
}
if (pthread_cancel(isrThreads[pin]) == 0) {
if (wiringPiDebug) {
printf ("wiringPi: waitForInterruptClose thread canceled successfuly\n") ;
}
} else {
if (wiringPiDebug) {
fprintf (stderr, "wiringPi: waitForInterruptClose could not cancel thread\n");
}
}
close(isrFds [pin]);
}
isrFds [pin] = -1;
isrFunctions [pin] = NULL;
/* -not closing so far - other isr may be using it - only close if no other is using - will code later
if (chipFd>0) {
close(chipFd);
}
chipFd = -1;
*/
if (wiringPiDebug) {
printf ("wiringPi: waitForInterruptClose finished\n") ;
}
return 0;
}

View File

@@ -3,7 +3,7 @@ CFLAGS = -Wall
LDFLAGS =
# Need BCM19 <-> BCM26, +PWM: BCM12 <-> BCM13, BCM18 <-> BCM17 connected (1kOhm)
tests = wiringpi_test0_version wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test7_bench wiringpi_test8_pwm wiringpi_test9_pwm
tests = wiringpi_test0_version wiringpi_test1_sysfs wiringpi_test2_sysfs wiringpi_test3_device_wpi wiringpi_test4_device_phys wiringpi_test5_default wiringpi_test6_isr wiringpi_test61_isr2 wiringpi_test62_isr_wpin wiringpi_test7_bench wiringpi_test8_pwm wiringpi_test9_pwm
# Need XO hardware
xotests = wiringpi_xotest_test1_spi wiringpi_i2c_test1_pcf8574 wiringpi_test8_pwm wiringpi_test9_pwm
@@ -34,6 +34,12 @@ wiringpi_test5_default:
wiringpi_test6_isr:
${CC} ${CFLAGS} wiringpi_test6_isr.c -o wiringpi_test6_isr -lwiringPi
wiringpi_test61_isr2:
${CC} ${CFLAGS} wiringpi_test61_isr2.c -o wiringpi_test61_isr2 -lwiringPi
wiringpi_test62_isr_wpin:
${CC} ${CFLAGS} wiringpi_test62_isr_wpin.c -o wiringpi_test62_isr_wpin -lwiringPi
wiringpi_test7_bench:
${CC} ${CFLAGS} wiringpi_test7_bench.c -o wiringpi_test7_bench -lwiringPi

View File

@@ -52,6 +52,7 @@ int main (void) {
delayMicroseconds(600000);
}
//Error wrong direction - only for fun
digitalWrite(GPIO, LOW);

View File

@@ -0,0 +1,279 @@
// WiringPi test program: 6.1 new ISR2 function with Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test61_isr2.c -o wiringpi_test61_isr2 -lwiringPi
#include "wpi_test.h"
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
int GPIO = 19;
int GPIOIN = 26;
const int ToggleValue = 4;
float irq_timstamp_duration_ms = 0;
float accuracy = 0.015;
float bounce_acc = 1.0;
static volatile int globalCounter;
volatile long long gStartTime, gEndTime;
struct WPIWfiStatus wfiStatusOld;
static void ISR(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++;
}
static void ISR2(struct WPIWfiStatus wfiStatus, void* userdata) {
struct timeval now;
char strEdge[3][10] = {"unknown", "falling", "raising"};
int strEdgeidx = 0; //default
int* localCounter = (int*) userdata;
gettimeofday(&now, 0);
if (0==gStartTime) {
gStartTime = now.tv_sec*1000000LL + now.tv_usec;
} else {
gEndTime = now.tv_sec*1000000LL + now.tv_usec;
}
globalCounter++;
if (localCounter) {
(*localCounter)++;
}
switch(wfiStatus.edge) {
case INT_EDGE_FALLING: strEdgeidx = INT_EDGE_FALLING; break;
case INT_EDGE_RISING: strEdgeidx = INT_EDGE_RISING; break;
}
if (wfiStatusOld.statusOK>0 && wfiStatusOld.pinBCM==wfiStatus.pinBCM) {
irq_timstamp_duration_ms = (wfiStatus.timeStamp_us - wfiStatusOld.timeStamp_us) / 1000.0f;
} else {
irq_timstamp_duration_ms = 0.0f;
}
printf("ISR occured @ %lld us: statusOK=%d, pin=%u, edge=%s (%d), duration=%g ms, userdata=%p\n",
wfiStatus.timeStamp_us, wfiStatus.statusOK, wfiStatus.pinBCM, strEdge[strEdgeidx], wfiStatus.edge, irq_timstamp_duration_ms, userdata);
wfiStatusOld = wfiStatus;
}
void digitalWriteBounce(int OUTpin, int value, int bounce) {
digitalWrite(OUTpin, value);
if (bounce>0) {
delay(1);
digitalWrite(OUTpin, !value);
delay(1);
digitalWrite(OUTpin, value);
}
}
void DelayAndSumDuration(int ms, float* irq_timstamp_sum, const int doSum) {
delay(20);
if (doSum) {
*irq_timstamp_sum += irq_timstamp_duration_ms;
}
delay(ms-20);
}
double StartSequence2(int Edge, int OUTpin, int INpin, int bounce, int* localCounter) {
int expected;
float timeExpected_ms;
float irq_timstamp_sum = 0.0f;
gStartTime = 0;
gEndTime = 0;
globalCounter = 0;
*localCounter = 0;
printf("Start\n");
digitalWriteBounce(OUTpin, HIGH, bounce);
delay(200);
digitalWriteBounce(OUTpin, LOW, bounce);
DelayAndSumDuration(100, &irq_timstamp_sum, INT_EDGE_BOTH == Edge);
digitalWriteBounce(OUTpin, HIGH, bounce);
DelayAndSumDuration(200, &irq_timstamp_sum, INT_EDGE_RISING == Edge || INT_EDGE_BOTH == Edge);
digitalWriteBounce(OUTpin, LOW, bounce);
DelayAndSumDuration(100, &irq_timstamp_sum, INT_EDGE_FALLING == Edge || INT_EDGE_BOTH == Edge);
printf("Stop\n");
int globalCounterCopy = globalCounter;
if (INT_EDGE_BOTH == Edge) {
expected = 4;
timeExpected_ms = bounce ? 508: 500;
} else {
expected = 2;
timeExpected_ms = bounce ? 304: 300;
}
CheckSame("Global counted IRQ", globalCounter, expected);
CheckSame("Userdata pointer / Local counted IRQ ", *localCounter, expected);
if (globalCounter==expected) {
char str[1024];
float fTime = (gEndTime - gStartTime) / 1000.0;
sprintf(str, "IRQ measured %g msec (~%g expected)", fTime, timeExpected_ms);
CheckSameFloat(str, fTime, timeExpected_ms, timeExpected_ms*accuracy);
sprintf(str, "IRQ timestamp %g msec (~%g expected)", irq_timstamp_sum, timeExpected_ms);
CheckSameFloat(str, irq_timstamp_sum, timeExpected_ms, timeExpected_ms*accuracy);
// new data struct
CheckSame("GPIO IRQ pin", wfiStatusOld.pinBCM, INpin);
if (INT_EDGE_FALLING==Edge || INT_EDGE_RISING==Edge) {
CheckSame("GPIO IRQ edge", wfiStatusOld.edge, Edge);
}
CheckSame("GPIO IRQ status", wfiStatusOld.statusOK, 1);
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, int bounce) {
struct timeval now;
double fTime = 0.0;
const char* strOp = INT_EDGE_RISING == Enge ? "rising" : "fallling";
gStartTime = 0;
gEndTime = 0;
globalCounter = 0;
//printf("Start\n");
digitalWrite(OUTpin, INT_EDGE_RISING == Enge ? LOW : HIGH);
if (bounce>=0) {
printf("\nnew function, bounce time %d ms, %s :\n", bounce, strOp);
wiringPiISR2(IRQpin, Enge, &ISR2, bounce*1000, NULL);
} else {
printf("\nclassic function, %s :\n", strOp);
wiringPiISR(IRQpin, Enge, &ISR);
}
sleep(1);
gettimeofday(&now, 0);
gStartTime = now.tv_sec*1000000LL + now.tv_usec;
digitalWrite(OUTpin, INT_EDGE_RISING == Enge ? HIGH : LOW);
delay(20);
digitalWrite(OUTpin, LOW);
delay(20);
fTime = (gEndTime - gStartTime);
if (bounce<=0) {
printf("IRQ detection time %g usec", fTime);
} else {
printf("IRQ detection time %.1f msec", fTime/1000.0);
}
if (bounce>=0) {
// bounce time + 7ms (addtional bounce time) + 100 us (basic time)
CheckBetween("IRQ detection time with bounce [us]", fTime, 0, bounce*1000+ (bounce>0 ? 7000*bounce_acc : 0)+(100*bounce_acc));
} else {
CheckBetween("IRQ detection time [us]", fTime, 0, 100*bounce_acc);
}
wiringPiISRStop(IRQpin);
//printf("Stop\n");
return fTime;
}
int main (void) {
int major=0, minor=0;
wiringPiVersion(&major, &minor);
int _is40pin = piBoard40Pin();
CheckNotSame("40-Pin board: ", _is40pin, -1);
if (_is40pin==0) {
printf("Old 28pin system\n");
//GPIO = 23;
//GPIOIN = 24;
GPIO = 17;
GPIOIN = 18;
}
printf("WiringPi GPIO test program 6.2 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
printf("ISR and ISR2 test (WiringPi %d.%d)\n", major, minor);
wiringPiSetupGpio();
int RaspberryPiModel, rev, mem, maker, overVolted;
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
CheckNotSame("Model: ", RaspberryPiModel, -1);
switch(RaspberryPiModel) {
case PI_MODEL_A:
case PI_MODEL_B: //ARM=800MHz
case PI_MODEL_BP:
case PI_MODEL_AP:
case PI_MODEL_CM:
accuracy = 0.02;
bounce_acc = 2.7;
break;
case PI_MODEL_ZERO:
case PI_MODEL_ZERO_W: //ARM=1000MHz
accuracy = 0.02;
bounce_acc = 2.7;
break;
default:
accuracy = 0.012;
bounce_acc = 1.0;
break;
}
int IRQpin = GPIOIN;
int OUTpin = GPIO;
//wiringPiISR2(13, INT_EDGE_RISING, &ISR2, 0); // next pin
int localCounter;
memset(&wfiStatusOld, 0, sizeof(wfiStatusOld));
pinMode(IRQpin, INPUT);
pinMode(OUTpin, OUTPUT);
digitalWrite (OUTpin, LOW) ;
for (int bounce=0; bounce<=1; bounce++) {
unsigned long bouncetime = 0;
if (0==bounce) {
printf("! --- default test (no bounce) --- !\n");
} else {
bouncetime = 2000; //2 ms
printf("! --- test with bounce on input --- !\n");
}
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin);
wiringPiISR2(IRQpin, INT_EDGE_RISING, &ISR2, bouncetime, &localCounter);
sleep(1);
StartSequence2(INT_EDGE_RISING, OUTpin, IRQpin, bounce, &localCounter);
printf("Stopp IRQ\n");
wiringPiISRStop(IRQpin);
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin);
wiringPiISR2(IRQpin, INT_EDGE_FALLING, &ISR2, bouncetime, &localCounter);
sleep(1);
StartSequence2(INT_EDGE_FALLING, OUTpin, IRQpin, bounce, &localCounter);
printf("Stopp IRQ\n");
wiringPiISRStop(IRQpin);
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin);
wiringPiISR2(IRQpin, INT_EDGE_BOTH, &ISR2, bouncetime, &localCounter);
sleep(1);
StartSequence2(INT_EDGE_BOTH, OUTpin, IRQpin, bounce, &localCounter);
printf("Stopp IRQ\n");
wiringPiISRStop(IRQpin);
}
printf("Measuring duration IRQ @ GPIO%d with trigger @ GPIO%d rising and falling\n", IRQpin, OUTpin);
for (int bounce=-1; bounce<=5; bounce++) {
DurationTime(INT_EDGE_RISING, OUTpin, IRQpin, bounce);
DurationTime(INT_EDGE_FALLING, OUTpin, IRQpin, bounce);
}
pinMode(OUTpin, INPUT);
return UnitTestState();
}

View File

@@ -0,0 +1,129 @@
// WiringPi test program: Kernel char device interface / sysfs successor
// Compile: gcc -Wall wiringpi_test62_isr_wpin.c -o wiringpi_test62_isr_wpin -lwiringPi
#include "wpi_test.h"
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
//WPI pin numbers
int GPIO = 28;
int GPIOIN = 29;
static volatile int globalCounter;
static void wfiup(void) {
globalCounter++;
printf("I[%d] ", globalCounter);
fflush(stdout);
}
static void wfidown(void) {
globalCounter--;
printf("I[%d] ", globalCounter);
fflush(stdout);
}
void StartSequence (int Enge, int OUTpin, int count,int expected) {
/*
int expected = up ? count : 0;
globalCounter = up ? 0 : count;
*/
globalCounter = 0;
printf("Start: ");
fflush(stdout);
for (int loop=0; loop<count; ++loop) {
printf("H");
digitalWrite(OUTpin, HIGH);
printf("."); fflush(stdout);
delay(200);
printf("L");
digitalWrite(OUTpin, LOW);
delay(100);
printf("."); fflush(stdout);
}
printf("\n");
CheckSame("IRQ count", globalCounter, expected);
}
int main (void) {
int major, minor;
wiringPiVersion(&major, &minor);
printf("WiringPi GPIO test program 6.2 (using GPIO%d (output) and GPIO%d (input))\n", GPIO, GPIOIN);
printf(" testing irq with WPI pin numbers > 28\n");
printf("\nWiringPi %d.%d\n", major, minor);
//printf("Error check - next call create fatal error with exit!\n");
//CheckSame("wiringPiISRStop with wrong pin, result code:", wiringPiISRStop(5), 0);
CheckSame("wiringPiSetupPinType(WPI_PIN_WPI)", wiringPiSetupPinType(WPI_PIN_WPI), 0);
int rev, mem, maker, overVolted, RaspberryPiModel;
piBoardId(&RaspberryPiModel, &rev, &mem, &maker, &overVolted);
CheckNotSame("piBoardId", RaspberryPiModel, 0);
int _is40pin = piBoard40Pin();
CheckNotSame("is40pin", _is40pin, -1);
if (_is40pin==1) {
int IRQpin = GPIOIN;
int OUTpin = GPIO;
pinMode(IRQpin, INPUT);
pinMode(OUTpin, OUTPUT);
digitalWrite(OUTpin, LOW);
delayMicroseconds(100);
CheckSame("Input", digitalRead(IRQpin), LOW);
digitalWrite(OUTpin, HIGH);
delayMicroseconds(100);
if (digitalRead(IRQpin)==HIGH) {
digitalWrite(OUTpin, LOW);
delayMicroseconds(100);
printf("\nTesting IRQ @ WPI-GPIO%d with trigger @ WPI-GPIO%d rising\n", IRQpin, OUTpin);
CheckSame("wiringPiISR", wiringPiISR(IRQpin, INT_EDGE_RISING, &wfiup), 0);
sleep(1);
StartSequence(INT_EDGE_RISING, OUTpin, 3 , 3);
sleep(1);
CheckSame("wiringPiISRStop", wiringPiISRStop(IRQpin), 0);
printf("\n.IRQ off\n");
sleep(1);
StartSequence(INT_EDGE_RISING, OUTpin, 2, 0);
printf("\nTesting IRQ @ WPI-GPIO%d with trigger @ WPI-GPIO%d falling\n", IRQpin, OUTpin);
CheckSame("wiringPiISR", wiringPiISR(IRQpin, INT_EDGE_RISING, &wfidown), 0);
sleep(1);
StartSequence(INT_EDGE_FALLING, OUTpin, 4, -4);
sleep(1);
CheckSame("wiringPiISRStop", wiringPiISRStop(IRQpin), 0);
printf("\n.IRQ off\n");
sleep(1);
StartSequence(INT_EDGE_RISING, OUTpin, 2, 0);
printf("Error check - next call must be wrong!\n");
CheckSame("wiringPiISRStop with wrong pin, result code:", wiringPiISRStop(5555), EINVAL);
} else {
printf("Hardware connection for unit test missing!\n");
printf("unit test, need connection between Wiringpi pin 28 and 29!\n");
}
} else {
printf("unit test is for 40-pin hardware only!\n");
}
return UnitTestState();
}

View File

@@ -66,7 +66,7 @@ int main (void) {
case PI_MODEL_ZERO_W: //ARM=1000MHz
fExpectTimedigitalWrite = 0.104; //us;
fExpectTimedigitalRead = 0.135; //us
fExpectTimepinMode = 0.250; //us
fExpectTimepinMode = 0.360; //us
break;
case PI_MODEL_2:
ToggleValue /= 4;

View File

@@ -135,7 +135,7 @@ int main (void) {
pinMode(PWM, PWM_OUTPUT); //Mode BAL, pwmr=1024, pwmc=32
printf("pwmc 4.8kHz\n");
pwmSetClock(2000);
delay(250);
delay(1000);
printf("Register ISR@%d\n", PWM);
// INT_EDGE_BOTH, INT_EDGE_FALLING, INT_EDGE_RISING only one ISR per input

View File

@@ -94,6 +94,15 @@ void CheckNotSame(const char* msg, int value, int expect) {
}
}
void CheckBetween(const char* msg, int value, int min, int max) {
if (value>=min && value<=max) {
printf("%39s (% 3d< % 3d <% 3d) -> %spassed%s\n", msg, min, value, max, COLORGRN, COLORDEF);
} else {
printf("%39s (% 3d< % 3d <% 3d) -> %sfailed%s\n", msg, min, value, max, COLORRED, COLORDEF);
globalError=1;
}
}
void CheckSameFloat(const char* msg, float value, float expect, float epsilon) {
if (fabs(value-expect)<epsilon) {
@@ -104,10 +113,21 @@ void CheckSameFloat(const char* msg, float value, float expect, float epsilon) {
}
}
void CheckSameFloatX(const char* msg, float value, float expect) {
return CheckSameFloat(msg, value, expect, 0.08f);
}
void CheckBetweenDouble(const char* msg, double value, double min, double max) {
if (value>=min && value<=max) {
printf("%39s (%g< %g <%g) -> %spassed%s\n", msg, min, value, max, COLORGRN, COLORDEF);
} else {
printf("%39s (%g< %g <%g) -> %sfailed%s\n", msg, min, value, max, COLORRED, COLORDEF);
globalError=1;
}
}
void CheckSameDouble(const char* msg, double value, double expect, double epsilon) {
if (fabs(value-expect)<epsilon) {
printf("%35s (%.3f==%.3f) -> %spassed%s \n", msg, value, expect, COLORGRN, COLORDEF);

File diff suppressed because it is too large Load Diff

View File

@@ -144,6 +144,7 @@ extern const char *piRevisionNames [16] ;
extern const char *piMakerNames [16] ;
extern const int piMemorySize [ 8] ;
// Intended for the GPIO program Use at your own risk.
// Threads
@@ -276,8 +277,8 @@ extern int piBoardRev (void) ; // Deprecated, but does the sa
extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
extern int piBoard40Pin (void) ; // Interface V3.7
extern int piRP1Model (void) ; // Interface V3.14
extern int wpiPinToGpio (int wpiPin) ;
extern int physPinToGpio (int physPin) ;
extern int wpiPinToGpio (int wpiPin) ; // please don't use outside 0-63 and on RP1
extern int physPinToGpio (int physPin) ; // please don't use outside 0-63 and on RP1
extern void setPadDrive (int group, int value) ;
extern void setPadDrivePin (int pin, int value); // Interface V3.0
extern int getAlt (int pin) ;
@@ -292,12 +293,20 @@ extern void digitalWriteByte (int value) ;
extern void digitalWriteByte2 (int value) ;
// Interrupts
// (Also Pi hardware specific)
// status returned from waitForInterruptV2 V3.16
struct WPIWfiStatus {
int statusOK; // -1: error (return of 'poll' command), 0: timeout, 1: irq processed, next data values are valid if needed
unsigned int pinBCM; // gpio as BCM pin
int edge; // INT_EDGE_FALLING or INT_EDGE_RISING
long long int timeStamp_us; // time stamp in microseconds
};
extern int waitForInterrupt (int pin, int mS) ;
//extern int waitForInterrupt (int pin, int ms); unknown if still working, disabled for V3.16, please contact developer via github
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
extern struct WPIWfiStatus waitForInterrupt2(int pin, int edgeMode, int ms, unsigned long debounce_period_us) ; // V3.16
extern int wiringPiISR2 (int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus, void* userdata), unsigned long debounce_period_us, void* userdata) ; // V3.16
extern int wiringPiISRStop (int pin) ; //V3.2
extern int waitForInterruptClose(int pin) ; //V3.2
extern int waitForInterruptClose(int pin) ; //V3.2 legacy use wiringPiISRStop
// Threads
@@ -311,8 +320,8 @@ extern int piHiPri (const int pri) ;
// Extras from arduino land
extern void delay (unsigned int howLong) ;
extern void delayMicroseconds (unsigned int howLong) ;
extern void delay (unsigned int ms) ;
extern void delayMicroseconds (unsigned int us) ;
extern unsigned int millis (void) ;
extern unsigned int micros (void) ;