1 /*
2  * Copyright (c) 2006-2022, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2022-02-20     Meco Man     add RT-Thread copyright
9  */
10 
11 /*
12  * Copyright (c) 2001, Swedish Institute of Computer Science.
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions
17  * are met:
18  * 1. Redistributions of source code must retain the above copyright
19  *    notice, this list of conditions and the following disclaimer.
20  * 2. Redistributions in binary form must reproduce the above copyright
21  *    notice, this list of conditions and the following disclaimer in the
22  *    documentation and/or other materials provided with the distribution.
23  * 3. Neither the name of the Institute nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  * This file is part of the lwIP TCP/IP stack.
40  *
41  * Author: Adam Dunkels <adam@sics.se>
42  *
43  * $Id: cc.h,v 1.1.1.1 2004/12/16 14:17:13 bear Exp $
44  */
45 #ifndef __ARCH_CC_H__
46 #define __ARCH_CC_H__
47 
48 #include <rthw.h>
49 #include <rtthread.h>
50 
51 #ifndef BYTE_ORDER
52 #ifdef ARCH_CPU_BIG_ENDIAN
53 #define BYTE_ORDER BIG_ENDIAN
54 #else
55 #define BYTE_ORDER LITTLE_ENDIAN
56 #endif /* ARCH_CPU_BIG_ENDIAN */
57 #endif /* BYTE_ORDER */
58 
59 #if RT_USING_LWIP_VER_NUM < 0x20000
60 #include <stdint.h>
61 typedef uint8_t   u8_t;
62 typedef int8_t    s8_t;
63 typedef uint16_t  u16_t;
64 typedef int16_t   s16_t;
65 typedef uint32_t  u32_t;
66 typedef int32_t   s32_t;
67 typedef uintptr_t mem_ptr_t;
68 
69 #define U16_F "hu"
70 #define S16_F "hd"
71 #define X16_F "hx"
72 #define U32_F "lu"
73 #define S32_F "ld"
74 #define X32_F "lx"
75 #endif /* RT_USING_LWIP_VER_NUM < 0x20000 */
76 
77 #if defined(__CC_ARM)   /* ARMCC compiler */
78 #define PACK_STRUCT_FIELD(x) x
79 #define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
80 #define PACK_STRUCT_BEGIN
81 #define PACK_STRUCT_END
82 #elif defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050) /*Arm Compiler 6*/
83 #define PACK_STRUCT_FIELD(x) x
84 #define PACK_STRUCT_STRUCT __attribute__((packed))
85 #define PACK_STRUCT_BEGIN
86 #define PACK_STRUCT_END
87 #elif defined(__IAR_SYSTEMS_ICC__)   /* IAR Compiler */
88 #define PACK_STRUCT_BEGIN
89 #define PACK_STRUCT_STRUCT
90 #define PACK_STRUCT_END
91 #define PACK_STRUCT_FIELD(x) x
92 #define PACK_STRUCT_USE_INCLUDES
93 #elif defined(__GNUC__)     /* GNU GCC Compiler */
94 #define PACK_STRUCT_FIELD(x) x
95 #define PACK_STRUCT_STRUCT __attribute__((packed))
96 #define PACK_STRUCT_BEGIN
97 #define PACK_STRUCT_END
98 #elif defined(_MSC_VER)
99 #define PACK_STRUCT_FIELD(x) x
100 #define PACK_STRUCT_STRUCT
101 #define PACK_STRUCT_BEGIN
102 #define PACK_STRUCT_END
103 #define PACK_STRUCT_USE_INCLUDES
104 #endif
105 
106 void sys_arch_assert(const char* file, int line);
107 #define LWIP_PLATFORM_DIAG(x)   do {rt_kprintf x;} while(0)
108 #define LWIP_PLATFORM_ASSERT(x) do {rt_kprintf(x); sys_arch_assert(__FILE__, __LINE__);}while(0)
109 
110 #endif /* __ARCH_CC_H__ */
111