FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [September 2007 Threads] counting semaphores and event flagsPosted 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 flagsPosted by Borut on September 10, 2007 Anybody?
RE: counting semaphores and event flagsPosted 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 flagsPosted 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 flagsPosted 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 flagsPosted 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 flagsPosted 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
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|