SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
v1.1 release includes ioAlarm traps

Who changed what in which revision?

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