Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists