fdsf

Dependents:   sisk_proj_stat MQTT Hello_FXOS8700Q WireFSHandControl ... more

Committer:
grzemich
Date:
Wed Dec 07 23:47:50 2016 +0000
Revision:
0:d7bd7384a37c
dgd

Who changed what in which revision?

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