Daiki Kato / mbed-os-lychee

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

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  * These options cannot be \#defined in lwipopts.h since they are not options
00056  * of lwIP itself, but options of the lwIP port to your system.
00057  * @{
00058  */
00059 
00060 /** Define the byte order of the system.
00061  * Needed for conversion of network data to host byte order.
00062  * Allowed values: LITTLE_ENDIAN and BIG_ENDIAN
00063  */
00064 #ifndef BYTE_ORDER
00065 #define BYTE_ORDER LITTLE_ENDIAN
00066 #endif
00067 
00068 /** Define random number generator function of your system */
00069 #ifndef LWIP_RAND
00070 #define LWIP_RAND() ((u32_t)rand())
00071 #endif
00072 
00073 /** Platform specific diagnostic output.\n
00074  * Note the default implementation pulls in printf, which may
00075  * in turn pull in a lot of standard libary code. In resource-constrained 
00076  * systems, this should be defined to something less resource-consuming.
00077  */
00078 #ifndef LWIP_PLATFORM_DIAG
00079 #define LWIP_PLATFORM_DIAG(x)   do {printf x;} while(0)
00080 #include <stdio.h>
00081 #include <stdlib.h>
00082 #endif
00083 
00084 /** Platform specific assertion handling.\n
00085  * Note the default implementation pulls in printf, fflush and abort, which may
00086  * in turn pull in a lot of standard libary code. In resource-constrained 
00087  * systems, this should be defined to something less resource-consuming.
00088  */
00089 #ifndef LWIP_PLATFORM_ASSERT
00090 #define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
00091                                      x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
00092 #include <stdio.h>
00093 #include <stdlib.h>
00094 #endif
00095 
00096 /** Define this to 1 in arch/cc.h of your port if you do not want to
00097  * include stddef.h header to get size_t. You need to typedef size_t
00098  * by yourself in this case.
00099  */
00100 #ifndef LWIP_NO_STDDEF_H
00101 #define LWIP_NO_STDDEF_H 0
00102 #endif
00103 
00104 #if !LWIP_NO_STDDEF_H
00105 #include <stddef.h> /* for size_t */
00106 #endif
00107 
00108 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00109  * the stdint.h header. You need to typedef the generic types listed in
00110  * lwip/arch.h yourself in this case (u8_t, u16_t...).
00111  */
00112 #ifndef LWIP_NO_STDINT_H
00113 #define LWIP_NO_STDINT_H 0
00114 #endif
00115 
00116 /* Define generic types used in lwIP */
00117 #if !LWIP_NO_STDINT_H
00118 #include <stdint.h>
00119 typedef uint8_t   u8_t;
00120 typedef int8_t    s8_t;
00121 typedef uint16_t  u16_t;
00122 typedef int16_t   s16_t;
00123 typedef uint32_t  u32_t;
00124 typedef int32_t   s32_t;
00125 typedef uintptr_t mem_ptr_t;
00126 #endif
00127 
00128 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
00129  * the inttypes.h header. You need to define the format strings listed in
00130  * lwip/arch.h yourself in this case (X8_F, U16_F...).
00131  */
00132 #ifndef LWIP_NO_INTTYPES_H
00133 #define LWIP_NO_INTTYPES_H 0
00134 #endif
00135 
00136 /* Define (sn)printf formatters for these lwIP types */
00137 #if !LWIP_NO_INTTYPES_H
00138 #include <inttypes.h>
00139 #ifndef X8_F
00140 #define X8_F  "02" PRIx8
00141 #endif
00142 #ifndef U16_F
00143 #define U16_F PRIu16
00144 #endif
00145 #ifndef S16_F
00146 #define S16_F PRId16
00147 #endif
00148 #ifndef X16_F
00149 #define X16_F PRIx16
00150 #endif
00151 #ifndef U32_F
00152 #define U32_F PRIu32
00153 #endif
00154 #ifndef S32_F
00155 #define S32_F PRId32
00156 #endif
00157 #ifndef X32_F
00158 #define X32_F PRIx32
00159 #endif
00160 #ifndef SZT_F
00161 #define SZT_F PRIuPTR
00162 #endif
00163 #endif
00164 
00165 /** C++ const_cast<target_type>(val) equivalent to remove constness from a value (GCC -Wcast-qual) */
00166 #ifndef LWIP_CONST_CAST
00167 #define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
00168 #endif
00169 
00170 /** Get rid of alignment cast warnings (GCC -Wcast-align) */
00171 #ifndef LWIP_ALIGNMENT_CAST
00172 #define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
00173 #endif
00174 
00175 /** Get rid of warnings related to pointer-to-numeric and vice-versa casts,
00176  * e.g. "conversion from 'u8_t' to 'void *' of greater size"
00177  */
00178 #ifndef LWIP_PTR_NUMERIC_CAST
00179 #define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
00180 #endif
00181 
00182 /** Allocates a memory buffer of specified size that is of sufficient size to align
00183  * its start address using LWIP_MEM_ALIGN.
00184  * You can declare your own version here e.g. to enforce alignment without adding
00185  * trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement
00186  * requirements.\n
00187  * e.g. if you use gcc and need 32 bit alignment:\n
00188  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] \_\_attribute\_\_((aligned(4)))\n
00189  * or more portable:\n
00190  * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
00191  */
00192 #ifndef LWIP_DECLARE_MEMORY_ALIGNED
00193 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
00194 #endif
00195 
00196 /** Calculate memory size for an aligned buffer - returns the next highest
00197  * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
00198  * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
00199  */
00200 #ifndef LWIP_MEM_ALIGN_SIZE
00201 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
00202 #endif
00203 
00204 /** Calculate safe memory size for an aligned buffer when using an unaligned
00205  * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
00206  * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
00207  */
00208 #ifndef LWIP_MEM_ALIGN_BUFFER
00209 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
00210 #endif
00211 
00212 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
00213  * so that ADDR % MEM_ALIGNMENT == 0
00214  */
00215 #ifndef LWIP_MEM_ALIGN
00216 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
00217 #endif
00218 
00219 #ifdef __cplusplus
00220 extern "C" {
00221 #endif
00222 
00223 /** Packed structs support.
00224   * Placed BEFORE declaration of a packed struct.\n
00225   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00226   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00227   */
00228 #ifndef PACK_STRUCT_BEGIN
00229 #define PACK_STRUCT_BEGIN
00230 #endif /* PACK_STRUCT_BEGIN */
00231 
00232 /** Packed structs support.
00233   * Placed AFTER declaration of a packed struct.\n
00234   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00235   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00236   */
00237 #ifndef PACK_STRUCT_END
00238 #define PACK_STRUCT_END
00239 #endif /* PACK_STRUCT_END */
00240 
00241 /** Packed structs support.
00242   * Placed between end of declaration of a packed struct and trailing semicolon.\n
00243   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00244   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00245   */
00246 #ifndef PACK_STRUCT_STRUCT
00247 #if defined(__GNUC__) || defined(__clang__)
00248 #define PACK_STRUCT_STRUCT __attribute__((packed))
00249 #else
00250 #define PACK_STRUCT_STRUCT
00251 #endif
00252 #endif /* PACK_STRUCT_STRUCT */
00253 
00254 /** Packed structs support.
00255   * Wraps u32_t and u16_t members.\n
00256   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00257   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00258   */
00259 #ifndef PACK_STRUCT_FIELD
00260 #define PACK_STRUCT_FIELD(x) x
00261 #endif /* PACK_STRUCT_FIELD */
00262 
00263 /** Packed structs support.
00264   * Wraps u8_t members, where some compilers warn that packing is not necessary.\n
00265   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00266   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00267   */
00268 #ifndef PACK_STRUCT_FLD_8
00269 #define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
00270 #endif /* PACK_STRUCT_FLD_8 */
00271 
00272 /** Packed structs support.
00273   * Wraps members that are packed structs themselves, where some compilers warn that packing is not necessary.\n
00274   * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00275   * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00276   */
00277 #ifndef PACK_STRUCT_FLD_S
00278 #define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
00279 #endif /* PACK_STRUCT_FLD_S */
00280 
00281 /** Packed structs support using \#include files before and after struct to be packed.\n
00282  * The file included BEFORE the struct is "arch/bpstruct.h".\n
00283  * The file included AFTER the struct is "arch/epstruct.h".\n
00284  * This can be used to implement struct packing on MS Visual C compilers, see
00285  * the Win32 port in the lwIP contrib repository for reference.
00286  * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
00287  * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
00288  */
00289 #ifdef __DOXYGEN__
00290 #define PACK_STRUCT_USE_INCLUDES
00291 #endif
00292 
00293 /** Eliminates compiler warning about unused arguments (GCC -Wextra -Wunused). */
00294 #ifndef LWIP_UNUSED_ARG
00295 #define LWIP_UNUSED_ARG(x) (void)x
00296 #endif /* LWIP_UNUSED_ARG */
00297 
00298 /**
00299  * @}
00300  */
00301 
00302 #ifdef __cplusplus
00303 }
00304 #endif
00305 
00306 #endif /* LWIP_HDR_ARCH_H */