disable_irq与disable_irq_nosync使用场景
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使用场景的更多相关文章
- disable_irq()与disable_irq_nosync()区别
disable_irq关闭中断并等待中断处理完后返回, 而disable_irq_nosync立即返回.
- 【转】中断处理函数中不用disable_irq而用disable_irq_nosync原因
原文网址:http://blog.csdn.net/skyflying2012/article/details/8265869 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现 ...
- 中断处理函数中不用disable_irq而用disable_irq_nosync原因【转】
转自:http://blog.csdn.net/beyondioi/article/details/9201695 今天在写触摸屏驱动时在中断处理函数中使用disable_irq关中断发现在进入中断处 ...
- Linux内核设计与实现 读书笔记
第三章 进程管理 1. fork系统调用从内核返回两次: 一次返回到子进程,一次返回到父进程 2. task_struct结构是用slab分配器分配的,2.6以前的是放在内核栈的栈底的:所有进程的ta ...
- kernel笔记——中断
cpu与磁盘.网卡.键盘等外围设备(相对于cpu和内存而言)交互时,cpu下发I/O请求到这些设备后,相对cpu的处理能力而言,磁盘.网卡等设备需要较长时间完成请求处理. 那么在请求发出到处理完成这段 ...
- Linux设备驱动 之 中断处理程序
注册中断处理程序 中断处理程序是管理硬件驱动程序的组成部分:如果设备使用中断,那么相应的驱动程序就注册一个中断处理程序: 驱动程序通过request_irq()函数注册,并且激活给定的中断线,以处理中 ...
- local_irq_disable和disable_irq的区别
local_irq_disable: local_irq_disable的功能是屏蔽当前CPU上的所有中断,通过操作arm核心中的寄存器来屏蔽到达CPU上的中断,此时中断控制器中所有送往该CPU上的中 ...
- 拨开迷雾,找回自我:DDD 应对具体业务场景,Domain Model 到底如何设计?
写在前面 除了博文内容之外,和 netfocus 兄的讨论,也可以让你学到很多(至少我是这样),不要错过哦. 阅读目录: 迷雾森林 找回自我 开源地址 后记 毫无疑问,领域驱动设计的核心是领域模型,领 ...
- [NodeJS] 优缺点及适用场景讨论
概述: NodeJS宣称其目标是“旨在提供一种简单的构建可伸缩网络程序的方法”,那么它的出现是为了解决什么问题呢,它有什么优缺点以及它适用于什么场景呢? 本文就个人使用经验对这些问题进行探讨. 一. ...
随机推荐
- oracle中函数和存储过程的区别和联系【转载竹沥半夏】
oracle中函数和存储过程的区别和联系[转载竹沥半夏] 在oracle中,函数和存储过程是经常使用到的,他们的语法中有很多相似的地方,但也有自己的特点.刚学完函数和存储过程,下面来和大家分享一下自己 ...
- selinux 导致无法启动httpd
selinux 导致无法启动httpd ansible_dire:~ # /etc/init.d/httpd restart 停止 httpd: [失败]正在启动 httpd:(13)Permissi ...
- win7怎么彻底关闭全/半角转换快捷键? imetool.exe
from:http://bbs.csdn.net/topics/370040889 全半角转换最tm的烦人,快捷键是shift+space,不小心按到,就各种不爽, 系统看着是可以重新设置快捷键的,但 ...
- Node.js 安装与配置
引言: JavaScript是一种运行在浏览器的脚本,它简单,轻巧,易于编辑,这种脚本通常用于浏览器的前端编程,但是一位开发者Ryan有一天发现这种前端式的脚本语言可以运行在服务器上的时候,一场席卷全 ...
- C# (灰度)加权平均法将图片转换为灰度图
private Bitmap ToG(string file) { using (Bitmap o = new Bitmap(file)) { Bitmap g = new Bitmap(o.Widt ...
- Windows Phone 十九、罗盘
磁力计概述 拥有磁力计硬件支持的设备可以根据磁力计来确定相对于北极的角度 磁力计的访问 API 定义在 Compass 类中 调用方式和加速计类似 <Grid Background=" ...
- Timer的故事----Jdk源码解读
咱们今天也来说说定时器Timer Timer是什么? Timer n. [电子] 定时器:计时器:计时员 从翻译来看,我们可以知道Timer的本意是,定时定点. 而JDK中Timer类也的确是这个本 ...
- 最新一代文件结构 超高性能解析IP数据库 qqzeng-ip.dat
高性能IP数据库格式 qqzeng-ip.dat 编码:UTF8 字节序:Little-Endian 返回多个字段信息(如:亚洲|中国|香港|九龙|油尖旺|新世界电讯|810200 ...
- eBox(stm32) 之中断结构
eBox的中断结构参考了mbed,和我们平时所用的中断结构有些差异,不容易理解,最近仔细看了底层代码,终于搞清楚了,总结一下 一 首先要要搞清楚的几个概念:类的静态成员,实例成员 ...
- easyUI+springMVC的DataGrid-demo
DataGrid (一).搭建springMVC: 错误:无法访问HTML页面,HTTP Status 404- 原因:springMVC拦截了静态资源的访问 解决方案:方案①:(web.xml下)& ...