2013-10-17 5 views
1

Beaglebone Black의 핀 중 하나에 상승 에지가있을 때마다 이벤트를 트리거하려고합니다. 문제는, 비록 내가 그 핀을 아무 것에도 연결하지 않는다해도, 출력은 단지 인쇄가되고, 인터럽트가 발생하고, 인터럽트가 발생합니다. stackoverflow의 Interrupts in Beaglebone 질문을 발견하고 단계를 수행하려고했습니다. 이 기능을 구현하는 Program에 대한 링크가있었습니다. poll()에 대해 읽었을 때 프로그램에서 약간의 변경을가했는데 하나의 핀만 모니터링하려고하기 때문입니다. 변경된 코드는 다음과 같습니다.BeagleBone Black의 핀을 모니터하는 Poll(). 핀이 연결되지 않아도 연속 출력.

int main(int argc, char **argv, char **envp) 
{ 
struct pollfd fdset[1]; // fdset[2] changed to fdset[1] since I will monitor just 1 pin 
int nfds = 1;   // nfds changed from 2 to 1 
int gpio_fd, timeout, rc; 
char *buf[MAX_BUF]; 
unsigned int gpio; 
int len; 



if (argc < 2) { 
    printf("Usage: gpio-int <gpio-pin>\n\n"); 
    printf("Waits for a change in the GPIO pin voltage level or input on stdin\n"); 
    exit(-1); 
} 

gpio = atoi(argv[1]); 

gpio_export(gpio); 
gpio_set_dir(gpio, 0); 
gpio_set_edge(gpio, "rising"); 
gpio_fd = gpio_fd_open(gpio); 

timeout = POLL_TIMEOUT; 

while (1) { 
    memset((void*)fdset, 0, sizeof(fdset)); 

    fdset[0].fd = gpio_fd;     // This is the pin to be monitored 
    fdset[0].events = POLLIN; 

    //fdset[1].fd = gpio_fd;    // commented since I do not need this 
    //fdset[1].events = POLLPRI; 

    rc = poll(fdset, nfds, timeout);  

    if (rc < 0) { 
     printf("\npoll() failed!\n"); 
     return -1; 
    } 

    if (rc == 0) { 
     printf("."); 
    } 

    if (fdset[0].revents & POLLIN) { 
     len = read(fdset[0].fd, buf, MAX_BUF); 
     printf("\npoll() GPIO %d interrupt occurred\n", gpio); 
    } 

      // ****Commented block**** 
    //if (fdset[0].revents & POLLIN) { 
    // (void)read(fdset[0].fd, buf, 1); 
    // printf("\npoll() stdin read 0x%2.2X\n", (unsigned int) buf[0]); 
    //} 

    fflush(stdout); 
} 

gpio_fd_close(gpio_fd); 
return 0; 
} 

Beaglebone black에서 Angstrom을 실행합니다.

답변

1

내부적으로 연결되어 있지 않거나 높지 않은 경우 부동 핀이 연결되어있어 보이지 않는 인터럽트가 발생할 수 있습니다.

+0

여러분이 인용하는 예제는 pollfd.events를 정의 할 때와 GPIO에 대해 수신 된 revents를 마스킹 할 때 둘 다 POLPRI를 사용합니다 – user2832475

2

https://www.kernel.org/doc/Documentation/gpio/sysfs.txt 핀이 인터럽트 인터럽트 발생으로 구성이 인터럽트를 발생 시키도록 구성되어있는 경우 ("가장자리"의 설명 참조) 할 수있는 경우

하면 폴링 할 수있다 (2)의 인터럽트가 트리거 될 때마다 해당 파일과 poll (2)이 리턴됩니다. poll (2)를 사용하는 경우 POLLPRI 및 POLLERR 이벤트를 설정하십시오. select (2)를 사용하는 경우 exceptfds에 파일 설명자를 설정하십시오. poll (2)가 sysfs 파일의 시작 부분에 lseek (2)를 반환하고 새 값을 읽거나 파일을 닫은 후 을 다시 열어 값을 읽습니다.

이벤트 POLLPRI 및 POLLERR을 설정하지 않았습니다.

struct pollfd fdset[1]; 
memset((void*)fdset, 0, sizeof(fdset)); 
fdset[0].fd = fd; 
fdset[0].events = POLLPRI | POLLERR; 
... 
poll() 
... 
lseek(fdset[0].fd, 0, SEEK_SET); 
const ssize_t rc = read(fdset[0].fd, buf, MAX_BUF); 

위의 작업은 Linux 3.8.13-bone47이 설치된 Debian을 실행하는 BeagleBone Black Rev. C에서 작동합니다.