TuyaOS
include
components
tal_lwip
include
lwip
arch.h
浏览该文件的文档.
1
6
/*
7
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8
* All rights reserved.
9
*
10
* Redistribution and use in source and binary forms, with or without modification,
11
* are permitted provided that the following conditions are met:
12
*
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.
20
*
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
30
* OF SUCH DAMAGE.
31
*
32
* This file is part of the lwIP TCP/IP stack.
33
*
34
* Author: Adam Dunkels <adam@sics.se>
35
*
36
*/
37
#ifndef LWIP_HDR_ARCH_H
38
#define LWIP_HDR_ARCH_H
39
40
#ifndef LITTLE_ENDIAN
41
#define LITTLE_ENDIAN 1234
42
#endif
43
44
#ifndef BIG_ENDIAN
45
#define BIG_ENDIAN 4321
46
#endif
47
48
#include "
arch/cc.h
"
49
66
#ifndef BYTE_ORDER
67
#define BYTE_ORDER LITTLE_ENDIAN
68
#endif
69
71
#ifdef __DOXYGEN__
72
#define LWIP_RAND() ((u32_t)rand())
73
#endif
74
80
#ifndef LWIP_PLATFORM_DIAG
81
#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
82
#include <stdio.h>
83
#include <stdlib.h>
84
#endif
85
91
#ifndef LWIP_PLATFORM_ASSERT
92
#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n"
, \
93
x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
94
#include <stdio.h>
95
#include <stdlib.h>
96
#endif
97
102
#ifndef LWIP_NO_STDDEF_H
103
#define LWIP_NO_STDDEF_H 0
104
#endif
105
106
#if !LWIP_NO_STDDEF_H
107
#include <stddef.h>
/* for size_t */
108
#endif
109
114
#ifndef LWIP_NO_STDINT_H
115
#define LWIP_NO_STDINT_H 0
116
#endif
117
118
/* Define generic types used in lwIP */
119
#if !LWIP_NO_STDINT_H
120
#include <stdint.h>
121
/* stdint.h is C99 which should also provide support for 64-bit integers */
122
#if !defined(LWIP_HAVE_INT64) && defined(UINT64_MAX)
123
#define LWIP_HAVE_INT64 1
124
#endif
125
typedef
uint8_t u8_t;
126
typedef
int8_t s8_t;
127
typedef
uint16_t u16_t;
128
typedef
int16_t s16_t;
129
typedef
uint32_t u32_t;
130
typedef
int32_t s32_t;
131
#if LWIP_HAVE_INT64
132
typedef
uint64_t u64_t;
133
typedef
int64_t s64_t;
134
#endif
135
typedef
uintptr_t mem_ptr_t;
136
#endif
137
142
#ifndef LWIP_NO_INTTYPES_H
143
#define LWIP_NO_INTTYPES_H 0
144
#endif
145
146
/* Define (sn)printf formatters for these lwIP types */
147
#if !LWIP_NO_INTTYPES_H
148
#include <inttypes.h>
149
#ifndef X8_F
150
#define X8_F "02"
PRIx8
151
#endif
152
#ifndef U16_F
153
#define U16_F PRIu16
154
#endif
155
#ifndef S16_F
156
#define S16_F PRId16
157
#endif
158
#ifndef X16_F
159
#define X16_F PRIx16
160
#endif
161
#ifndef U32_F
162
#define U32_F PRIu32
163
#endif
164
#ifndef S32_F
165
#define S32_F PRId32
166
#endif
167
#ifndef X32_F
168
#define X32_F PRIx32
169
#endif
170
#ifndef SZT_F
171
#define SZT_F PRIuPTR
172
#endif
173
#endif
174
179
#ifndef LWIP_NO_LIMITS_H
180
#define LWIP_NO_LIMITS_H 0
181
#endif
182
183
/* Include limits.h? */
184
#if !LWIP_NO_LIMITS_H
185
#include <limits.h>
186
#endif
187
188
/* Do we need to define ssize_t? This is a compatibility hack:
189
* Unfortunately, this type seems to be unavailable on some systems (even if
190
* sys/types or unistd.h are available).
191
* Being like that, we define it to 'int' if SSIZE_MAX is not defined.
192
*/
193
#ifdef SSIZE_MAX
194
/* If SSIZE_MAX is defined, unistd.h should provide the type as well */
195
#ifndef LWIP_NO_UNISTD_H
196
#define LWIP_NO_UNISTD_H 0
197
#endif
198
#if !LWIP_NO_UNISTD_H
199
#include <unistd.h>
200
#endif
201
#else
/* SSIZE_MAX */
202
#ifndef LWIP_LIBC_HAVE_SSIZE_T
203
typedef
int
ssize_t;
204
#endif
/* LWIP_LIBC_HAVE_SSIZE_T */
205
#define SSIZE_MAX INT_MAX
206
#endif
/* SSIZE_MAX */
207
208
/* some maximum values needed in lwip code */
209
#define LWIP_UINT32_MAX 0xffffffff
210
216
#ifndef LWIP_NO_CTYPE_H
217
#define LWIP_NO_CTYPE_H 0
218
#endif
219
220
#if LWIP_NO_CTYPE_H
221
#define lwip_in_range(c, lo, up) ((u8_t)(c) >= (lo) && (u8_t)(c) <= (up))
222
#define lwip_isdigit(c) lwip_in_range((c), '0', '9')
223
#define lwip_isxdigit(c) (lwip_isdigit(c) || lwip_in_range((c), 'a', 'f') || lwip_in_range((c), 'A', 'F'))
224
#define lwip_islower(c) lwip_in_range((c), 'a', 'z')
225
#define lwip_isspace(c) ((c) == ' ' || (c) == '\f' || (c) == '\n' || (c) == '\r' || (c) == '\t' || (c) == '\v')
226
#define lwip_isupper(c) lwip_in_range((c), 'A', 'Z')
227
#define lwip_tolower(c) (lwip_isupper(c) ? (c) - 'A' + 'a' : c)
228
#define lwip_toupper(c) (lwip_islower(c) ? (c) - 'a' + 'A' : c)
229
#else
230
#include <ctype.h>
231
#define lwip_isdigit(c) isdigit((unsigned char)(c))
232
#define lwip_isxdigit(c) isxdigit((unsigned char)(c))
233
#define lwip_islower(c) islower((unsigned char)(c))
234
#define lwip_isspace(c) isspace((unsigned char)(c))
235
#define lwip_isupper(c) isupper((unsigned char)(c))
236
#define lwip_tolower(c) tolower((unsigned char)(c))
237
#define lwip_toupper(c) toupper((unsigned char)(c))
238
#endif
239
241
#ifndef LWIP_CONST_CAST
242
#define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
243
#endif
244
246
#ifndef LWIP_ALIGNMENT_CAST
247
#define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
248
#endif
249
253
#ifndef LWIP_PTR_NUMERIC_CAST
254
#define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
255
#endif
256
258
#ifndef LWIP_PACKED_CAST
259
#define LWIP_PACKED_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
260
#endif
261
272
#ifndef LWIP_DECLARE_MEMORY_ALIGNED
273
#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
274
#endif
275
280
#ifndef LWIP_MEM_ALIGN_SIZE
281
#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
282
#endif
283
288
#ifndef LWIP_MEM_ALIGN_BUFFER
289
#define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
290
#endif
291
295
#ifndef LWIP_MEM_ALIGN
296
#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
297
#endif
298
299
#ifdef __cplusplus
300
extern
"C"
{
301
#endif
302
308
#ifndef PACK_STRUCT_BEGIN
309
#define PACK_STRUCT_BEGIN
310
#endif
/* PACK_STRUCT_BEGIN */
311
317
#ifndef PACK_STRUCT_END
318
#define PACK_STRUCT_END
319
#endif
/* PACK_STRUCT_END */
320
326
#ifndef PACK_STRUCT_STRUCT
327
#if defined(__GNUC__) || defined(__clang__)
328
#define PACK_STRUCT_STRUCT __attribute__((packed))
329
#else
330
#define PACK_STRUCT_STRUCT
331
#endif
332
#endif
/* PACK_STRUCT_STRUCT */
333
339
#ifndef PACK_STRUCT_FIELD
340
#define PACK_STRUCT_FIELD(x) x
341
#endif
/* PACK_STRUCT_FIELD */
342
348
#ifndef PACK_STRUCT_FLD_8
349
#define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
350
#endif
/* PACK_STRUCT_FLD_8 */
351
357
#ifndef PACK_STRUCT_FLD_S
358
#define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
359
#endif
/* PACK_STRUCT_FLD_S */
360
369
#ifdef __DOXYGEN__
370
#define PACK_STRUCT_USE_INCLUDES
371
#endif
372
374
#ifndef LWIP_UNUSED_ARG
375
#define LWIP_UNUSED_ARG(x) (void)x
376
#endif
/* LWIP_UNUSED_ARG */
377
383
#if defined __DOXYGEN__
384
#define LWIP_PROVIDE_ERRNO
385
#endif
386
391
#ifdef __cplusplus
392
}
393
#endif
394
395
#endif
/* LWIP_HDR_ARCH_H */
cc.h
LWIP编译器相关接口封装
制作者
1.9.4