00001 /* 00002 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd. 00003 00004 *************************************************************************** 00005 * * 00006 * If you are: * 00007 * * 00008 * + New to FreeRTOS, * 00009 * + Wanting to learn FreeRTOS or multitasking in general quickly * 00010 * + Looking for basic training, * 00011 * + Wanting to improve your FreeRTOS skills and productivity * 00012 * * 00013 * then take a look at the FreeRTOS eBook * 00014 * * 00015 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" * 00016 * http://www.FreeRTOS.org/Documentation * 00017 * * 00018 * A pdf reference manual is also available. Both are usually delivered * 00019 * to your inbox within 20 minutes to two hours when purchased between 8am * 00020 * and 8pm GMT (although please allow up to 24 hours in case of * 00021 * exceptional circumstances). Thank you for your support! * 00022 * * 00023 *************************************************************************** 00024 00025 This file is part of the FreeRTOS distribution. 00026 00027 FreeRTOS is free software; you can redistribute it and/or modify it under 00028 the terms of the GNU General Public License (version 2) as published by the 00029 Free Software Foundation AND MODIFIED BY the FreeRTOS exception. 00030 ***NOTE*** The exception to the GPL is included to allow you to distribute 00031 a combined work that includes FreeRTOS without being obliged to provide the 00032 source code for proprietary components outside of the FreeRTOS kernel. 00033 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT 00034 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00035 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00036 more details. You should have received a copy of the GNU General Public 00037 License and the FreeRTOS license exception along with FreeRTOS; if not it 00038 can be viewed here: http://www.freertos.org/a00114.html and also obtained 00039 by writing to Richard Barry, contact details for whom are available on the 00040 FreeRTOS WEB site. 00041 00042 1 tab == 4 spaces! 00043 00044 http://www.FreeRTOS.org - Documentation, latest information, license and 00045 contact details. 00046 00047 http://www.SafeRTOS.com - A version that is certified for use in safety 00048 critical systems. 00049 00050 http://www.OpenRTOS.com - Commercial support, development, porting, 00051 licensing and training services. 00052 */ 00053 00054 #ifndef INC_FREERTOS_H 00055 #error "#include FreeRTOS.h" must appear in source files before "#include semphr.h" 00056 #endif 00057 00058 #ifndef SEMAPHORE_H 00059 #define SEMAPHORE_H 00060 00061 #include "queue.h" 00062 00063 typedef xQueueHandle xSemaphoreHandle; 00064 00065 #define semBINARY_SEMAPHORE_QUEUE_LENGTH ( ( unsigned char ) 1 ) 00066 #define semSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned char ) 0 ) 00067 #define semGIVE_BLOCK_TIME ( ( portTickType ) 0 ) 00068 00069 00108 #define vSemaphoreCreateBinary( xSemaphore ) { \ 00109 xSemaphore = xQueueCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH ); \ 00110 if( xSemaphore != NULL ) \ 00111 { \ 00112 xSemaphoreGive( xSemaphore ); \ 00113 } \ 00114 } 00115 00181 #define xSemaphoreTake( xSemaphore, xBlockTime ) xQueueGenericReceive( ( xQueueHandle ) xSemaphore, NULL, xBlockTime, pdFALSE ) 00182 00274 #define xSemaphoreTakeRecursive( xMutex, xBlockTime ) xQueueTakeMutexRecursive( xMutex, xBlockTime ) 00275 00276 00277 /* 00278 * xSemaphoreAltTake() is an alternative version of xSemaphoreTake(). 00279 * 00280 * The source code that implements the alternative (Alt) API is much 00281 * simpler because it executes everything from within a critical section. 00282 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the 00283 * preferred fully featured API too. The fully featured API has more 00284 * complex code that takes longer to execute, but makes much less use of 00285 * critical sections. Therefore the alternative API sacrifices interrupt 00286 * responsiveness to gain execution speed, whereas the fully featured API 00287 * sacrifices execution speed to ensure better interrupt responsiveness. 00288 */ 00289 #define xSemaphoreAltTake( xSemaphore, xBlockTime ) xQueueAltGenericReceive( ( xQueueHandle ) xSemaphore, NULL, xBlockTime, pdFALSE ) 00290 00352 #define xSemaphoreGive( xSemaphore ) xQueueGenericSend( ( xQueueHandle ) xSemaphore, NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) 00353 00436 #define xSemaphoreGiveRecursive( xMutex ) xQueueGiveMutexRecursive( xMutex ) 00437 00438 /* 00439 * xSemaphoreAltGive() is an alternative version of xSemaphoreGive(). 00440 * 00441 * The source code that implements the alternative (Alt) API is much 00442 * simpler because it executes everything from within a critical section. 00443 * This is the approach taken by many other RTOSes, but FreeRTOS.org has the 00444 * preferred fully featured API too. The fully featured API has more 00445 * complex code that takes longer to execute, but makes much less use of 00446 * critical sections. Therefore the alternative API sacrifices interrupt 00447 * responsiveness to gain execution speed, whereas the fully featured API 00448 * sacrifices execution speed to ensure better interrupt responsiveness. 00449 */ 00450 #define xSemaphoreAltGive( xSemaphore ) xQueueAltGenericSend( ( xQueueHandle ) xSemaphore, NULL, semGIVE_BLOCK_TIME, queueSEND_TO_BACK ) 00451 00541 #define xSemaphoreGiveFromISR( xSemaphore, pxHigherPriorityTaskWoken ) xQueueGenericSendFromISR( ( xQueueHandle ) xSemaphore, NULL, pxHigherPriorityTaskWoken, queueSEND_TO_BACK ) 00542 00588 #define xSemaphoreCreateMutex() xQueueCreateMutex() 00589 00590 00643 #define xSemaphoreCreateRecursiveMutex() xQueueCreateMutex() 00644 00706 #define xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ) xQueueCreateCountingSemaphore( uxMaxCount, uxInitialCount ) 00707 00708 00709 #endif /* SEMAPHORE_H */ 00710 00711