System Tick

smallcracker 2021-01-29 00:00:00
Categories: Tags:

SysTick

SysTick is a simple timer that is part of the NVIC controller in the Cortex-M microprocessor. Its
intended purpose is to provide a periodic interrupt for an RTOS, but it can be used for other simple
timing purposes.
The SysTick interrupt handler does not need to clear the SysTick interrupt source as it is cleared
automatically by the NVIC when the SysTick interrupt handler is called.
This driver is contained in driverlib/systick.c, with driverlib/systick.h containing the
API declarations for use by applications.

大概的翻译一下

SysTick是一个简单的定时器,是Cortex-M微处理器中NVIXC控制器的一部分。他的目的在于为RTOS提供一个周期性的中断,也可以被用于其他简单的计时目的。

Systick 中断处理不需要清除Sys tick中断源,当SysTick中断处理被调用时NVIC会自动清理中断源。

头文件是driverlib/systick.h

The SysTick API is fairly simple, like SysTick itself. There are functions for configuring and enabling
SysTick (SysTickEnable(), SysTickDisable(), SysTickPeriodSet(), SysTickPeriodGet(), and
SysTickValueGet()) and functions for dealing with an interrupt handler for SysTick (SysTickIntRegister(),
SysTickIntUnregister(), SysTickIntEnable(), and SysTickIntDisable()).

他所包含的函数也特别少

主要有设置和使能函数还有处理中断的函数

image-20201212171840774

设置和使能的函数有

(SysTickEnable(), SysTickDisable(), SysTickPeriodSet(), SysTickPeriodGet(), and
SysTickValueGet())

先看头两个SysTickEnable(), SysTickDisable(), 使能和停止SysTick

如果中断处理已经注册,那就等中断重启时再停止。

其中SysTickEnable还有个note

Calling this function causes the SysTick counter to (re)commence counting from its current
value. The counter is not automatically reloaded with the period as specified in a previous call
to SysTickPeriodSet(). If an immediate reload is required, the NVIC_ST_CURRENT register
must be written to force the reload. Any write to this register clears the SysTick counter to 0
and causes a reload with the supplied period on the next clock.

上面是使能定时器的函数,接下来是使能定时器中断的函数SysTickIntEnable(), and SysTickIntDisable()

然后时注册/去除注册的函数SysTickIntRegister(),SysTickIntUnregister(),

其中SysTickIntRegister(),的参数是一个函数指针,表示中断发生时要调用的函数

还有两个函数能设置/返回计时器周期

周期可以设置在1到16777216之间,单位是处理器的时钟数

最后一个函数是获取定时器counter的函数SysTickValueGet()