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


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