/* Bits used by the three tasks. */ #define TASK_0_BIT ( 1 << 0 ) #define TASK_1_BIT ( 1 << 1 ) #define TASK_2_BIT ( 1 << 2 ) #define ALL_SYNC_BITS ( TASK_0_BIT | TASK_1_BIT | TASK_2_BIT ) /* Use an event group to synchronise three tasks. It is assumed this event group has already been created elsewhere. */ EventGroupHandle_t xEventBits; void vTask0( void *pvParameters ) { EventBits_t uxReturn; TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS; for( ;; ) { /* Perform task functionality here. */ . . . /* Set bit 0 in the event group to note this task has reached the sync point. The other two tasks will set the other two bits defined by ALL_SYNC_BITS. All three tasks have reached the synchronisation point when all the ALL_SYNC_BITS are set. Wait a maximum of 100ms for this to happen. */ uxReturn = xEventGroupSync( xEventBits, TASK_0_BIT, ALL_SYNC_BITS, xTicksToWait ); if( ( uxReturn & ALL_SYNC_BITS ) == ALL_SYNC_BITS ) { /* All three tasks reached the synchronisation point before the call to xEventGroupSync() timed out. */ } } } void vTask1( void *pvParameters ) { for( ;; ) { /* Perform task functionality here. */ . . . /* Set bit 1 in the event group to note this task has reached the synchronisation point. The other two tasks will set the other two bits defined by ALL_SYNC_BITS. All three tasks have reached the synchronisation point when all the ALL_SYNC_BITS are set. Wait indefinitely for this to happen. */ xEventGroupSync( xEventBits, TASK_1_BIT, ALL_SYNC_BITS, portMAX_DELAY ); /* xEventGroupSync() was called with an indefinite block time, so this task will only reach here if the syncrhonisation was made by all three tasks, so there is no need to test the return value. */ } } void vTask2( void *pvParameters ) { for( ;; ) { /* Perform task functionality here. */ . . . /* Set bit 2 in the event group to note this task has reached the synchronisation point. The other two tasks will set the other two bits defined by ALL_SYNC_BITS. All three tasks have reached the synchronisation point when all the ALL_SYNC_BITS are set. Wait indefinitely for this to happen. */ xEventGroupSync( xEventBits, TASK_2_BIT, ALL_SYNC_BITS, portMAX_DELAY ); /* xEventGroupSync() was called with an indefinite block time, so this task will only reach here if the syncrhonisation was made by all three tasks, so there is no need to test the return value. */ } }
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
|