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




xSemaphoreGiveFromISR
[Semaphores]

semphr. h
xSemaphoreGiveFromISR ( SemaphoreHandle_t xSemaphore, signed BaseType_t *pxHigherPriorityTaskWoken )

Macro to release a semaphore. The semaphore must have previously been created with a call to xSemaphoreCreateBinary() or xSemaphoreCreateCounting().

Mutex type semaphores (those created using a call to xSemaphoreCreateMutex()) must not be used with this macro.

This macro can be used from an ISR.

Parameters:
xSemaphore A handle to the semaphore being released. This is the handle returned when the semaphore was created.
pxHigherPriorityTaskWoken xSemaphoreGiveFromISR() will set *pxHigherPriorityTaskWoken to pdTRUE if giving the semaphore caused a task to unblock, and the unblocked task has a priority higher than the currently running task. If xSemaphoreGiveFromISR() sets this value to pdTRUE then a context switch should be requested before the interrupt is exited.

From FreeRTOS V7.3.0 pxHigherPriorityTaskWoken is an optional parameter and can be set to NULL.

Returns:
pdTRUE if the semaphore was successfully given, otherwise errQUEUE_FULL.
Example usage:

Note the functionality shown below can often be achieved in a more efficient way by using a direct to task notification in place of a semaphore.

#define LONG_TIME 0xffff #define TICKS_TO_WAIT 10 SemaphoreHandle_t xSemaphore = NULL; /* Repetitive task. */ void vATask( void * pvParameters ) { /* We are using the semaphore for synchronisation so we create a binary semaphore rather than a mutex. We must make sure that the interrupt does not attempt to use the semaphore before it is created! */ xSemaphore = xSemaphoreCreateBinary(); for( ;; ) { /* We want this task to run every 10 ticks of a timer. The semaphore was created before this task was started. Block waiting for the semaphore to become available. */ if( xSemaphoreTake( xSemaphore, LONG_TIME ) == pdTRUE ) { /* It is time to execute. */ ... /* We have finished our task. Return to the top of the loop where we will block on the semaphore until it is time to execute again. Note when using the semaphore for synchronisation with an ISR in this manner there is no need to 'give' the semaphore back. */ } } } /* Timer ISR */ void vTimerISR( void * pvParameters ) { static unsigned char ucLocalTickCount = 0; static signed BaseType_t xHigherPriorityTaskWoken; /* A timer tick has occurred. */ ... Do other time functions. /* Is it time for vATask() to run? */ xHigherPriorityTaskWoken = pdFALSE; ucLocalTickCount++; if( ucLocalTickCount >= TICKS_TO_WAIT ) { /* Unblock the task by releasing the semaphore. */ xSemaphoreGiveFromISR( xSemaphore, &xHigherPriorityTaskWoken ); /* Reset the count so we release the semaphore again in 10 ticks time. */ ucLocalTickCount = 0; } /* If xHigherPriorityTaskWoken was set to true you we should yield. The actual macro used here is port specific. */ portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); }






[ 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