Quality RTOS & Embedded Software

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


Use API in interrupt

Posted by yaozhiman on May 9, 2011
I am very confused about use API in interrupt ,In this sentence-"API functions must not be called from an interrupt if the interrupt has a priority above the priority set by configMAX_SYSCALL_INTERRUPT_PRIORITY."Do all of the API cannot be called or part API cannot be called?If I use the API in a higher priority interrupt, does the system will collapse crash?

RE: Use API in interrupt

Posted by woops_ on May 9, 2011

Only api that have FromISR in the name can every be called in in interrupt. The link above describes the other things.

RE: Use API in interrupt

Posted by yaozhiman on May 10, 2011
it is this, I build a DMA interrupt and a task in my project, the interrupt priority of DMA is higher than configMAX_SYSCALL_INTERRUPT_PRIORITY 's priority ,which can preempted the OS's interruption. the interrupt of DMA send a semaphore to the task by xSemaphoreGiveFromISR( xSemaphoreHandle1, &xHigherPriorityTaskWoken );and the task receive semaphore by call xSemaphoreTake (xSemaphoreHandle1, if (portMAX_DELAY) = = pdTRUE) , according to the conventional ,ths OS should Crash, but I tested for a few days it still run very well.

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//set DMA's priority =11
/* Enable the DMA1 Interrupt */

#define configKERNEL_INTERRUPT_PRIORITY (15<<4)
#define configMAX_SYSCALL_INTERRUPT_PRIORITY (13<<4) /* . */

void DMA1_Channel1_IRQHandler(void)//ADC is triggered by Timer4's PWM
signed portBASE_TYPE xHigherPriorityTaskWoken= pdFALSE;
xSemaphoreGiveFromISR( xSemaphoreHandle1, &xHigherPriorityTaskWoken );
// printf("DMA1_Channel1_IRQHandler is Running!\n");//ITM trace
if( xHigherPriorityTaskWoken )

void vTaskAdc1( void * pvParameters )
if( xSemaphoreTake( xSemaphoreHandle1, portMAX_DELAY) == pdTRUE )
//printf("vTaskAdc1 is Running!\n");
I tested for a few days it still run very well.


RE: Use API in interrupt

Posted by Richard on May 10, 2011
If you are relying on your system not crashing, then don't do it, and stick to the rules. You may get luck for days, weeks, years even, but there is a bug in your code that is just waiting for all the necessary circumstances to happen, by change, simultaneously.

Lower the interrupt priority so it is equal to or less than configMAX_SYSCALL_INTERRUPT_PRIORITY.

Are you sure what you think is a higher priority really is? If this is a cortex M3 system, then high numeric values equate to *low* actual priority values.


RE: Use API in interrupt

Posted by yaozhiman on May 12, 2011
I think it's so, assuming that,the priority of DMA1_Channel1_IRQHandler is above configMAX_SYSCALL_INTERRUPT_PRIORITY, and suppose that only a DMA1_Channel1_IRQHandler calls xSemaphoreGiveFromISR (xSemaphoreHandle1, & xHigherPriorityTaskWoken), so long as DMA1_Channel1_IRQHandler does not preempte itself, the system is safe, is right? Also ,is the different of the priority of DMA1_Channel1_IRQHandler is above or below configMAX_SYSCALL_INTERRUPT_PRIORITY that when DMA1_Channel1_IRQHandler call API,the DMA1_Channel1_IRQHandler may be nested by itself or be nested by other interrupt, which could cause the abnormal of API's execute , is this?(the CPU is STM32)
Above is my stupid idea and my English isn't good

RE: Use API in interrupt

Posted by Richard Damon on May 14, 2011
If an interrupt has a priority such that a critical section does not disable the interrupt, (based on configMAX_SYSCALL_INTERRUPT_PRIORIRY) then the program runs the risk of corruption if the interrupt occurs during a critical section in a task level operation. It doesn't matter if no one else is calling a given FromISR function, the danger is in manipulating the common base data structures (ready lists and the like).

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS v10.2.1 is available for immediate download. MIT licensed, includes 64-bit RISC-V, NXP Cortex-M33 demo & Nuvoton Cortex-M23 demo.

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


FreeRTOS and other embedded software careers at AWS.

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Cadence Tensilica Cortes

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers





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