FreeRTOS 7.4 :: LWIP :: configASSERT(xInsideISR == (portBASE_TYPE) 0);

xdan01 wrote on Friday, November 15, 2013:

Hello,

i am using lwip 1.4.1 and FreeRTOS 7.4. in sys_arch.c i am getting this assert:

configASSERT(xInsideISR == (portBASE_TYPE) 0); (full code below). So im asking why is that happened ?

I am rookie at these staff so be patient :slight_smile:

If anyone can help :slight_smile:

Full code:

u32_t sys_arch_mbox_fetch(sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut)

{

void *pvDummy;

portTickType xStartTime, xEndTime, xElapsed;

unsigned long ulReturn;

xStartTime = xTaskGetTickCount();

if(NULL == ppvBuffer) {

ppvBuffer = &pvDummy;

}

if(ulTimeOut != 0UL) {

configASSERT(xInsideISR == (portBASE_TYPE) 0);

if(pdTRUE == xQueueReceive(*pxMailBox, &(*ppvBuffer), ulTimeOut / portTICK_RATE_MS)) {

xEndTime = xTaskGetTickCount();

xElapsed = (xEndTime - xStartTime) * portTICK_RATE_MS;

ulReturn = xElapsed;

} else {

/* Timed out. */

*ppvBuffer = NULL;

ulReturn = SYS_ARCH_TIMEOUT;

}

} else {

while(pdTRUE != xQueueReceive(*pxMailBox, &(*ppvBuffer), portMAX_DELAY));

xEndTime = xTaskGetTickCount();

xElapsed = (xEndTime - xStartTime) * portTICK_RATE_MS;

if(xElapsed == 0UL) {

xElapsed = 1UL;

}

ulReturn = xElapsed;

}

return ulReturn;

}

rtel wrote on Friday, November 15, 2013:

I didn’t realise you posted the question here too. Here is a copy of the reply I just sent to the lwIP mailing list;

configASSERT(xInsideISR == (portBASE_TYPE) 0); (full code below). So im asking why is that happened ?

I am rookie at these staff so be patient :slight_smile:

If anyone can help :slight_smile:

Full code:

if(pdTRUE == xQueueReceive(*pxMailBox, &(*ppvBuffer), ulTimeOut / portTICK_RATE_MS)) {

I’m not sure which code you are basing your project on, or where the
xInsideISR variable is getting set, but if the code really is being
called from inside an interrupt then the assert is quite right to stop
you. The line above (and several other lines in your post) have two
issues for use in an interrupt:

  1. FreeRTOS maintains a separate API for use inside and outside
    interrupts. This is for several reasons, but in summary, it means you
    don’t need any special code when entering an interrupt, you don’t need
    to count nesting, and both the code intended for use in an interrupt and
    outside of an interrupt can be optimised for their single purpose. Only
    FreeRTOS API functions that end in “FromISR” can be used in an interrupt.

  2. It just makes no program flow/sequencing sense to define a block time
    when you are inside an interrupt.

In any case, generally it is best to get out of the interrupt as quickly
as you can, and defer processing to a task. The simple Ethernet driver
on the link below is an example of how that is done. The interrupt uses
an xSemaphoreGiveFromISR() function to unblock a task, then requests a
yield if the task unblocked by the semaphore has a higher priority than
the task the interrupt interrupted. That way, the code still runs as
the very next thing, as if it were actually executed in the interrupt,
but it is actually executed in a task.

http://goo.gl/iubh1m -> see the ETH_Handler() interrupt handler and the
prvEMACDeferredInterruptHandlerTask() task definition.

xdan01 wrote on Friday, November 15, 2013:

Hm. Thank you very much for the answer! Am I doing something wrong ?

I dont see any staff used from FreeRTOS here. My sources are from FreeRTOS Plus Demo 2. There is used LwIP as for example. Do I need some to adjust ? Thank you for replay.

I have this:

  • LWIP src/lwIP/netif/ethernetif.c ENET_IRQHandler

Which have:

void ENET_IRQHandler(void)
{
uint32_t ulInterruptCause;
extern volatile portBASE_TYPE xInsideISR;
struct pbuf *p;
struct eth_hdr *pxHeader;

xInsideISR++;

while((ulInterruptCause = LPC_EMAC->IntStatus) != 0) {
/* Clear the interrupt. */
LPC_EMAC->IntClear = ulInterruptCause;

/* Clear fatal error conditions.  */
if((ulInterruptCause & EMAC_INT_TX_UNDERRUN) != 0U) {
  LPC_EMAC->Command |= EMAC_CR_TX_RES;
}

if((ulInterruptCause & EMAC_INT_RX_DONE) != 0UL) {
  /* A packet has been received. */
  if(EMAC_CheckReceiveIndex() != FALSE) {
    if(EMAC_CheckReceiveDataStatus(EMAC_RINFO_LAST_FLAG) == SET) {
      /* move received packet into a new pbuf */
      p = prvLowLevelInput();

      /* no packet could be read, silently ignore this */
      if(p != NULL) {
        /* points to packet payload, which starts with an Ethernet header */
        pxHeader = p->payload;

        switch(htons(pxHeader->type)) {
            /* IP or ARP packet? */
          case ETHTYPE_IP:
          case ETHTYPE_ARP:
            /* Full packet send to tcpip_thread to process */
            configASSERT(pxNetIfInUse);
            if(pxNetIfInUse->input(p, pxNetIfInUse) != ERR_OK) {
              LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
              pbuf_free(p);
              p = NULL;
            }
            break;

          default:
            pbuf_free(p);
            p = NULL;
            break;
        }
      } else {
    	  return;
        //configASSERT((volatile void *) NULL);
      }
    }

    /* Release the frame. */
    EMAC_UpdateRxConsumeIndex();
  }
}

if((ulInterruptCause & EMAC_INT_TX_DONE) != 0UL) {
  /* Nothing to do here. */
}

}

xInsideISR–;
}