[FreeRTOS]软件定时器

FreeRTOS 定时器基本使用

软件定时器本质上是一个周期性的task

配置

使用软件定时器需要在FreeRTOSConfig.h先配置, 需要注意的是优先级和堆栈

#define configUSE_TIMERS             1
#define configTIMER_TASK_PRIORITY    (1)
#define configTIMER_QUEUE_LENGTH     10
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )

创建定时器

  • 函数原型
xTimerHandle xTimerCreate( 	const signed char *pcTimerName,
                            portTickType xTimerPeriodInTicks,
                            unsigned portBASE_TYPE uxAutoReload,
                            void * pvTimerID,
                            tmrTIMER_CALLBACK pxCallbackFunction );
- pcTimerName           : 任务名
- xTimerPeriodInTicks   : 定时周期
- uxAutoReload          : pdTRUE, 自动重载; pdFALSE, 一次性
- pvTimerID             :
- pxCallbackFunction    : 回调函数
  • 使用
xTimerMain = xTimerCreate("TimerMain", (1000*30 / portTICK_RATE_MS), pdTRUE, (void *)0, MainCallback);`

启动定时器

#define xTimerStart( xTimer, xBlockTime ) xTimerGenericCommand( ( xTimer ), tmrCOMMAND_START, ( xTaskGetTickCount() ), NULL, ( xBlockTime ) )
  • 使用
xTimerStart( xTimerMain, 0 );

Good Good Study! Day Day Up!

原文地址:https://www.cnblogs.com/kdurant/p/4174347.html