Two files are included in the download that demonstrate using co-routines with queues:
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.
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:
- In FreeRTOSConfig.h set configUSE_CO_ROUTINES and configUSE_IDLE_HOOK to 1.
- In the IDE project or project makefile (depending on the demo project being used):
- Replace the reference to file FreeRTOS/Demo/Common/Minimal/flash.c with FreeRTOS/Demo/Common/Minimal/crflash.c.
- Add the file FreeRTOS/Source/croutine.c to the build.
- In main.c:
- Include the header file croutine.h which contains the co-routine macros and function prototypes.
- Replace the inclusion of flash.h with crflash.h.
- Remove the call to the function that creates the flash tasks vStartLEDFlashTasks() ....
- ... 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.
- 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.
- 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) 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.