Quality RTOS & Embedded Software

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


Loading

Scheduling

Posted by keick on July 16, 2012
Pardon the brevity of this post, I wrote up a fairly length discussion only to have it flagged as SPAM; which instead of letting me just log in decided to just delete all my work.

In vxWorks I could have n tasks all blocked on the same rate semaphore, and have a 'scheduler' task reset the rate semaphore causing all blocked tasks to become ready at which point they'd run in priority order. The biggest benefit was the 'scheduler' task didn't have to know how many tasks were in the system, just when to release which rates.

How would I do something similar in freertos? I bought the PDFs hoping they would have the solution (it didn't). The examples in the book barely discuss dealing with more than one task. If I only had 1-2 tasks I wouldn't need an OS.

The queue API specifically says it only release ONE reader on a block, which isn't good. And since semaphores seems to be 2nd class citizens they suffer the same unfortunate fate.

Ideas?

RE: Scheduling

Posted by Richard Damon on July 17, 2012
One way to active this is to have a list of semaphores to be signaled when the time comes, and rather than signal just one, run a loop and signal the whole list. If you need to do this a lot, it shouldn't be hard to write a simple set of routines to manage this, adding the feature as a layer above the FreeRTOS kernel. The fact that is can be easily done as a user routine may be one reason the capability isn't built into the core of FreeRTOS.

RE: Scheduling

Posted by keick on July 17, 2012
I guess my one concern, and maybe it really isn't, is that triggering the semaphores in a loop isn't atomic. I'll also have to setup an framework for everyone to share the semaphores that each task wants triggered if I truly want a decoupled system.

I know what I did in vxWorks was more of a trick than a feature, but I've looked at other APIs and it seems that doing a reset on a semaphore is common, and it may have come from posix.

RE: Scheduling

Posted by Richard Damon on July 17, 2012
If you want the operation atomic, then just disable the scheduler before signaling all the semaphores, then re-enable it after, then no task can interfere with the process by being started when it is signaled.

RE: Scheduling

Posted by Richard on July 17, 2012
It is not always a good idea to call API functions with the scheduler disabled (depends on the API function itself), but you can temporarily raise the task priority to the highest in the system during the operation, then lower it back to its original priority afterwards.

Regards.

RE: Scheduling

Posted by keick on July 17, 2012
I started digging into the code and thought I could implement my own semFlush operation. It seems to simple to work, but I haven't had a chance to try it. Will this actually put all the waiting tasks into the ready state?

/*
* Custom SemaphoreFlush() function; Used to release ALL blocked tasks waiting on a semaphore.
*/
void vSemaphoreFlush( xSemaphoreHandle xSemaphore ) {
portSHORT higherPriorityTaskFlushed = pdFALSE;

//Release all tasks trying to take the semaphore
taskENTER_CRITICAL();
while( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToReceive ) ) == pdFALSE )
{
higherPriorityTaskFlushed != xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) );
}
taskEXIT_CRITICAL();

//If any of the tasks release have a higher priority than the currently running task then switch
if( higherPriorityTaskFlushed == pdTRUE )
{
/* The unblocked task has a priority higher than our own so yield immediately.*/
portYIELD_WITHIN_API();
}
}


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

Xilinx Microblaze and Zynq partner