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

[More about co-routines]

FreeRTOS Demo Application Examples

Two files are included in the download that demonstrate using co-routines with queues:
  1. crflash.c

    This is functionally equivalent to the standard demo file flash.c but uses co-routines instead of tasks. In addition, and just for demonstration purposes, instead of directly toggling an LED from within a co-routine (as per the quick example above) the number of the LED that should be toggled is passed on a queue to a higher priority co-routine.

  2. crhook.c

    Demonstrates passing data from a interrupt to a co-routine. A tick hook function is used as the data source.

The PC and one of the older ARM Cortex-M3 demo applications are already pre-configured to use these sample co-routine files and can be used as a reference. All the other demo applications are configured to use tasks only, but can be easily converted to demonstrate co-routines by following the procedure below. This replaces the functionality implemented within flash.c with that implemented with crflash.c:

  1. In FreeRTOSConfig.h set configUSE_CO_ROUTINES and configUSE_IDLE_HOOK to 1.
  2. In the IDE project or project makefile (depending on the demo project being used):

    1. Replace the reference to file FreeRTOS/Demo/Common/Minimal/flash.c with FreeRTOS/Demo/Common/Minimal/crflash.c.
    2. Add the file FreeRTOS/Source/croutine.c to the build.
  3. In main.c:

    1. Include the header file croutine.h which contains the co-routine macros and function prototypes.
    2. Replace the inclusion of flash.h with crflash.h.
    3. Remove the call to the function that creates the flash tasks vStartLEDFlashTasks() ....
    4. ... and replace it with the function that creates the flash co-routines vStartFlashCoRoutines( n ), where n is the number of co-routines that should be created. Each co-routine flashes a different LED at a different rate.
    5. Add an idle hook function that schedules the co-routines as:
          void vApplicationIdleHook( void )
              vCoRoutineSchedule( void );
      If main() already contains an idle hook then simply add a call to vCoRoutineSchedule() to the existing hook function.

  4. Replacing the flash tasks with the flash co-routines means there are at least two less stacks that need allocating and less heap space can therefore be set aside for use by the RTOS scheduler. If your project has insufficient RAM to include croutine.c in the build then simply reduce the definition of portTOTAL_HEAP_SPACE by ( 2 * portMINIMAL_STACK_SIZE ) within FreeRTOSConfig.h.

[ 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