eRPC API Reference  Rev. 1.9.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 defined(__has_include) && __has_include("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 #warning "ERPC_CODEC_COUNT is not defined. Default is used."
74 #endif
75 #if !defined(ERPC_MESSAGE_LOGGERS_COUNT)
76 #define ERPC_MESSAGE_LOGGERS_COUNT (0U)
77 #warning "ERPC_MESSAGE_LOGGERS_COUNT is not defined. Default is used."
78 #endif
79 #if !defined(ERPC_CLIENTS_THREADS_AMOUNT)
80 #define ERPC_CLIENTS_THREADS_AMOUNT (1U)
81 #warning "ERPC_CLIENTS_THREADS_AMOUNT is not defined. Default is used."
82 #endif
83 #endif
84 
85 // Safely detect tx_api.h.
86 #define ERPC_HAS_THREADX_API_H (0)
87 #if defined(__has_include)
88  #if __has_include("tx_api.h")
89  #undef ERPC_HAS_THREADX_API_H
90  #define ERPC_HAS_THREADX_API_H (1)
91  #endif
92 #endif
93 
94 // Detect threading model if not already set.
95 #if !defined(ERPC_THREADS)
96  #if ERPC_HAS_POSIX
97  // Default to pthreads for POSIX systems.
98  #define ERPC_THREADS (ERPC_THREADS_PTHREADS)
99  #elif ERPC_HAS_FREERTOSCONFIG_H
100  // Use FreeRTOS if we can auto detect it.
101  #define ERPC_THREADS (ERPC_THREADS_FREERTOS)
102  #elif ERPC_HAS_WIN32
103  #define ERPC_THREADS (ERPC_THREADS_WIN32)
104  #elif ERPC_HAS_THREADX_API_H
105  #define ERPC_THREADS (ERPC_THREADS_THREADX)
106  #else
107  // Otherwise default to no threads.
108  #define ERPC_THREADS (ERPC_THREADS_NONE)
109  #endif
110 #endif
111 
112 // Handy macro to test threading model. You can also ERPC_THREADS directly to test for threading
113 // support, i.e. "#if ERPC_THREADS", because ERPC_THREADS_NONE has a value of 0.
114 #define ERPC_THREADS_IS(_n_) (ERPC_THREADS == (ERPC_THREADS_##_n_))
115 
116 // Set default buffer size.
117 #if !defined(ERPC_DEFAULT_BUFFER_SIZE)
118  #define ERPC_DEFAULT_BUFFER_SIZE (256U)
120 #endif
121 
122 // Set default buffers count.
123 #if !defined(ERPC_DEFAULT_BUFFERS_COUNT)
124  #define ERPC_DEFAULT_BUFFERS_COUNT (2U)
126 #endif
127 
128 // Disable/enable noexcept.
129 #if !defined(ERPC_NOEXCEPT)
130  #if ERPC_HAS_POSIX
131  #define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED)
132  #else
133  #define ERPC_NOEXCEPT (ERPC_NOEXCEPT_DISABLED)
134  #endif
135 #endif
136 
137 //NOEXCEPT support
138 #if defined(__cplusplus) && __cplusplus >= 201103 && ERPC_NOEXCEPT
139 #define NOEXCEPT noexcept
140 #else
141 #define NOEXCEPT
142 #endif // NOEXCEPT
143 
144 // Disabling nesting calls support as default.
145 #if !defined(ERPC_NESTED_CALLS)
146  #define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_DISABLED)
147 #endif
148 
149 #if ERPC_NESTED_CALLS && !ERPC_THREADS
150  #error "Nested calls currently working only with Threads."
151 #endif
152 
153 // Enabling nesting calls detection as default for debug.
154 #if !defined(ERPC_NESTED_CALLS_DETECTION)
155  #if defined(NDEBUG) || (ERPC_NESTED_CALLS == ERPC_NESTED_CALLS_ENABLED)
156  #define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED)
157  #else
158  #define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_ENABLED)
159  #endif
160 #endif
161 
162 // Disabling tracing the eRPC.
163 #if !defined(ERPC_MESSAGE_LOGGING)
164  #define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_DISABLED)
165 #endif
166 
167 #if defined(__CC_ARM) || defined(__ARMCC_VERSION) /* Keil MDK */
168 #define THROW_BADALLOC throw(std::bad_alloc)
169 #define THROW throw()
170 #else
171 #define THROW_BADALLOC
172 #define THROW
173 #endif
174 
175 #ifndef ERPC_TRANSPORT_MU_USE_MCMGR
176  #if defined(__has_include)
177  #if (__has_include("mcmgr.h"))
178  #define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED)
179  #else
180  #define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED)
181  #endif
182  #endif
183 #else
184  #if defined(__has_include)
185  #if ((!(__has_include("mcmgr.h"))) && (ERPC_TRANSPORT_MU_USE_MCMGR == ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED))
186  #error "Do not forget to add the MCMGR library into your project!"
187  #endif
188  #endif
189 #endif
190 
191 // Disabling pre and post callback function related code.
192 #if !defined(ERPC_PRE_POST_ACTION)
193  #define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_DISABLED)
194 #endif
195 
196 // Disabling pre and post default callback function code.
197 #if !defined(ERPC_PRE_POST_ACTION_DEFAULT)
198  #define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_DISABLED)
199 #endif
200 
201 /* clang-format on */
202 #endif // _ERPC_DETECT_H_
203 // EOF