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

cooperative vs preemptive

Posted by Nobody/Anonymous on January 15, 2005
Hi, is ther a configuration maro for cooperative/ preemptive compilation? If I need only coperative OS, will it take less ram and rom?

RE: cooperative vs preemptive

Posted by Richard on January 15, 2005
See the page:

http://www.FreeRTOS.org/a00132.html

Also, most ports have a macro portUSE_PREEMPTION. This can be found near the top of the portmacro.h file for the port you are using (described on the port documentation page). It is best to set portUSE_PREEMPTION to either 1 or 0 (to use preemptive or cooperative respectively), and then pass this macro to vTaskStartScheduler(). For example:

[in portmacro.h]
#define portUSE_PREEMPTION 1

[in your application source code]
vTaskStartScheduler( portUSE_PREEMPTION );


The amount of RAM and ROM used depends on how many tasks you create, not which scheduler is used. However, the scheduler processing overhead is less with the cooperative scheduler.

If RAM usage is important then consider how you create tasks. Each task requires its own stack so the fewer tasks the less RAM is required.

For example, if your application has one periodic function that must run with very regular frequency, and a few other functions that can be considered 'background' then:

Option 1:
You can create one task for each function and use preemptive scheduling. The periodic task has the highest priority to ensure it meets its timing requirements. This gives the simplest design but uses the most RAM.

Option 2:
You can create a high priority task for the periodic function, and a single low priority task for the other functions and use the preemptive scheduler. The low priority task would contain some kind of loop that loops through all the background functions. Whenever the periodic function needed to execute the background function task would be preempted. This option uses less RAM as there are less tasks, but still maintains the timing requirements of the periodic task. Provided your background functions never block you could even add them to the Idle task - saving even more RAM.

Option 3:
This is a hybrid option. It is the same as option 2, but using the cooperative scheduler. If the periodic task can be signalled by an interrupt then you can perform a context switch to the periodic task from the interrupt handler even though the cooperative scheduler is being used.

There will be some more WEB documentation on this very subject appearing in the next week or so.

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