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

waiting on semaphores - indefinitely

Posted by spreet on December 18, 2007
1. To wait indefinitely, one needs to use:
xSemaphoreTake( xSemaPhore, portMAX_DELAY );
Also, the configuration #define INCLUDE_vTaskSuspend1
has to be set to 1.
What is the relationship between the two?
Is portMax_DELAY not enough in itself?

2. Documentation on xSemaphoreCreateMutex() in semaphor.h is confusing
It is defined as:
#define xSemaphoreCreateMutex() xQueueCreateMutex()
where as the explanation calls for:
xSemaphoreCreateMutex( xSemaphoreHandle xSemaphore )
and the usage is:
XMutex = xSemaphoreCreateMutex();

3. What is the difference between binary semaphore and mutex -
If taskA takes a semaphore xSemaphoreTake( xSema1, portMAX_DELAY );
and not give, can TaskB get the xSema1 or will it go into waiting for the sema till it is given back by taskA?





RE: waiting on semaphores - indefinitely

Posted by Richard on December 18, 2007
> 1. To wait indefinitely, one needs to use:
> xSemaphoreTake( xSemaPhore, portMAX_DELAY );
> Also, the configuration #define INCLUDE_vTaskSuspend
> 1
> has to be set to 1.
> What is the relationship between the two?
> Is portMax_DELAY not enough in itself?


Including INCLUDE_vTaskSuspend causes a new state list to be included - one in which suspended tasks are referenced (not surprisingly). Suspended tasks differ from blocked tasks as they do not have a timeout. If this list was not included in the build then the only option is to place tasks in a blocked list, from which it would eventually unblock. On 32bit systems unblocking after 0xffffffff ticks is usually very similar to blocking indefinitely anyway.

The suspended list is used for convenience only - tasks that are blocked indefinitely remain conceptually in the blocked state - not the suspended state.

If you don't want to use INCLUDE_vTaskSuspend then you have the option to place calls in a loop, for example:

while( xSemaphoreTake( xSemaphore, portMAX_DELAY ) != pdPASS );

has the same effect as waiting indefinitely, if a little less efficient.



>
> 2. Documentation on xSemaphoreCreateMutex() in semaphor.h is
> confusing
> It is defined as:
> #define xSemaphoreCreateMutex() xQueueCreateMutex()
> where as the explanation calls for:
> xSemaphoreCreateMutex( xSemaphoreHandle xSemaphore )
> and the usage is:
> XMutex = xSemaphoreCreateMutex();


Err - its even worse on the WEB site. I will fix this. Thought it had been already.

For now take a look in FreeRTOS/Demo/Common/Minimal/GenQTest.c for an example usage.



> 3. What is the difference between binary semaphore and mutex -
> If taskA takes a semaphore xSemaphoreTake( xSema1, portMAX_DELAY );
> and not give, can TaskB get the xSema1 or will it go into
> waiting for the sema
> till it is given back by taskA?


The primary difference is that mutexes use priority inheritance, binary semaphores don't. This means mutexes must always be 'given back', whereas binary semaphores can be used for unidirectional synchronisation, with an ISR for example, where the semaphore is always given by the ISR and always taken by a task and never the other way around.

Regards.

RE: waiting on semaphores - indefinitely

Posted by Richard on December 18, 2007
The WEB docs should now be correct (?), I have also updated the SVN copy of semphr.h.

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