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