异步通知,中断 例子(AM335X)
驱动程序:
#include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<sys/select.h> #include<unistd.h> #include<signal.h> #include<string.h> unsigned int flag = 0; void sig_handler(int sig) { printf("%s\n",__FUNCTION__); flag++; printf("flag = %d\n", flag);} int main(void) { char r_buf[20]; char *w_buf = "hello write!\n"; int r_count = 0; int fd; int f_flags; flag++; fd=open("/dev/fpga_key",O_RDWR); if(fd<0) { perror("open"); return-1; } signal(SIGIO, sig_handler); fcntl(fd, F_SETOWN, getpid()); f_flags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, FASYNC | f_flags); while(1) { printf("waiting \n"); sleep(2); if(flag > 3) break; } close(fd); return 0; }