Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

xQueueReceive never returns

Posted by Gabe on December 15, 2009
We have been trying for a while to track down a particularly nasty problem. At some point during execution one of our tasks fails to ever return from a call to xQueueReceive() in spite of the fact that data has been added to the queue.

Specifically, the task executes at priority 10, and spends most of it's time just waiting to receive data from the queue. An interrupt occurs periodically and calls xQueueSendFromISR() to push data into the queue. At this point the task should resume and process the data, but at some point it just never wakes up.

It is important to note that we changed the critical section code to mask ALL interrupts during critical sections (not just the OS tick). We are using the Pic24 port. We changed the following lines:

In portasm_PIC24.S line 56:
`MOV#224, W0/* changed from 32 to 224 to*/`

In portmacro.h line 90:
`#define portINTERRUPT_BITS( ( unsigned portSHORT ) 7 << ( unsigned portSHORT ) 5 )`

Any suggestions/thoughts/help would be greatly appreciated!

RE: xQueueReceive never returns

Posted by Richard on December 15, 2009
Are you using the stack overflow checking? Could it be an overflow causing the problem?

Regards.

RE: xQueueReceive never returns

Posted by mike costa on December 15, 2009
I'm working with Gabe on the same project. We are checking the stack and it is fine. (we have seen the stack problem before with Queues but that caused an address error). There is no address error this time and we don't hit a breakpoint in the stackcheckhook(). The OS and all other tasks are still running.

RE: xQueueReceive never returns

Posted by Gabe on December 15, 2009
I also noticed that if I pause the debugger at this point the OS is in a very bizarre state. Specifically, the task was successfully added to the ready list, but variable uxTopReadyPriority does not equal 10 (even though it should, since that is the highest priority task ready to run). Has anyone ever seen anything like this before?

RE: xQueueReceive never returns

Posted by mike costa on December 17, 2009
We found that disabling interrupt nesting fixes the problem. We tracked it down to some interrupt is corrupting the ready task list. But I don't see why this would be the case. All our interrupt priorities are set to 1 which is the same priority as the kernel and system tick. I'm glad we at least know what is going on but it does not seem to make sense.

Any ideas?

RE: xQueueReceive never returns

Posted by Gabe on December 17, 2009
We finally figured this out. It appears that even if two interrupts share the same priority they **can** interrupt each other. This can occur only if the interrupt flag has been cleared for the interrupt that is serviced first. This is what was happening with us:

- Timer 3 Interrupt cccurs and the CPU enters the timer 3 ISR
- Timer 3 interrupt flag cleared
- OS tick interrupt occurs in the middle of prvAddTaskToReadyQueue after uxTopReadyPriority had been set, but before vListInsertEnd was called. When the OS tick yields it decrements uxTopReadyPriority down to a low priority.
- When the Timer 3 interrupt is able to run again it adds the high priority task to pxReadyTasksLists
- Now uxTopReadyPriority and pxReadyTasksLists are out of sync. This meant that the high priority task was never woken up again.


All problems were solved by making absolutely sure that all interrupt flags are cleared **after** the last OS call in an interrupt (except for the yield). This ensures that interrupts that use OS functions are never nested.

Alternately you can just disable nested interrupts if you don't need them.

RE: xQueueReceive never returns

Posted by Richard on December 18, 2009
Thanks for taking the time to post the solution.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists