Quality RTOS & Embedded Software

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


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner