task not resumed after taskswitch

wacko_eddie wrote on Friday, April 07, 2006:

I have freertos 4.0.0 with the lwip tcp/ip stack version 1.1.1. I have a task that gets a website from a sd-card on a request on port 80 and sends it to the client. I’m using the at91sam7x256 port for rowley commandline.

The webserver task at random points stops sending data to the client. Sometimes it stops after sending a few KB and sometimes after a few MB.

Besides this task there is the errorcheck and the tcp/ip stack task. Those both stay alive. The led keeps flashing and my board is still pingable.

I’ve found that my webserver fails in this function:
signed portBASE_TYPE xQueueReceive( xQueueHandle pxQueue, void *pvBuffer, portTickType xTicksToWait )

When calling the taskYIELD(); function.

The taskYIELD function is a define of portYIELD();, which is a define for asm volatile ("SWI");
SWI is the assembly instruction for the software interrupt.

At this point the os wil switch to a task with a higher priority wich has something to do. After that it wil never handle my webservertask again.
The task is still visible in the tasklist.

nobody wrote on Friday, April 07, 2006:

I presume it is calling taskYIELD() in xQueueReceive because it is blocking on the queue to wait for data to become available?

If so, is any data posted to the queue ever again?  Maybe the problem is with the data source, rather than the task receiving the data.

wacko_eddie wrote on Monday, April 10, 2006:

hmm strange thing… the more debug info I put out through the uart the more stable the webserver becomes. Is there any logic?

wacko_eddie wrote on Tuesday, April 11, 2006:

Okay finaly making progress. While debugging with the tasklist over the uart I saw that the stack of
the webeserver task decreased. After increasing the stack at init from 250 to 500 it remained stable. But it didn’t yet solve the problem. \

What happend was that after the taskyield it came in a timout loop. In the file sys.c of the ip-stack. in the function sys_mbox_fetch(…)
I implemented a counter which after 2 timeouts leaps out of this function. This solves the hanging.

void sys_mbox_fetch2(sys_mbox_t mbox, void **msg)
{
     u32_t time;
     struct sys_timeouts *timeouts;
    struct sys_timeout *tmptimeout;
    sys_timeout_handler h;
    void *arg;
    u8_t iCounter = 0;

again:
    timeouts = sys_arch_timeouts();
   
    if (!timeouts || !timeouts->next)
    {
               
        sys_arch_mbox_fetch(mbox, msg, 0);
    }
    else
    {
       
        if (timeouts->next->time > 0)
        {
            time = sys_arch_mbox_fetch2(mbox, msg, timeouts->next->time);
        }
        else
        {
            time = SYS_ARCH_TIMEOUT;
        }
   
        if (time == SYS_ARCH_TIMEOUT)
        {
          /* If time == SYS_ARCH_TIMEOUT, a timeout occured before a message
        could be fetched. We should now call the timeout handler and
        deallocate the memory allocated for the timeout. */
           
            tmptimeout = timeouts->next;
            timeouts->next = tmptimeout->next;
            h = tmptimeout->h;
            arg = tmptimeout->arg;
            memp_free(MEMP_SYS_TIMEOUT, tmptimeout);
            if (h != NULL)
            {
                LWIP_DEBUGF(SYS_DEBUG, ("smf calling h=%p(%p)\n", (void *)h, (void *)arg));
                h(arg);
            }
            /* We try again to fetch a message from the mbox. */
            iCounter++;
            if(iCounter < 2)
                goto again;
        }
        else
        {
            /* If time != SYS_ARCH_TIMEOUT, a message was received before the timeout
            occured. The time variable is set to the number of
            milliseconds we waited for the message. */
            if (time <= timeouts->next->time)
            {
                timeouts->next->time -= time;
            }
            else
            {
                //AT91C_BASE_PIOB->PIO_CODR = LED3;
                timeouts->next->time = 0;
            }
        }
    }
}

nobody wrote on Tuesday, April 11, 2006:

Stack issues again :wink:

Maybe take a look at the lwIP mail list for answers to your timeout problem?

wacko_eddie wrote on Tuesday, April 11, 2006:

Yes indeed that was part of it. But mainly the timeout caused the hanging and I worked around that.

So if you’re the one pointing out to me to check the stack. Thanks for your assistance