Quality RTOS & Embedded Software
About   Contact   Support   FAQ

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs Books & Kits Visualisation Ecosystem FreeRTOS Labs Training




Last site update Oct 5 2014

Loading

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?
regards

RE: Use API in interrupt

Posted by woops_ on May 9, 2011
http://www.freertos.org/a00110.html#kernel_priority

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 */
NVIC_SetPriority(DMA1_Channel1_IRQn,11);
NVIC_EnableIRQ(DMA1_Channel1_IRQn);//

#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;
if(((DMA1->ISR)&0x02))
{
TIM4->CR1&=(~0x01);
xSemaphoreGiveFromISR( xSemaphoreHandle1, &xHigherPriorityTaskWoken );
DMA1->IFCR=0x02;
// printf("DMA1_Channel1_IRQHandler is Running!\n");//ITM trace
}
if( xHigherPriorityTaskWoken )
{
vPortYieldFromISR();
}
//xTaskGetTickCount();
//TIM4->CR1|=0x01;
}

void vTaskAdc1( void * pvParameters )
{
ADC1_Parameter_Init();
//TIM4->CR1|=0x01;
while(1)
{
if( xSemaphoreTake( xSemaphoreHandle1, portMAX_DELAY) == pdTRUE )
{
ADC_Handle2();
TIM4->CR1|=0x01;
//printf("vTaskAdc1 is Running!\n");
}
}
}
I tested for a few days it still run very well.

Regards

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.

Regards.

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
regards

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-2013 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.