字符设备驱动-初级篇按键中断程序驱动
#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"
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;
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 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");
=================================================================================================
测试命令:
lsmod :检测当前已经安装的驱动程序
insmod ./keydrv.ko :安装keydrv.ko驱动程序
cat /proc/devices :查看当前设备
cat /proc/interrupts :查看当前中断程序
exec 5<|dev/buttons :打开设备(等同于应用程序调用open函数),定位到5
此时再执行:cat /proc/interrupts 命令就可以看到S2、S3、S4、S5四个中断程序
ps :查看所有进程(770 0 3096 S -sh)
top :查看各进程所占CPU比例
ls -l /proc/770/fd :可以查看到定位到5上面(lr-x-- 1 0 0 64 Jan 1 00:22 5 -> /dev/buttons)
exec 5<&- :关闭设备(等同于应用程序调用close函数)
评论