lwIP: add ethernet glue for lwIP
[bertos.git] / bertos / net / lwip / src / include / arch / cc.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Luca Ottaviano <lottaviano@develer.com>
34  *
35  * \brief Compiler defines for Emulation Layer for lwIP
36  *      - Architecture environment, some compiler specific, some
37  *        environment specific (probably should move env stuff
38  *        to sys_arch.h.)
39  *
40  */
41
42 #ifndef LWIP_CC_H
43 #define LWIP_CC_H
44
45 #include <cfg/compiler.h>
46 #include <cpu/attr.h>
47 #include <lwip/arch.h>
48 #ifndef BYTE_ORDER
49         #if CPU_BYTE_ORDER == CPU_BIG_ENDIAN
50                 #define BYTE_ORDER   BIG_ENDIAN
51         #elif CPU_BYTE_ORDER == CPU_LITTLE_ENDIAN
52                 #define BYTE_ORDER   LITTLE_ENDIAN
53         #endif
54 #endif
55
56 #include <cfg/debug.h>
57
58 #include <sys/time.h>
59 // Unix error codes required by lwip
60 #include <errno.h>
61 // memset required by lwip
62 #include <string.h>
63
64 typedef uint8_t u8_t;
65 typedef int8_t s8_t;
66 typedef uint16_t u16_t;
67 typedef int16_t s16_t;
68 typedef uint32_t u32_t;
69 typedef int32_t s32_t;
70 typedef int mem_ptr_t;
71
72
73 /* Define (sn)printf formatters for these lwIP types */
74 #if CPU_ARM_AT91 || (ARCH & ARCH_EMUL)
75         #define U16_F "hu"
76         #define S16_F "d"
77         #define X16_F "x"
78         #define U32_F "lu"
79         #define S32_F "ld"
80         #define X32_F "lx"
81 #elif CPU_AVR
82         #define U16_F "u"
83         #define S16_F "d"
84         #define X16_F "x"
85         #define U32_F "lu"
86         #define S32_F "ld"
87         #define X32_F "lx"
88 #else
89         #error This CPU is currently unsupported by lwip
90 #endif
91
92 /**
93  * Compiler hints for packing lwip's structures
94  */
95 #define PACK_STRUCT_STRUCT    PACKED
96
97 /*
98  * Platform specific diagnostic output
99  */
100 // not fatal, print a message
101 #define LWIP_PLATFORM_DIAG(y)   kprintf y
102
103 // fatal, print message and abandon execution.
104 #define LWIP_PLATFORM_ASSERT(y) \
105         do { \
106                 kprintf(y); \
107                 ASSERT(0); \
108         } while(0)
109
110 /*
111  * "lightweight" synchronization mechanisms
112  *
113  * SYS_LIGHTWEIGHT_PROT
114  * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
115  * for certain critical regions during buffer allocation, deallocation and memory
116  * allocation and deallocation.
117  */
118
119 // TODO: if lwip is not used within multiple processes or interrupts, it's ok
120 // not to define them
121 /* #define SYS_ARCH_DECL_PROTECT(x) - declare a protection state variable.
122     SYS_ARCH_PROTECT(x)      - enter protection mode.
123     SYS_ARCH_UNPROTECT(x)    - leave protection mode. */
124
125 #define SYS_ARCH_DECL_PROTECT(x)
126 #define SYS_ARCH_PROTECT(x)             proc_forbid()
127 #define SYS_ARCH_UNPROTECT(x)           proc_permit()
128
129 #endif