hattori&ide

Dependencies:   mbed

Committer:
hattori_atsushi
Date:
Sun Dec 18 08:16:01 2022 +0000
Revision:
0:f77369cabd75
hattori

Who changed what in which revision?

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