Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

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. */
vTaskSuspendAll();
{
    /* 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;
        }

        xTaskResumeAll();
        xSemaphoreTake( pxEventGroup->xWaitQueue, xTicksToWait );
        vTaskSuspendAll();

        /* 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 = ...
    }
    else
    {
        xResult = 0ul;
    }
}
xTaskResumeAll();
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. */
vTaskSuspendAll();
{
    /* The value returned is the event group value prior to the bits being
    cleared. */
    uxReturn = pxEventGroup->uxEventBits;

    /* Clear the bits. */
    pxEventGroup->uxEventBits &= ~uxBitsToClear;
}
xTaskResumeAll();

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.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




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.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists