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
7 * @addtogroup PIOS_Semaphore Semaphore Abstraction
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
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
36 struct pios_semaphore
{
37 #if defined(PIOS_INCLUDE_FREERTOS)
38 uintptr_t sema_handle
;
39 #elif defined(PIOS_INCLUDE_CHIBIOS)
41 #elif defined(PIOS_INCLUDE_IRQ)
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
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_ */