# Queues with portMAX\_DELAY on NIOS not working

**URL:** <https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388>\
**Category:** Kernel\
**Created:** [August 13, 2010, 1:04am UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388 "2010-08-13T01:04:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 13, 2010, 1:04am UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388/1 "2010-08-13T01:04:15Z")

</div>

**[robertklem](https://sourceforge.net/u/robertklem/)** wrote on [Friday, August 13, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/1064e586/#4f84):

I am having problems getting message queues to work propery.&nbsp; I have Task1 which sends a message to a queue, and then suspends.&nbsp; I have Task2 do the same.&nbsp; I have Task3 looping on recieve from the queue.&nbsp; All Queues are set to priority 0.

If I use xStatus = xQueueReceive(QueuePtrList, &ReceiveMessage, 100); I can get it to loop and print messages indicating that it read both messages that were sent.

If I use xStatus = xQueueReceive(&QueuePtrList, &ReceiveMessage, portMAX\_DELAY); It appears the receive never triggers.&nbsp; I do have the indicaction from Task1 that there were 2 items onthe queue before it suspended.

My understanding from the documentaion is that when using portMAX\_DELAY, the xQueueReceive() should remain blocked until the Queue is not empty.&nbsp; (I do have INCLUDE\_vTaskSuspend set to 1 per the documentation)

Interrupts appaer to be working the whole time in both scenerios.

Does anyone have any suggestions?… Or has anyone been able to get the NIOS port working with indefinitley blocked receive queues?

-Bob

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [August 13, 2010, 5:37am UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388/2 "2010-08-13T05:37:43Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Friday, August 13, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/1064e586/#f8de):

Somebody recently reported an issue (and kindly provided a fix) for NIOS when optimisation is set to be high.&nbsp; Are you using optimisation?

See [https://sourceforge.net/tracker/?func=detail&atid=659633&aid=3037968&group\_id=111543](https://sourceforge.net/tracker/?func=detail&atid=659633&aid=3037968&group_id=111543)

Regards.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 13, 2010, 7:45pm UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388/3 "2010-08-13T19:45:29Z")

</div>

**[robertklem](https://sourceforge.net/u/robertklem/)** wrote on [Friday, August 13, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/1064e586/#75d3):

My compiler uses -O0 (Do not optimize) so that is not the problem.

I did elaborate on my test and added a Task4 that would just print a message every 5 seconds.&nbsp; It (as all other tasks) is running at task priority 0.

Task 1 will delay 3 seconds before sending its message and suspending.

Task 2 will delay 6 seconds before sending its message and suspending.

Task 3 will still start at T0, but I change the block to be 30 seconds.

Below are the results of my testing.&nbsp; The first set looks as I would expect with a 30 block time.&nbsp; It triggers immediately after a message is sent or after 30 seconds of the last message that was sent.

The second set of results only changed the block time from 30000 to portMAX\_DELAY (0xFFFFFFFF).&nbsp; Once receive is called, all tasks stop running.

Again, all interrupts appear to be working as they are toggling LEDs at their expected rates.

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\* Results of wait for 30 seconds (looks good)  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TSK3: \<\<\< Calling Receive \>\>\>  
Rcv:&nbsp; Tasks on Que3: 0&nbsp;  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
Rcv:&nbsp; Calling\_TID = 7a, xTicksToWait = 30000  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK1:  
TSK1: \<\<\< Calling send \>\>\>  
SND:&nbsp; Tasks on Que3: 1  
TSK1: \<\<\< Message sent \>\>\>  
Rcv: TX\_SUCCESS  
TSK3: \*\*\*Data ==\>&nbsp; Message from TSK1…  
TSK3: \<\<\< Calling Receive \>\>\>  
Rcv:&nbsp; Tasks on Que3: 0&nbsp;  
Rcv:&nbsp; Calling\_TID = 7a, xTicksToWait = 30000  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK2:  
TSK2: \<\<\< Calling send \>\>\>  
SND:&nbsp; Tasks on Que3: 1  
TSK2: \<\<\< Message sent \>\>\>  
Rcv: TX\_SUCCESS  
TSK3: \*\*\*Data ==\>&nbsp; Message from TSK2…  
TSK3: \<\<\< Calling Receive \>\>\>  
Rcv:&nbsp; Tasks on Que3: 0&nbsp;  
Rcv:&nbsp; Calling\_TID = 7a, xTicksToWait = 30000  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
Rcv: TX\_QUEUE\_EMPTY  
TSK3: Queue Cnt = \<\<\< 0 \>\>\>  
TSK3: \<\<\< Calling Receive \>\>\>  
Rcv:&nbsp; Tasks on Que3: 0&nbsp;  
Rcv:&nbsp; Calling\_TID = 7a, xTicksToWait = 30000  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
\*\* Rusults of wait forever (Hangs)  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
TSK3: \<\<\< Calling Receive \>\>\>  
Rcv: Start 7a  
Rcv:&nbsp; Tasks on Que3: 0&nbsp;  
TSK4:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Queue Cnt = \<\<\<\<\< 0 \>\>\>\>\>  
Rcv:&nbsp; Calling\_TID = 7a, xTicksToWait (portMAX\_DELAY)= 0xFFFFFFFF

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 13, 2010, 9:43pm UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388/4 "2010-08-13T21:43:30Z")

</div>

**[robertklem](https://sourceforge.net/u/robertklem/)** wrote on [Friday, August 13, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/1064e586/#b17c):

ADDITIONAL&nbsp;&nbsp; INFORMATION:

Stepping through the code I get to a place in list.c where there is the following code:

if( xValueOfInsertion == portMAX\_DELAY )  
{  
pxIterator = pxList-\>xListEnd.pxPrevious;  
}  
else  
{  
/\* \*\*\* NOTE \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
If you find your application is crashing here then likely causes are:  
1) Stack overflow -  
&nbsp;&nbsp; see [http://www.freertos.org/Stacks-and-stack-overflow-checking.html](http://www.freertos.org/Stacks-and-stack-overflow-checking.html)  
2) Incorrect interrupt priority assignment, especially on Cortex M3  
&nbsp;&nbsp; parts where numerically high priority values denote low actual  
&nbsp;&nbsp; interrupt priories, which can seem counter intuitive.&nbsp; See  
&nbsp;&nbsp; configMAX\_SYSCALL\_INTERRUPT\_PRIORITY on [http://www.freertos.org/a00110.html](http://www.freertos.org/a00110.html)  
3) Calling an API function from within a critical section or when  
&nbsp;&nbsp; the scheduler is suspended.  
4) Using a queue or semaphore before it has been initialised or  
&nbsp;&nbsp; before the scheduler has been started (are interrupts firing  
&nbsp;&nbsp; before vTaskStartScheduler() has been called?).  
See [http://www.freertos.org/FAQHelp.html](http://www.freertos.org/FAQHelp.html) for more tips.  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

for( pxIterator = ( xListItem \* ) &( pxList-\>xListEnd ); pxIterator-\>pxNext-\>xItemValue \<= xValueOfInsertion; pxIterator = pxIterator-\>pxNext )  
{  
/\* There is nothing to do here, we are just iterating to the  
wanted insertion position. \*/  
}  
}

In the case where I passed portMAX\_DELAY into xQueueReceive, It takes the “else” as xValueOfInsertion = 10 (which is where the portMAX\_DELAY was stored).&nbsp; The first time I attempt to step in the FOR loop, my debugger hangs.&nbsp; I have a break point set in vApplicationStackOverflowHook() which is never hit, so I don’t think it is a stack overflow problem.

-Bob

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [August 17, 2010, 4:48pm UTC](https://forums.freertos.org/t/queues-with-portmax-delay-on-nios-not-working/388/5 "2010-08-17T16:48:35Z")

</div>

**[robertklem](https://sourceforge.net/u/robertklem/)** wrote on [Tuesday, August 17, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/1064e586/#707d):

I found the problem….operator error.&nbsp;

Although the only thing that I have changed was the wait value, in the wait forever case I took a slightly different code path where the queue handle became corrupt.&nbsp; The xQueueReceive() was then called with the wrong handle and therefore would not trigger when the queue was written.

I am able to get the xQueueReceive() to work fine when I give it a good handle.

-Bob
