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] [November 2014 Threads]
Hi,
I started working recently with FreeRTOS, and while trying to implement a binary semaphore, I was taking a look at your website for an explanation on how to use it.
In the webpage http://www.freertos.org/xSemaphoreCreateBinary.html it is said that “The semaphore is created in the 'empty' state, meaning the semaphore must first be given before it can be taken (obtained) using the xSemaphoreTake() function.“
I wonder if this function differs from the older “vSemaphoreCreateBinary”, since I noticed that what is written in the website is different than what really happens when creating a binary semaphore.
I’m using an older version of FreeRTOS (v7.5.2) with the function “vSemaphoreCreateBinary” and in fact I must first take the semaphore (and not “give”, as it is said in the website) for it to work in the same way.
For example, as in a version written for Arduino, by William Greiman ( https://github.com/greiman/FreeRTOS-Arduino ), in example 12 from the book, he included the following comment in the code:
~~~~~~
static void vHandlerTask( void pvParameters )
{
/ Note that when you create a binary semaphore in FreeRTOS, it is ready
to be taken, so you may want to take the semaphore after you create it
so that the task waiting on this semaphore will block until given by
another task. */
xSemaphoreTake( xBinarySemaphore, 0);
for( ;; )
{
…
~~~~~~
The same happens with me and I’m not sure if it’s due to the version I’m using (and his version as well).
I checked the examples provided in the FreeRTOS website (standard edition examples) and although there is version v5.0.4 in the description, I noticed that this comment doesn’t exist as well as the call to the function “xSemaphoreTake” before the start of the “for” cycle.
so... in the end, my question is: the behaviour of the semaphores depends on the version/function used, or are the examples and explanations provided in the official website wrong?
I hope my explanation was enough to understand my problem. Could you please clarify this situation?
vSemaphoreCreateBinary() is the old way of creating a binary semaphore and will leave the semaphore in the opposite state to xSemaphoreCreateBinary(). I suspect the API documentation pages for the two functions will tell you how they are used, and the question has been asked a couple of times on the forum already so try searching the archive on the FreeRTOS website.
Thanks for the clarification! It justifies the problem I was having.
I would suggest to update the contents on the API page of vSemaphoreCreateBinary(), as there's no reference to the initial state of the semaphore. I'm pretty sure more people will run into the same problem when using this function, although it should not be used in the recent versions.
Regards
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.