参数ticks: 设置多少个Systick时钟周期产生一次中断
__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks)
{
if ((ticks - 1) > SysTick_LOAD_RELOAD_Msk) return (1); /* ticks参数有效性检查 */
SysTick->LOAD = ticks - 1; /* 设置重装载值,
-1:因为装载时消耗掉一个systick时钟周期*/
NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt 配置NVIC */
SysTick->VAL = 0; /* 初始化VAL=0,使能Systick后立刻进入重装载 */
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | \*选择时钟源*\
SysTick_CTRL_TICKINT_Msk | \*开启Systick中断*\
SysTick_CTRL_ENABLE_Msk; /* 使能Systick定时器 */
return (0); /* Function successful */
}
SysTick_Handler()处理:
void SysTick_Handler(void)
{
rt_interrupt_enter();
rt_tick_increase();
rt_interrupt_leave();
}
|