eRPC API Reference  Rev. 1.11.0
NXP Semiconductors
erpc_config_internal.h
1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 NXP
4  * Copyright 2020 ACRIOS Systems s.r.o.
5  * All rights reserved.
6  *
7  *
8  * SPDX-License-Identifier: BSD-3-Clause
9  */
10 
11 #ifndef _ERPC_DETECT_H_
12 #define _ERPC_DETECT_H_
13 
14 #include "erpc_config.h"
15 
17 // Declarations
19 /* clang-format off */
20 
21 // Determine if this is a POSIX system.
22 #if !defined(ERPC_HAS_POSIX)
23  // Detect Linux, BSD, Cygwin, and Mac OS X.
24  #if defined(__linux__) || defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
25  defined(__OpenBSD__) || defined(__DragonFly__) || defined(__CYGWIN__) || defined(__MACH__)
26  #define ERPC_HAS_POSIX (1)
27  #else
28  #define ERPC_HAS_POSIX (0)
29  #endif
30 #endif
31 
32 // Determine if we are targeting WIN32 environment
33 #if !defined(ERPC_HAS_WIN32)
34  #if defined(_WIN32)
35  #define ERPC_HAS_WIN32 (1)
36  #else
37  #define ERPC_HAS_WIN32 (0)
38  #endif
39 #endif
40 
41 // Safely detect FreeRTOSConfig.h.
42 #define ERPC_HAS_FREERTOSCONFIG_H (0)
43 #if defined(__has_include)
44  #if __has_include("FreeRTOSConfig.h")
45  #undef ERPC_HAS_FREERTOSCONFIG_H
46  #define ERPC_HAS_FREERTOSCONFIG_H (1)
47  #endif
48 #endif
49 
50 // Detect allocation policy if not already set.
51 #if !defined(ERPC_ALLOCATION_POLICY)
52  #if ERPC_HAS_FREERTOSCONFIG_H
53  #ifdef __cplusplus
54  extern "C" {
55  #endif
56  #include "FreeRTOSConfig.h"
57  #ifdef __cplusplus
58  }
59  #endif
60  #if defined(configSUPPORT_STATIC_ALLOCATION) && configSUPPORT_STATIC_ALLOCATION
61  #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC)
62  #else
63  #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_DYNAMIC)
64  #endif
65  #else
66  #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_DYNAMIC)
67  #endif
68 #endif
69 
70 #if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
71  #if !defined(ERPC_CODEC_COUNT)
72  #define ERPC_CODEC_COUNT (2U)
73  #endif
74  #if !defined(ERPC_MESSAGE_LOGGERS_COUNT)
75  #define ERPC_MESSAGE_LOGGERS_COUNT (0U)
76  #endif
77  #if !defined(ERPC_CLIENTS_THREADS_AMOUNT)
78  #define ERPC_CLIENTS_THREADS_AMOUNT (1U)
79  #endif
80 #endif
81 
82 // Safely detect tx_api.h.
83 #define ERPC_HAS_THREADX_API_H (0)
84 #if defined(__has_include)
85  #if __has_include("tx_api.h")
86  #undef ERPC_HAS_THREADX_API_H
87  #define ERPC_HAS_THREADX_API_H (1)
88  #endif
89 #endif
90 
91 // Detect threading model if not already set.
92 #if !defined(ERPC_THREADS)
93  #if ERPC_HAS_POSIX
94  // Default to pthreads for POSIX systems.
95  #define ERPC_THREADS (ERPC_THREADS_PTHREADS)
96  #elif ERPC_HAS_FREERTOSCONFIG_H
97  // Use FreeRTOS if we can auto detect it.
98  #define ERPC_THREADS (ERPC_THREADS_FREERTOS)
99  #elif ERPC_HAS_WIN32
100  #define ERPC_THREADS (ERPC_THREADS_WIN32)
101  #elif ERPC_HAS_THREADX_API_H
102  #define ERPC_THREADS (ERPC_THREADS_THREADX)
103  #else
104  // Otherwise default to no threads.
105  #define ERPC_THREADS (ERPC_THREADS_NONE)
106  #endif
107 #endif
108 
109 // Handy macro to test threading model. You can also ERPC_THREADS directly to test for threading
110 // support, i.e. "#if ERPC_THREADS", because ERPC_THREADS_NONE has a value of 0.
111 #define ERPC_THREADS_IS(_n_) (ERPC_THREADS == (ERPC_THREADS_##_n_))
112 
113 // Set default buffer size.
114 #if !defined(ERPC_DEFAULT_BUFFER_SIZE)
115  #define ERPC_DEFAULT_BUFFER_SIZE (256U)
117 #endif
118 
119 // Set default buffers count.
120 #if !defined(ERPC_DEFAULT_BUFFERS_COUNT)
121  #define ERPC_DEFAULT_BUFFERS_COUNT (2U)
123 #endif
124 
125 // Disable/enable noexcept.
126 #if !defined(ERPC_NOEXCEPT)
127  #if ERPC_HAS_POSIX
128  #define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED)
129  #else
130  #define ERPC_NOEXCEPT (ERPC_NOEXCEPT_DISABLED)
131  #endif
132 #endif
133 
134 //NOEXCEPT support
135 #if defined(__cplusplus) && __cplusplus >= 201103 && ERPC_NOEXCEPT
136  #define NOEXCEPT noexcept
137 #else
138  #define NOEXCEPT
139 #endif // NOEXCEPT
140 
141 // Disabling nesting calls support as default.
142 #if !defined(ERPC_NESTED_CALLS)
143  #define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_DISABLED)
144 #endif
145 
146 #if ERPC_NESTED_CALLS && !ERPC_THREADS
147  #error "Nested calls currently working only with Threads."
148 #endif
149 
150 // Enabling nesting calls detection as default for debug.
151 #if !defined(ERPC_NESTED_CALLS_DETECTION)
152  #if defined(NDEBUG) || (ERPC_NESTED_CALLS == ERPC_NESTED_CALLS_ENABLED)
153  #define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED)
154  #else
155  #define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_ENABLED)
156  #endif
157 #endif
158 
159 // Disabling tracing the eRPC.
160 #if !defined(ERPC_MESSAGE_LOGGING)
161  #define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_DISABLED)
162 #endif
163 
164 #if defined(__CC_ARM) || defined(__ARMCC_VERSION) /* Keil MDK */
165  #define THROW_BADALLOC throw(std::bad_alloc)
166  #define THROW throw()
167 #else
168  #define THROW_BADALLOC
169  #define THROW
170 #endif
171 
172 #ifndef ERPC_TRANSPORT_MU_USE_MCMGR
173  #if defined(__has_include)
174  #if (__has_include("mcmgr.h"))
175  #define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED)
176  #else
177  #define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED)
178  #endif
179  #endif
180 #else
181  #if defined(__has_include)
182  #if ((!(__has_include("mcmgr.h"))) && (ERPC_TRANSPORT_MU_USE_MCMGR == ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED))
183  #error "Do not forget to add the MCMGR library into your project!"
184  #endif
185  #endif
186 #endif
187 
188 // Disabling pre and post callback function related code.
189 #if !defined(ERPC_PRE_POST_ACTION)
190  #define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_DISABLED)
191 #endif
192 
193 // Disabling pre and post default callback function code.
194 #if !defined(ERPC_PRE_POST_ACTION_DEFAULT)
195  #define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_DISABLED)
196 #endif
197 
198 #if !defined(erpc_assert)
199  #if ERPC_HAS_FREERTOSCONFIG_H
200  #ifdef __cplusplus
201  extern "C" {
202  #endif
203  #include "FreeRTOS.h"
204  #include "task.h"
205  #ifdef __cplusplus
206  }
207  #endif
208  #define erpc_assert(condition) configASSERT(condition)
209  #elif defined(ERPC_THREADS) && (ERPC_THREADS == ERPC_THREADS_MBED)
210  #include "platform/mbed_assert.h"
211  #define erpc_assert(condition) MBED_ASSERT(condition)
212  #else
213  #ifdef __cplusplus
214  #include <cassert>
215  #else
216  #include "assert.h"
217  #endif
218  #define erpc_assert(condition) assert(condition)
219  #endif
220 #endif
221 
222 // Disabling endianness agnostic feature.
223 #ifndef ENDIANNESS_HEADER
224  #define ENDIANNESS_HEADER "erpc_endianness_undefined.h"
225 #endif
226 
227 /* clang-format on */
228 #endif // _ERPC_DETECT_H_
229 // EOF