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 and vTaskResume

Posted by Nobody/Anonymous on May 26, 2005
Is it safe to call these functions from inside an ISR? Instead of using semaphores or queues to save on memory, my application can make do with suspend and resume but after suspending i require that the task is resumed from inside an ISR. Can this be done?

Also can passing NULL to vTaskSuspend function called by another function suspend the main calling task. I am pretty sure this would work as i suppose that the 'running' task information would be taken from the scheduler.

RE: vTaskSuspend and vTaskResume

Posted by Richard on May 26, 2005
Q1) Generally this would be a VERY bad idea, however what would actually happen depends on the port you are using. Ports that use software interrupts for task switches might be ok provided the interrupt is cleared prior to suspending.

Can you give an example of why you would want to do this? Perhaps there is a different solution?

Q2) Not sure what you are asking here. Are you still meaning from within an ISR? If so then I still think that using these functions from within an ISR would not be a good idea. It was never intended and not tested.

Again what actually happens would depend on the port. It could well work - but I cannot guarantee it. If a task is interrupted, and the ISR calls vTaskSuspend(NULL) then the function call would try to suspend the task that was interrupted. Another task would be chosen as the current task. Then returning from the interrupt could start the new task.

Regards.

RE: vTaskSuspend and vTaskResume

Posted by Nobody/Anonymous on May 26, 2005
Hmmm... Yup it is a bad idea indeed but was just a thought i had for saving some RAM. I would actually be more interested in knowing if i can safely use vTaskResume from an ISR as i can do vTaskSuspend from within the task code itself.

The second question was not referring to an ISR but any normal function called within the Task code. I guess there should be no problem here. (?)

I am using the AVR port.

RE: vTaskSuspend and vTaskResume

Posted by Richard on May 26, 2005
If you look at the demo AVR serial port ISR [ SIGNAL( SIG_UART_RECV ) in serial.c if you are using the GCC port ] you will see that if receiving the character makes another task wake it calls taskYIELD() to ensure that the ISR returns to the highest priority task.

Now if you look at the function vTaskResume() within tasks.c you will see that if the function being resumed has a higher priority than the current task a task switch is performed again by calling taskYIELD(). The mechanism is therefore the same so this to could well work from within an ISR. The stack structures would be identical so should switch with no problem. I say >should< because I don't know :-)

Give it a go and see but look out for requiring more stack space within the task as you are using more stack within the interrupting ISR. Also ensure that the call to vTaskResume() is the very last call in the ISR and that the interrupt is cleared prior to it being called.

Regards.


RE: vTaskSuspend and vTaskResume

Posted by Nobody/Anonymous on May 27, 2005
Thanks for the help. Actually here is why i am looking at this option.

I have a task whose job starts with triggering the ADC start conversion process. The ADC driver itself is interrupt driven. Hence i would like to suspend the task until the ADC conversion is complete. After calling the start conversion function which returns immidiately, the task suspends itself. Then once the conversion complete interrupt is triggered, the ISR resumes this task.

I could use semaphores here but a was held back considering the amount of memory being consumed to setup a semaphore.

Any better ways of doing this?

RE: vTaskSuspend and vTaskResume

Posted by Nobody/Anonymous on May 27, 2005
Hi guys,

Using vTaskResume for this is a nice idea as the example is similar to the serial port example quoted previously. But beware. The semaphore also provides sequencing. If the task starts the conversion, but the ADC interrupt occurs before the task completes its suspend (maybe it was pre-empted so took a long time) then when it does suspend it will sleep forever as the interrupt has already occurred.

RE: vTaskSuspend and vTaskResume

Posted by Nobody/Anonymous on May 27, 2005
Oops! Ur absolutely right! I am still not thinking multithreading here! Still the good old fashioned guy.

Thanks for pointing out. I think ill just stick to traditions for my first application. Will experiment later then.


[ 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