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

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