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


vTaskDelay() from ISR ?

Posted by niekiran on February 17, 2017

What happens if we call vTaskDealy() from ISR ? Does it has any effect ?


vTaskDelay() from ISR ?

Posted by tlafleur on February 17, 2017

ISR, need to be quick and in most cases, have minimal code as it stall all other activities on the CPU....

Adding ANY type of delays in an ISR just degrades total system performance and should be avoided at all costs.

~~ _/) ~~~~ _/) ~~~~ _/) ~~~~ _/) ~~

Tom Lafleur

On Feb 17, 2017, at 4:59 AM, kiran nayak niekiran@users.sf.net wrote:

What happens if we call vTaskDealy() from ISR ? Does it has any effect ?


vTaskDelay() from ISR ?

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/


alternate (1756 bytes)

vTaskDelay() from ISR ?

Posted by heinbali01 on February 17, 2017

Hi Kiran,

It is a custom not to create any delay from within an ISR. Often it is better to defer the handling of interrupt events to a normal task. A typical method is to call vTaskNotifyGiveFromISR() to wake-up a task from within an ISR.

Here is an example from a FreeRTOS+TCP driver:


/* The task is created and 'xEMACTaskHandle' contains a handle to that task. */ xTaskCreate( prvEMACHandlerTask, "EMAC", configEMACTASKSTACKSIZE, NULL, configMAXPRIORITIES - 1, &xEMACTaskHandle );

/* The ISR for Ethernet: */ void ETHIRQHandler(void) { portBASETYPE xHigherPriorityTaskWoken = pdFALSE; uint32_t ulDMASR = ETH->DMASR;

/* Frame received */
if( ( ulDMASR & ETH_DMA_IT_R ) != 0 )
	/* Remember the event. */
	/* Give the semaphore to wakeup prvEMACHandlerTask. */
	if( xEMACTaskHandle != NULL )
		vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );

/* Clear all interrupt flags. */

/* Switch tasks if necessary. */	
if( xHigherPriorityTaskWoken != pdFALSE )
	portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );

} /-----------------------------------------------------------/

/* The interrupt events are handle by a task called prvEMACHandlerTask() */

static void prvEMACHandlerTask( void pvParameters ) { for( ;; ) { / No events to process now, wait for the next. / ulTaskNotifyTake( pdFALSE, ulMaxBlockTime ); / Handle the events. */ }


Now if you call vTaskDelay() from within an interrupt the application gets into serious trouble :-)

Beside being non-interrupt proof, vTaskDelay() normally last very long, 1 ms or more.

What you can do ( but it's not usual ), is to call some blocking udelay() functions.

vTaskDelay() from ISR ?

Posted by rtel on February 17, 2017

What happens if we call vTaskDealy() from ISR ?

In addition to the other replies about never wanting to delay at all in an ISR:

Only API functions that end in FromISR() can be called from an ISR.

vTaskDelay() places the calling task into the Blocked state for a fixed period. This is possible because tasks are controlled by software, namely the FreeRTOS scheduler. Interrupts on the other hand are controlled completely by hardware, so there is no semantic sense in calling vTaskDelay() from an ISR - first it is not a task, and second the hardware is not going to change its behaviour whether you are running an RTOS or not.

[ 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