disable_irq与disable_irq_nosync使用场景
    Linux设备驱动,关于中断屏蔽有两个接口:disable_irq和disable_irq_nosync,该两接口使用场景如下:
 
    1、disable_irq:在非中断处理函数中使用,会阻塞;
    2、disable_irq_nosync:在中断处理函数中使用,不会阻塞;用于屏蔽相应中断;
 
 一、为什么要屏蔽中断?  
    使能中断后,一旦触发中断,系统会进入中断处理函数;如果下一个中断触发的时候,前一个中断处理函数已经完成,这是理想状态,不会发生异常;如果前一个中断处理函数还未完成,那么就会导致中断嵌套。为了不出现中断嵌套,必须在中断处理函数中屏蔽中断,待中断处理完成后,再主动使能中断
 
 
二、disable_irq不能放在中断处理函数中
    如果在中断处理函数中使用disable_irq屏蔽相应中断,系统将会出现死锁状态,最后死机,然后重启。(已验证)
 
三、enable_irq配套使用
    当中断处理函数已经完成所有工作,在返回之前需要主动调用接口enable_irq使能中断,否则该中断将一直被屏蔽。(已验证)
 
 
四、附上距离传感器中断处理处理函数
 
//PS中断处理
static irqreturn_t ltr559_irq_handler(int irq, void *arg)
{
struct ltr559_data *data = (struct ltr559_data *)arg;

//printk("%s\n",__func__);

if (NULL == data)
return IRQ_HANDLED;

//后面必须有使能中断
disable_irq_nosync(data->irq);
//屏蔽中断,不会造成死锁
schedule_delayed_work(&data->ps_work, 0);
//调用延时工作队列
return IRQ_HANDLED;
}
 
 

//PS工作任务
//重要接口
static void ltr559_ps_work_func(struct work_struct *work)
{
struct ltr559_data *data = container_of(work, struct ltr559_data, ps_work.work);
struct i2c_client *client=data->client;
int als_ps_status;
int psval_lo, psval_hi, psdata;
static u32 ps_state_last = 2;
//Far as default.

mutex_lock(&data->op_lock);

als_ps_status = i2c_smbus_read_byte_data(client, LTR559_ALS_PS_STATUS);
//printk("%s ps_open_state=%d, als_ps_status=0x%x\n",__func__,data->ps_open_state,als_ps_status);
if (als_ps_status < 0)
goto workout;
/* Here should check data status,ignore interrupt status. */
/* Bit 0: PS Data
* Bit 1: PS interrupt
* Bit 2: ASL Data
* Bit 3: ASL interrupt
* Bit 4: ASL Gain 0: ALS measurement data is in dynamic range 2 (2 to 64k lux)
*                 1: ALS measurement data is in dynamic range 1 (0.01 to 320 lux)
*/

//使能情况
if ((data->ps_open_state == 1) && (als_ps_status & 0x02)) {
psval_lo = i2c_smbus_read_byte_data(client, LTR559_PS_DATA_0);
if (psval_lo < 0) {
psdata = psval_lo;
goto workout;
}
psval_hi = i2c_smbus_read_byte_data(client, LTR559_PS_DATA_1);
if (psval_hi < 0) {
psdata = psval_hi;
goto workout;
}
psdata = ((psval_hi & 7) << 8) | psval_lo;
printk("%s: psdata=%d(0x%x), near_thrd=%u, far_thrd=%u, dynamic_noise=%u\n",
  __func__, psdata, (u32)psdata, data->platform_data->prox_threshold,
  data->platform_data->prox_hsyteresis_threshold, data->dynamic_noise);

if(psdata >= data->platform_data->prox_threshold){

data->ps_state = 0; //near
ltr559_set_ps_threshold(client, LTR559_PS_THRES_LOW_0, data->platform_data->prox_hsyteresis_threshold);
ltr559_set_ps_threshold(client, LTR559_PS_THRES_UP_0, 0x07ff);
printk("%s: near, update near_thrd=%u, far_thrd=%u\n",
  __func__, 0x7ff, data->platform_data->prox_hsyteresis_threshold);
} else if (psdata <= data->platform_data->prox_hsyteresis_threshold){
data->ps_state = 1; //far

//该宏已经定义
#if defined(CONFIG_PICCOLO_COMMON)
  if (data->dynamic_noise > 20 && psdata < (data->dynamic_noise - 50) ) {
 data->dynamic_noise = psdata;
 if(psdata < 100) {
 }else if(psdata < 200){
 data->platform_data->prox_threshold = psdata+230;
 data->platform_data->prox_hsyteresis_threshold = psdata+180;
 }else if(psdata < 500){
 data->platform_data->prox_threshold = psdata+280;
 data->platform_data->prox_hsyteresis_threshold = psdata+230;
 }else if(psdata < 1500){
 data->platform_data->prox_threshold = psdata+420;
 data->platform_data->prox_hsyteresis_threshold = psdata+350;
 }else{  
 data->platform_data->prox_threshold= 1800;
 data->platform_data->prox_hsyteresis_threshold= 1700;
 pr_err("ltr559 the proximity sensor rubber or structure is error!\n");
 }
 printk("%s: NEW prox_threshold=%u, prox_hsyteresis_threshold=%u !!!\n",
__func__, data->platform_data->prox_threshold,
    data->platform_data->prox_hsyteresis_threshold);
  }
#endif

ltr559_set_ps_threshold(client, LTR559_PS_THRES_LOW_0, 0);
ltr559_set_ps_threshold(client, LTR559_PS_THRES_UP_0, data->platform_data->prox_threshold);
printk("%s: far, update near_thrd=%u, far_thrd=0\n",
  __func__, data->platform_data->prox_threshold);
} else {
data->ps_state = ps_state_last;
}

printk("%s: ps_state_last = %u, ps_state = %u\n", __func__, ps_state_last, data->ps_state);
if((ps_state_last != data->ps_state) || (data->ps_state == 0)) //need report the input event constant when near 
{
//上报数据
input_report_abs(data->input_dev_ps, ABS_DISTANCE, data->ps_state);
input_sync(data->input_dev_ps);
printk("%s: report ABS_DISTANCE=%s\n",__func__, data->ps_state ? "far" : "near");

ps_state_last = data->ps_state; 
//Report ABS value only if the state changed.
}
else
printk("%s: ps_state still %s\n", __func__, data->ps_state ? "far" : "near");
}
workout:
enable_irq(data->irq);
//使能
irq
mutex_unlock(&data->op_lock);
//解锁
}

