binary semaphore, ISR not yielding to switch

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 ) ; void    emac_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("Bn");                     }         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!

binary semaphore, ISR not yielding to switch

oh, I just forgot, I’m creating the semaphore as a binary one, just before enabling the EMAC interrupt in the uip task.

binary semaphore, ISR not yielding to switch

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

binary semaphore, ISR not yielding to switch

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)

binary semaphore, ISR not yielding to switch

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