Michael Fischler / Mbed 2 deprecated Contest_Winner

Dependencies:   mbed

Committer:
mafischl
Date:
Thu Oct 13 17:02:29 2011 +0000
Revision:
0:d9266031f832

        

Who changed what in which revision?

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