update credits
[librepilot.git] / flight / pios / inc / pios_semaphore.h
blobc0468e1ccf8260690b628d46481e3794ba13e1e8
1 /**
2 ******************************************************************************
3 * @file pios_semaphore.h
4 * @author Tau Labs, http://taulabs.org, Copyright (C) 2013-2014
5 * @addtogroup PIOS PIOS Core hardware abstraction layer
6 * @{
7 * @addtogroup PIOS_Semaphore Semaphore Abstraction
8 * @{
9 * @brief Abstracts the concept of a binary semaphore to hide different implementations
10 *****************************************************************************/
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #ifndef PIOS_SEMAPHORE_H_
29 #define PIOS_SEMAPHORE_H_
31 #define PIOS_SEMAPHORE_TIMEOUT_MAX 0xffffffff
33 #include <stdint.h>
34 #include <stdbool.h>
36 struct pios_semaphore {
37 #if defined(PIOS_INCLUDE_FREERTOS)
38 uintptr_t sema_handle;
39 #elif defined(PIOS_INCLUDE_CHIBIOS)
40 BinarySemaphore sema;
41 #elif defined(PIOS_INCLUDE_IRQ)
42 uint32_t sema_count;
43 #endif /* defined(PIOS_INCLUDE_IRQ) */
47 * The following functions implement the concept of a binary semaphore usable
48 * with PIOS_INCLUDE_FREERTOS, PIOS_INCLUDE_CHIBIOS or PIOS_INCLUDE_IRQ.
50 * Note that this is not the same as:
51 * - counting semaphore
52 * - mutex
53 * - recursive mutex
55 * see FreeRTOS documentation for details: http://www.freertos.org/a00113.html
56 * see ChibiOS documentation for details: http://chibios.sourceforge.net/html/group__synchronization.html
59 struct pios_semaphore *PIOS_Semaphore_Create(void);
60 bool PIOS_Semaphore_Take(struct pios_semaphore *sema, uint32_t timeout_ms);
61 bool PIOS_Semaphore_Give(struct pios_semaphore *sema);
63 bool PIOS_Semaphore_Take_FromISR(struct pios_semaphore *sema, bool *woken);
64 bool PIOS_Semaphore_Give_FromISR(struct pios_semaphore *sema, bool *woken);
66 #endif /* PIOS_SEMAPHORE_H_ */
68 /**
69 * @}
70 * @}