Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

vTaskSuspend() how to use correct

Posted by Peter on August 19, 2009
Hi,
i would like to create a task suspended but it seems, that FreeRTOS does not have such a feature?!. So i've tried to create a task suspended... But strangely even if i suspended a task, on scheduler start the task runs... (The defines for vTaskSuspend are enabled)


xTaskHandle xTest1Task;

prvSetupHardware();
res = xTaskCreate( prvTest1Task, "Test1Tsk", 410, NULL, 4, &xTest1Task);
vTaskSuspend(xTest1Task);
vTaskStartScheduler();

Strangely the task is being started. But the following works:

void prvTest1Task(void * pvParameters)
{
while(1)
{
vTaskSuspend();
// we idle here until someone resumes us...
{...}
}

xTaskHandle xTest1Task;
prvSetupHardware();
res = xTaskCreate( prvTest1Task, "Test1Tsk", 410, NULL, 4, &xTest1Task);
vTaskStartScheduler();

And strangely the following will not work:

void prvTest1Task(void * pvParameters)
{
while(1)
{
vTaskSuspend();
// we idle here until someone resumes us...
{...}
}

xTaskHandle xTest1Task;
prvSetupHardware();
res = xTaskCreate( prvTest1Task, "Test1Tsk", 410, NULL, 4, &xTest1Task);
vTaskSuspend(xTest1Task);
vTaskStartScheduler();


Kind regards,
Peter

RE: vTaskSuspend() how to use correct

Posted by MEdwards on August 19, 2009
In tasks.c find the implementation of vTaskSuspend(). At the bottom of the function you will see the line if( ( void * ) pxTaskToSuspend == NULL ). Change this to

if( (( void * ) pxTaskToSuspend == NULL )&&(xSchedulerRunning != pdFALSE) )

Then in main() create the task then use the task handle as the parameter to vTaskSuspend().

xTaskCreate( prvTest1Task, "Test1Tsk", 410, NULL, 4, &xTest1Task);
vTaskSuspend(xTest1Task);
//other code goes here.
vTaskStartScheduler().

RE: vTaskSuspend() how to use correct

Posted by Peter on August 20, 2009
Hi Edward,
thanks for the idea - because otherwise the the task is being YIELDed before the scheduler has been started. Unfortunately the solution does not work. Do you have any idea? (Iam not that deep into that, yet).
Thanks in advance,
Peter

RE: vTaskSuspend() how to use correct

Posted by Ben on August 20, 2009
If just use the following to suspend a task when it first runs, and then resume it when needed from another task.

void TaskA( void *pvParameters )
{
vTaskSuspend( NULL );

while(1) {

}
}

RE: vTaskSuspend() how to use correct

Posted by Peter on August 20, 2009
Hi Ben,
yes you are right! That was also my idea, but i've found that way not that beautiful ;-)

Kind regards,
Peter


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS