#337 ISr user datat and unit test
This commit is contained in:
@@ -32,10 +32,12 @@ static void ISR(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ISR2(struct WPIWfiStatus wfiStatus) {
|
|
||||||
|
static void ISR2(struct WPIWfiStatus wfiStatus, void* userdata) {
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
char strEdge[3][10] = {"unknown", "falling", "raising"};
|
char strEdge[3][10] = {"unknown", "falling", "raising"};
|
||||||
int strEdgeidx = 0; //default
|
int strEdgeidx = 0; //default
|
||||||
|
int* localCounter = (int*) userdata;
|
||||||
|
|
||||||
gettimeofday(&now, 0);
|
gettimeofday(&now, 0);
|
||||||
if (0==gStartTime) {
|
if (0==gStartTime) {
|
||||||
@@ -44,6 +46,9 @@ static void ISR2(struct WPIWfiStatus wfiStatus) {
|
|||||||
gEndTime = now.tv_sec*1000000LL + now.tv_usec;
|
gEndTime = now.tv_sec*1000000LL + now.tv_usec;
|
||||||
}
|
}
|
||||||
globalCounter++;
|
globalCounter++;
|
||||||
|
if (localCounter) {
|
||||||
|
(*localCounter)++;
|
||||||
|
}
|
||||||
switch(wfiStatus.edge) {
|
switch(wfiStatus.edge) {
|
||||||
case INT_EDGE_FALLING: strEdgeidx = INT_EDGE_FALLING; break;
|
case INT_EDGE_FALLING: strEdgeidx = INT_EDGE_FALLING; break;
|
||||||
case INT_EDGE_RISING: strEdgeidx = INT_EDGE_RISING; break;
|
case INT_EDGE_RISING: strEdgeidx = INT_EDGE_RISING; break;
|
||||||
@@ -53,8 +58,8 @@ static void ISR2(struct WPIWfiStatus wfiStatus) {
|
|||||||
} else {
|
} else {
|
||||||
irq_timstamp_duration_ms = 0.0f;
|
irq_timstamp_duration_ms = 0.0f;
|
||||||
}
|
}
|
||||||
printf("ISR occured @ %lld us: statusOK=%d, pin=%u, edge=%s (%d), duration=%g ms\n",
|
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);
|
wfiStatus.timeStamp_us, wfiStatus.statusOK, wfiStatus.pinBCM, strEdge[strEdgeidx], wfiStatus.edge, irq_timstamp_duration_ms, userdata);
|
||||||
wfiStatusOld = wfiStatus;
|
wfiStatusOld = wfiStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +84,7 @@ void DelayAndSumDuration(int ms, float* irq_timstamp_sum, const int doSum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
double StartSequence2(int Edge, int OUTpin, int INpin, int bounce) {
|
double StartSequence2(int Edge, int OUTpin, int INpin, int bounce, int* localCounter) {
|
||||||
int expected;
|
int expected;
|
||||||
float timeExpected_ms;
|
float timeExpected_ms;
|
||||||
float irq_timstamp_sum = 0.0f;
|
float irq_timstamp_sum = 0.0f;
|
||||||
@@ -87,6 +92,7 @@ double StartSequence2(int Edge, int OUTpin, int INpin, int bounce) {
|
|||||||
gStartTime = 0;
|
gStartTime = 0;
|
||||||
gEndTime = 0;
|
gEndTime = 0;
|
||||||
globalCounter = 0;
|
globalCounter = 0;
|
||||||
|
*localCounter = 0;
|
||||||
printf("Start\n");
|
printf("Start\n");
|
||||||
digitalWriteBounce(OUTpin, HIGH, bounce);
|
digitalWriteBounce(OUTpin, HIGH, bounce);
|
||||||
delay(200);
|
delay(200);
|
||||||
@@ -101,7 +107,7 @@ double StartSequence2(int Edge, int OUTpin, int INpin, int bounce) {
|
|||||||
DelayAndSumDuration(100, &irq_timstamp_sum, INT_EDGE_FALLING == Edge || INT_EDGE_BOTH == Edge);
|
DelayAndSumDuration(100, &irq_timstamp_sum, INT_EDGE_FALLING == Edge || INT_EDGE_BOTH == Edge);
|
||||||
|
|
||||||
printf("Stop\n");
|
printf("Stop\n");
|
||||||
int globalCounterCopy = globalCounter;
|
int globalCounterCopy = globalCounter;
|
||||||
|
|
||||||
if (INT_EDGE_BOTH == Edge) {
|
if (INT_EDGE_BOTH == Edge) {
|
||||||
expected = 4;
|
expected = 4;
|
||||||
@@ -111,6 +117,9 @@ double StartSequence2(int Edge, int OUTpin, int INpin, int bounce) {
|
|||||||
timeExpected_ms = bounce ? 304: 300;
|
timeExpected_ms = bounce ? 304: 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckSame("Global counted IRQ", globalCounter, expected);
|
||||||
|
CheckSame("Userdata pointer / Local counted IRQ ", *localCounter, expected);
|
||||||
|
|
||||||
if (globalCounter==expected) {
|
if (globalCounter==expected) {
|
||||||
char str[1024];
|
char str[1024];
|
||||||
float fTime = (gEndTime - gStartTime) / 1000.0;
|
float fTime = (gEndTime - gStartTime) / 1000.0;
|
||||||
@@ -144,7 +153,7 @@ double DurationTime(int Enge, int OUTpin, int IRQpin, int bounce) {
|
|||||||
digitalWrite(OUTpin, INT_EDGE_RISING == Enge ? LOW : HIGH);
|
digitalWrite(OUTpin, INT_EDGE_RISING == Enge ? LOW : HIGH);
|
||||||
if (bounce>=0) {
|
if (bounce>=0) {
|
||||||
printf("\nnew function, bounce time %d ms, %s :\n", bounce, strOp);
|
printf("\nnew function, bounce time %d ms, %s :\n", bounce, strOp);
|
||||||
wiringPiISR2(IRQpin, Enge, &ISR2, bounce*1000);
|
wiringPiISR2(IRQpin, Enge, &ISR2, bounce*1000, NULL);
|
||||||
} else {
|
} else {
|
||||||
printf("\nclassic function, %s :\n", strOp);
|
printf("\nclassic function, %s :\n", strOp);
|
||||||
wiringPiISR(IRQpin, Enge, &ISR);
|
wiringPiISR(IRQpin, Enge, &ISR);
|
||||||
@@ -210,7 +219,7 @@ int main (void) {
|
|||||||
int OUTpin = GPIO;
|
int OUTpin = GPIO;
|
||||||
|
|
||||||
//wiringPiISR2(13, INT_EDGE_RISING, &ISR2, 0); // next pin
|
//wiringPiISR2(13, INT_EDGE_RISING, &ISR2, 0); // next pin
|
||||||
|
int localCounter;
|
||||||
memset(&wfiStatusOld, 0, sizeof(wfiStatusOld));
|
memset(&wfiStatusOld, 0, sizeof(wfiStatusOld));
|
||||||
|
|
||||||
pinMode(IRQpin, INPUT);
|
pinMode(IRQpin, INPUT);
|
||||||
@@ -227,23 +236,23 @@ int main (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin);
|
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d rising\n", IRQpin, OUTpin);
|
||||||
wiringPiISR2(IRQpin, INT_EDGE_RISING, &ISR2, bouncetime);
|
wiringPiISR2(IRQpin, INT_EDGE_RISING, &ISR2, bouncetime, &localCounter);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
StartSequence2(INT_EDGE_RISING, OUTpin, IRQpin, bounce);
|
StartSequence2(INT_EDGE_RISING, OUTpin, IRQpin, bounce, &localCounter);
|
||||||
printf("Stopp IRQ\n");
|
printf("Stopp IRQ\n");
|
||||||
wiringPiISRStop(IRQpin);
|
wiringPiISRStop(IRQpin);
|
||||||
|
|
||||||
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin);
|
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d falling\n", IRQpin, OUTpin);
|
||||||
wiringPiISR2(IRQpin, INT_EDGE_FALLING, &ISR2, bouncetime);
|
wiringPiISR2(IRQpin, INT_EDGE_FALLING, &ISR2, bouncetime, &localCounter);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
StartSequence2(INT_EDGE_FALLING, OUTpin, IRQpin, bounce);
|
StartSequence2(INT_EDGE_FALLING, OUTpin, IRQpin, bounce, &localCounter);
|
||||||
printf("Stopp IRQ\n");
|
printf("Stopp IRQ\n");
|
||||||
wiringPiISRStop(IRQpin);
|
wiringPiISRStop(IRQpin);
|
||||||
|
|
||||||
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin);
|
printf("\nTesting IRQ @ GPIO%d with trigger @ GPIO%d both\n", IRQpin, OUTpin);
|
||||||
wiringPiISR2(IRQpin, INT_EDGE_BOTH, &ISR2, bouncetime);
|
wiringPiISR2(IRQpin, INT_EDGE_BOTH, &ISR2, bouncetime, &localCounter);
|
||||||
sleep(1);
|
sleep(1);
|
||||||
StartSequence2(INT_EDGE_BOTH, OUTpin, IRQpin, bounce);
|
StartSequence2(INT_EDGE_BOTH, OUTpin, IRQpin, bounce, &localCounter);
|
||||||
printf("Stopp IRQ\n");
|
printf("Stopp IRQ\n");
|
||||||
wiringPiISRStop(IRQpin);
|
wiringPiISRStop(IRQpin);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -491,7 +491,8 @@ static int isrFds [64] =
|
|||||||
|
|
||||||
// ISR Data
|
// ISR Data
|
||||||
static int chipFd = -1;
|
static int chipFd = -1;
|
||||||
static void (*isrFunctionsV2[64])(struct WPIWfiStatus) ;
|
static void* isrUserdata[64];
|
||||||
|
static void (*isrFunctionsV2[64])(struct WPIWfiStatus, void* userdata) ;
|
||||||
static void (*isrFunctions [64])(void) ;
|
static void (*isrFunctions [64])(void) ;
|
||||||
static pthread_t isrThreads[64];
|
static pthread_t isrThreads[64];
|
||||||
static int isrEdgeMode[64]; // irq on rising/falling edge
|
static int isrEdgeMode[64]; // irq on rising/falling edge
|
||||||
@@ -2871,6 +2872,7 @@ int wiringPiISRStop (int pin) {
|
|||||||
isrFds [pin] = -1;
|
isrFds [pin] = -1;
|
||||||
isrFunctions[pin] = NULL;
|
isrFunctions[pin] = NULL;
|
||||||
isrFunctionsV2[pin] = NULL;
|
isrFunctionsV2[pin] = NULL;
|
||||||
|
isrUserdata[pin] = NULL;;
|
||||||
isrDebouncePeriodUs[pin] = 0;
|
isrDebouncePeriodUs[pin] = 0;
|
||||||
|
|
||||||
/* -not closing so far - other isr may be using it - only close if no other is using - will code later
|
/* -not closing so far - other isr may be using it - only close if no other is using - will code later
|
||||||
@@ -3036,7 +3038,7 @@ void *interruptHandlerV2(void *arg)
|
|||||||
if (wiringPiDebug) {
|
if (wiringPiDebug) {
|
||||||
printf( "interruptHandlerV2: call isr function\n");
|
printf( "interruptHandlerV2: call isr function\n");
|
||||||
}
|
}
|
||||||
isrFunctionsV2[pin](wfiStatus);
|
isrFunctionsV2[pin](wfiStatus, isrUserdata[pin]);
|
||||||
if (wiringPiDebug) {
|
if (wiringPiDebug) {
|
||||||
printf( "interruptHandlerV2: return from isr function\n");
|
printf( "interruptHandlerV2: return from isr function\n");
|
||||||
}
|
}
|
||||||
@@ -3073,7 +3075,7 @@ void *interruptHandlerV2(void *arg)
|
|||||||
*********************************************************************************
|
*********************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int wiringPiISRInternal(int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus), void (*functionClassic)(void), unsigned long debounce_period_us)
|
int wiringPiISRInternal(int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus, void* userdata), void (*functionClassic)(void), unsigned long debounce_period_us, void* userdata)
|
||||||
{
|
{
|
||||||
const int maxpin = GetMaxPin();
|
const int maxpin = GetMaxPin();
|
||||||
|
|
||||||
@@ -3096,6 +3098,7 @@ int wiringPiISRInternal(int pin, int edgeMode, void (*function)(struct WPIWfiSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
isrFunctionsV2[pin] = function;
|
isrFunctionsV2[pin] = function;
|
||||||
|
isrUserdata[pin] = userdata;
|
||||||
isrFunctions[pin] = functionClassic;
|
isrFunctions[pin] = functionClassic;
|
||||||
isrEdgeMode[pin] = edgeMode;
|
isrEdgeMode[pin] = edgeMode;
|
||||||
isrDebouncePeriodUs[pin] = debounce_period_us;
|
isrDebouncePeriodUs[pin] = debounce_period_us;
|
||||||
@@ -3138,12 +3141,12 @@ int wiringPiISRInternal(int pin, int edgeMode, void (*function)(struct WPIWfiSta
|
|||||||
|
|
||||||
int wiringPiISR (int pin, int mode, void (*function)(void))
|
int wiringPiISR (int pin, int mode, void (*function)(void))
|
||||||
{
|
{
|
||||||
return wiringPiISRInternal(pin, mode, NULL, function, 0);
|
return wiringPiISRInternal(pin, mode, NULL, function, 0, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wiringPiISR2(int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus), unsigned long debounce_period_us)
|
int wiringPiISR2(int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus, void* userdata), unsigned long debounce_period_us, void* userdata)
|
||||||
{
|
{
|
||||||
return wiringPiISRInternal(pin, edgeMode, function, NULL, debounce_period_us);
|
return wiringPiISRInternal(pin, edgeMode, function, NULL, debounce_period_us, userdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ struct WPIWfiStatus {
|
|||||||
//extern int waitForInterrupt (int pin, int ms); unknown if still working, disabled for V3.16, please contact developer via github
|
//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 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 struct WPIWfiStatus waitForInterrupt2(int pin, int edgeMode, int ms, unsigned long debounce_period_us) ; // V3.16
|
||||||
extern int wiringPiISR2 (int pin, int mode, void (*function)(struct WPIWfiStatus wfiStatus), 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 wiringPiISRStop (int pin) ; //V3.2
|
||||||
extern int waitForInterruptClose(int pin) ; //V3.2 legacy use wiringPiISRStop
|
extern int waitForInterruptClose(int pin) ; //V3.2 legacy use wiringPiISRStop
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user