在定时器中调用i2c_transfer或者i2c_smbus_read_byte将会导致内核崩溃,c出错内容部分如下:

WARNING: at kernel/mutex.c:  mutex_trylock   i2c

 

原因:i2c_transfer或者i2c_smbus_read_byte都会进行schedule,也就是任务切换,但是若在非进程上下文环境中schedule那么也就必然会导致内核崩溃。改用work queue问题解决。

====

中断下半部执行方法:

1.tasklet   中断上下文

使用:

void my_tasklet_func(unsigned long);

DECLARE_TASKLET(my_tastlet,my_tasklet_func,data);

tasklet_schedule(&my_tasklet);

2.work queue   处于进程上下文

使用:

#include <linux/workqueue.h>

struct work_struct my_wq;

void my_wq_func(struct work_struct *work);

INIT_WORK(&my_wq,my_wq_func);

schedule_work(&my_wq);

3.软中断    中断上下文

4.timerlist  中断上下文

struct timer_list timer_my;

void timer_func(unsigned long arg){};

init_timer(&timer_my);

timer_my.function = timer_func;

timer_my.expires = jiffies + delay;
add_timer(&timer_my); 

mod_timer(&timer_my, jiffies + delay);

del_timer(&timer_my);

相关文章:

  • 2021-08-01
  • 2022-03-09
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2021-11-08
  • 2021-05-21
猜你喜欢
  • 2022-02-01
  • 2021-07-28
  • 2021-10-31
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案