内核编译init_timer失败

内核编译和嵌入式产品的设计与开发
回复
maple_169324
帖子: 10
注册时间: 2018-12-29 14:13
系统: ubuntu
送出感谢: 4 次
接收感谢: 0

内核编译init_timer失败

#1

帖子 maple_169324 » 2020-02-17 20:56

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include<linux/jiffies.h>

struct second_dev{
struct cdev cdev;
atomic_t counter;
struct timer_list s_timer;
};

static struct second_dev *second_devp;

static int second_open(struct inode *ins_timerode,struct file *filep)
{
init_timer(&second_devp->s_timer);   #调用init_timer进行定时器初始化
second_devp->s_timer.function=&second_timer_handler;
second_devp->s_timer.expires=jiffies+HZ;
add_timer(&second_devp->s_timer);
atomic_set(&second_devp->counter,0);
return 0;
}

编译的时候出现如下错误:内核版本4.15.0-76-generic

error: implicit declaration of function ‘init_timer’; did you mean ‘init_timers’? [-Werror=implicit-function-declaration]
init_timer(&second_devp->s_timer);
^~~~~~~~~~
init_timers
头像
astolia
论坛版主
帖子: 4428
注册时间: 2008-09-18 13:11
送出感谢: 1 次
接收感谢: 740 次

Re: 内核编译init_timer失败

#2

帖子 astolia » 2020-02-18 12:48

在4.15内核里,init_timer被移除了。需要换用新的timer_setup接口
https://stackoverflow.com/a/53842823
回复

回到 “内核及嵌入式开发”