Quality RTOS & Embedded Software

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




Loading

counting semaphores and event flags

Posted by Borut on September 9, 2007
Hello,

i read some time ago a tread about counting semaphores and event flags. Is there something new about event flags and what would be the best way to do the counting semaphore? Thank you.

RE: counting semaphores and event flags

Posted by Borut on September 10, 2007
Anybody?

RE: counting semaphores and event flags

Posted by Richard on September 10, 2007
Sorry for the delay - other people normally respond before me but I guess I'm the only one that can answer this question.

Event flags are not on the radar just yet, although they will be added when time permits. Counting semaphores on the other hand can be implemented easily with some small extensions to the binary semaphore implementation. Binary semaphores are implemented using a queue that can hold 1 item. Taking the semaphore removes the item from the queue, giving the semaphore places the item back in the queue. As there is only space for one item the semaphore is binary. If you created a queue with more spaces, then you have the effect of a counting semaphore.

As an example, if you wanted a counting semaphore of 3, then create the queue with 3 spaces. Three tasks can then 'take' the semaphore before the queue is empty (no more semaphores available).

[see the macro definitions within semphr.h, hopefully you can see how this simple mechanism works]

The V4.5.0 adds a different type of mutex, and some new queue functionality.

Regards.

RE: counting semaphores and event flags

Posted by Borut on September 10, 2007
Thank you. I have also sent you an email before I saw your answer hear. Sorry :) I'm checking that macros for binary semaphore and I'm already working on implementing a macro for couting semaphore. Mutexe is also a great feature and I must just say that the work you do one the kernel is really great. I just wish you won't stop doing it :)

Thanks again.

Borut

RE: counting semaphores and event flags

Posted by Borut on September 17, 2007
Richard,

one question regarding counting semaphores. When semaphore is created all resources are available in the begining. What must I do to have all resouces taken on the semaphore creation? It is very useful to have both options available, let say:

vSemaphoreCreate( xSemaphoreHandleName, 128, 0 ); 128 is the maximum size and 0 means that none of the resources are available.

or

vSemaphoreCreate( xSemaphoreHandleName, 128, 128 ); 128 is the maximum size and 128 means that all of the resources are available.

Thank you very much.

Best regards,

Borut

RE: counting semaphores and event flags

Posted by Dave on September 18, 2007
Just add a loop to 'take' the semaphore the required number of times either from you application code after the semaphore is created, or by extending the macro to do this within the create macro itself. This is what the binary semaphore create macro does, creates the semaphore then takes it before returning.

RE: counting semaphores and event flags

Posted by Borut on September 19, 2007
Is't here an easier solution? Like setting something in the queue's? Or is there too many things to do?

Thank you


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




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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