Quality RTOS & Embedded Software

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


Co-routines
[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 ]    [ 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