Quality RTOS & Embedded Software

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


Loading

Binary Semaphores - version problem?

Posted by xanderwar on November 18, 2014

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?


Binary Semaphores - version problem?

Posted by davedoors on November 21, 2014

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.


Binary Semaphores - version problem?

Posted by xanderwar on November 24, 2014

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


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

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

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.


Careers

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

Renesas

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