Hi guys, I’m trying to implement a menu using freertos. There are 7 screens showing tasks in total, and when switching menus all tasks are suspended first and then one task is resumed. When I create a task, I can hang all the tasks without any problem, but when I switch, the task cannot be hung without any problem. Here is my code and debugging result.
void appStartTask(void){
queueKeyHandle = xQueueCreate(2,sizeof(uint8_t));
smaMutexHandle = xSemaphoreCreateMutex();
tmrSingleHandler = xTimerCreate("singleTimer",
6000,
pdFALSE,
(void *) 1,
singleTimerCallBack
);
tmrCycleHandler = xTimerCreate("cycleTimer",
500,
pdTRUE,
(void *) 2,
cycleTimerCallBack
);
taskENTER_CRITICAL();
xTaskCreate(keyTask, /*任务函数*/
"keyTask", /*任务名*/
256, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
1, /*任务优先级,越小越高*/
&keyTaskHandle); /*任务句柄*/
xTaskCreate(walkTask, /*任务函数*/
"walkTask", /*任务名*/
256, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
4, /*任务优先级,越小越高*/
&walkTaskHandle); /*任务句柄*/
xTaskCreate(timeCheckTask, /*任务函数*/
"timeCheckTask", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&timeCheckTaskHandle); /*任务句柄*/
xTaskCreate(MainMenuTask, /*任务函数*/
"MainMenu", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&mainMenuTaskHandle); /*任务句柄*/
xTaskCreate(timeSetTask, /*任务函数*/
"timeSetTask", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&timeSetTaskHandle); /*任务句柄*/
xTaskCreate(alarmSetTask, /*任务函数*/
"alarmSetTask", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&alarmSetTaskHandle); /*任务句柄*/
xTaskCreate(secondTask, /*任务函数*/
"secondTask", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&secondTaskHandle); /*任务句柄*/
xTaskCreate(alarmDispTask, /*任务函数*/
"alarmDispTask", /*任务名*/
256, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&alarmDispTaskHandle); /*任务句柄*/
xTaskCreate(heartTask, /*任务函数*/
"heartMesu", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&heartTaskHandle); /*任务句柄*/
xTaskCreate(stepTask, /*任务函数*/
"stepTask", /*任务名*/
256, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&stepTaskHandle); /*任务句柄*/
xTaskCreate(infoMenuTask, /*任务函数*/
"infoMenuTask", /*任务名*/
512, /*任务堆栈大小,单位为word,128word = 4B*/
NULL, /*任务参数*/
3, /*任务优先级,越小越高*/
&infoTaskHandle); /*任务句柄*/
taskEXIT_CRITICAL();
suspendScreen();
vTaskResume(mainMenuTaskHandle);
}
static void keyTask(void * pvParameters){
keyvalue ucKeyValue;
while(1){
printf("key task\n");
ucKeyValue = KeyScan();
if(ucKeyValue == PWRLong){
suspendScreen();
LCD_Clear(WHITE);
pageNum = pageNone;
}
if(ucKeyValue == MODEDown){
printf("mode down\n");
suspendScreen();
if(++pageNum > TOTAL_PAGE) pageNum = pageNone;
printf("key task end\n");
resumeScreen(pageNum);
}
if(ucKeyValue != 0){
xQueueSendToBack(queueKeyHandle, &ucKeyValue, 100);
xTimerStart(tmrSingleHandler, 10);
}
vTaskDelay(pdMS_TO_TICKS(100)); /*延时500MS*/
}
}
static void suspendScreen(void){
printf("suspendall\n");
vTaskSuspend(mainMenuTaskHandle);
printf("suspend1\n");
vTaskSuspend(timeSetTaskHandle);
printf("suspend2\n");
vTaskSuspend(infoTaskHandle);
printf("suspend3\n");
vTaskSuspend(secondTaskHandle);
printf("suspend4\n");
vTaskSuspend(heartTaskHandle);
printf("suspend5\n");
vTaskSuspend(alarmSetTaskHandle);
printf("suspend6\n");
vTaskSuspend(stepTaskHandle);
printf("suspend ok\n");
HAL_GPIO_WritePin(led0_GPIO_Port, led0_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(led1_GPIO_Port, led1_Pin, GPIO_PIN_RESET);
}