disable_irq与disable_irq_nosync使用场景的更多相关文章

  1. disable_irq()与disable_irq_nosync()区别

    disable_irq关闭中断并等待中断处理完后返回, 而disable_irq_nosync立即返回.

  2. 【转】中断处理函数中不用disable_irq而用disable_irq_nosync原因

    原文网址:http://blog.csdn.net/skyflying2012/article/details/8265869 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现 ...

  3. 中断处理函数中不用disable_irq而用disable_irq_nosync原因【转】

    转自:http://blog.csdn.net/beyondioi/article/details/9201695 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现在进入中断处 ...

  4. Linux内核设计与实现 读书笔记

    第三章 进程管理 1. fork系统调用从内核返回两次: 一次返回到子进程,一次返回到父进程 2. task_struct结构是用slab分配器分配的,2.6以前的是放在内核栈的栈底的:所有进程的ta ...

  5. kernel笔记——中断

    cpu与磁盘.网卡.键盘等外围设备(相对于cpu和内存而言)交互时,cpu下发I/O请求到这些设备后,相对cpu的处理能力而言,磁盘.网卡等设备需要较长时间完成请求处理. 那么在请求发出到处理完成这段 ...

  6. Linux设备驱动 之 中断处理程序

    注册中断处理程序 中断处理程序是管理硬件驱动程序的组成部分:如果设备使用中断,那么相应的驱动程序就注册一个中断处理程序: 驱动程序通过request_irq()函数注册,并且激活给定的中断线,以处理中 ...

  7. local_irq_disable和disable_irq的区别

    local_irq_disable: local_irq_disable的功能是屏蔽当前CPU上的所有中断,通过操作arm核心中的寄存器来屏蔽到达CPU上的中断,此时中断控制器中所有送往该CPU上的中 ...

  8. 拨开迷雾,找回自我:DDD 应对具体业务场景,Domain Model 到底如何设计?

    写在前面 除了博文内容之外,和 netfocus 兄的讨论,也可以让你学到很多(至少我是这样),不要错过哦. 阅读目录: 迷雾森林 找回自我 开源地址 后记 毫无疑问,领域驱动设计的核心是领域模型,领 ...

  9. [NodeJS] 优缺点及适用场景讨论

    概述: NodeJS宣称其目标是“旨在提供一种简单的构建可伸缩网络程序的方法”,那么它的出现是为了解决什么问题呢,它有什么优缺点以及它适用于什么场景呢? 本文就个人使用经验对这些问题进行探讨. 一. ...

随机推荐

  1. spark-submit 分发应用

    Spark 提供了一个名为spark-submit 的单一工具来跨集群管理器的提交作业,命令如下: bin/spark-submit [options] <app jar | python fi ...

  2. [Python笔记]序列(一)索引、分片

    Python包含6种内建序列:列表.元组.字符串.Unicode字符串.buffer对象.xrange对象. 这些序列支持通用的操作: 索引 索引是从0开始计数:当索引值为负数时,表示从最后一个元素( ...

  3. Android开发环境配置

    由于公司项目需要,最近转做Android开发,这里我来介绍一下Android开发环境的配置过程. 首先,需要下载所需要的软件工具,如下所示: 1.Java:开发基础环境,JDK和JRE这两个都要下载的 ...

  4. LeetCode First Unique Character in a String

    原题链接在这里:https://leetcode.com/problems/first-unique-character-in-a-string/ 题目: Given a string, find t ...

  5. python pip安装问题

    scipy-0.18.1-cp34-cp34m-win32.whl is not a supported wheel on this platform. 遇到该问题需要更新pip版本 1.更新pip: ...

  6. Linux 命令快捷键

    Linux 命令快捷键 tab 自动补齐(有不知道的吗)Ctrl+u 删除(剪切)此处至开始所有内容 Ctrl+k 删除从光标所在位置到行末 快速命令行 – 快捷方式• history 搜索历史执行过 ...

  7. AOP programming paradiag

    AOP https://en.wikipedia.org/wiki/Aspect-oriented_programming Typically, an aspect is scattered or t ...

  8. Linux服务器ftp命令找不到

    ftp commond not find 先用命令rpm -q vsftpd检查是否安装了ftp服务器 若显示vsftpd-2.2.2-11.el6_4.1.x86_64这样的信息,说明FTP服务器已 ...

  9. win8.1 Framework3.5安装不上的问题

    问题症状:安装的WIN8系统无法安装Framework,SQL等都有问题 解决误区:直接安装或者更新后在线安装(结果一样各种错误) 解决方法: 1.先gpedit.msc进入本地组策略管理,目录:计算 ...

  10. zjuoj 3780 Paint the Grid Again

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3780 Paint the Grid Again Time Limit: 2 ...