Quality RTOS & Embedded Software

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


2 sources that 'give' the same interrupt

Posted by biker126 on September 28, 2007
hey guys

does anyone know if it is possible to have a semaphore taken by 1 task and given back by 2 different sources?

in the demo's semaphores are used for synchronisation between 1 task and 1 ISR. but i'd like to synchronize a task with TWO ISR's.

so my idea was that the task does a
xSemaphoreTake( xSemaphore, WAIT_TIME);

and ISR1 and ISR2 both do:
xSemaphoreGiveFromISR( xEMACSemaphore, pdFALSE );

but i dont know what happens if the semaphore is currently 'free' and the function above is called... (would be nice if there's a function to check wether the semaphore is in use or not. but afaik there aint such a function).

if there would be event-flags available in freeRTOS i would use that but since there are none i need something different... ;-)

D. Holzwarth

RE: 2 sources that 'give' the same interrupt

Posted by Richard on September 28, 2007
There is no problem in giving from two different locations in this manner.

The xSemaphoreGiveFromISR() would have been better constructed if its return told you whether or not the give was successful.

Binary semaphores are just queues with a length of 1. You could therefore easily write a function/macro to see if the semaphore is currently taken or not - something like the uxQueueMessageWaiting() function, but without the critical section so it can be used from an ISR. For example (untested code):

unsigned portBASE_TYPE uxGetSemaphoreStatusFromISR( xSemaphoreHandle pxSemaphore )
return pxSemaphore->uxMessagesWaiting;

If this returns 0 then the semaphore can be given, but not taken, and visa versa.


RE: 2 sources that 'give' the same interrupt

Posted by biker126 on September 30, 2007
its good to know that you can release a semaphore twice :-)

I solved my current synchronizing problem with a queue tho (instead the semaphore) which is filled by the 2 sources.

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

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

Latest News

Meet us at Embedded World. Hall 3A-525.

Hear from Richard Barry at Embedded World. Feb 28, 16:00, Hall 4-428.

Video: Watch James Gosling & Richard Barry at re:Invent, Las Vegas 2017.

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

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

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