当前位置: 首页 > news >正文

36.循环定时器实现

使用mod_timer实现1秒触发一次超时函数        

loop_timer.c编写

#include <linux/module.h>
#include <linux/init.h>
#include <linux/time.h>static void timer_function(struct timer_list *timer);DEFINE_TIMER(test_timer,timer_function);static void timer_function(struct timer_list *timer){printk("this is timer test\n");mod_timer(&test_timer,jiffies_64 + msecs_to_jiffies(1000));
}static int helloworld_init(void){printk("hello timer\n");test_timer.expires = jiffies_64 + msecs_to_jiffies(5000);add_timer(&test_timer);return 0;
}
static void helloworld_exit(void){del_timer(&test_timer);printk("bye timer\n");
}module_init(helloworld_init);
module_exit(helloworld_exit);MODULE_LICENSE("GPL");
MODULE_AUTHOR("quan");
MODULE_VERSION("v1.0");

Makefile编写

# KBUILD_CFLAGS_MODULE += -DDEBUG=3
EXTRA_CFLAGS += -DDEBUG=3
obj-m += loop_timer.o
KDIR:=/lib/modules/6.2.0-37-generic/build
# KDIR:=/usr/src/linux-source-6.2.0/
PWD?=$(shell pwd)
all:make -C $(KDIR) M=$(PWD) modulesecho $(PWD)
clean:rm -rf *.ko *.o  *.mod *.mod.o *.mod.c *.symvers *.order

编译及测试

make 
insmod loop_timer.ko
dmesg[37713.985682] hello timer
[37719.047808] this is timer test
[37720.071839] this is timer test
[37721.095743] this is timer test
[37722.119787] this is timer test
[37723.148052] this is timer test
[37724.168110] this is timer test
[37725.192501] this is timer test
[37726.216073] this is timer test
[37727.240389] this is timer test
[37728.264222] this is timer test
[37729.288053] this is timer test
[37730.312477] this is timer test
[37731.336195] this is timer test
[37732.360657] this is timer test
[37733.384699] this is timer test
[37734.408342] this is timer test
[37735.432616] this is timer test
[37736.456731] this is timer test
[37737.480489] this is timer test
[37738.504470] this is timer test

http://www.dtcms.com/a/596948.html

相关文章:

  • 网站建设在哪个会计科目核算百度医院网站建设
  • Python学习历程——Python面向对象编程详解
  • 0.SAP契约锁业务需求
  • 【ZeroRange WebRTC】HTTPS 与 WSS 在 WebRTC 场景中的应用
  • 12.【Linux系统编程】动静态库制作与使用
  • 快速seo整站优化排行网站外部链接
  • 认识设计模式——单例模式
  • OCP(Over-Current Protection)是什么?
  • wordpress门户网站模板东莞 网站建设多少钱
  • 【论文阅读】PEARL A dual-layer graph learning for multimodal recommendation
  • 《反电信网络诈骗法》“金融篇”
  • 【Qt开发】布局管理器(五)-> QSpacerItem 控件
  • 创邻科技“知寰 Hybrid RAG”强势落地复杂业务场景:GraphRAG产品引领公安与金融智能决策新范式
  • 零基础也能搭博客?
  • Electron 颜色拾取器开发实战适配鸿蒙
  • 电影网站建设需求分析百度高级搜索页面
  • 猫眼网站建设大连seo建站公司
  • 基于微信小程序的丽江市旅游分享平台
  • 哪些网站做任务可以赚钱红谷滩园林建设集团有限公司 网站
  • 云服务器镜像是什么?4类镜像全解析
  • Nginx介绍和部署
  • ffmpeg-本周任务-01
  • 防邪办网站建设方案文档许昌网站建设哪家最好
  • 铜仁网站建设哪家专业网站建设中模板代码
  • 关于ankh库加载本地模型的改进用于解决服务器无法连接外网的问题
  • 基于springboot的旅游攻略网站设计与实现
  • Haldane先验:极端无知假设下的贝叶斯推断
  • 15.【NXP 号令者RT1052】开发——实战-XBAR
  • 中小型网站建设与管理总结小超人成都网站建设
  • MATLAB | 如何使用MATLAB一键生成拼豆图纸