Quality RTOS & Embedded Software

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


Resource management

Posted by Thomas on July 8, 2013

I have a question about mutexes and semaphores.
Is it possible to use a mutex (or semaphore) to control the access to a peripheral within one task?
I want to implement a block data transfer. Therefore I want to generate a mutex which is taken before the data is written to the peripheral. If the peripherals FIFO is empty I want an interrupt service routine to give the mutex back so that the next data can be sent.
I have already tried to implement this behavior but without success.
The xSemaphoreTake(SBP_ClientTxSem, 0x00) function does not block before the mutex was given by the ISR. This produces data loss.
Can anybody help me?


RE: Resource management

Posted by Dave on July 8, 2013
That is the normal way of doing it, but if it is only used by a single task use a binary semaphore instead of a mutex.

In you post the second parameter to xSemaphroeTake() is zero, so the block time is 0 and the function will return right away. If you want to wait for a finite time then set the second parameter to the number of ticks you want to block and check the return value to see if the semaphore was taken (true) or if the call timed out (false).

RE: Resource management

Posted by Thomas on July 9, 2013
Hi davedoors,

thank you for your quick reply.
Unfortunately I misinterpreted the sentence "A block time of zero can be used to poll the semaphore."

It works perfectly.

Thank you

[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]

Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.


FreeRTOS and other embedded software careers at AWS.

Latest News

FreeRTOS kernel V10.0.1 is available for immediate download. Now MIT licensed.

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

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