免费注册 查看新帖 |

Chinaunix

广告
  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 732 | 回复: 0
打印 上一主题 下一主题

KEY测试(查询) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-18 16:36 |只看该作者 |倒序浏览

KEY测试(查询)
作好了LED,现在做一个按键,板子的按键是接在PIOB0-3,只需要稍微改动一下就可以了,程序如下
#include
#include
#include
#include
#include
#include  /* get the user-level API */
#include
#include
#include
#include
#include "at91_pio.h"
MODULE_LICENSE("GPL");
static void __iomem *pio_base;
size_t key_read (struct file *filp, char __user *buf, size_t count, loff_t *pos){
     printk("watchdog read.\r\n");
     return 0;
}
ssize_t key_write (struct file *filp, const char __user *buf, size_t count,off_t *pos){
     printk("watchdog write.\r\n");
     return count;
}
int key_ioctl (struct inode *inode, struct file *filp,unsigned int cmd, unsigned long arg){
     arg=readl(pio_base + PIO_PDSR)&0x0000000f;
     //printk("led ioctl cmd:%d%ld\r\n",cmd,arg);
     return arg;
}
static struct file_operations key_fops = {
     .owner = THIS_MODULE,
     .read  = key_read,
     .write = key_write,
     .ioctl = key_ioctl,
};
static int key_init(void){
     int result;
     printk(KERN_ALERT "key_test:%s,%s\r\n",__DATE__,__TIME__);
     pio_base = ioremap(0xFFFFF600,512);      
     writel(0x0000000f, pio_base + PIO_PUER);   
     writel(0x0000000f, pio_base + PIO_PER);     
     writel(0x0000000f, pio_base + PIO_IDR);
     
     result = register_chrdev(61, "key", &key_fops);
     if (result
         printk("register device fail.\r\n");
return result;
     }
     return 0;
}
static void key_exit(void){
printk("stop key\r\n");
     unregister_chrdev(61, "key");
     iounmap(pio_base);
     printk(KERN_ALERT "stop clear key\r\n");
}
module_init(key_init);
module_exit(key_exit);

同样编译好后,在运行之前,先要创建一个设备文件
# mknod "/dev/led" c 61 1
即创建一个主设备号为61,次设备号为1名称为KEY的字符型设备。
然后运行这个函数,按下按键,即可看见终端会有相应的显示。

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/68643/showart_1085521.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP