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


binary semaphore, ISR not yielding to switch

Posted by Carlos B on February 1, 2008
hi everybody,

here I am coding an ISR to tell uIP when to read data from an ethernet MAC.

here is the ISR:

void __attribute__ ((naked)) emac_interrupt( void ) ;


volatile u32 regValue = 0;

static portBASE_TYPE xTaskWoken = pdFALSE;

//leemos int status

if (regValue == 0)

if (regValue & MAC_INT_RXOVERRUN)

if (regValue & MAC_INT_RXERROR)

if (regValue & MAC_INT_RXFINISHED)

if (regValue & MAC_INT_RXDONE)

//wake up!
xTaskWoken = xSemaphoreGiveFromISR( xETH_RX_Sem, xTaskWoken );


if (regValue & MAC_INT_TXUNDERRUN)

if (regValue & MAC_INT_TXERROR)

if (regValue & MAC_INT_TXFINISHED)

if (regValue & MAC_INT_TXDONE)

} while (0);

VICVectAddr = 0;//clear

if( xTaskWoken )
portYIELD_FROM_ISR();//sip, hay que levantar la tarea!

void __attribute__ ((naked)) emac_interrupt( void )
/* Save the context of the interrupted task. */

/* Call the handler. This must be a separate function to ensure the
stack frame is correctly set up. */

/* Restore the context of whichever task will run next. */

so then I just do this in the UIP task:

if ( xSemaphoreTake( xETH_RX_Sem, portMAX_DELAY ) != pdTRUE )


it doesn't matter if portMAX_DELAY is configured to undefinitely block or not.
I tested it and portYIELD_FROM_ISR() is called, but the task is not woken, and there are lower priorities task running, so I don't know what's wrong.

I'm using a LPC2468 in THUMB mode, but tried purely ARM mode and it's the same behaviour.

any ideas?


RE: binary semaphore, ISR not yielding to swi

Posted by Carlos B on February 1, 2008
oh, I just forgot, I'm creating the semaphore as a binary one, just before enabling the EMAC interrupt in the uip task.

RE: binary semaphore, ISR not yielding to swi

Posted by Carlos B on February 4, 2008
finally, the problem was the static declaration of xTaskWoken and initialization in the same line. Quite subtle, but enough to avoid it from doing things right.


RE: binary semaphore, ISR not yielding to switch

Posted by Jeff Smith on February 4, 2008
Do I understand correctly that the problem is you are not running proper "startup code" in order to initialize global variables on powerup? Why not?

It is just not C without proper startup code.

(sorry, I don't mean to start an off-topic discussion about GCC)

RE: binary semaphore, ISR not yielding to switch

Posted by Carlos B on February 5, 2008
Not actually. GCC is doing right and the startup code is too.

By declaring
static portBASE_TYPE xTaskWoken = pdFALSE;

it means that at startup it will contain pdFALSE, but as for the ISR routine implies, it will see it just as:
static portBASE_TYPE xTaskWoken;

only that it will be initialized to pdFALSE at startup.

Since I never do a xTaskWoken = pdFALSE; statement in the ISR, it will never get back to pdFALSE except when calling xSemaphoreGiveFromISR, which never returned false in my current implementation.

it's amazing how a single statement-splitting changes meanings:

static portBASE_TYPE xTaskWoken;
xTaskWoken = pdFALSE;

but it's the way it is meant to be, as what C regards.

hope I made it clear,


[ 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