1. 程式人生 > >stm32在rt-thread上的SysTick(系統定時器)

stm32在rt-thread上的SysTick(系統定時器)

在rt-thread的board.c裡面已經配置了systick --> SysTick_Config( SystemCoreClock / RT_TICK_PER_SECOND );  10ms = (72M/100) * (1/72M)s   [720000tick, 1tick = 1/72 us]

systick的中斷函式 SysTick_Handler()呼叫了 rt_tick_increase(), 自增rt_tick值

clock.c裡面有幾個介面函式

rt_tick_t rt_tick_get(void)  返回當前的rt_tick

void rt_tick_set(rt_tick_t tick)  設定rt_tick

rt_tick_t rt_tick_from_millisecond(rt_uint32_t ms)  根據傳入值計算需多少個tick.  1ms-10ms 返回1tick, 11-20ms返回2tick ....

test: 

rt_tick_set(10000);

rt_kprintf("rt_tick_from_millisecond:%d\r\n",rt_tick_from_millisecond(1));

rt_kprintf("rt_tick_from_millisecond:%d\r\n",rt_tick_from_millisecond(11));

rt_kprintf("rt_tick_get:%d\r\n",rt_tick_get());