Quality RTOS & Embedded Software

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




Loading

PIC18F4550, taskYIELD() and queueing broken

Posted by Giorgis Georgakoudis on March 23, 2009
I'm using the FreeRTOS v5.0.0 with a PIC18 mcu and the MPLAB building toolchain.

I have two tasks, with the same priority (tskIDLE_PRIORITY + 1). Task T1 sends a message every two seconds (using vTaskDelayUntil) to a Queue and Task T2 receives this message from the Queue using a blocking xQueueReceive (meaning porTMAX_DELAY is used as blocking time and vTaskSuspend support is enabled) and sends it over the serial.

System hangs for some reason Monitoring what happens the execution sequence until system stops is:

1) T2 starts execution and blocks waiting for a message to arrive at the Queue
2) T1 starts execution, successfully waits for two seconds and then calls XQueueSend

System is hanged!

I've pinpointed the problem on using taskYIELD() inside the critical section of xQueueGenericSend(). When T2 is removed from the event list, xTaskRemoveFromEventList() returns pdTRUE because both tasks have the same priority (it's supposed to return true if the unblocked task has higher priority but it works the same way for equal priorities too). The taskYIELD() following for some reasons fails. Any ideas? I'm still looking out why this is happening. If I comment out taskYIELD() everything works fine.

ggeorgak

RE: PIC18F4550, taskYIELD() and queueing broken

Posted by Samuel Tardieu on March 23, 2009
Just to answer the part on trying to switch to the receiving task when it has the same priority as the sending task: I wouldn't want to second-guess Richard's intent here, but this is probably just an optimization (which is also done in the Erlang language runtime when one Erlang process sends a message to another one if I remember correctly). If two tasks do have the same priority, the scheduler is free to choose which one to execute. If one of them is trying to get a message from a queue, it is often more efficient to schedule it so that one place in the queue can be freed.

This optimization reduces the chance of later having a higher priority task block because it wants to write into the queue, thus causing a priority inversion. It's generally best to have empty queues than full ones.

RE: PIC18F4550, taskYIELD() and queueing brok

Posted by Richard on March 23, 2009
Could it simply be a stack overflow?

Regards.


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

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

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

OpenRTOS and SafeRTOS