Library for Bert van Dam's book "ARM MICROCONTROLLERS" For all chapters with internet.

Dependencies:   mbed

Committer:
ICTFBI
Date:
Fri Oct 16 14:28:26 2015 +0000
Revision:
0:4edb816d21e1
Pre-update 16-10-15

Who changed what in which revision?

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