Task Suspend & Resume

hi I am using FreeRTOS CORTEX_M4F_STM32F407ZG-SK Project for my STM32F4-Discovery board.
I have two tasks i.e, Task1(Priority 4) & Task2(Priority 3)
1. Task1 gives input to the Task2 and goes to suspend state
2. Task2 does some data processing and writes onto SPI and then it resumes Task1.
Above two steps are repeated infinite times(150-200 times in a second).
Issue:
After running it for 2-3hours, found Task1 is giving input to Task2 but Task2 doesn’t process the data.
FreeRTOS plugin shows both tasks as suspended. Can anyone help me on how to debug this issue. Thanks in advance
akhil

Task Suspend & Resume

FreeRTOS plugin shows both tasks as suspended.
Be careful how you interpret what the plug-in is telling you.  The plug-in cannot tell the difference between a task that is actually suspended (in the Suspended state) and a task that is in the Blocked state with an infinite timeout.  Therefore if you call a blocking function such as xQueueReceive() and give it a block time of portMAX_DELAY then, if INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h (which it must be in your case), the plug-in will show the task as being in the Suspended state. It is almost certain that the task is actually in the Blocked state, not the Suspended state. Regards.

Task Suspend & Resume

Thanks for the reply richardbarry, -> I am not using any FreeRTOS Queue SPIs.
-> I have question:
how can I suspend a task with timeout, something like this…vTaskSuspend(handle,timeout)? My code template looks like this:
Code Template:
xTaskHandle task1_handle;
xTaskHandle task2_handle;
void *data_pkt = NULL;
void task1_prepare(void *arg)
{
while(1)
{
data_pkt = malloc(1000);
vTaskSuspend(task1_handle);
free(data_pkt);
data_pkt = NULL;
}
} void task2_process(void *arg)
{
while(1)
{
if(data_pkt!=NULL)
{
/*do some processing like writing onto USART/SPI*/
vTaskResume(task1_handle);
}
else
{
while(1)
printf(”input buffer is NULLn”);
|
}
}

Task Suspend & Resume

sorry, It is ,  -> I am not using any FreeRTOS Queue APIs.

Task Suspend & Resume

I’m not sure why you would be allocating a packet in one task for use by another task – but assume if I saw all your code rather than this snippet it would be more obvious.  Also personally I would always try and avoid repeatedly allocating and freeing memory blocks in this way – although heap_4.c would normally make this ok. There is no suspend with timeout function.  For that you would need to use a delay, not a suspend, but then there is no way of another task ‘undelaying’ as per your unsuspending (resuming).  You could probably make the functionality by having the task block on a semaphore with a delay – then the other task can “give” the semaphore to unblock the task if the delay has not expired. Task suspend and resume are not features I use very often myself.  They can be dangerous to use as a synchronisation method because if a task tries to a resume another task that has not yet got to the point of suspending itself then the resume has no effect (and is not latches, as it would be if a semaphore were used instead). Regards.

Task Suspend & Resume

Thanks for your inputs, Actually , Task1 has another job like taking user inputs from USART, before while(1) loop.
and In future I have  to create few more tasks and all these tasks will use Task2 to send the data out on USART/SPI. Anyway, I will try using semaphore once. Thanks
Akhil