Download FreeRTOS

Quality RTOS & Embedded Software

FreeRTOS website now available in Simplified Chinese
New FreeRTOS Long Term Support version now available.
FreeRTOS Extended Maintenance Program (EMP) registration now open.
FreeRTOS-Plus-TCP v3.0.0 released:
Featured FreeRTOS IoT Integrations:

[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.

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