Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UAVCAN UAVCAN_Subscriber
build_config.hpp
00001 /* 00002 * Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com> 00003 */ 00004 00005 #ifndef UAVCAN_BUILD_CONFIG_HPP_INCLUDED 00006 #define UAVCAN_BUILD_CONFIG_HPP_INCLUDED 00007 00008 /** 00009 * UAVCAN version definition 00010 */ 00011 #define UAVCAN_VERSION_MAJOR 1 00012 #define UAVCAN_VERSION_MINOR 0 00013 00014 /** 00015 * UAVCAN_CPP_VERSION - version of the C++ standard used during compilation. 00016 * This definition contains the integer year number after which the standard was named: 00017 * - 2003 for C++03 00018 * - 2011 for C++11 00019 * 00020 * This config automatically sets according to the actual C++ standard used by the compiler. 00021 * 00022 * In C++03 mode the library has almost zero dependency on the C++ standard library, which allows 00023 * to use it on platforms with a very limited C++ support. On the other hand, C++11 mode requires 00024 * many parts of the standard library (e.g. <functional>), thus the user might want to force older 00025 * standard than used by the compiler, in which case this symbol can be overridden manually via 00026 * compiler flags. 00027 */ 00028 #define UAVCAN_CPP11 2011 00029 #define UAVCAN_CPP03 2003 00030 00031 #ifndef UAVCAN_CPP_VERSION 00032 # if __cplusplus > 201200 00033 # error Unsupported C++ standard. You can explicitly set UAVCAN_CPP_VERSION=UAVCAN_CPP11 to silence this error. 00034 # elif (__cplusplus > 201100) || defined(__GXX_EXPERIMENTAL_CXX0X__) 00035 # define UAVCAN_CPP_VERSION UAVCAN_CPP11 00036 # else 00037 # define UAVCAN_CPP_VERSION UAVCAN_CPP03 00038 # endif 00039 #endif 00040 00041 /** 00042 * The library uses UAVCAN_NULLPTR instead of UAVCAN_NULLPTR and nullptr in order to allow the use of 00043 * -Wzero-as-null-pointer-constant. 00044 */ 00045 #ifndef UAVCAN_NULLPTR 00046 # if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 00047 # define UAVCAN_NULLPTR nullptr 00048 # else 00049 # define UAVCAN_NULLPTR NULL 00050 # endif 00051 #endif 00052 00053 /** 00054 * By default, libuavcan enables all features if it detects that it is being built for a general-purpose 00055 * target like Linux. Value of this macro influences other configuration options located below in this file. 00056 * This macro can be overriden if needed. 00057 */ 00058 #ifndef UAVCAN_GENERAL_PURPOSE_PLATFORM 00059 # if (defined(__linux__) || defined(__linux) || defined(__APPLE__) ||\ 00060 defined(_WIN64) || defined(_WIN32) || defined(__ANDROID__) ||\ 00061 defined(_SYSTYPE_BSD) || defined(__FreeBSD__)) 00062 # define UAVCAN_GENERAL_PURPOSE_PLATFORM 1 00063 # else 00064 # define UAVCAN_GENERAL_PURPOSE_PLATFORM 0 00065 # endif 00066 #endif 00067 00068 /** 00069 * This macro enables built-in runtime checks and debug output via printf(). 00070 * Should be used only for library development. 00071 */ 00072 #ifndef UAVCAN_DEBUG 00073 # define UAVCAN_DEBUG 0 00074 #endif 00075 00076 /** 00077 * This option allows to select whether libuavcan should throw exceptions on fatal errors, or try to handle 00078 * errors differently. By default, exceptions will be enabled only if the library is built for a general-purpose 00079 * OS like Linux. Set UAVCAN_EXCEPTIONS explicitly to override. 00080 */ 00081 #ifndef UAVCAN_EXCEPTIONS 00082 # define UAVCAN_EXCEPTIONS UAVCAN_GENERAL_PURPOSE_PLATFORM 00083 #endif 00084 00085 /** 00086 * This specification is used by some error reporting functions like in the Logger class. 00087 * The default can be overriden by defining the macro UAVCAN_NOEXCEPT explicitly, e.g. via compiler options. 00088 */ 00089 #ifndef UAVCAN_NOEXCEPT 00090 # if UAVCAN_EXCEPTIONS 00091 # if UAVCAN_CPP_VERSION >= UAVCAN_CPP11 00092 # define UAVCAN_NOEXCEPT noexcept 00093 # else 00094 # define UAVCAN_NOEXCEPT throw() 00095 # endif 00096 # else 00097 # define UAVCAN_NOEXCEPT 00098 # endif 00099 #endif 00100 00101 /** 00102 * Declaration visibility 00103 * http://gcc.gnu.org/wiki/Visibility 00104 */ 00105 #ifndef UAVCAN_EXPORT 00106 # define UAVCAN_EXPORT 00107 #endif 00108 00109 /** 00110 * Trade-off between ROM/RAM usage and functionality/determinism. 00111 * Note that this feature is not well tested and should be avoided. 00112 * Use code search for UAVCAN_TINY to find what functionality will be disabled. 00113 * This is particularly useful for embedded systems with less than 40kB of ROM. 00114 */ 00115 #ifndef UAVCAN_TINY 00116 # define UAVCAN_TINY 0 00117 #endif 00118 00119 /** 00120 * Disable the global data type registry, which can save some space on embedded systems. 00121 */ 00122 #ifndef UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY 00123 # define UAVCAN_NO_GLOBAL_DATA_TYPE_REGISTRY 0 00124 #endif 00125 00126 /** 00127 * toString() methods will be disabled by default, unless the library is built for a general-purpose target like Linux. 00128 * It is not recommended to enable toString() on embedded targets as code size will explode. 00129 */ 00130 #ifndef UAVCAN_TOSTRING 00131 # if UAVCAN_EXCEPTIONS 00132 # define UAVCAN_TOSTRING UAVCAN_GENERAL_PURPOSE_PLATFORM 00133 # else 00134 # define UAVCAN_TOSTRING 0 00135 # endif 00136 #endif 00137 00138 #if UAVCAN_TOSTRING 00139 # if !UAVCAN_EXCEPTIONS 00140 # error UAVCAN_TOSTRING requires UAVCAN_EXCEPTIONS 00141 # endif 00142 # include <string> 00143 #endif 00144 00145 /** 00146 * Some C++ implementations are half-broken because they don't implement the placement new operator. 00147 * If UAVCAN_IMPLEMENT_PLACEMENT_NEW is defined, libuavcan will implement its own operator new (std::size_t, void*) 00148 * and its delete() counterpart, instead of relying on the standard header <new>. 00149 */ 00150 #ifndef UAVCAN_IMPLEMENT_PLACEMENT_NEW 00151 # define UAVCAN_IMPLEMENT_PLACEMENT_NEW 0 00152 #endif 00153 00154 /** 00155 * Allows the user's application to provide custom implementation of uavcan::snprintf(), 00156 * which is often useful on deeply embedded systems. 00157 */ 00158 #ifndef UAVCAN_USE_EXTERNAL_SNPRINTF 00159 # define UAVCAN_USE_EXTERNAL_SNPRINTF 0 00160 #endif 00161 00162 /** 00163 * Allows the user's application to provide a custom implementation of IEEE754Converter::nativeIeeeToHalf and 00164 * IEEE754Converter::halfToNativeIeee. 00165 */ 00166 #ifndef UAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION 00167 # define UAVCAN_USE_EXTERNAL_FLOAT16_CONVERSION 0 00168 #endif 00169 00170 /** 00171 * Run time checks. 00172 * Resolves to the standard assert() by default. 00173 * Disabled completely if UAVCAN_NO_ASSERTIONS is defined. 00174 */ 00175 #ifndef UAVCAN_ASSERT 00176 # ifndef UAVCAN_NO_ASSERTIONS 00177 # define UAVCAN_NO_ASSERTIONS 0 00178 # endif 00179 # if UAVCAN_NO_ASSERTIONS 00180 # define UAVCAN_ASSERT(x) 00181 # else 00182 # define UAVCAN_ASSERT(x) assert(x) 00183 # endif 00184 #endif 00185 00186 #ifndef UAVCAN_LIKELY 00187 # if __GNUC__ 00188 # define UAVCAN_LIKELY(x) __builtin_expect(!!(x), true) 00189 # else 00190 # define UAVCAN_LIKELY(x) (x) 00191 # endif 00192 #endif 00193 00194 #ifndef UAVCAN_UNLIKELY 00195 # if __GNUC__ 00196 # define UAVCAN_UNLIKELY(x) __builtin_expect(!!(x), false) 00197 # else 00198 # define UAVCAN_UNLIKELY(x) (x) 00199 # endif 00200 #endif 00201 00202 namespace uavcan 00203 { 00204 /** 00205 * Memory pool block size. 00206 * 00207 * The default of 64 bytes should be OK for any target arch up to AMD64 and any compiler. 00208 * 00209 * The library leverages compile-time checks to ensure that all types that are subject to dynamic allocation 00210 * fit this size, otherwise compilation fails. 00211 * 00212 * For platforms featuring small pointer width (16..32 bits), UAVCAN_MEM_POOL_BLOCK_SIZE can often be safely 00213 * reduced to 56 or even 48 bytes, which leads to lower memory footprint. 00214 * 00215 * Note that the pool block size shall be aligned at biggest alignment of the target platform (detected and 00216 * checked automatically at compile time). 00217 */ 00218 #ifdef UAVCAN_MEM_POOL_BLOCK_SIZE 00219 /// Explicitly specified by the user. 00220 static const unsigned MemPoolBlockSize = UAVCAN_MEM_POOL_BLOCK_SIZE; 00221 #elif defined(__BIGGEST_ALIGNMENT__) && (__BIGGEST_ALIGNMENT__ <= 8) 00222 /// Convenient default for GCC-like compilers - if alignment allows, pool block size can be safely reduced. 00223 static const unsigned MemPoolBlockSize = 56; 00224 #else 00225 /// Safe default that should be OK for any platform. 00226 static const unsigned MemPoolBlockSize = 64; 00227 #endif 00228 00229 #ifdef __BIGGEST_ALIGNMENT__ 00230 static const unsigned MemPoolAlignment = __BIGGEST_ALIGNMENT__; 00231 #else 00232 static const unsigned MemPoolAlignment = 16; 00233 #endif 00234 00235 typedef char _alignment_check_for_MEM_POOL_BLOCK_SIZE[((MemPoolBlockSize & (MemPoolAlignment - 1)) == 0) ? 1 : -1]; 00236 00237 /** 00238 * This class that allows to check at compile time whether type T can be allocated using the memory pool. 00239 * If the check fails, compilation fails. 00240 */ 00241 template <typename T> 00242 struct UAVCAN_EXPORT IsDynamicallyAllocatable 00243 { 00244 static void check() 00245 { 00246 char dummy[(sizeof(T) <= MemPoolBlockSize) ? 1 : -1] = { '0' }; 00247 (void)dummy; 00248 } 00249 }; 00250 00251 /** 00252 * Float comparison precision. 00253 * For details refer to: 00254 * http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ 00255 * https://code.google.com/p/googletest/source/browse/trunk/include/gtest/internal/gtest-internal.h 00256 */ 00257 #ifdef UAVCAN_FLOAT_COMPARISON_EPSILON_MULT 00258 static const unsigned FloatComparisonEpsilonMult = UAVCAN_FLOAT_COMPARISON_EPSILON_MULT; 00259 #else 00260 static const unsigned FloatComparisonEpsilonMult = 10; 00261 #endif 00262 00263 /** 00264 * Maximum number of CAN acceptance filters available on the platform 00265 */ 00266 #ifdef UAVCAN_MAX_CAN_ACCEPTANCE_FILTERS 00267 /// Explicitly specified by the user. 00268 static const unsigned MaxCanAcceptanceFilters = UAVCAN_MAX_CAN_ACCEPTANCE_FILTERS; 00269 #else 00270 /// Default that should be OK for any platform. 00271 static const unsigned MaxCanAcceptanceFilters = 32; 00272 #endif 00273 00274 } 00275 00276 #endif // UAVCAN_BUILD_CONFIG_HPP_INCLUDED
Generated on Tue Jul 12 2022 17:17:30 by
1.7.2