一、单次触发和自动重装载的软件定时器的区别
单次触发(one-shot)定时器启动后只会执行一次,不会自动重启。
自动重装载(auto-load)定时器会周期执行,执行完后会自动重启。
软件定时器两种状态:
- 休眠(dormant)
- 运行(running)
二、创建软件定时器
TimerHandle_t xTimerCreate( const char * const pcTimerName,
TickType_t xTimerPeriodInTicks,
UBaseType_t uxAutoReload,
void * pvTimerID,
TimerCallbackFunction_t pxCallbackFunction );
三、开启定时器
BaseType_t xTimerStart( TimerHandle_t xTimer, TickType_t xTicksToWait );
四、关闭定时器
BaseType_t xTimerStop( TimerHandle_t xTimer, TickType_t xTicksToWait );
#include "rtos_test.h"
//one-shot & periodic
u32 ulCallCount=0;
static void prvOneShotTimerCallback( TimerHandle_t xTimer )
{
TickType_t xTimeNow;
/* Obtain the current tick count. */
xTimeNow = xTaskGetTickCount();
/* Output a string to show the time at which the callback was executed. */
vPrintStringAndNumber( "One-shot timer callback executing :%d", xTimeNow );
/* File scope variable. */
ulCallCount++;
}
static void prvAutoReloadTimerCallback( TimerHandle_t xTimer )
{
TickType_t xTimeNow;
/* Obtain the current tick count. */
xTimeNow = xTaskGetTickCount();
/* Output a string to show the time at which the callback was executed. */
vPrintStringAndNumber( "Auto-reload timer callback executing :%d", xTimeNow );
ulCallCount++;
}
/* The periods assigned to the one-shot and auto-reload timers are 3.333 second and half a
second respectively. */
#define mainONE_SHOT_TIMER_PERIOD pdMS_TO_TICKS( 3333 )
#define mainAUTO_RELOAD_TIMER_PERIOD pdMS_TO_TICKS( 500 )
int main( void