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