vTaskStartScheduler(); while(1) { } } ~~~ ~~~ FreeRTOSConfig.h
No context switching after portYIELD_FROM_ISR() cortex M4
hi everyone
I´m using the TM4c123 cortex m4 of TI and i’m trying to use the interrupts in FreeRTOS… here is the situation
I’ve two tasks running, the Task 1 is blocking after attempting to get a binary semaphore(this task has the higher priority) then the Task 2 is running a simple for loop, waiting for an interrupt(the interrupt is the Rx of the UART0) then in the ISR(UARTIntHandler) call the xSemaphoreGiveFromISR and then the portYIELDFROMISR and here comes the problem because i’m expecting the running task will be the Task 1 because of the call to give the semaphore, but the Task 2 is actually running here is the simplified code also i put FreeRTOSconfig.h
~~~
void
ConfigureUART(void)
{
// Configure GPIO Pins for UART mode.
// Enable the GPIO Peripheral used by the UART.
//…
ROMIntPrioritySet(INTUART0, 0xA3 );//Here im setting the interrupt priority
portDISABLEINTERRUPTS();
UARTIntDisable(INTUART0, UARTINTTX | UARTINTRI);
ROMIntEnable(INTUART0);
ROMUARTIntEnable(UART0BASE, UARTINTRX | UARTINTRT);
}
~~~
~~~
void
vTask1 (void *pvParamaters)
{
while(1)
{
xSemaphoreTake( xBinarySemaphore, portMAX_DELAY ); //blocking the task
ROM_UARTCharGetNonBlocking(UART0_BASE)…;
}
}
~~~
~~~
void
vTask2 (void *pvParamaters)
{
while(1)
{
for ( u1 = 0; u1 < mainDELAY_LOOP_COUNT; u1++ ){}
}
}
~~~
~~~
void
UARTIntHandler(void)
{
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken );
ROMUARTIntClear(INTUART0, UARTINTRX | UARTINTRT);
if( xHigherPriorityTaskWoken )
{
portYIELDFROMISR( xHigherPriorityTaskWoken );//After this, the context switch to Task 1 never happens
}
}
~~~
~~~
int
main(void)
{
ROMSysCtlClockSet(SYSCTLSYSDIV1 | SYSCTLUSEOSC | SYSCTLXTAL16MHZ |SYSCTLOSC_MAIN);
ConfigureUART();
xBinarySemaphore = xSemaphoreCreateBinary();
xHigherPriorityTaskWoken = pdFALSE;
xTaskCreate( vTask1, “Task 1”, 100, NULL, 2, NULL );
xTaskCreate( vTask2, “Task 2”, 100, NULL, 1, NULL );
vTaskStartScheduler(); while(1) { } } ~~~ ~~~ FreeRTOSConfig.h
vTaskStartScheduler(); while(1) { } } ~~~ ~~~ FreeRTOSConfig.h
No context switching after portYIELD_FROM_ISR() cortex M4
At first glance there is not anything obviously wrong with your code.
There is no need to test xHigherPriorityTaskWoken before passing it to
portYIELDFROMISR, and xHigherPriorityTaskWoken should be initialised
to 0, but neither of those are going to be the source of the problem.
Which version of FreeRTOS are you using and do you have configASSERT
defined? The reason I ask about the version is that the newer the
version the more assert points there are.
You say Task1 should run immediately, implying it does not, but does it
run at all after the semaphore is given?
Task notifications can be used in place of semaphores as they are much
lighter weight.
No context switching after portYIELD_FROM_ISR() cortex M4
Thanks for the reply!,
Which version of FreeRTOS are you using
I’m using the FreeRTOS V9.0.0
do you have configASSERT defined? Yes, in FreeRTOSConfig I’ve… ~~~
You say Task1 should run immediately, implying it does not, but does it run at all after the semaphore is given? Task 1 just executes at the first time after vTaskStartScheduler(); then it never runs… :/
Task notifications can be used in place of semaphores as they are much lighter weight. I also have tried with task notifications but actually when i call vTaskNotifyGiveFromISR() xHigherPriorityTaskWoken never change to pdTRUE(1)
do you have configASSERT defined? Yes, in FreeRTOSConfig I’ve… ~~~
define configASSERT( x ) if( ( x ) == 0 ) {
taskDISABLE_INTERRUPTS(); for( ;; );
}
~~~
You say Task1 should run immediately, implying it does not, but does it run at all after the semaphore is given? Task 1 just executes at the first time after vTaskStartScheduler(); then it never runs… :/
Task notifications can be used in place of semaphores as they are much lighter weight. I also have tried with task notifications but actually when i call vTaskNotifyGiveFromISR() xHigherPriorityTaskWoken never change to pdTRUE(1)
No context switching after portYIELD_FROM_ISR() cortex M4
Hi there,
I’ve tried a simple modification in the code, specifically, inside the ISR
~~~
void UARTIntHandler(void)
{
xHigherPriorityTaskWoken = pdFALSE;
while(ROMUARTCharsAvail(UART0BASE))
{
ROMUARTCharGetNonBlocking(UART0BASE); }
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken ); portYIELDFROMISR( xHigherPriorityTaskWoken ); ROMUARTIntClear(INTUART0, UARTINTRX | UARTINTRT); } ~~~ If i clean the fifo here, the Task 1 is executed after the end of the ISR but i do not realy want this because of the time spending inside the ISR, does anyone knows a better way to deferred the work of an ISR? thanks… 🙂
ROMUARTCharGetNonBlocking(UART0BASE); }
xSemaphoreGiveFromISR( xBinarySemaphore, &xHigherPriorityTaskWoken ); portYIELDFROMISR( xHigherPriorityTaskWoken ); ROMUARTIntClear(INTUART0, UARTINTRX | UARTINTRT); } ~~~ If i clean the fifo here, the Task 1 is executed after the end of the ISR but i do not realy want this because of the time spending inside the ISR, does anyone knows a better way to deferred the work of an ISR? thanks… 🙂