Browse Source

Adds function wiringPiISRX to add an ISR with pin number as parameter

pull/151/head
riban 2 years ago
parent
commit
8c58a342a3
2 changed files with 46 additions and 8 deletions
  1. +45
    -8
      wiringPi/wiringPi.c
  2. +1
    -0
      wiringPi/wiringPi.h

+ 45
- 8
wiringPi/wiringPi.c View File

@@ -304,6 +304,7 @@ static uint64_t epochMilli, epochMicro ;


static int wiringPiMode = WPI_MODE_UNINITIALISED ; static int wiringPiMode = WPI_MODE_UNINITIALISED ;
static volatile int pinPass = -1 ; static volatile int pinPass = -1 ;
static volatile int withPinPass = -1 ;
static pthread_mutex_t pinMutex ; static pthread_mutex_t pinMutex ;


// Debugging & Return codes // Debugging & Return codes
@@ -328,7 +329,9 @@ static int sysFds [64] =


// ISR Data // ISR Data


static void (*isrFunctions [64])(void) ;
typedef void isr_function_t();
typedef void isr_function1_t();
static void *isrFunctions [64] ;




// Doing it the Arduino way with lookup tables... // Doing it the Arduino way with lookup tables...
@@ -1968,29 +1971,36 @@ int waitForInterrupt (int pin, int mS)
static void *interruptHandler (UNU void *arg) static void *interruptHandler (UNU void *arg)
{ {
int myPin ; int myPin ;
int withPin;


(void)piHiPri (55) ; // Only effective if we run as root (void)piHiPri (55) ; // Only effective if we run as root


myPin = pinPass ; myPin = pinPass ;
withPin = withPinPass ;
pinPass = -1 ; pinPass = -1 ;


for (;;) for (;;)
{
if (waitForInterrupt (myPin, -1) > 0) if (waitForInterrupt (myPin, -1) > 0)
isrFunctions [myPin] () ;
{
if (withPin < 0)
((isr_function_t*) isrFunctions [myPin]) () ;
else
((isr_function1_t*) isrFunctions [myPin]) (withPin) ;
}
}


return NULL ; return NULL ;
} }



/* /*
* wiringPiISR:
* Pi Specific.
* Take the details and create an interrupt handler that will do a call-
* back to the user supplied function.
* _wiringPiISR :
* Internal function that adds an ISR
********************************************************************************* *********************************************************************************
*/ */


int wiringPiISR (int pin, int mode, void (*function)(void))

int _wiringPiISR (int pin, int mode, int withPin, void *function)
{ {
pthread_t threadId ; pthread_t threadId ;
const char *modeS ; const char *modeS ;
@@ -2072,6 +2082,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void))


pthread_mutex_lock (&pinMutex) ; pthread_mutex_lock (&pinMutex) ;
pinPass = pin ; pinPass = pin ;
withPinPass = withPin;
pthread_create (&threadId, NULL, interruptHandler, NULL) ; pthread_create (&threadId, NULL, interruptHandler, NULL) ;
while (pinPass != -1) while (pinPass != -1)
delay (1) ; delay (1) ;
@@ -2080,6 +2091,32 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
return 0 ; return 0 ;
} }


/*
* wiringPiISR:
* Pi Specific.
* Take the details and create an interrupt handler that will do a call-
* back to the user supplied function.
*********************************************************************************
*/

int wiringPiISR (int pin, int mode, void (*function)(void))
{
return _wiringPiISR (pin, mode, -1, function);
}

/*
* wiringPiISR:
* Pi Specific.
* Take the details and create an interrupt handler that will do a call-
* back to the user supplied function passing the pin that triggered interrupt.
*********************************************************************************
*/

int wiringPiISRX (int pin, int mode, void (*function)(int))
{
return _wiringPiISR (pin, mode, pin, function);
}



/* /*
* initialiseEpoch: * initialiseEpoch:


+ 1
- 0
wiringPi/wiringPi.h View File

@@ -246,6 +246,7 @@ extern void digitalWriteByte2 (int value) ;


extern int waitForInterrupt (int pin, int mS) ; extern int waitForInterrupt (int pin, int mS) ;
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ; extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
extern int wiringPiISRX (int pin, int mode, void (*function)(void)) ;


// Threads // Threads




Loading…
Cancel
Save