Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
定时器
5
rt_thread_create()创建线程时候,初始化的定时器的作用是什么
发布于 2022-07-05 14:30:04 浏览:735
订阅该版
请教一个问题 调用rt_thread_create()创建线程的时候,调用了下面的代码,作用是什么? ```c /* initialize thread timer */ rt_timer_init(&(thread->thread_timer),thread->name,rt_thread_timeout,thread,0,RT_TIMER_FLAG_ONE_SHOT); ``` 为什么要创建这个定时器? 在系统时钟中断回调函数里面,已经调用了下面的代码 ```c void rt_tick_increase(void) { struct rt_thread *thread; /* increase the global tick */ ++ rt_tick; /* check time slice */ thread = rt_thread_self(); -- thread->remaining_tick; if (thread->remaining_tick == 0) { /* change to initialized tick */ thread->remaining_tick = thread->init_tick; /* yield */ rt_thread_yield(); } /* check timer */ rt_timer_check(); } ``` 上面的代码已经会去判断`remaining_tick`,这个为0就执行让出cpu操作了。
查看更多
2
个回答
默认排序
按发布时间排序
jizhongbiao
2022-07-05
这家伙很懒,什么也没写!
用来控制挂起时间的。例如你主动调用delay或者阻塞于获取信号量等都会用到这个定时器。截取了一段信号量获取函数中的源码: ` /* start */ rt_ipc_list_suspend(&(sem->parent.suspend_thread), thread, sem->parent.parent.flag); /* has waiting time, start thread timer */ if (time > 0) { RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n", thread->name)); /* reset the timeout of thread timer and start it */ rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time); rt_timer_start(&(thread->thread_timer)); } /* enable interrupt */ rt_hw_interrupt_enable(temp); /* do schedule */ rt_schedule(); rt_ipc_list_suspend(&(sem->parent.suspend_thread), thread, sem->parent.parent.flag); /* has waiting time, start thread timer */ if (time > 0) { RT_DEBUG_LOG(RT_DEBUG_IPC, ("set thread:%s to timer list\n", thread->name)); /* reset the timeout of thread timer and start it */ rt_timer_control(&(thread->thread_timer), RT_TIMER_CTRL_SET_TIME, &time); rt_timer_start(&(thread->thread_timer)); } /* enable interrupt */ rt_hw_interrupt_enable(temp); /* do schedule */ rt_schedule();`
a1012112796
2022-07-06
这家伙很懒,什么也没写!
用于IPC逻辑的超时等待,线程初始化时已经配置好了超时回调函数。
撰写答案
登录
注册新账号
关注者
0
被浏览
735
关于作者
吴晟? ? ?
这家伙很懒,什么也没写!
提问
4
回答
0
被采纳
0
关注TA
发私信
相关问题
1
定时器中要延时,用什么办法?
2
cubemx配置定时器PWM可以输出移到RT_stdio不能输出?
3
对源码中优先级处理和定时器的两个疑问?
4
关于定时器时钟,怎么定时一个1MHz时钟
5
rt_spi_send、rt_spi_recv不能放在定时器里进行使用
6
关闭定时器中断,再开启中断
7
关于在L4潘多拉上定时器TIM3跑hwtimer_sample例程出错的问题
8
rtthread studio里定时器倍频问题
9
rt-thread-studio开发潘多拉的定时器出现问题?
10
多个软件定时器之间会不会冲突
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
【CFP】2025 RT-Thread全球技术大会演讲征集开始啦!
2
在 RT-Thread Studio 环境中为 ART-Pi 2 移植 CherryUSB(以 usb_device 为例)
3
嵌入式ARM RISCV toolchain工具 梳理arm-none-eabi-gcc
4
使用官方BOOT升级,看这一篇就够了?(以STM32F407VGT6为例)
5
可以使用MQTT连接AI大模型吗
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
rt-smart
FAL
I2C_IIC
cubemx
ESP8266
WIZnet_W5500
UART
ota在线升级
BSP
PWM
flash
packages_软件包
freemodbus
潘多拉开发板_Pandora
ADC
GD32
定时器
flashDB
编译报错
keil_MDK
socket
中断
rt_mq_消息队列_msg_queue
Debug
ulog
SFUD
msh
C++_cpp
at_device
本月问答贡献
聚散无由
9
个答案
6
次被采纳
RTT_逍遥
7
个答案
2
次被采纳
a1012112796
5
个答案
2
次被采纳
加缪
2
个答案
2
次被采纳
踩姑娘的小蘑菇
9
个答案
1
次被采纳
本月文章贡献
wake_mirco
2
篇文章
7
次点赞
mushroom
1
篇文章
9
次点赞
张世争
1
篇文章
7
次点赞
RTT_逍遥
1
篇文章
5
次点赞
Jack_____
1
篇文章
5
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部