初级会员
- 积分
- 99
- 金钱
- 99
- 注册时间
- 2019-5-5
- 在线时间
- 16 小时
|
5金钱
今天,在调试FreeRTOS的过程中,发现使用BaseType_t xTimerDelete( TimerHandle_t xTimer,TickType_t xBlockTime );这个API函数时,会出现如下问题。
使用按键删除了周期定时器函数后,仍旧可以再次启动周期定时器函数,只有再一次使用该函数删除,这样才不会再启动定时器函数了。
代码如下:
/* 任务相关信息定义 */
#define START_TASK_PRIO 1 //任务优先级
#define START_TASK_STACK_SIZE 128 //任务堆栈大小128*4Byte=512Bytes
TaskHandle_t Start_Task_Handler; //任务句柄
void Start_task(void *para); //任务函数
#define SOFTWARE_TIMER_TASK_PRIO 2
#define SOFTWARE_TIMER_TASK_STACK_SIZE 256
TaskHandle_t SOFTWARE_TIMER_Task_Handler;
void SOFTWARE_TIMER_task(void *para);
void Once_time_call_back(TimerHandle_t xTimer); //单次定时器回调函数
void Reload_call_back(TimerHandle_t xTimer); //周期定时器回调函数
TimerHandle_t Once_timer_handler;
TimerHandle_t Reload_timer_handler;
#define COLOR_NUMBER 10
uint16_t Color_Set[COLOR_NUMBER]=
{
BLACK,BLUE,GRED,RED,GREEN,YELLOW,BROWN,GRAY,DARKBLUE,LIGHTGREEN
};
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
delay_init(168);
uart_init(115200);
LED_init();
LCD_Init();
key_init();
POINT_COLOR = RED;
LCD_ShowString(10,10,400,16,16,"STM32F407ZGT6");
LCD_ShowString(10,30,400,16,16,"FreeRTOS Expriment");
LCD_ShowString(10,50,400,16,16,"Lozang 2019/12/09");
LCD_ShowString(10,70,400,16,16,"Software Timer Test");
LCD_ShowString(10,90,400,16,16,"Let`s Start!");
LCD_ShowString(10,110,400,16,16,"Key0:start once timer Key1:start reload timer");
LCD_ShowString(10,130,480,16,16,"Key2:stop reload timer Keywakeupelete reload timer");
/* 创建开始任务 */
xTaskCreate((TaskFunction_t) Start_task,
(const char* ) "Start_task",
(uint16_t ) START_TASK_STACK_SIZE,
(void * ) NULL,
(UBaseType_t ) START_TASK_PRIO,
(TaskHandle_t *) &Start_Task_Handler);
/* 开启任务调度器 */
vTaskStartScheduler();
while(1)
{
;
}
}
void Start_task(void *para)
{
taskENTER_CRITICAL(); //进入临界区
/* 创建单周期定时器 */
Once_timer_handler = xTimerCreate((const char * ) "Once_timer",
(TickType_t ) 1000,
(UBaseType_t ) pdFALSE,
(void * ) 0,
(TimerCallbackFunction_t ) Once_time_call_back);
/* 创建多周期定时器 */
Reload_timer_handler = xTimerCreate((const char * ) "Reload_timer",
(TickType_t ) 2000,
(UBaseType_t ) pdTRUE,
(void * ) 1,
(TimerCallbackFunction_t ) Reload_call_back);
/* 创建SOFTWARE_TIMER任务 */
xTaskCreate((TaskFunction_t ) SOFTWARE_TIMER_task,
(const char* ) "SOFTWARE_TIMER_task",
(uint16_t ) SOFTWARE_TIMER_TASK_STACK_SIZE,
(void * ) NULL,
(UBaseType_t ) SOFTWARE_TIMER_TASK_PRIO,
(TaskHandle_t * ) &SOFTWARE_TIMER_Task_Handler);
/* 删除开始任务 */
vTaskDelete(Start_Task_Handler);
taskEXIT_CRITICAL(); //退出临界区
}
void SOFTWARE_TIMER_task(void *para)
{
uint8_t key_value;
BaseType_t err_msg;
LCD_ShowString(10,250,400,20,16,"Once timer is run 00 times");
LCD_ShowString(10,270,400,20,16,"Reload timer is run 00 times");
while(1)
{
key_value = key_scan(1);
if((Once_timer_handler == NULL)||(Reload_timer_handler == NULL))
{
LCD_ShowString(10,150,400,20,16,"Software Timer creat failed.");
}
else
{
switch(key_value)
{
case key_0_set:
{
err_msg = xTimerStart(Once_timer_handler,0);
if(pdPASS == err_msg)
{
LCD_ShowString(10,170,400,20,16,"Once timer is start!");
}
}break;
case key_1_set:
{
err_msg = xTimerStart(Reload_timer_handler,0);
if(pdPASS == err_msg)
{
LCD_ShowString(10,190,400,20,16,"Reload timer is start!");
}
}break;
case key_2_set:
{
err_msg = xTimerStop(Reload_timer_handler,0);
if(pdPASS == err_msg)
{
LCD_ShowString(10,210,400,20,16,"Reload timer is Stop!");
}
}break;
case key_wakeup_set:
{
err_msg = xTimerDelete(Reload_timer_handler,0);
if(pdPASS == err_msg)
{
LCD_ShowString(10,230,400,20,16,"Reload timer is Delete!");
}
}break;
default:break;
}
}
vTaskDelay(10);
}
}
void Once_time_call_back(TimerHandle_t xTimer)
{
static uint8_t tmr1_num=0;
tmr1_num++;
LCD_ShowxNum(10+18*8,250,tmr1_num,2,16,0);
}
void Reload_call_back(TimerHandle_t xTimer)
{
static u8 tmr2_num = 0;
tmr2_num++;
LCD_ShowxNum(10+20*8,270,tmr2_num,2,16,0);
}
|
|