csp_semaphore.h
Go to the documentation of this file.
1 /*
2 Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
3 Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
4 Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
27 #ifndef _CSP_SEMAPHORE_H_
28 #define _CSP_SEMAPHORE_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdint.h>
35 
36 #include <csp/csp.h>
37 
38 /* POSIX interface */
39 #if defined(CSP_POSIX)
40 
41 #include <pthread.h>
42 #include <semaphore.h>
43 
44 #define CSP_SEMAPHORE_OK 1
45 #define CSP_SEMAPHORE_ERROR 2
46 #define CSP_MUTEX_OK CSP_SEMAPHORE_OK
47 #define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
48 
49 typedef sem_t csp_bin_sem_handle_t;
50 typedef pthread_mutex_t csp_mutex_t;
51 
52 #endif // CSP_POSIX
53 
54 /* MAC OS X interface */
55 #if defined(CSP_MACOSX)
56 
57 #include <pthread.h>
58 #include "posix/pthread_queue.h"
59 
60 #define CSP_SEMAPHORE_OK PTHREAD_QUEUE_OK
61 #define CSP_SEMAPHORE_ERROR PTHREAD_QUEUE_EMPTY
62 #define CSP_MUTEX_OK CSP_SEMAPHORE_OK
63 #define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
64 
65 typedef pthread_queue_t * csp_bin_sem_handle_t;
66 typedef pthread_queue_t * csp_mutex_t;
67 
68 #endif // CSP_MACOSX
69 
70 #if defined(CSP_WINDOWS)
71 
72 #include <Windows.h>
73 #undef interface
74 
75 #define CSP_SEMAPHORE_OK 1
76 #define CSP_SEMAPHORE_ERROR 2
77 #define CSP_MUTEX_OK CSP_SEMAPHORE_OK
78 #define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
79 
80 typedef HANDLE csp_bin_sem_handle_t;
81 typedef HANDLE csp_mutex_t;
82 
83 #endif
84 
85 /* FreeRTOS interface */
86 #if defined(CSP_FREERTOS)
87 
88 #include <FreeRTOS.h>
89 #include <semphr.h>
90 
91 #define CSP_SEMAPHORE_OK pdPASS
92 #define CSP_SEMAPHORE_ERROR pdFAIL
93 #define CSP_MUTEX_OK CSP_SEMAPHORE_OK
94 #define CSP_MUTEX_ERROR CSP_SEMAPHORE_ERROR
95 
96 typedef xSemaphoreHandle csp_bin_sem_handle_t;
97 typedef xSemaphoreHandle csp_mutex_t;
98 
99 #endif // CSP_FREERTOS
100 
105 int csp_mutex_create(csp_mutex_t * mutex);
106 
111 int csp_mutex_remove(csp_mutex_t * mutex);
112 
117 int csp_mutex_lock(csp_mutex_t * mutex, uint32_t timeout);
118 
123 int csp_mutex_unlock(csp_mutex_t * mutex);
124 
129 int csp_bin_sem_create(csp_bin_sem_handle_t * sem);
130 
135 int csp_bin_sem_remove(csp_bin_sem_handle_t * sem);
136 
141 int csp_bin_sem_wait(csp_bin_sem_handle_t * sem, uint32_t timeout);
142 
147 int csp_bin_sem_post(csp_bin_sem_handle_t * sem);
148 
153 int csp_bin_sem_post_isr(csp_bin_sem_handle_t * sem, CSP_BASE_TYPE * task_woken);
154 
155 #ifdef __cplusplus
156 } /* extern "C" */
157 #endif
158 
159 #endif // _CSP_SEMAPHORE_H_
160 
161 /* @} */
int csp_bin_sem_post(csp_bin_sem_handle_t *sem)
int csp_bin_sem_remove(csp_bin_sem_handle_t *sem)
Definition: pthread_queue.h:44
int csp_bin_sem_post_isr(csp_bin_sem_handle_t *sem, CSP_BASE_TYPE *task_woken)
int csp_bin_sem_create(csp_bin_sem_handle_t *sem)
int csp_mutex_unlock(csp_mutex_t *mutex)
int csp_mutex_create(csp_mutex_t *mutex)
int csp_mutex_lock(csp_mutex_t *mutex, uint32_t timeout)
int csp_mutex_remove(csp_mutex_t *mutex)
int csp_bin_sem_wait(csp_bin_sem_handle_t *sem, uint32_t timeout)