Quality RTOS & Embedded Software

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


FreeRTOS Event groups

Posted by lciummo on September 11, 2015

I've have to port several Freescale SDK drivers that make use of Event Groups to SafeRTOS, which doesn't support Events. I can complete remove the event bit code and replace it with semaphore OR I can type to emulate event bits in an OSAL function.

Any ideas and issues with removing them would be appreciated.

Thanks Larry

FreeRTOS Event groups

Posted by heinbali01 on September 12, 2015

Hi Larry,

That is an interesting challenge!

It depends on the way in which Event Groups are being used by the Freescale SDK drivers. Some properties of the Event Groups are much more difficult to simulate than others.

Simplicity: the simulation of Event Groups would be easier if you have the following limitations:

  • event groups are not being accessed from an interrupt
  • there is one Taker ( a task constantly calling xEventGroupWaitBits() )
  • there are many Givers ( calling xEventGroupSetBits() ).

In that case, I would store the following information in a struct:

~~~~~ typedef struct { /* The event bits. / EventBits_t uxEventBits; / Information about the waiting task. */ QueueHandlet xWaitQueue; EventBitst uxBitsToWaitFor; } EventGroupInfo_t;


Here below a rough scatch. it is far from safe and it is far from complete. Please make a study of the existing event_groups.c to understand the exact functioning.

~~~~~ /* The xEventGroupWaitBits() function. */ EventBitst xEventGroupWaitBits( EventGroupInfot *pxEventGroup, const EventBitst uxBitsToWaitFor, const BaseTypet xClearOnExit, const BaseTypet xWaitForAllBits, TickTypet xTicksToWait ) { EventBitst xResult; BaseTypet xWaitConditionMet;

/* Suspend the scheduler, or use taskENTER_CRITICAL() in
case the Event Groups are accessible from an interrupt. */
    /* Source code of prvTestWaitCondition() : see event_groups.c ) */
    xWaitConditionMet = prvTestWaitCondition( pxEventGroup->uxEventBits,
        uxBitsToWaitFor, xWaitForAllBits );

    if( xWaitConditionMet == pdFALSE )
        /* This API is about to block until the condition has been met,
        or until a time-out has been reached.  Tell what it is waiting for. */
        pxEventGroup->uxBitsToWaitFor = uxBitsToWaitFor;
        if( xWaitForAllBits != pdFALSE )
            pxEventGroup->uxBitsToWaitFor |= eventWAIT_FOR_ALL_BITS;

        xSemaphoreTake( pxEventGroup->xWaitQueue, xTicksToWait );

        /* We're not waiting any more. */
        pxEventGroup->uxBitsToWaitFor = 0;

        /* Now test again of the conditions are met. */
        xWaitConditionMet = prvTestWaitCondition( pxEventGroup->uxEventBits,
            uxBitsToWaitFor, xWaitForAllBits );
    if( xWaitConditionMet != pdFALSE )
        /* Apply 'xClearOnExit', if set. */
        xResult = ...
        xResult = 0ul;
return xResult;


EventBitst xEventGroupSetBits( EventGroupInfot pxEventGroup, const EventBits_t uxBitsToSet ) { / Set the bits from 'uxBitsToSet'. / / If the condition has been reached, wake up the Waiter: */ if( conditionismet... ) { SemaphoreGive( pxEventGroup->xWaitQueue );
} }

EventBitst xEventGroupClearBits( EventGroupInfot *pxEventGroup, const EventBitst uxBitsToClear ) { EventBitst uxReturn;

/* Suspend the scheduler, or use taskENTER_CRITICAL() if necessary. */
    /* The value returned is the event group value prior to the bits being
    cleared. */
    uxReturn = pxEventGroup->uxEventBits;

    /* Clear the bits. */
    pxEventGroup->uxEventBits &= ~uxBitsToClear;

return uxReturn;



Once again: the above code is far from correct and far from complete. The simulation misses the most important aspect of FreeRTOS' Event Groups: several tasks waiting for the same event group.


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

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.


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


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