dev

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
yihui
Date:
Mon Mar 02 08:19:15 2015 +0000
Revision:
19:6c91d95ef874
Parent:
0:51ac1d130fd4
minor changes

Who changed what in which revision?

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