Linux驱动:外部中断

本文详述了Linux驱动程序中的外部中断处理,包括实验平台(Linux-4.19.5,SAMSUNG JZ2440),中断注册、释放函数的解析以及中断执行函数的功能介绍。在中断注册时,指定中断编号、执行函数、类型和名称;中断释放则根据中断编号和设备标识来解除;中断执行函数在每次中断触发时被调用,处理中断事件。
摘要由CSDN通过智能技术生成

Linux驱动程序:外部中断

实验平台

内核版本:Linux-4.19.5
开发板:SAMSUNG JZ2440

主要函数

1.中断注册函数
函数原型
int request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
				const char *name, void *dev_id)
函数参数解析

irq:中断编号,在\arch\arm\mach-s3c24xx\include\mach\irqs.h头文件中定义了各个中断编号的宏定义
handler:中断执行函数,就是发生中断的时候会自动跳转执行的函数
flags:中断类型,在include\linux\interrupt.h头文件中定义了各个中断类型的宏定义
name:中断的名称
dev_id:传参,中断执行函数有两个传入参数一个是中断号irq,另一个就是dev_id指针

函数功能

注册一个中断,并设置对应的引脚

2.中断释放函数
函数原型
void *free_irq(unsigned int irq, void *dev_id)
函数参数解析

irq:中断编号,free_irq函数通过传入的irq,dev_id来释放中断,填写和request_irq中相同的参数,就可以释放对应的中断。
dev_id:同上。

函数功能

释放一个中断

3.中断执行函数
函数原型
irqreturn_t (*irq_handler_t)(int irq, void *dev_id)
函数参数解析

irq:中断编号,触发该中断的中断编号
dev_id:注册中断时候request_irq,设置的dev_id指针的值

函数功能

中断执行函数,每次中断触发都会执行该函数

实验程序

/* 驱动程序 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/uaccess.h>
#include <asm/irq.h>
#include <asm/io.h>
#include <linux/interrupt.h>

int major;	//主设备号

static struct class *buttons_class;

volatile unsigned long *gpfcon;
volatile unsigned long *gpfdat;

volatile unsigned long *gpgcon;
volatile unsigned long *gpgdat;

/* 键值: 按下时, 0x01, 0x02, 0x03, 0x04 */
/* 键值: 松开时, 0x81, 0x82, 0x83, 0x84 */
static unsigned char key_val;	//返回给用户的键值


static DECLARE_WAIT_QUEUE_HEAD(button_waitq);	//休眠队列
static volatile int ev_press = 0;	//条件变量

const int t_s3c2440_devid[4] = {
   1, 2, 3, 4};	//键值数组

static irqreturn_t buttons_irq(int irq, void *dev_id)
{
   
    int i_pinselect = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值