字符設(shè)備驅(qū)動(dòng)-初級(jí)篇按鍵中斷程序驅(qū)動(dòng)
#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");
=================================================================================================
測(cè)試命令:
lsmod :檢測(cè)當(dāng)前已經(jīng)安裝的驅(qū)動(dòng)程序
insmod ./keydrv.ko :安裝keydrv.ko驅(qū)動(dòng)程序
cat /proc/devices :查看當(dāng)前設(shè)備
cat /proc/interrupts :查看當(dāng)前中斷程序
exec 5<|dev/buttons :打開設(shè)備(等同于應(yīng)用程序調(diào)用open函數(shù)),定位到5
此時(shí)再執(zhí)行:cat /proc/interrupts 命令就可以看到S2、S3、S4、S5四個(gè)中斷程序
ps :查看所有進(jìn)程(770 0 3096 S -sh)
top :查看各進(jìn)程所占CPU比例
ls -l /proc/770/fd :可以查看到定位到5上面(lr-x-- 1 0 0 64 Jan 1 00:22 5 -> /dev/buttons)
exec 5<&- :關(guān)閉設(shè)備(等同于應(yīng)用程序調(diào)用close函數(shù))
評(píng)論