Freertos stuck in vTaskDelay with Nios II port

vasuviroja wrote on Wednesday, April 11, 2018:

I am using Nios II with freerots. I am using Enhanced mode interrupt API of Nios. I have changed port.c file accordingly. Freertos is working correctly while not using vTaskDelay() function. But if I call vTaskDelay then it will never return.

rtel wrote on Wednesday, April 11, 2018:

Do you just end up in the Idle task and stay there? If so, the first
thing to check is that the tick interrupt is executing as you expect.
If the tick is not incrementing the time then the delay period will
never expire.

Had a similar issue. Found that there was a bug in the Nios alt_irq_handler.c file. Basically, the handler can get stuck in a loop. This chunk of code:

     do
     {
       if (active & mask)
       { 
         alt_irq[i].handler(alt_irq[i].context, i); 
         break;
       }
       mask <<= 1;
       i++;
 
     } while (1);

The “while (1)” is the problem. This section will loop forever, even after the “1” token has been long-ago shifted out of “mask.” Fix this by substituting:
} while (mask);
The loop will only persist while the mask variable has a “1” in it somewhere.

Thank you for taking time to report your solution.