RT-Thread 学习笔记(一)---系统节拍tick

基础知识,本人学习记录,仅供参考。

 

系统rt_tick大小定义在rtconfig.h中:

/* Tick per Second */
#define RT_TICK_PER_SECOND 100

默认大小为100/秒,即10ms

时钟采用SysTick定时,初始化在startup.c文件中:

rtthread_startup() -> rt_hw_board_init() -> SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND);

SysTick中断处理函数在board.c中:

SysTick_Handler();

在SysTick_Handler();中对tick进行计数的函数为:

rt_tick_increase();

rt_tick随着系统运行不断增加

跟进去分析下rt_tick_increase();函数:

 1 /**
 2  * This function will notify kernel there is one tick passed. Normally,
 3  * this function is invoked by clock ISR.
 4  */
 5 void rt_tick_increase(void)
 6 {
 7     struct rt_thread *thread;
 8 
 9     /* increase the global tick */
10     ++ rt_tick;
11 
12     /* check time slice */
13     thread = rt_thread_self();  //获取当前线程id
14 
15     -- thread->remaining_tick;
16     if (thread->remaining_tick == 0)
17     {
18         /* change to initialized tick */
19         thread->remaining_tick = thread->init_tick;
20 
21         /* yield */
22         rt_thread_yield();  //线程让出处理器函数,判断当前线程tick时间到达,出让处理器使用权
23     }
24 
25     /* check timer */
26     rt_timer_check();
27 }

根据函数说明可知:这个函数通知内核经过了一个tick,通常这个函数由时钟中断处理函数调用。

最后进行定时器链表检查,rt_timer_check()检测当前tick时间是否达到定时器timeout时间。

 

RT-Thread提供软件定时器,由操作系统提供系统接口,构建于硬件定时器基础之上,使系统能够提供不受限制于硬件资源的定时服务。

 

 未完待续!!!

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值