Donatien Garnier / LwIPNetworking

Dependencies:   DebugLib Socket lwip lwip-sys

Dependents:   EthernetInterface

Fork of NetworkingCoreLib by Donatien Garnier

Committer:
donatien
Date:
Thu May 24 14:49:40 2012 +0000
Revision:
0:013f5d54248c
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:013f5d54248c 1 /* cc.h */
donatien 0:013f5d54248c 2 /*
donatien 0:013f5d54248c 3 Copyright (C) 2012 ARM Limited.
donatien 0:013f5d54248c 4
donatien 0:013f5d54248c 5 Permission is hereby granted, free of charge, to any person obtaining a copy of
donatien 0:013f5d54248c 6 this software and associated documentation files (the "Software"), to deal in
donatien 0:013f5d54248c 7 the Software without restriction, including without limitation the rights to
donatien 0:013f5d54248c 8 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
donatien 0:013f5d54248c 9 of the Software, and to permit persons to whom the Software is furnished to do
donatien 0:013f5d54248c 10 so, subject to the following conditions:
donatien 0:013f5d54248c 11
donatien 0:013f5d54248c 12 The above copyright notice and this permission notice shall be included in all
donatien 0:013f5d54248c 13 copies or substantial portions of the Software.
donatien 0:013f5d54248c 14
donatien 0:013f5d54248c 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
donatien 0:013f5d54248c 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
donatien 0:013f5d54248c 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
donatien 0:013f5d54248c 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
donatien 0:013f5d54248c 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
donatien 0:013f5d54248c 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
donatien 0:013f5d54248c 21 SOFTWARE.
donatien 0:013f5d54248c 22 */
donatien 0:013f5d54248c 23
donatien 0:013f5d54248c 24 #ifndef CC_H_
donatien 0:013f5d54248c 25 #define CC_H_
donatien 0:013f5d54248c 26
donatien 0:013f5d54248c 27 #include <stdint.h>
donatien 0:013f5d54248c 28
donatien 0:013f5d54248c 29 //This file was written according to http://lwip.wikia.com/wiki/Porting_for_an_OS and http://git.savannah.gnu.org/cgit/lwip.git/tree/doc/sys_arch.txt
donatien 0:013f5d54248c 30
donatien 0:013f5d54248c 31 //Data types
donatien 0:013f5d54248c 32 typedef uint8_t u8_t;
donatien 0:013f5d54248c 33 typedef uint16_t u16_t;
donatien 0:013f5d54248c 34 typedef uint32_t u32_t;
donatien 0:013f5d54248c 35
donatien 0:013f5d54248c 36 typedef int8_t s8_t;
donatien 0:013f5d54248c 37 typedef int16_t s16_t;
donatien 0:013f5d54248c 38 typedef int32_t s32_t;
donatien 0:013f5d54248c 39
donatien 0:013f5d54248c 40 typedef uint32_t mem_ptr_t;
donatien 0:013f5d54248c 41
donatien 0:013f5d54248c 42 //Debug
donatien 0:013f5d54248c 43 //__DEBUG__ must be defined to enable the macros
donatien 0:013f5d54248c 44 #ifndef __DEBUG__
donatien 0:013f5d54248c 45 #define __DEBUG__ 4 //Maximum verbosity
donatien 0:013f5d54248c 46 #endif
donatien 0:013f5d54248c 47 #ifndef __MODULE__
donatien 0:013f5d54248c 48 #define __MODULE__ "LwIP"
donatien 0:013f5d54248c 49 #endif
donatien 0:013f5d54248c 50 #include "dbg.h"
donatien 0:013f5d54248c 51
donatien 0:013f5d54248c 52 #define LWIP_PLATFORM_DIAG(...) DBG(__VA_ARGS__)
donatien 0:013f5d54248c 53 //#define LWIP_PLATFORM_ASSERT(x) do{ ERR(x); } while(0)
donatien 0:013f5d54248c 54 #define LWIP_PLATFORM_ASSERT(...) ERR(__VA_ARGS__)
donatien 0:013f5d54248c 55
donatien 0:013f5d54248c 56 //Printf formatters
donatien 0:013f5d54248c 57 #define U16_F "hu"
donatien 0:013f5d54248c 58 #define S16_F "d"
donatien 0:013f5d54248c 59 #define X16_F "hx"
donatien 0:013f5d54248c 60 #define U32_F "u"
donatien 0:013f5d54248c 61 #define S32_F "d"
donatien 0:013f5d54248c 62 #define X32_F "x"
donatien 0:013f5d54248c 63 #define SZT_F "uz"
donatien 0:013f5d54248c 64
donatien 0:013f5d54248c 65 //Endianness
donatien 0:013f5d54248c 66 #define BYTE_ORDER LITTLE_ENDIAN
donatien 0:013f5d54248c 67
donatien 0:013f5d54248c 68 #define LWIP_PLATFORM_BYTESWAP 1
donatien 0:013f5d54248c 69 /*
donatien 0:013f5d54248c 70 #define LWIP_PLATFORM_HTONS(x) ( (((u16_t)(x))>>8) | (((x)&0xFF)<<8) )
donatien 0:013f5d54248c 71 #define LWIP_PLATFORM_HTONL(x) ( (((u32_t)(x))>>24) | (((x)&0xFF0000)>>8) \
donatien 0:013f5d54248c 72 | (((x)&0xFF00)<<8) | (((x)&0xFF)<<24) )
donatien 0:013f5d54248c 73 */
donatien 0:013f5d54248c 74
donatien 0:013f5d54248c 75 #include "cmsis.h"
donatien 0:013f5d54248c 76 #define LWIP_PLATFORM_HTONS(x) __REV16(x)
donatien 0:013f5d54248c 77 #define LWIP_PLATFORM_HTONL(x) __REV(x)
donatien 0:013f5d54248c 78
donatien 0:013f5d54248c 79 //Checksums
donatien 0:013f5d54248c 80 /*
donatien 0:013f5d54248c 81 IP protocols use checksums (see RFC 1071). LwIP gives you a choice of 3 algorithms:
donatien 0:013f5d54248c 82 load byte by byte, construct 16 bits word and add: not efficient for most platforms
donatien 0:013f5d54248c 83 load first byte if odd address, loop processing 16 bits words, add last byte.
donatien 0:013f5d54248c 84 load first byte and word if not 4 byte aligned, loop processing 32 bits words, add last word/byte.
donatien 0:013f5d54248c 85 */
donatien 0:013f5d54248c 86 #define LWIP_CHKSUM_ALGORITHM 3
donatien 0:013f5d54248c 87
donatien 0:013f5d54248c 88 //Structure packing
donatien 0:013f5d54248c 89 #if defined ( __CC_ARM )
donatien 0:013f5d54248c 90
donatien 0:013f5d54248c 91 //This will work with ARMCC
donatien 0:013f5d54248c 92 #define PACK_STRUCT_FIELD(x) x//__packed x
donatien 0:013f5d54248c 93 #define PACK_STRUCT_STRUCT
donatien 0:013f5d54248c 94 #define PACK_STRUCT_BEGIN __packed
donatien 0:013f5d54248c 95 #define PACK_STRUCT_END
donatien 0:013f5d54248c 96 #define ALIGNED(n) __align(n)
donatien 0:013f5d54248c 97
donatien 0:013f5d54248c 98 #elif defined ( __GNUC__ )
donatien 0:013f5d54248c 99
donatien 0:013f5d54248c 100 //This will work with GCC and ARMCC in GCC-compatible mode
donatien 0:013f5d54248c 101 #define PACK_STRUCT_FIELD(x) x __attribute__((packed))
donatien 0:013f5d54248c 102 #define PACK_STRUCT_STRUCT __attribute__((packed))
donatien 0:013f5d54248c 103 #define PACK_STRUCT_BEGIN
donatien 0:013f5d54248c 104 #define PACK_STRUCT_END
donatien 0:013f5d54248c 105 #define ALIGNED(n) __attribute__((aligned (n)))
donatien 0:013f5d54248c 106
donatien 0:013f5d54248c 107 #else
donatien 0:013f5d54248c 108 #error "This toolchain is not currently supported for LwIP support (you can FIXME)"
donatien 0:013f5d54248c 109 #endif
donatien 0:013f5d54248c 110
donatien 0:013f5d54248c 111 #define LWIP_PROVIDE_ERRNO
donatien 0:013f5d54248c 112
donatien 0:013f5d54248c 113 #define SYS_LIGHTWEIGHT_PROT 1
donatien 0:013f5d54248c 114 /*
donatien 0:013f5d54248c 115 sys.h will provide default definitions (as of version 1.3.0) of these macros as:
donatien 0:013f5d54248c 116 #define SYS_ARCH_DECL_PROTECT(lev) sys_prot_t lev
donatien 0:013f5d54248c 117 #define SYS_ARCH_PROTECT(lev) lev = sys_arch_protect()
donatien 0:013f5d54248c 118 #define SYS_ARCH_UNPROTECT(lev) sys_arch_unprotect(lev)
donatien 0:013f5d54248c 119 */
donatien 0:013f5d54248c 120
donatien 0:013f5d54248c 121 #endif /* CC_H_ */