字符设备驱动笔记——中断方式按键驱动之linux中断处理结构(五)
一、单片机下的中断处理
)分辨是哪一个中断
)调用处理函数
)清中断
二、linux下的中断处理 1)/arch/arm/kernel/irq.c
asmlinkage void __exception asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
{
struct pt_regs *old_regs = set_irq_regs(regs);
struct irq_desc *desc = irq_desc + irq; /*
* Some hardware gives randomly wrong interrupts. Rather
* than crashing, do something sensible.
*/
if (irq >= NR_IRQS)
desc = &bad_irq_desc; irq_enter(); desc_handle_irq(irq, desc); /* AT91 specific workaround */
irq_finish(irq); irq_exit();
set_irq_regs(old_regs);
} 2)/kernel/irq/handle.c
static inline void desc_handle_irq(unsigned int irq, struct irq_desc *desc)
{
desc->handle_irq(irq, desc);
} 3)/kernel/irq/chip.c
__set_irq_handler{
...
desc->handle_irq = handle;
...
} 4)/include/linux/irq.h
static inline void
set_irq_handler(unsigned int irq, irq_flow_handler_t handle)
{
__set_irq_handler(irq, handle, , NULL);
} 5)/arch/arm/plat-s3c24xx/irq.c
void __init s3c24xx_init_irq(void) 6)/arch/arm/plat-s3c24xx/irq.c
set_irq_handler(irqno, handle_edge_irq); 7)/kernel/irq/chip.c
调用4)
调用3)
8)在s3c24xx_init_irq这个函数里面,初始化irq_desc结构体
struct irq_desc {
irq_flow_handler_t handle_irq; //set_irq_handler(irqno, handle_edge_irq);
struct irq_chip *chip; //set_irq_chip(irqno, &s3c_irq_eint0t4);
struct msi_desc *msi_desc;
void *handler_data;
void *chip_data;
struct irqaction *action; /* IRQ action list */
unsigned int status; /* IRQ status */ ....
9)/kernel/irq/chip.c
分析handle_edge_irq:
void fastcall
handle_edge_irq(unsigned int irq, struct irq_desc *desc)
{
const unsigned int cpu = smp_processor_id(); spin_lock(&desc->lock); desc->status &= ~(IRQ_REPLAY | IRQ_WAITING); /*
* If we're currently running this IRQ, or its disabled,
* we shouldn't process the IRQ. Mark it pending, handle
* the necessary masking and go out
*/
if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
!desc->action)) {
desc->status |= (IRQ_PENDING | IRQ_MASKED);
mask_ack_irq(desc, irq);
goto out_unlock;
} kstat_cpu(cpu).irqs[irq]++; //发生中断的次数 /* Start handling the irq */ //开始处理中断
desc->chip->ack(irq); //desc->chip chip是之前初始化的s3c_irqext_chip /* Mark the IRQ currently in progress.*/
desc->status |= IRQ_INPROGRESS; do {
struct irqaction *action = desc->action;
irqreturn_t action_ret; if (unlikely(!action)) { //判断链表是否为空
desc->chip->mask(irq);
goto out_unlock;
} /*
* When another irq arrived while we were handling
* one, we could have masked the irq.
* Renable it, if it was not disabled in meantime.
*/
if (unlikely((desc->status &
(IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
(IRQ_PENDING | IRQ_MASKED))) {
desc->chip->unmask(irq);
desc->status &= ~IRQ_MASKED;
} desc->status &= ~IRQ_PENDING;
spin_unlock(&desc->lock);
action_ret = handle_IRQ_event(irq, action);//真正的处理过程
if (!noirqdebug)
note_interrupt(irq, desc, action_ret);
......
} 10)
/arch/arm/plat-s3c24xx/irq.c
s3c_irqext_chip中的.ack
static struct irq_chip s3c_irqext_chip = {
.name = "s3c-ext",
.mask = s3c_irqext_mask,
.unmask = s3c_irqext_unmask,
.ack = s3c_irqext_ack,
.set_type = s3c_irqext_type,
.set_wake = s3c_irqext_wake
};
s3c_irqext_ack分析:
static void
s3c_irqext_ack(unsigned int irqno)
{
unsigned long req;
unsigned long bit;
unsigned long mask; bit = 1UL << (irqno - EXTINT_OFF); mask = __raw_readl(S3C24XX_EINTMASK); __raw_writel(bit, S3C24XX_EINTPEND); req = __raw_readl(S3C24XX_EINTPEND);
req &= ~mask; /* not sure if we should be acking the parent irq... */ if (irqno <= IRQ_EINT7 ) {
if ((req & 0xf0) == )
s3c_irq_ack(IRQ_EINT4t7);
} else {
if ((req >> ) == )
s3c_irq_ack(IRQ_EINT8t23);
}
} static inline void
s3c_irq_ack(unsigned int irqno)
{
unsigned long bitval = 1UL << (irqno - IRQ_EINT0); __raw_writel(bitval, S3C2410_SRCPND);
__raw_writel(bitval, S3C2410_INTPND);
}
①desc->chip->ack(irq);//上面是清理中断
============================================================
②handle_edge_irq取出action链表中的成员,执行action->handler irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
{
irqreturn_t ret, retval = IRQ_NONE;
unsigned int status = ; handle_dynamic_tick(action); if (!(action->flags & IRQF_DISABLED))
local_irq_enable_in_hardirq(); do {
ret = action->handler(irq, action->dev_id);
if (ret == IRQ_HANDLED)
status |= action->flags;
retval |= ret;
action = action->next;
} while (action); if (status & IRQF_SAMPLE_RANDOM)
add_interrupt_randomness(irq);
local_irq_disable(); return retval;
} 总结:
按下按键
1>cup进入异常处理模式
b vector_irq + ...
2>__irq_user
3>asm_do_IRQ
4>irq_des[irq]以中断号为下标取出一项 ->handle_irq
struct irq_desc {
irq_flow_handler_t handle_irq; //set_irq_handler(irqno, handle_edge_irq);
//handle_edge_irq取出action链表中的成员,
//执行action->handler(自定义实现)
struct irq_chip *chip; //set_irq_chip(irqno, &s3c_irq_eint0t4);
//芯片相关的一些操作
...
}
5>handle_irq = handle_edge_irq
6>handle_edge_irq的操作:
(1)desc->chip->ack(irq);
(2)handle_IRQ_event(irq, action); ===========================================================================================
自定义异常处理函数action->handler,注册进内核 request_irq 1./kernel/irq/manage.c
int request_irq(unsigned int irq, irq_handler_t handler,
unsigned long irqflags, const char *devname, void *dev_id)
{
//1)分配了一个结构,结构中的成员指向传递进来的参数
action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
//2)设置irq
retval = setup_irq(irq, action);
} .setup_irq()函数分析:
)irq_des[irq] 已irq为下标找到数组项
)在irq_des[irq]链表里面加入传递进来的参数action
)desc->chip->settype()设置为中断引脚
)desc->chip->startup / desc->chip->enable 使能中断 free_irq(irq, dev_id)
1)从链表中除去
)禁止中断
字符设备驱动笔记——中断方式按键驱动之linux中断处理结构(五)的更多相关文章
- 字符设备驱动笔记——中断方式按键驱动之linux异常处理结构(四)
.中断方式获取按键值 单片机: )按键按下 )cup发生中断,跳转到异常向量入口执行 )b 函数 a.保存被中断的现场 b.执行中断处理函数 c.恢复 linux: )trap_init()函数构造异 ...
- linux驱动之中断方式获取键值
linux驱动之中断方式获取键值 ----------------------------------------------------------------------------------- ...
- linux字符驱动之poll机制按键驱动
在上一节中,我们讲解了如何自动创建设备节点,实现一个中断方式的按键驱动.虽然中断式的驱动,效率是蛮高的,但是大家有没有发现,应用程序的死循环里的读函数是一直在读的:在实际的应用场所里,有没有那么一种情 ...
- linux字符设备学习笔记【原创】
1.申请设备号 int register_chrdev_region(dev_t from, unsigned count, const char *name) 指定从设备号from开始,申请coun ...
- ARM Linux 驱动Input子系统之按键驱动测试
上一篇已经谈过,在现内核的中引入设备树之后对于内核驱动的编写,主要集中在硬件接口的配置上了即xxxx.dts文件的编写. 在自己的开发板上移植按键驱动: 1.根据开发板的原理图 确定按键的硬件接口为: ...
- 3.字符设备驱动------Poll机制
1.poll情景描述 以之前的按键驱动为例进行说明,用阻塞的方式打开按键驱动文件/dev/buttons,应用程序使用read()函数来读取按键的键值. ) { read(fd, &key_v ...
- 谈谈Linux字符设备驱动的实现
@ 目录 字符设备驱动基础 申请设备号 创建设备节点 在驱动中实现操作方法 文件IO调用驱动中的操作 应用程序与驱动的数据交互 内核驱动如何控制外设 控制LED的简单驱动实例 驱动程序的改进 框架复盘 ...
- 入门级的按键驱动——按键驱动笔记之poll机制-异步通知-同步互斥阻塞-定时器防抖
文章对应视频的第12课,第5.6.7.8节. 在这之前还有查询方式的驱动编写,中断方式的驱动编写,这篇文章中暂时没有这些类容.但这篇文章是以这些为基础写的,前面的内容有空补上. 按键驱动——按下按键, ...
- 驱动开发--【字符设备、块设备简介】【sky原创】
驱动开发 字符设备,块设备,网络设备 字符设备 以字节流的方式访问, 不能随机访问 有例外,显卡.EEPROM可以随机访问 EEPROM可以擦写1亿次,是一种字符设备,可以随机访问 读写是 ...
随机推荐
- xcode 打包
iOS的要安装Xcode,否则执行下面命令的时候报错 ionic platform add ios ionic build ios ionic emulate ios 方法二: 1.打开终端 -- b ...
- word2vec模型cbow与skip-gram的比较
cbow和skip-gram都是在word2vec中用于将文本进行向量表示的实现方法,具体的算法实现细节可以去看word2vec的原理介绍文章.我们这里大体讲下两者的区别,尤其注意在使用当中的不同特点 ...
- 解决Win10系统backgroundTaskHost占用cpu大
打开照片应用后,点击左下角“设置”按钮,如下图
- SVN如何查看修改的文件记录
主要是有四个命令,svn log用来展示svn 的版本作者.日期.路径等等:svn diff,用来显示特定修改的行级详细信息:svn cat,取得在特定版本的某文件显示在当前屏幕:svn list, ...
- 〖Linux〗使用gsoap搭建web server(C)
1. gsoap的好处就不用说了:百度百科 2. gsoap的下载地址:项目地址,目前我使用的是2.8.15版本 3. 开发环境:Ubuntu13.10 4. 具体操作步骤(以简单相加为例): 1) ...
- python之模块csv之CSV文件的写入(按行写入)
# -*- coding: utf-8 -*- #python 27 #xiaodeng #CSV文件的写入(按行写入) import csv #csv文件,是一种常用的文本格式,用以存储表格数据,很 ...
- (一)Linux Shell编程——简介、变量、字符串、数组
1. Shell简介 1.1 Shell出现背景 Shell 既是一种脚本编程语言,也是一个连接内核和用户的软件. 对于图形界面,用户点击某个图标就能启动某个程序:对于命令行,用户输入某个程序的名字( ...
- C#编写的 8种初级+高级排序方法(转)
摘自:http://blog.csdn.net/mevin/article/details/6714520 程序代码: view plaincopy to clipboard using System ...
- function声明的深刻含义和jquery属性注入区别
在js中有两类对象 1.json对象,仅仅代表对象而已 2.function声明的对象 (1) 它定义了构造器 可以用new 对象 来初始化 数据对象 (2) 它指明对象是一个函数对象 通过后面加 ...
- js控制swf播放
<html> <head> <title>用js代码控制flash的播放</title> <meta charset="utf-8&qu ...