Poll() GPIO on IMX6SL

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Poll() GPIO on IMX6SL

1,471件の閲覧回数
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;
}

ラベル(2)
タグ(3)
0 件の賞賛
返信
2 返答(返信)

1,312件の閲覧回数
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 件の賞賛
返信

1,312件の閲覧回数
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 件の賞賛
返信