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

Function interruptHandlerV2

wiringPi/wiringPi.c:2960–3062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2958 */
2959
2960static void *interruptHandlerV2(void *arg)
2961{
2962 struct interrupt_handler_params *params;
2963 int pin, ret, fd, i;
2964 unsigned int readret;
2965 struct pollfd polls ;
2966 struct gpio_v2_line_event evdat[64];
2967 struct WPIWfiStatus wfiStatus;
2968 struct timespec tspec = {0, 5e5}; /* 0.5 ms timeout {0, 1e6} */
2969
2970 params = (struct interrupt_handler_params *)arg;
2971 pin = params->pin;
2972 fd = params->fd;
2973
2974 /* set event fd */
2975 isrFds [pin] = fd;
2976
2977 (void)piHiPri (55) ; // Only effective if we run as root
2978
2979 for (;;) { // check if event data is available, check if interruptHandlerV2 thread must be canceled
2980
2981 // Setup poll structure
2982 polls.fd = fd;
2983 polls.events = POLLIN | POLLPRI;
2984 polls.revents = 0;
2985
2986 // get event data, this is also a cancelation point, when pthread_cancel is called
2987 ret = ppoll(&polls, 1, &tspec, NULL); // returns -1 on error, 0 on timeout, >0 number of elements
2988
2989 if (ret < 0) { // we do not reach this point if canceled, ppoll does not return, is Cancellation Point
2990 if (wiringPiDebug)
2991 printf("interruptHandlerV2: ERROR: poll returned=%d\n", ret);
2992 pthread_exit(NULL);
2993 return NULL; // never landing here
2994 } else if (ret == 0) {
2995// if (wiringPiDebug)
2996// printf("interruptHandlerV2: timeout: poll returned=%d\n", ret);
2997 continue;
2998 }
2999 else {
3000 if (wiringPiDebug)
3001 printf ("interruptHandlerV2: IRQ line %d received %d events, fd=%d\n", pin, ret, isrFds[pin]) ;
3002 if (polls.revents & POLLIN) {
3003 /* read event data */
3004 readret = read(fd, &evdat, sizeof(evdat));
3005 if (readret >= sizeof(evdat[0])) {
3006 if (wiringPiDebug)
3007 printf ("interruptHandlerV2: IRQ at PIN: %d, events: %u\n", evdat[0].offset, readret/(unsigned int)sizeof(evdat[0])) ;
3008
3009 ret = readret/sizeof(evdat[0]); // number of events read from fd
3010 for (i = 0; i < ret; ++i) {
3011 if (isrFunctionsV2[pin]) {
3012 if (wiringPiDebug)
3013 printf( "interruptHandlerV2: GPIO EVENT at %llu on line %u (%u|%u) \n", evdat[i].timestamp_ns, evdat[i].offset, evdat[i].line_seqno, evdat[i].seqno);
3014 wfiStatus.statusOK = 1;
3015 wfiStatus.pinBCM = pin;
3016 switch (evdat[i].id) {
3017 case GPIO_V2_LINE_EVENT_RISING_EDGE:

Callers

nothing calls this directly

Calls 1

piHiPriFunction · 0.85

Tested by

no test coverage detected