Linux的notifier机制在TP中的应用

 在     linux      内核系统中,各个模块、子系统之间是相互独立的。Linux内核可以通过通知链机制来获取由其它模块或子系统产生的它感兴趣的某些事件。

    Linux的notifier机制在TP中的应用_设计制作_测量仪表  

no     ti   fier_block结构体在include/linux/no  TI fier.h中定义:

struct no  TI fier_block {
no  TI fier_fn_t no  TI fier_call;
struct notifier_block __rcu *next;
int priority;
};
priority用来定义优先级,高优先级的处理例程将被优先执行,数值越大,优先级越高。
回到函数的原型定义:
typedef int (*notifier_fn_t)(struct notifier_block *nb,
unsigned long action, void *data);
TP属于输入子系统,可以通过获取f     ram   ebuffer子系统来实现亮屏和灭屏时触发相应的事件。
fb_regis     te   r_client和fb_unregister_client函数定义在drive     rs   /video/fb_notify.c:
/**
* fb_register_client - register a client notifier
* @nb: notifier block to callback on events
*/
int fb_register_client(struct notifier_block *nb)
{
return blocking_notifier_ch     ai   n_register(&fb_notifier_list, nb);
}

/**
*    fb_unregister_client - unregister a client notifier
*    @nb: notifier block to callback on events
*/
int fb_unregister_client(struct notifier_block *nb)
{
return blocking_notifier_chain_unregister(&fb_notifier_list, nb);
}
当framebuffer子系统发生事件时,调用notifier_call_chain()来触发相应的处理函数。
/**
* fb_notifier_call_chain - notify clients of fb_events
*
*/
int fb_notifier_call_chain(unsigned long val, void *v)
{
return blocking_notifier_call_chain(&fb_notifier_list, val, v);
}
下面是一个实例:
struct msg21xx_ts_data {
struct input_dev *input;
struct hrtimer timer;
struct work_struct work;
int irq;
struct dentry *dir;
char *ts_info;
u8 addr;
int fw_major;
int fw_     mi   nor;
#ifdef CONFIG_FB
struct notifier_block fb_notif;
#endif
bool suspended;
struct     i2c   _client *client;
struct regulator *vdd;
struct regulator *vcc_i2c;
struct msg21xx_platform_data *pdata;
struct workqueue_struct *msg21xx_wq;
struct mutex msg21xx_mutex;
};
probe函数中与notifier相关部分实现:
struct msg21xx_ts_data *data;

data = kzalloc(sizeof(struct msg21xx_ts_data), GFP_KERNEL);
if (!data) {
dev_err(&client->dev, "%s: Alloc mem fail!", __func__);
err = -ENOMEM;
goto exit;
}

#ifdef CONFIG_FB
data->fb_notif.notifier_call = fb_notifier_callback;
err = fb_register_client(&data->fb_notif);
if (err)
dev_err(&client->dev, "Unable to register fb_notifier: %d\n",
err);
#endif
fb_notifier_callback实现:
#ifdef CONFIG_FB
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{
struct fb_event *evdata = data;
int *blank;
struct msg21xx_ts_data *msg21xx_data =
container_of(self, struct msg21xx_ts_data, fb_notif);

if (evdata && evdata->data && event == FB_EVENT_BLANK &&
msg21xx_data && msg21xx_data->client) {
blank = evdata->data;
if (*blank == FB_BLANK_UNBLANK)
msg21xx_ts_resume(&msg21xx_data->client->dev);
else if (*blank == FB_BLANK_POWERDOWN)



97
158
0
79

相关资讯

  1. 1、IGBT长期依赖国外巨头新能源行业一“芯”难求4219
  2. 2、关于存储技术涉及的专业名词介绍及各存储器的区别884
  3. 3、2019年一季度纺织机械行业运行概况2417
  4. 4、双通道降压型DC/DC转换器LT3506的性能特点及功能实现1154
  5. 5、实现PLC与PC机互联通信的三种方式介绍2766
  6. 6、工程塑料助力无人机产业蓬勃发展,引领无人机轻量化1614
  7. 7、美国国家制造业如何重回巅峰4730
  8. 8、采用HoneywellS9000系统实现对锅炉燃烧进行优化控制492
  9. 9、关于数字电路中触发器的应用3866
  10. 10、2018纺织机械行业亮点知多少?4970
全部评论(0)
我也有话说
0
收藏
点赞
顶部