来讲讲clock.c里面的几个函数,其实文件里面的英文注释写的清楚的了
void rt_system_tick_init(void) //用于初始化时钟并置零,从1.1.0版本起不在需要
{
}
rt_tick_t rt_tick_get(void) //获取从系统启动后到现在的 tick 值
{
return rt_tick;
}
void rt_tick_set(rt_tick_t tick) //设置当前 tick 值
{
rt_base_t level;
level = rt_hw_interrupt_disable(); //关中断
rt_tick = tick;
rt_hw_interrupt_enable(level); //开中断
}
void rt_tick_increase(void) //通知内核一个 tick 产生,通常放置与systick 中断里面(对于STM32来说)
{
struct rt_thread *thread;
++ rt_tick; //增加一个tick
thread = rt_thread_self(); //获取当前线程
-- thread->remaining_tick; //减少当前线程一个时间片
if (thread->remaining_tick == 0) //时间到?
{
thread->remaining_tick = thread->init_tick; //恢复线程时间片
rt_thread_yield(); //让出CPU
}
rt_timer_check(); //检查定时器list
}
rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms) //毫秒换算tick
{
return (RT_TICK_PER_SECOND * ms + 999) / 1000;
} |