kEIS

Dependents:   EthernetInterface_ccx

Fork of lwip by mbed official

Committer:
khayakawa
Date:
Sat Sep 28 16:34:37 2013 +0000
Revision:
11:7799ae488ba0
Parent:
0:51ac1d130fd4
KEIS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:51ac1d130fd4 1 /**
mbed_official 0:51ac1d130fd4 2 * @file
mbed_official 0:51ac1d130fd4 3 * Common functions used throughout the stack.
mbed_official 0:51ac1d130fd4 4 *
mbed_official 0:51ac1d130fd4 5 */
mbed_official 0:51ac1d130fd4 6
mbed_official 0:51ac1d130fd4 7 /*
mbed_official 0:51ac1d130fd4 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mbed_official 0:51ac1d130fd4 9 * All rights reserved.
mbed_official 0:51ac1d130fd4 10 *
mbed_official 0:51ac1d130fd4 11 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 0:51ac1d130fd4 12 * are permitted provided that the following conditions are met:
mbed_official 0:51ac1d130fd4 13 *
mbed_official 0:51ac1d130fd4 14 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 0:51ac1d130fd4 15 * this list of conditions and the following disclaimer.
mbed_official 0:51ac1d130fd4 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 0:51ac1d130fd4 17 * this list of conditions and the following disclaimer in the documentation
mbed_official 0:51ac1d130fd4 18 * and/or other materials provided with the distribution.
mbed_official 0:51ac1d130fd4 19 * 3. The name of the author may not be used to endorse or promote products
mbed_official 0:51ac1d130fd4 20 * derived from this software without specific prior written permission.
mbed_official 0:51ac1d130fd4 21 *
mbed_official 0:51ac1d130fd4 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbed_official 0:51ac1d130fd4 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed_official 0:51ac1d130fd4 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbed_official 0:51ac1d130fd4 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbed_official 0:51ac1d130fd4 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbed_official 0:51ac1d130fd4 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 0:51ac1d130fd4 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 0:51ac1d130fd4 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbed_official 0:51ac1d130fd4 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbed_official 0:51ac1d130fd4 31 * OF SUCH DAMAGE.
mbed_official 0:51ac1d130fd4 32 *
mbed_official 0:51ac1d130fd4 33 * This file is part of the lwIP TCP/IP stack.
mbed_official 0:51ac1d130fd4 34 *
mbed_official 0:51ac1d130fd4 35 * Author: Simon Goldschmidt
mbed_official 0:51ac1d130fd4 36 *
mbed_official 0:51ac1d130fd4 37 */
mbed_official 0:51ac1d130fd4 38
mbed_official 0:51ac1d130fd4 39 #include "lwip/opt.h"
mbed_official 0:51ac1d130fd4 40 #include "lwip/def.h"
mbed_official 0:51ac1d130fd4 41
mbed_official 0:51ac1d130fd4 42 /**
mbed_official 0:51ac1d130fd4 43 * These are reference implementations of the byte swapping functions.
mbed_official 0:51ac1d130fd4 44 * Again with the aim of being simple, correct and fully portable.
mbed_official 0:51ac1d130fd4 45 * Byte swapping is the second thing you would want to optimize. You will
mbed_official 0:51ac1d130fd4 46 * need to port it to your architecture and in your cc.h:
mbed_official 0:51ac1d130fd4 47 *
mbed_official 0:51ac1d130fd4 48 * #define LWIP_PLATFORM_BYTESWAP 1
mbed_official 0:51ac1d130fd4 49 * #define LWIP_PLATFORM_HTONS(x) <your_htons>
mbed_official 0:51ac1d130fd4 50 * #define LWIP_PLATFORM_HTONL(x) <your_htonl>
mbed_official 0:51ac1d130fd4 51 *
mbed_official 0:51ac1d130fd4 52 * Note ntohs() and ntohl() are merely references to the htonx counterparts.
mbed_official 0:51ac1d130fd4 53 */
mbed_official 0:51ac1d130fd4 54
mbed_official 0:51ac1d130fd4 55 #if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN)
mbed_official 0:51ac1d130fd4 56
mbed_official 0:51ac1d130fd4 57 /**
mbed_official 0:51ac1d130fd4 58 * Convert an u16_t from host- to network byte order.
mbed_official 0:51ac1d130fd4 59 *
mbed_official 0:51ac1d130fd4 60 * @param n u16_t in host byte order
mbed_official 0:51ac1d130fd4 61 * @return n in network byte order
mbed_official 0:51ac1d130fd4 62 */
mbed_official 0:51ac1d130fd4 63 u16_t
mbed_official 0:51ac1d130fd4 64 lwip_htons(u16_t n)
mbed_official 0:51ac1d130fd4 65 {
mbed_official 0:51ac1d130fd4 66 return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
mbed_official 0:51ac1d130fd4 67 }
mbed_official 0:51ac1d130fd4 68
mbed_official 0:51ac1d130fd4 69 /**
mbed_official 0:51ac1d130fd4 70 * Convert an u16_t from network- to host byte order.
mbed_official 0:51ac1d130fd4 71 *
mbed_official 0:51ac1d130fd4 72 * @param n u16_t in network byte order
mbed_official 0:51ac1d130fd4 73 * @return n in host byte order
mbed_official 0:51ac1d130fd4 74 */
mbed_official 0:51ac1d130fd4 75 u16_t
mbed_official 0:51ac1d130fd4 76 lwip_ntohs(u16_t n)
mbed_official 0:51ac1d130fd4 77 {
mbed_official 0:51ac1d130fd4 78 return lwip_htons(n);
mbed_official 0:51ac1d130fd4 79 }
mbed_official 0:51ac1d130fd4 80
mbed_official 0:51ac1d130fd4 81 /**
mbed_official 0:51ac1d130fd4 82 * Convert an u32_t from host- to network byte order.
mbed_official 0:51ac1d130fd4 83 *
mbed_official 0:51ac1d130fd4 84 * @param n u32_t in host byte order
mbed_official 0:51ac1d130fd4 85 * @return n in network byte order
mbed_official 0:51ac1d130fd4 86 */
mbed_official 0:51ac1d130fd4 87 u32_t
mbed_official 0:51ac1d130fd4 88 lwip_htonl(u32_t n)
mbed_official 0:51ac1d130fd4 89 {
mbed_official 0:51ac1d130fd4 90 return ((n & 0xff) << 24) |
mbed_official 0:51ac1d130fd4 91 ((n & 0xff00) << 8) |
mbed_official 0:51ac1d130fd4 92 ((n & 0xff0000UL) >> 8) |
mbed_official 0:51ac1d130fd4 93 ((n & 0xff000000UL) >> 24);
mbed_official 0:51ac1d130fd4 94 }
mbed_official 0:51ac1d130fd4 95
mbed_official 0:51ac1d130fd4 96 /**
mbed_official 0:51ac1d130fd4 97 * Convert an u32_t from network- to host byte order.
mbed_official 0:51ac1d130fd4 98 *
mbed_official 0:51ac1d130fd4 99 * @param n u32_t in network byte order
mbed_official 0:51ac1d130fd4 100 * @return n in host byte order
mbed_official 0:51ac1d130fd4 101 */
mbed_official 0:51ac1d130fd4 102 u32_t
mbed_official 0:51ac1d130fd4 103 lwip_ntohl(u32_t n)
mbed_official 0:51ac1d130fd4 104 {
mbed_official 0:51ac1d130fd4 105 return lwip_htonl(n);
mbed_official 0:51ac1d130fd4 106 }
mbed_official 0:51ac1d130fd4 107
mbed_official 0:51ac1d130fd4 108 #endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */