首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

异步通报,中断 例子(AM335X)

2012-12-18 
异步通知,中断 例子(AM335X)驱动程序:#includestdio.h#includesys/types.h#includesys/stat.h#inclu

异步通知,中断 例子(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;  }  



热点排行