csp_platform.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_PLATFORM_H_
28 #define _CSP_PLATFORM_H_
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdint.h>
35 
36 /* Set OS */
37 #if defined(CSP_POSIX) || defined(CSP_WINDOWS) || defined(CSP_MACOSX)
38  #define CSP_BASE_TYPE int
39  #define CSP_MAX_DELAY (UINT32_MAX)
40  #define CSP_INFINITY (UINT32_MAX)
41  #define CSP_DEFINE_CRITICAL(lock) static csp_bin_sem_handle_t lock
42  #define CSP_INIT_CRITICAL(lock) ({(csp_bin_sem_create(&lock) == CSP_SEMAPHORE_OK) ? CSP_ERR_NONE : CSP_ERR_NOMEM;})
43  #define CSP_ENTER_CRITICAL(lock) do { csp_bin_sem_wait(&lock, CSP_MAX_DELAY); } while(0)
44  #define CSP_EXIT_CRITICAL(lock) do { csp_bin_sem_post(&lock); } while(0)
45 #elif defined(CSP_FREERTOS)
46  #include "FreeRTOS.h"
47  #define CSP_BASE_TYPE portBASE_TYPE
48  #define CSP_MAX_DELAY portMAX_DELAY
49  #define CSP_INFINITY portMAX_DELAY
50  #define CSP_DEFINE_CRITICAL(lock)
51  #define CSP_INIT_CRITICAL(lock) ({CSP_ERR_NONE;})
52  #define CSP_ENTER_CRITICAL(lock) do { portENTER_CRITICAL(); } while (0)
53  #define CSP_EXIT_CRITICAL(lock) do { portEXIT_CRITICAL(); } while (0)
54 #else
55  #error "OS must be either CSP_POSIX, CSP_MACOSX, CSP_FREERTOS OR CSP_WINDOWS"
56 #endif
57 
58 #ifdef __cplusplus
59 } /* extern "C" */
60 #endif
61 
62 #endif // _CSP_PLATFORM_H_
63 
64 /* @} */