Poll() GPIO on IMX6SL

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Poll() GPIO on IMX6SL

668 Views
stephangm
Contributor I

This may not be the right place to ask but.... Im trying to use poll() on a board using the IMX6SL. It hangs on poll() on the second loop iteration. The commented out code and comment above it shows says what happens when this code is added. Does the interrupt need to be unmasked or something? I've seen code almost identical to mine in a few places, yet this hasn't seemed to work.

This is the c code:

int read_gpio(char *path, void (*callback)(int)){

   int fd = open(path, O_RDONLY);
   if(fd == -1){

       perror("error opening file");
   return -1;
   }

   char buf[11];
   int res, off;
   char c;
   struct pollfd pfd = {

       .fd = fd,
       .events = POLLPRI,
       .revents = 0
   };
   for(;;){

       LOGD("for begins");
     // dummy read causes poll never to run
     // read(fd, &buf[],1);
    // lseek(fd, 0, SEEK_SET);
       res = poll(&pfd,1,-1);
       LOGD("polling ended");
       if(res == -1){

          perror("error polling");
          break;
   }

   if((pfd.revents & POLLPRI) == POLLPRI){

       LOGD("POLLPRI");
       off = lseek(fd, 0, SEEK_SET);
       if(off == -1) break;
       memset(&buf[0], 0, 11);
       read(fd, &buf[0], 10*sizeof(char));
    // These two lines will cause it to poll constantly
    // close(fd);
   // fd = open(path, O_RDONLY);
       LOGD("Before callback");
       callback(atoi(buf));
       LOGD("After Callback");
   }

      LOGD("for ends");
   }

  close(fd);
   LOGD("for exits");

   return 0;
}

Labels (2)
Tags (3)
0 Kudos
2 Replies

509 Views
jamesbone
NXP TechSupport
NXP TechSupport

Take in consideration that The poll() function shall support regular files, terminal and pseudo-terminal devices, FIFOs, pipes, sockets  STREAMS-based files.   From the portion of code I don´t see if this is accomplish. Maybe that it is the problem.

0 Kudos

509 Views
stephangm
Contributor I

I don't see what you mean, I am using poll() through the sysfs interface and polling path which is sys/class/gpio/gpioXX/value​.

0 Kudos