Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherckuith 0:479ce5546098 1 /*
sherckuith 0:479ce5546098 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
sherckuith 0:479ce5546098 3 * All rights reserved.
sherckuith 0:479ce5546098 4 *
sherckuith 0:479ce5546098 5 * Redistribution and use in source and binary forms, with or without modification,
sherckuith 0:479ce5546098 6 * are permitted provided that the following conditions are met:
sherckuith 0:479ce5546098 7 *
sherckuith 0:479ce5546098 8 * 1. Redistributions of source code must retain the above copyright notice,
sherckuith 0:479ce5546098 9 * this list of conditions and the following disclaimer.
sherckuith 0:479ce5546098 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
sherckuith 0:479ce5546098 11 * this list of conditions and the following disclaimer in the documentation
sherckuith 0:479ce5546098 12 * and/or other materials provided with the distribution.
sherckuith 0:479ce5546098 13 * 3. The name of the author may not be used to endorse or promote products
sherckuith 0:479ce5546098 14 * derived from this software without specific prior written permission.
sherckuith 0:479ce5546098 15 *
sherckuith 0:479ce5546098 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
sherckuith 0:479ce5546098 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
sherckuith 0:479ce5546098 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
sherckuith 0:479ce5546098 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
sherckuith 0:479ce5546098 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
sherckuith 0:479ce5546098 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
sherckuith 0:479ce5546098 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
sherckuith 0:479ce5546098 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
sherckuith 0:479ce5546098 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
sherckuith 0:479ce5546098 25 * OF SUCH DAMAGE.
sherckuith 0:479ce5546098 26 *
sherckuith 0:479ce5546098 27 * This file is part of the lwIP TCP/IP stack.
sherckuith 0:479ce5546098 28 *
sherckuith 0:479ce5546098 29 * Author: Adam Dunkels <adam@sics.se>
sherckuith 0:479ce5546098 30 *
sherckuith 0:479ce5546098 31 */
sherckuith 0:479ce5546098 32 #ifndef __LWIP_DEF_H__
sherckuith 0:479ce5546098 33 #define __LWIP_DEF_H__
sherckuith 0:479ce5546098 34
sherckuith 0:479ce5546098 35 /* arch.h might define NULL already */
sherckuith 0:479ce5546098 36 #include "lwip/arch.h"
sherckuith 0:479ce5546098 37 #include "lwip/opt.h"
sherckuith 0:479ce5546098 38
sherckuith 0:479ce5546098 39 #ifdef __cplusplus
sherckuith 0:479ce5546098 40 extern "C" {
sherckuith 0:479ce5546098 41 #endif
sherckuith 0:479ce5546098 42
sherckuith 0:479ce5546098 43 #define LWIP_MAX(x , y) (((x) > (y)) ? (x) : (y))
sherckuith 0:479ce5546098 44 #define LWIP_MIN(x , y) (((x) < (y)) ? (x) : (y))
sherckuith 0:479ce5546098 45
sherckuith 0:479ce5546098 46 #ifndef NULL
sherckuith 0:479ce5546098 47 #define NULL ((void *)0)
sherckuith 0:479ce5546098 48 #endif
sherckuith 0:479ce5546098 49
sherckuith 0:479ce5546098 50 /** Get the absolute difference between 2 u32_t values (correcting overflows)
sherckuith 0:479ce5546098 51 * 'a' is expected to be 'higher' (without overflow) than 'b'. */
sherckuith 0:479ce5546098 52 #define LWIP_U32_DIFF(a, b) (((a) >= (b)) ? ((a) - (b)) : (((a) + ((b) ^ 0xFFFFFFFF) + 1)))
sherckuith 0:479ce5546098 53
sherckuith 0:479ce5546098 54 /* Endianess-optimized shifting of two u8_t to create one u16_t */
sherckuith 0:479ce5546098 55 #if BYTE_ORDER == LITTLE_ENDIAN
sherckuith 0:479ce5546098 56 #define LWIP_MAKE_U16(a, b) ((a << 8) | b)
sherckuith 0:479ce5546098 57 #else
sherckuith 0:479ce5546098 58 #define LWIP_MAKE_U16(a, b) ((b << 8) | a)
sherckuith 0:479ce5546098 59 #endif
sherckuith 0:479ce5546098 60
sherckuith 0:479ce5546098 61 #ifndef LWIP_PLATFORM_BYTESWAP
sherckuith 0:479ce5546098 62 #define LWIP_PLATFORM_BYTESWAP 0
sherckuith 0:479ce5546098 63 #endif
sherckuith 0:479ce5546098 64
sherckuith 0:479ce5546098 65 #ifndef LWIP_PREFIX_BYTEORDER_FUNCS
sherckuith 0:479ce5546098 66 /* workaround for naming collisions on some platforms */
sherckuith 0:479ce5546098 67
sherckuith 0:479ce5546098 68 #ifdef htons
sherckuith 0:479ce5546098 69 #undef htons
sherckuith 0:479ce5546098 70 #endif /* htons */
sherckuith 0:479ce5546098 71 #ifdef htonl
sherckuith 0:479ce5546098 72 #undef htonl
sherckuith 0:479ce5546098 73 #endif /* htonl */
sherckuith 0:479ce5546098 74 #ifdef ntohs
sherckuith 0:479ce5546098 75 #undef ntohs
sherckuith 0:479ce5546098 76 #endif /* ntohs */
sherckuith 0:479ce5546098 77 #ifdef ntohl
sherckuith 0:479ce5546098 78 #undef ntohl
sherckuith 0:479ce5546098 79 #endif /* ntohl */
sherckuith 0:479ce5546098 80
sherckuith 0:479ce5546098 81 #define htons(x) lwip_htons(x)
sherckuith 0:479ce5546098 82 #define ntohs(x) lwip_ntohs(x)
sherckuith 0:479ce5546098 83 #define htonl(x) lwip_htonl(x)
sherckuith 0:479ce5546098 84 #define ntohl(x) lwip_ntohl(x)
sherckuith 0:479ce5546098 85 #endif /* LWIP_PREFIX_BYTEORDER_FUNCS */
sherckuith 0:479ce5546098 86
sherckuith 0:479ce5546098 87 #if BYTE_ORDER == BIG_ENDIAN
sherckuith 0:479ce5546098 88 #define lwip_htons(x) (x)
sherckuith 0:479ce5546098 89 #define lwip_ntohs(x) (x)
sherckuith 0:479ce5546098 90 #define lwip_htonl(x) (x)
sherckuith 0:479ce5546098 91 #define lwip_ntohl(x) (x)
sherckuith 0:479ce5546098 92 #define PP_HTONS(x) (x)
sherckuith 0:479ce5546098 93 #define PP_NTOHS(x) (x)
sherckuith 0:479ce5546098 94 #define PP_HTONL(x) (x)
sherckuith 0:479ce5546098 95 #define PP_NTOHL(x) (x)
sherckuith 0:479ce5546098 96 #else /* BYTE_ORDER != BIG_ENDIAN */
sherckuith 0:479ce5546098 97 #if LWIP_PLATFORM_BYTESWAP
sherckuith 0:479ce5546098 98 #define lwip_htons(x) LWIP_PLATFORM_HTONS(x)
sherckuith 0:479ce5546098 99 #define lwip_ntohs(x) LWIP_PLATFORM_HTONS(x)
sherckuith 0:479ce5546098 100 #define lwip_htonl(x) LWIP_PLATFORM_HTONL(x)
sherckuith 0:479ce5546098 101 #define lwip_ntohl(x) LWIP_PLATFORM_HTONL(x)
sherckuith 0:479ce5546098 102 #else /* LWIP_PLATFORM_BYTESWAP */
sherckuith 0:479ce5546098 103 u16_t lwip_htons(u16_t x);
sherckuith 0:479ce5546098 104 u16_t lwip_ntohs(u16_t x);
sherckuith 0:479ce5546098 105 u32_t lwip_htonl(u32_t x);
sherckuith 0:479ce5546098 106 u32_t lwip_ntohl(u32_t x);
sherckuith 0:479ce5546098 107 #endif /* LWIP_PLATFORM_BYTESWAP */
sherckuith 0:479ce5546098 108
sherckuith 0:479ce5546098 109 /* These macros should be calculated by the preprocessor and are used
sherckuith 0:479ce5546098 110 with compile-time constants only (so that there is no little-endian
sherckuith 0:479ce5546098 111 overhead at runtime). */
sherckuith 0:479ce5546098 112 #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
sherckuith 0:479ce5546098 113 #define PP_NTOHS(x) PP_HTONS(x)
sherckuith 0:479ce5546098 114 #define PP_HTONL(x) ((((x) & 0xff) << 24) | \
sherckuith 0:479ce5546098 115 (((x) & 0xff00) << 8) | \
sherckuith 0:479ce5546098 116 (((x) & 0xff0000UL) >> 8) | \
sherckuith 0:479ce5546098 117 (((x) & 0xff000000UL) >> 24))
sherckuith 0:479ce5546098 118 #define PP_NTOHL(x) PP_HTONL(x)
sherckuith 0:479ce5546098 119
sherckuith 0:479ce5546098 120 #endif /* BYTE_ORDER == BIG_ENDIAN */
sherckuith 0:479ce5546098 121
sherckuith 0:479ce5546098 122 #ifdef __cplusplus
sherckuith 0:479ce5546098 123 }
sherckuith 0:479ce5546098 124 #endif
sherckuith 0:479ce5546098 125
sherckuith 0:479ce5546098 126 #endif /* __LWIP_DEF_H__ */
sherckuith 0:479ce5546098 127