FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [February 2008 Threads] binary semaphore, ISR not yielding to switchPosted 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 ) ;
voidemac_int_not_naked(void) {
volatile u32 regValue = 0;
static portBASE_TYPE xTaskWoken = pdFALSE;
//leemos int status regValue = MAC_INTSTATUS;
do { if (regValue == 0) { break; }
if (regValue & MAC_INT_RXOVERRUN) { m_nic_write(MAC_INTCLEAR, MAC_INT_RXOVERRUN); break; }
if (regValue & MAC_INT_RXERROR) { m_nic_write(MAC_INTCLEAR, MAC_INT_RXERROR); break; }
if (regValue & MAC_INT_RXFINISHED) { m_nic_write(MAC_INTCLEAR, MAC_INT_RXFINISHED); //p_priv->stats.rx_erros++; //while ( MAC_RXPRODUCEINDEX != (MAC_RXCONSUMEINDEX - 1) ); }
if (regValue & MAC_INT_RXDONE) { m_nic_write(MAC_INTCLEAR, MAC_INT_RXDONE);
//wake up! xTaskWoken = xSemaphoreGiveFromISR( xETH_RX_Sem, xTaskWoken );
}
if (regValue & MAC_INT_TXUNDERRUN) { m_nic_write(MAC_INTCLEAR, MAC_INT_TXUNDERRUN); break; }
if (regValue & MAC_INT_TXERROR) { m_nic_write(MAC_INTCLEAR, MAC_INT_TXERROR); break; }
if (regValue & MAC_INT_TXFINISHED) { m_nic_write(MAC_INTCLEAR, MAC_INT_TXFINISHED); }
if (regValue & MAC_INT_TXDONE) { m_nic_write(MAC_INTCLEAR, 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. */ portSAVE_CONTEXT();
/* Call the handler. This must be a separate function to ensure the stack frame is correctly set up. */ emac_int_not_naked();
/* Restore the context of whichever task will run next. */ portRESTORE_CONTEXT(); } --------------------------------------------------
so then I just do this in the UIP task:
.... if ( xSemaphoreTake( xETH_RX_Sem, portMAX_DELAY ) != pdTRUE ) { printf("B\n");
} else { something(); } .....
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?
thanks!
RE: binary semaphore, ISR not yielding to swiPosted 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 swiPosted 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.
thanks
RE: binary semaphore, ISR not yielding to switchPosted 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 switchPosted 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,
Carlos
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|