Hello,
I am implementing two tasks code as follow
/*******************************************************************************/
{
/ Two task created/
xTaskCreate(vtask_1, “Task-1”, 500, NULL, 2, &xTaskHandle1);
xTaskCreate(vtask_2, “Task-2”, 500, NULL, 5, &xTaskHandle2);
/* Schedule the task */
vTaskStartScheduler();
}
/* Task_1 Handler*/
void (vtask_1)( void *params )
{
UBaseType_t p1,p2;
sprintf(usr_msg,"TASK 1 is runnung\r\n");
printmsg(usr_msg);
sprintf(usr_msg,"TASK 1 priority is : %ld\r\n",uxTaskPriorityGet(xTaskHandle1));
printmsg(usr_msg);
sprintf(usr_msg,"TASK 2 priority is : %ld \r\n",uxTaskPriorityGet(xTaskHandle2));
printmsg(usr_msg);
while(1)
{
if(prio)
{
prio = FALSE;
p1 = uxTaskPriorityGet(xTaskHandle1);
p2 = uxTaskPriorityGet(xTaskHandle2);
//switch prio
vTaskPrioritySet(xTaskHandle1, p2);
vTaskPrioritySet(xTaskHandle2, p1);
}else
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(1000);
}
}
}
/* Task_2 Handler*/
void (vtask_2)( void *params )
{
UBaseType_t p1,p2;
sprintf(usr_msg,“TASK 2 is runnung\r\n”);
printmsg(usr_msg);
sprintf(usr_msg,"TASK 1 priority is : %ld\r\n",uxTaskPriorityGet(xTaskHandle1));
printmsg(usr_msg);
sprintf(usr_msg,"TASK 2 priority is : %ld \r\n",uxTaskPriorityGet(xTaskHandle2));
printmsg(usr_msg);
while(1)
{
if(prio)
{
prio = FALSE;
p1 = uxTaskPriorityGet(xTaskHandle1);
p2 = uxTaskPriorityGet(xTaskHandle2);
//switch prio
vTaskPrioritySet(xTaskHandle1, p2);
vTaskPrioritySet(xTaskHandle2, p1);
}else
{
HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_5);
HAL_Delay(100);
}
}
}
I was under the impression that each time a task runs it runs the whole handler body. Meaning from the open brace of task_1 to the closing brace of the function body. However, i realized that after Task1 has switched in from Task2 or Task2 has switched in from Task1, for subsequent context switches, only the while loop or for loop gets executed.
Thus, subsequent button presses to switch priority between the 2 tasks will not print out the messages to Teraterm.
Only the 1st run context switching will run the whole handler body whereas subsequent switching won’t?
What is the reason?
Please refer the screenshot
Thanks