1 系统时钟中断驱动引擎
rt-thread操作系统中当线程时间片耗尽,或是当线程sleep一段时间后唤醒再被调度,此过程又是如何进行的呢?到底是谁来驱动这一过程的呢?
答案是时钟中断源。且来看看时钟中断例程:
在bsp/stm32f20x/drivers/board.c源文件中存在这么一个时钟中断例程代码:(这里以stm32f20x的MCU为例)
/**
* This is the timer interrupt service routine.
*
*/
void SysTick_Handler(void)
{
/* enter interrupt */
rt_interrupt_enter();//进入中断
rt_tick_increase();//增加tick
/* leave interrupt */
rt_interrupt_leave();//离开中断
}
其中rt_tick_increase的函数如下定义:
/**
* This function will notify kernel there is one tick passed. Normally,
* this function is invoked by clock ISR.
*/
void rt_tick_increase(void)
{
struct rt_thread *thread;
/* increase the global tick */
++ rt_tick;//全局变量rt_tick加1
/* check time slice */
thread = rt_thread_self();//获取当前调度的线程
-- thread->remaining_tick;//当前调度的线程的剩余时间片减1