你好,游客 登录 注册 搜索
背景:
阅读新闻

ARM-Linux下的GPIO中断程序

[日期:2011-03-22] 来源:Linux社区  作者:cskywit [字体:大 中 小]
Linux上层应用程序:
 
  1. #include <stdio.h>   
  2. //#include <conio.h>  
  3. #include <unistd.h>  
  4. #include <stdlib.h>  
  5. #include <string.h>  
  6. #include <fcntl.h>  
  7. #include <sys/types.h>  
  8. #include <sys/stat.h>  
  9. #include <linux/ioctl.h>  
  10. #include <signal.h>   
  11.   
  12.   
  13. int main(int argc ,char *argv[])   
  14. {   
  15.     int fd;   
  16.         char input;   
  17.     fd = open("/dev/PB18_IRQTest",O_RDWR);   
  18.     if(fd < 0)   
  19.         {          
  20.             perror("open PB18_IRQTest device");   
  21.                 return 0;   
  22.         }   
  23.     while(1)   
  24.         {   
  25.              printf("input 0 to trigger int\n");   
  26.              scanf("%c",&input);   
  27.              switch(input)   
  28.              {   
  29.             case '0':   
  30.                         ioctl(fd,0,0);   
  31.             printf("\n");   
  32.             break;   
  33.             case '1':   
  34.             ioctl(fd,1,0);   
  35.             printf("\n");   
  36.             break;   
  37.                 default:   
  38.             printf("\n");   
  39.                     break;                                           
  40.                      }   
  41.                  }                                                            
  42.                   return 0;   
  43. }  

     由上面的代码可以看出,Linux内核在中断程序处理方面已经做了很多抽象,对于驱动程序编写者只需要按照内核中断构架去实现一定的控制函数就可以,以后有时间会专门撰文剖析还原Linux内核里那些对中断实现的抽象。

linux
相关资讯       Arm Linux 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款