MCPcopy Create free account
hub / github.com/WiringPi/WiringPi / wiringPiISRInternal

Function wiringPiISRInternal

wiringPi/wiringPi.c:3073–3139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3071 */
3072
3073int wiringPiISRInternal(int pin, int edgeMode, void (*function)(struct WPIWfiStatus wfiStatus, void* userdata), void (*functionClassic)(void), unsigned long debounce_period_us, void* userdata)
3074{
3075 if (wiringPiMode == WPI_MODE_UNINITIALISED) {
3076 return wiringPiFailure(WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n");
3077 }
3078 if (!ToBCMPin(&pin)) {
3079 fprintf(stderr, "wiringPiISRStop: wrong pin %d (mode: %d) number!\n", pin, wiringPiMode);
3080 return EINVAL;
3081 }
3082 if (wiringPiDebug) {
3083 printf("wiringPi: wiringPiISR pin %d, edgeMode %d\n", pin, edgeMode);
3084 }
3085 if (isrFunctions[pin] || isrFunctionsV2[pin]) {
3086 fprintf(stderr, "wiringPi: ISR function already active\n");
3087 }
3088
3089 if (wiringPiDebug) {
3090 printf("wiringPi: mutex in\n");
3091 }
3092 pthread_mutex_lock (&pinMutex) ;
3093 struct interrupt_handler_params params = {
3094 .pin = pin,
3095 };
3096 params.fd = interruptHandlerInit(pin, edgeMode, debounce_period_us);
3097 if (params.fd < 0) {
3098 pthread_mutex_unlock (&pinMutex) ;
3099 return -1;
3100 }
3101
3102 // OK to start the new ISR. Update the table.
3103 isrFunctionsV2[pin] = function;
3104 isrUserdata[pin] = userdata;
3105 isrFunctions[pin] = functionClassic;
3106 isrEdgeMode[pin] = edgeMode;
3107 isrDebouncePeriodUs[pin] = debounce_period_us;
3108
3109 pinPass = pin ;
3110 if (params.fd > 0) {
3111 if (wiringPiDebug) {
3112 printf("wiringPi: pthread_create before 0x%lX\n", (unsigned long)isrThreads[pin]);
3113 }
3114 if (pthread_create (&isrThreads[pin], NULL, interruptHandlerV2, &params)==0) {
3115 if (wiringPiDebug) {
3116 printf("wiringPi: pthread_create successed, 0x%lX\n", (unsigned long)isrThreads[pin]);
3117 }
3118 } else {
3119 if (wiringPiDebug) {
3120 printf("wiringPi: pthread_create failed\n");
3121 }
3122 }
3123 // wait so that interruptHandler is up und running.
3124 // when interruptHandler is running, the calling function wiringPiISRInternal
3125 // must be still alive, otherwise the thread argument &param points into nirwana,
3126 // when it is picked up from interruptHandlerV2.
3127 delay(10);
3128 }
3129
3130 if (wiringPiDebug) {

Callers 2

wiringPiISRFunction · 0.85
wiringPiISR2Function · 0.85

Calls 4

wiringPiFailureFunction · 0.85
ToBCMPinFunction · 0.85
interruptHandlerInitFunction · 0.85
delayFunction · 0.70

Tested by

no test coverage detected