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

Resuming after vTaskSuspend(NULL);

Posted by andy-pevy on January 5, 2016

Hi,

  I have a number of tasks and I am trying to synchronise one of them with another.

I am using the ST Cube tool to create the base code, and it starts all the tasks at boot time.

I therefore, within the first task issue a vTaskSuspend(TIMER_TaskHandle); call. I was hoping that this would allow the second task to complete initializing some hardware (that takes a variable amount of time).

I then, from the second task issue a vTaskResume(TIMER_TaskHandle);

But, the first task does not continue after the suspend line.

Code fragment :-

Timer task:

TIMER_Task_Suspended = TRUE;
vTaskSuspend(TIMER_TaskHandle);		// Stop here until allowed to resume...
TIMER_Task_Suspended = FALSE;   <- Never reached :(.....

Supervisor task :

if(MODE_DC == my_mode)    <- This is true...
{
	vTaskResume(TIMER_TaskHandle);	// Re start the timer task.
}

So, Firstly, is what I am doing correct and allowed, and secondly, if it is, why does it not appar to work ?.

Thanks, Andy Pevy


Resuming after vTaskSuspend(NULL);

Posted by rtel on January 5, 2016

Are you sure the value in TIMER_TaskHandle is correct?

If so, then is the second task (the one that is calling vTaskResume()) higher, lower or equal priority to the first task? If it is higher priority then the first task will only execute when the higher priority task enters the Blocked state. It will enter the Blocked state if it makes a blocking FreeRTOS API call, such as vTaskDelay(), or xQueueReceive() on an empty queue with a block time specified.

Regards.


Resuming after vTaskSuspend(NULL);

Posted by andy-pevy on January 5, 2016

Hi, The value in Timer_TaskHandle is correct, and both tasks are running at the same priority.

The unblocking task enters "retval = xQueueReceive(SupervisortaskqueueHandle, (TransferType *) &supervisorinds, slottime.sleeptime);" a few lines later so it should allow the timer task to run.


Resuming after vTaskSuspend(NULL);

Posted by andy-pevy on January 5, 2016

Would adding a vTaskDelay or taskYIELD be a way of releasingf the timer task ?.


Resuming after vTaskSuspend(NULL);

Posted by rtel on January 5, 2016

That shouldn't be necessary.

Another thought - if the tasks are the same priority - are you 100% sure the task is suspended before you try un-suspending it?

For example, if:

1) the first task set TIMERTaskSuspended to true, then got swapped out before it called vTaskSuspend(), 2) Then the second task executed, did its thing, and called vTaskResume(), 3) Then the first task executed again and called vTaskSuspend()

you would end up with the behaviour your have observed.

Try creating the first task with a priority above that of the second task, so you know there is no chance of the second task executing until the first task has actually entered the Suspended state. Then when the first task leaves the Suspended state it can call vTaskPrioritySet( NULL, [whatever] ); to set its priority back down to the one you really want it to run at.

Alternatively, if the task is created before the scheduler has started, you can also suspend it before the scheduler starts, that way it will already be in the suspended state before any tasks run. vTaskSuspend() is one of the functions that it is ok to call before starting the scheduler.

Regards.


Resuming after vTaskSuspend(NULL);

Posted by rtel on January 5, 2016

By the way, you can use eTaskGetState() to determine the state of a task.


Resuming after vTaskSuspend(NULL);

Posted by andy-pevy on January 6, 2016

Bingo, looking at the relative timings, I think that this is a distinct possibility.

I will re-work the control logic to ensure that the timings are correct.

Thanks for your help.

Andy


[ 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