Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers arch.h Source File

arch.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Support for different processor and compiler architectures
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_ARCH_H
00038 #define LWIP_HDR_ARCH_H
00039 
00040 #ifndef LITTLE_ENDIAN
00041 #define LITTLE_ENDIAN 1234
00042 #endif
00043 
00044 #ifndef BIG_ENDIAN
00045 #define BIG_ENDIAN 4321
00046 #endif
00047 
00048 #include "arch/cc.h"
00049 
00050 /**
00051  * @defgroup compiler_abstraction Compiler/platform abstraction
00052  * @ingroup sys_layer
00053  * All defines related to this section must not be placed in lwipopts.h,
00054  * but in arch/cc.h!
00055  * If the compiler does not provide memset() this file must include a
00056  * definition of it, or include a file which defines it.
00057  * These options cannot be \#defined in lwipopts.h since they are not options
00058  * of lwIP itself, but options of the lwIP port to your system.
00059  * @{
00060  */
00061 
00062 /** Define the byte order of the system.
00063  * Needed for conversion of network data to host byte order.
00064  * Allowed values: LITTLE_ENDIAN and BIG_ENDIAN
00065  */
00066 #ifndef BYTE_ORDER
00067 #define BYTE_ORDER LITTLE_ENDIAN
00068 #endif
00069 
00070 /** Define random number generator function of your system */
00071 #ifdef __DOXYGEN__
00072 #define LWIP_RAND() ((u32_t)rand())
00073 #endif
00074 
00075 /** Platform specific diagnostic output.\n
00076  * Note the default implementation pulls in printf, which may
00077  * in turn pull in a lot of standard libary code. In resource-constrained 
00078  * systems, this should be defined to something less resource-consuming.
00079  */
00080 #ifndef LWIP_PLATFORM_DIAG
00081 #define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
00082 #include <stdio.h>
00083 #include <stdlib.h>
00084 #endif
00085 
00086 /** Platform specific assertion handling.\n
00087  * Note the default implementation pulls in printf, fflush and abort, which may
00088  * in turn pull in a lot of standard libary code. In resource-constrained 
00089  * systems, this should be defined to something less resource-consuming.
00090  */
00091 #ifndef LWIP_PLATFORM_ASSERT
00092 #define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
00093                                      x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
00094 #include <stdio.h>
00095 #include <stdlib.h>
00096 #endif
00097 
00098 /** Define this to 1 in arch/cc.h of your port if you do not want to
00099  * include stddef.h header to get size_t. You need to typedef size_t
00100  * by yourself in this case.
00101  */
00102 #ifndef LWIP_NO_STDDEF_H
00103 #define LWIP_NO_STDDEF_H 0
00104 #endif
00105 
00106 #if !LWIP_NO_STDDEF_H
00107 #include <stddef.h> /* for size_t */
00108 #endif
00109 
00110 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00111  * the stdint.h header. You need to typedef the generic types listed in
00112  * lwip/arch.h yourself in this case (u8_t, u16_t...).
00113  */
00114 #ifndef LWIP_NO_STDINT_H
00115 #define LWIP_NO_STDINT_H 0
00116 #endif
00117 
00118 /* Define generic types used in lwIP */
00119 #if !LWIP_NO_STDINT_H
00120 #include <stdint.h>
00121 /* stdint.h is C99 which should also provide support for 64-bit integers */
00122 #if !defined(LWIP_HAVE_INT64) && defined(UINT64_MAX)
00123 #define LWIP_HAVE_INT64 1
00124 #endif
00125 typedef uint8_t   u8_t;
00126 typedef int8_t    s8_t;
00127 typedef uint16_t  u16_t;
00128 typedef int16_t   s16_t;
00129 typedef uint32_t  u32_t;
00130 typedef int32_t   s32_t;
00131 #if LWIP_HAVE_INT64
00132 typedef uint64_t  u64_t;
00133 typedef int64_t   s64_t;
00134 #endif
00135 typedef uintptr_t mem_ptr_t;
00136 #endif
00137 
00138 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00139  * the inttypes.h header. You need to define the format strings listed in
00140  * lwip/arch.h yourself in this case (X8_F, U16_F...).
00141  */
00142 #ifndef LWIP_NO_INTTYPES_H
00143 #define LWIP_NO_INTTYPES_H 0
00144 #endif
00145 
00146 /* Define (sn)printf formatters for these lwIP types */
00147 #if !LWIP_NO_INTTYPES_H
00148 #include <inttypes.h>
00149 #ifndef X8_F
00150 #define X8_F  "02" PRIx8
00151 #endif
00152 #ifndef U16_F
00153 #define U16_F PRIu16
00154 #endif
00155 #ifndef S16_F
00156 #define S16_F PRId16
00157 #endif
00158 #ifndef X16_F
00159 #define X16_F PRIx16
00160 #endif
00161 #ifndef U32_F
00162 #define U32_F PRIu32
00163 #endif
00164 #ifndef S32_F
00165 #define S32_F PRId32
00166 #endif
00167 #ifndef X32_F
00168 #define X32_F PRIx32
00169 #endif
00170 #ifndef SZT_F
00171 #define SZT_F PRIuPTR
00172 #endif
00173 #endif
00174 
00175 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00176  * the limits.h header. You need to define the type limits yourself in this case
00177  * (e.g. INT_MAX, SSIZE_MAX).
00178  */
00179 #ifndef LWIP_NO_LIMITS_H
00180 #define LWIP_NO_LIMITS_H 0
00181 #endif
00182 
00183 /* Include limits.h? */
00184 #if !LWIP_NO_LIMITS_H
00185 #include <limits.h>
00186 #endif
00187 
00188 /* Do we need to define ssize_t? This is a compatibility hack:
00189  * Unfortunately, this type seems to be unavailable on some systems (even if
00190  * sys/types or unistd.h are available).
00191  * Being like that, we define it to 'int' if SSIZE_MAX is not defined.
00192  */
00193 #ifdef SSIZE_MAX
00194 /* If SSIZE_MAX is defined, unistd.h should provide the type as well */
00195 #ifndef LWIP_NO_UNISTD_H
00196 #define LWIP_NO_UNISTD_H 0
00197 #endif
00198 #if !LWIP_NO_UNISTD_H
00199 #include <unistd.h>
00200 #endif
00201 #else /* SSIZE_MAX */
00202 typedef int ssize_t;
00203 #define SSIZE_MAX INT_MAX
00204 #endif /* SSIZE_MAX */
00205 
00206 /* some maximum values needed in lwip code */
00207 #define LWIP_UINT32_MAX 0xffffffff
00208 
00209 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00210  * the ctype.h header. If ctype.h is available, a few character functions
00211  * are mapped to the appropriate functions (lwip_islower, lwip_isdigit...), if
00212  * not, a private implementation is provided.
00213  */
00214 #ifndef LWIP_NO_CTYPE_H
00215 #define LWIP_NO_CTYPE_H 0
00216 #endif
00217 
00218 #if LWIP_NO_CTYPE_H
00219 #define lwip_in_range(c, lo, up)  ((u8_t)(c) >= (lo) && (u8_t)(c) <= (up))
00220 #define lwip_isdigit(c)           lwip_in_range((c), '0', '9')
00221 #define lwip_isxdigit(c)          (lwip_isdigit(c) || lwip_in_range((c), 'a', 'f') || lwip_in_range((c), 'A', 'F'))
00222 #define lwip_islower(c)           lwip_in_range((c), 'a', 'z')
00223 #define lwip_isspace(c)           ((c) == ' ' || (c) == '\f' || (c) == '\n' || (c) == '\r' || (c) == '\t' || (c) == '\v')
00224 #define lwip_isupper(c)           lwip_in_range((c), 'A', 'Z')
00225 #define lwip_tolower(c)           (lwip_isupper(c) ? (c) - 'A' + 'a' : c)
00226 #define lwip_toupper(c)           (lwip_islower(c) ? (c) - 'a' + 'A' : c)
00227 #else
00228 #include <ctype.h>
00229 #define lwip_isdigit(c)           isdigit((unsigned char)(c))
00230 #define lwip_isxdigit(c)          isxdigit((unsigned char)(c))
00231 #define lwip_islower(c)           islower((unsigned char)(c))
00232 #define lwip_isspace(c)           isspace((unsigned char)(c))
00233 #define lwip_isupper(c)           isupper((unsigned char)(c))
00234 #define lwip_tolower(c)           tolower((unsigned char)(c))
00235 #define lwip_toupper(c)           toupper((unsigned char)(c))
00236 #endif
00237 
00238 /** C++ const_cast<target_type>(val) equivalent to remove constness from a value (GCC -Wcast-qual) */
00239 #ifndef LWIP_CONST_CAST
00240 #define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
00241 #endif
00242 
00243 /** Get rid of alignment cast warnings (GCC -Wcast-align) */
00244 #ifndef LWIP_ALIGNMENT_CAST
00245 #define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
00246 #endif
00247 
00248 /** Get rid of warnings related to pointer-to-numeric and vice-versa casts,
00249  * e.g. "conversion from 'u8_t' to 'void *' of greater size"
00250  */
00251 #ifndef LWIP_PTR_NUMERIC_CAST
00252 #define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
00253 #endif
00254 
00255 /** Avoid warnings/errors related to implicitly casting away packed attributes by doing a explicit cast */
00256 #ifndef LWIP_PACKED_CAST
00257 #define LWIP_PACKED_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
00258 #endif
00259 
00260 /** Allocates a memory buffer of specified size that is of sufficient size to align
00261  * its start address using LWIP_MEM_ALIGN.
00262  * You can declare your own version here e.g. to enforce alignment without adding
00263  * trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement
00264  * requirements.\n
00265  * e.g. if you use gcc and need 32 bit alignment:\n
00266  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] \_\_attribute\_\_((aligned(4)))\n
00267  * or more portable:\n
00268  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
00269  */
00270 #ifndef LWIP_DECLARE_MEMORY_ALIGNED
00271 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
00272 #endif
00273 
00274 /** Calculate memory size for an aligned buffer - returns the next highest
00275  * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
00276  * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
00277  */
00278 #ifndef LWIP_MEM_ALIGN_SIZE
00279 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
00280 #endif
00281 
00282 /** Calculate safe memory size for an aligned buffer when using an unaligned
00283  * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
00284  * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
00285  */
00286 #ifndef LWIP_MEM_ALIGN_BUFFER
00287 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
00288 #endif
00289 
00290 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
00291  * so that ADDR % MEM_ALIGNMENT == 0
00292  */
00293 #ifndef LWIP_MEM_ALIGN
00294 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
00295 #endif
00296 
00297 #ifdef __cplusplus
00298 extern "C" {
00299 #endif
00300 
00301 /** Packed structs support.
00302   * Placed BEFORE declaration of a packed struct.\n
00303   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00304   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00305   */
00306 #ifndef PACK_STRUCT_BEGIN
00307 #define PACK_STRUCT_BEGIN
00308 #endif /* PACK_STRUCT_BEGIN */
00309 
00310 /** Packed structs support.
00311   * Placed AFTER declaration of a packed struct.\n
00312   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00313   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00314   */
00315 #ifndef PACK_STRUCT_END
00316 #define PACK_STRUCT_END
00317 #endif /* PACK_STRUCT_END */
00318 
00319 /** Packed structs support.
00320   * Placed between end of declaration of a packed struct and trailing semicolon.\n
00321   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00322   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00323   */
00324 #ifndef PACK_STRUCT_STRUCT
00325 #if defined(__GNUC__) || defined(__clang__)
00326 #define PACK_STRUCT_STRUCT __attribute__((packed))
00327 #else
00328 #define PACK_STRUCT_STRUCT
00329 #endif
00330 #endif /* PACK_STRUCT_STRUCT */
00331 
00332 /** Packed structs support.
00333   * Wraps u32_t and u16_t members.\n
00334   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00335   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00336   */
00337 #ifndef PACK_STRUCT_FIELD
00338 #define PACK_STRUCT_FIELD(x) x
00339 #endif /* PACK_STRUCT_FIELD */
00340 
00341 /** Packed structs support.
00342   * Wraps u8_t members, where some compilers warn that packing is not necessary.\n
00343   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00344   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00345   */
00346 #ifndef PACK_STRUCT_FLD_8
00347 #define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
00348 #endif /* PACK_STRUCT_FLD_8 */
00349 
00350 /** Packed structs support.
00351   * Wraps members that are packed structs themselves, where some compilers warn that packing is not necessary.\n
00352   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00353   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00354   */
00355 #ifndef PACK_STRUCT_FLD_S
00356 #define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
00357 #endif /* PACK_STRUCT_FLD_S */
00358 
00359 /** PACK_STRUCT_USE_INCLUDES==1: Packed structs support using \#include files before and after struct to be packed.\n
00360  * The file included BEFORE the struct is "arch/bpstruct.h".\n
00361  * The file included AFTER the struct is "arch/epstruct.h".\n
00362  * This can be used to implement struct packing on MS Visual C compilers, see
00363  * the Win32 port in the lwIP contrib repository for reference.
00364  * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00365  * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00366  */
00367 #ifdef __DOXYGEN__
00368 #define PACK_STRUCT_USE_INCLUDES
00369 #endif
00370 
00371 /** Eliminates compiler warning about unused arguments (GCC -Wextra -Wunused). */
00372 #ifndef LWIP_UNUSED_ARG
00373 #define LWIP_UNUSED_ARG(x) (void)x
00374 #endif /* LWIP_UNUSED_ARG */
00375 
00376 /** LWIP_PROVIDE_ERRNO==1: Let lwIP provide ERRNO values and the 'errno' variable.
00377  * If this is disabled, cc.h must either define 'errno', include <errno.h>,
00378  * define LWIP_ERRNO_STDINCLUDE to get <errno.h> included or
00379  * define LWIP_ERRNO_INCLUDE to <errno.h> or equivalent.
00380  */
00381 #if defined __DOXYGEN__
00382 #define LWIP_PROVIDE_ERRNO
00383 #endif
00384 
00385 /**
00386  * @}
00387  */
00388 
00389 #ifdef __cplusplus
00390 }
00391 #endif
00392 
00393 #endif /* LWIP_HDR_ARCH_H */