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을 실행합니다.
여러분이 인용하는 예제는 pollfd.events를 정의 할 때와 GPIO에 대해 수신 된 revents를 마스킹 할 때 둘 다 POLPRI를 사용합니다 – user2832475