3 * Support for different processor and compiler architectures
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * This file is part of the lwIP TCP/IP stack.
34 * Author: Adam Dunkels <adam@sics.se>
37 #ifndef LWIP_HDR_ARCH_H
38 #define LWIP_HDR_ARCH_H
40 #if CHIP_HAVE_CONFIG_H
41 #include <lwip/lwip_buildconfig.h>
45 #define LITTLE_ENDIAN 1234
49 #define BIG_ENDIAN 4321
55 * @defgroup compiler_abstraction Compiler/platform abstraction
57 * All defines related to this section must not be placed in lwipopts.h,
59 * These options cannot be \#defined in lwipopts.h since they are not options
60 * of lwIP itself, but options of the lwIP port to your system.
64 /** Define the byte order of the system.
65 * Needed for conversion of network data to host byte order.
66 * Allowed values: LITTLE_ENDIAN and BIG_ENDIAN
69 #define BYTE_ORDER LITTLE_ENDIAN
72 /** Define random number generator function of your system */
74 #define LWIP_RAND() ((u32_t)rand())
77 /** Platform specific diagnostic output.\n
78 * Note the default implementation pulls in printf, which may
79 * in turn pull in a lot of standard libary code. In resource-constrained
80 * systems, this should be defined to something less resource-consuming.
82 #ifndef LWIP_PLATFORM_DIAG
83 #define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
88 /** Platform specific assertion handling.\n
89 * Note the default implementation pulls in printf, fflush and abort, which may
90 * in turn pull in a lot of standard libary code. In resource-constrained
91 * systems, this should be defined to something less resource-consuming.
93 #ifndef LWIP_PLATFORM_ASSERT
94 #define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
95 x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
100 /** Define this to 1 in arch/cc.h of your port if you do not want to
101 * include stddef.h header to get size_t. You need to typedef size_t
102 * by yourself in this case.
104 #ifndef LWIP_NO_STDDEF_H
105 #define LWIP_NO_STDDEF_H 0
108 #if !LWIP_NO_STDDEF_H
109 #include <stddef.h> /* for size_t */
112 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
113 * the stdint.h header. You need to typedef the generic types listed in
114 * lwip/arch.h yourself in this case (u8_t, u16_t...).
116 #ifndef LWIP_NO_STDINT_H
117 #define LWIP_NO_STDINT_H 0
120 /* Define generic types used in lwIP */
121 #if !LWIP_NO_STDINT_H
123 typedef uint8_t u8_t;
125 typedef uint16_t u16_t;
126 typedef int16_t s16_t;
127 typedef uint32_t u32_t;
128 typedef int32_t s32_t;
129 typedef uintptr_t mem_ptr_t;
132 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
133 * the inttypes.h header. You need to define the format strings listed in
134 * lwip/arch.h yourself in this case (X8_F, U16_F...).
136 #ifndef LWIP_NO_INTTYPES_H
137 #define LWIP_NO_INTTYPES_H 0
140 /* Define (sn)printf formatters for these lwIP types */
141 #if !LWIP_NO_INTTYPES_H
142 #include <inttypes.h>
144 #define X8_F "02" PRIx8
165 #define SZT_F PRIuPTR
169 /** Define this to 1 in arch/cc.h of your port if your compiler does not provide
170 * the limits.h header. You need to define the type limits yourself in this case
173 #ifndef LWIP_NO_LIMITS_H
174 #define LWIP_NO_LIMITS_H 0
177 /* Include limits.h? */
178 #if !LWIP_NO_LIMITS_H
182 /** C++ const_cast<target_type>(val) equivalent to remove constness from a value (GCC -Wcast-qual) */
183 #ifndef LWIP_CONST_CAST
184 #define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
187 /** Get rid of alignment cast warnings (GCC -Wcast-align) */
188 #ifndef LWIP_ALIGNMENT_CAST
189 #define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
192 /** Get rid of warnings related to pointer-to-numeric and vice-versa casts,
193 * e.g. "conversion from 'u8_t' to 'void *' of greater size"
195 #ifndef LWIP_PTR_NUMERIC_CAST
196 #define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
199 /** Allocates a memory buffer of specified size that is of sufficient size to align
200 * its start address using LWIP_MEM_ALIGN.
201 * You can declare your own version here e.g. to enforce alignment without adding
202 * trailing padding bytes (see LWIP_MEM_ALIGN_BUFFER) or your own section placement
204 * e.g. if you use gcc and need 32 bit alignment:\n
205 * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[size] \_\_attribute\_\_((aligned(4)))\n
206 * or more portable:\n
207 * \#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u32_t variable_name[(size + sizeof(u32_t) - 1) / sizeof(u32_t)]
209 #ifndef LWIP_DECLARE_MEMORY_ALIGNED
210 #define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
213 /** Calculate memory size for an aligned buffer - returns the next highest
214 * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
215 * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
217 #ifndef LWIP_MEM_ALIGN_SIZE
218 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
221 /** Calculate safe memory size for an aligned buffer when using an unaligned
222 * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
223 * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
225 #ifndef LWIP_MEM_ALIGN_BUFFER
226 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
229 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
230 * so that ADDR % MEM_ALIGNMENT == 0
232 #ifndef LWIP_MEM_ALIGN
233 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
240 /** Packed structs support.
241 * Placed BEFORE declaration of a packed struct.\n
242 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
243 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
245 #ifndef PACK_STRUCT_BEGIN
246 #define PACK_STRUCT_BEGIN
247 #endif /* PACK_STRUCT_BEGIN */
249 /** Packed structs support.
250 * Placed AFTER declaration of a packed struct.\n
251 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
252 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
254 #ifndef PACK_STRUCT_END
255 #define PACK_STRUCT_END
256 #endif /* PACK_STRUCT_END */
258 /** Packed structs support.
259 * Placed between end of declaration of a packed struct and trailing semicolon.\n
260 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
261 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
263 #ifndef PACK_STRUCT_STRUCT
264 #if defined(__GNUC__) || defined(__clang__)
265 #define PACK_STRUCT_STRUCT __attribute__((packed))
267 #define PACK_STRUCT_STRUCT
269 #endif /* PACK_STRUCT_STRUCT */
271 /** Packed structs support.
272 * Wraps u32_t and u16_t members.\n
273 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
274 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
276 #ifndef PACK_STRUCT_FIELD
277 #define PACK_STRUCT_FIELD(x) x
278 #endif /* PACK_STRUCT_FIELD */
280 /** Packed structs support.
281 * Wraps u8_t members, where some compilers warn that packing is not necessary.\n
282 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
283 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
285 #ifndef PACK_STRUCT_FLD_8
286 #define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
287 #endif /* PACK_STRUCT_FLD_8 */
289 /** Packed structs support.
290 * Wraps members that are packed structs themselves, where some compilers warn that packing is not necessary.\n
291 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
292 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
294 #ifndef PACK_STRUCT_FLD_S
295 #define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
296 #endif /* PACK_STRUCT_FLD_S */
298 /** Packed structs support using \#include files before and after struct to be packed.\n
299 * The file included BEFORE the struct is "arch/bpstruct.h".\n
300 * The file included AFTER the struct is "arch/epstruct.h".\n
301 * This can be used to implement struct packing on MS Visual C compilers, see
302 * the Win32 port in the lwIP contrib repository for reference.
303 * For examples of packed struct declarations, see include/lwip/prot/ subfolder.\n
304 * A port to GCC/clang is included in lwIP, if you use these compilers there is nothing to do here.
307 #define PACK_STRUCT_USE_INCLUDES
310 /** Eliminates compiler warning about unused arguments (GCC -Wextra -Wunused). */
311 #ifndef LWIP_UNUSED_ARG
312 #define LWIP_UNUSED_ARG(x) (void)x
313 #endif /* LWIP_UNUSED_ARG */
323 #endif /* LWIP_HDR_ARCH_H */