Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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