Hi Everyone, I am new to using freeRTOS and i was setting up my project to demonstrate inter task comms using queues. I am unable to understand the nature of the issue. Basically the tasks stops from executing if i read from queue. My code is as follows:
main.c
atmel_start_init();
printf( "initializing all threads\n");
xTaskCreate( mdrMngTask,
"MDR_MANAGEMENT_TASK",
configMINIMAL_STACK_SIZE*2,
NULL,
0,
NULL );
xTaskCreate( timeMngTask,
"TIME_MANAGEMENT_TASK",
configMINIMAL_STACK_SIZE,
NULL,
0,
NULL );
printf("Starting the scheduler\n");
/* Start the tasks and timer running. */
vTaskStartScheduler();
for( ;; )
printf("Stuck in main\n");
mdr_mng_task.c
void mdrMngTask( void *pvParameters )
{
TickType_t xNextWakeTime;
printf("mdrMngTask started \n");
xNextWakeTime = xTaskGetTickCount();
uint8_t count=1;
for( ;; )
{
printf("MM - start\n");
vTaskDelay(mdr_MANAGEMENT_PERIOD_MS/1.5);
printf("MM - delayed\n");
tm_addToQueue(&count);
count++;
printf("MM - running\n");
}
}
time_mng_task.c
QueueHandle_t q_timeMngQueue;
uint8_t tm_addToQueue(uint8_t *value)
{
if ( xQueueSend(q_timeMngQueue,value,0) == pdTRUE )
{
printf("TM_q - %d @ %d\n",*value, (uxQueueSpacesAvailable(q_timeMngQueue)+1));
return pdTRUE ;
}
else
{
printf("q_full\n");
return errQUEUE_FULL;
}
}
void timeMngTask( void *pvParameters )
{
printf("timeMngTask started \n");
q_timeMngQueue = xQueueCreate( 10, sizeof(uint8_t));
uint8_t buffer;
for( ;; )
{
printf("TM - start\n");
vTaskDelay(timer_MANAGEMENT_PERIOD_MS/2);
printf("TM - delayed\n");
if(xQueueReceive(q_timeMngQueue, &buffer, ( TickType_t ) 10) == pdTRUE)
{
printf("TM - recv - %d\n",buffer);
printf("TM_q - %d\n",uxQueueSpacesAvailable(q_timeMngQueue));
}
else
printf("TM - timed out\n");
printf("TM - running\n");
}
}
If i compile and run this code i get following output:
“7/08/2024 11:26:18 AM”,initializing all threads
“7/08/2024 11:26:18 AM”,Starting the scheduler
“7/08/2024 11:26:18 AM”,mdrMngtimeMnTask sgTask tartedstarte
“7/08/2024 11:26:18 AM”,MM -d
“7/08/2024 11:26:18 AM”,TM start- star
“7/08/2024 11:26:18 AM”,t
“7/08/2024 11:26:21 AM”,TM - delayed
“7/08/2024 11:26:21 AM”,TM - timed out
“7/08/2024 11:26:21 AM”,TM - running
“7/08/2024 11:26:21 AM”,TM - start
“7/08/2024 11:26:23 AM”,MM - delayed
“7/08/2024 11:26:23 AM”,TM_q - 1 @ 10
“7/08/2024 11:26:23 AM”,MM - running
“7/08/2024 11:26:23 AM”,MM - start
“7/08/2024 11:26:25 AM”,TM - delayed
“7/08/2024 11:26:25 AM”,TM - recv - 1
“7/08/2024 11:26:25 AM”,TM_q - 10
“7/08/2024 11:26:25 AM”,TM - running
“7/08/2024 11:26:25 AM”,TM - start
After this the rtos appears to be halted forever. You can notice from this that its stuck at vTaskDelay. How can i enable more debugging or resolve this issue.
Another thing i have noticed is that if i comment out the following section from time_mng_task.c
if(xQueueReceive(q_timeMngQueue, &buffer, ( TickType_t ) 10) == pdTRUE)
{
printf("TM - recv - %d\n",buffer);
printf("TM_q - %d\n",uxQueueSpacesAvailable(q_timeMngQueue));
}
else
printf("TM - timed out\n");
The mdr_mng_task is able to consistently store info into the queue until it gets full.