Quality RTOS & Embedded Software

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


Loading

vTaskDelay() from ISR ?

Posted by niekiran on February 17, 2017

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

Thanks


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 ?

Thanks

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/

Attachments

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. */
	ulISREvents |= EMAC_IF_RX_EVENT;
	/* Give the semaphore to wakeup prvEMACHandlerTask. */
	if( xEMACTaskHandle != NULL )
	{
		vTaskNotifyGiveFromISR( xEMACTaskHandle, &xHigherPriorityTaskWoken );
	}
}


/* Clear all interrupt flags. */
ETH->DMASR = ulDMASR;

/* 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 ]    [ 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