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