驱动源码:
#include “linux/module.h”
#include “linux/kernel.h”
#include “linux/fs.h”
#include “linux/init.h”
#include “linux/delay.h”
#include “linux/irq.h”
#include “asm/uaccess.h”
#include “asm/irq.h”
#include “asm/io.h”
#include “asm/arch/regs-gpio.h”
#include “asm/hardware.h”
#include “linux/poll.h”
int major = 0;
static struct class *keydrv_class;
static struct class_device *keydrv_class_dev;
volatile unsigned long *gpfcon;
volatile unsigned long *gpfdat;
volatile unsigned long *gpgcon;
volatile unsigned long *gpgdat;
struct pin_desc{
};
struct pin_desc pins_desc[4] = {
};
// 键值: 按下时, 0x01, 0x02, 0x03, 0x04
// 键值: 松开时, 0x81, 0x82, 0x83, 0x84
static unsigned char key_val;
static DECLARE_WAIT_QUEUE_HEAD(button_waitq);
// 中止事情标志, 中止服务程序将它置1,third_drv_read将它清0
static volatile int ev_press = 0;
static irqreturn_t buttons_irq(int irq, void *dev_id)
{
}
static int key_drv_open(struct inode *inode, struct file *file)
{
}
ssize_t key_drv_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
{
}
int key_drv_close(struct inode *inode, struct file *file)
{
}
static unsigned key_drv_poll(struct file *file, poll_table *wait)
{
}
static struct file_operations key_drv_fops = {
};
static int key_drv_init(void)
{
}
static void key_drv_exit(void)
{
}
module_init(key_drv_init);
module_exit(key_drv_exit);
MODULE_LICENSE(“GPL”);
=================================================================
测验源码:
#include
#include
#include
#include
#include
int main(int argc, char **argv)
{
}
==================================================================
解析:
1、key_drv_fops 结构体中添加:.poll = key_drv_poll,
2、应用程序中循环调用poll函数,判别按键值有没有更新;假如更新则读取,不然超时提示。