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 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
lorcansmith 0:2a53a4c3238c 3 * All rights reserved.
lorcansmith 0:2a53a4c3238c 4 *
lorcansmith 0:2a53a4c3238c 5 * Redistribution and use in source and binary forms, with or without modification,
lorcansmith 0:2a53a4c3238c 6 * are permitted provided that the following conditions are met:
lorcansmith 0:2a53a4c3238c 7 *
lorcansmith 0:2a53a4c3238c 8 * 1. Redistributions of source code must retain the above copyright notice,
lorcansmith 0:2a53a4c3238c 9 * this list of conditions and the following disclaimer.
lorcansmith 0:2a53a4c3238c 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
lorcansmith 0:2a53a4c3238c 11 * this list of conditions and the following disclaimer in the documentation
lorcansmith 0:2a53a4c3238c 12 * and/or other materials provided with the distribution.
lorcansmith 0:2a53a4c3238c 13 * 3. The name of the author may not be used to endorse or promote products
lorcansmith 0:2a53a4c3238c 14 * derived from this software without specific prior written permission.
lorcansmith 0:2a53a4c3238c 15 *
lorcansmith 0:2a53a4c3238c 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
lorcansmith 0:2a53a4c3238c 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lorcansmith 0:2a53a4c3238c 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
lorcansmith 0:2a53a4c3238c 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
lorcansmith 0:2a53a4c3238c 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
lorcansmith 0:2a53a4c3238c 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
lorcansmith 0:2a53a4c3238c 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
lorcansmith 0:2a53a4c3238c 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
lorcansmith 0:2a53a4c3238c 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
lorcansmith 0:2a53a4c3238c 25 * OF SUCH DAMAGE.
lorcansmith 0:2a53a4c3238c 26 *
lorcansmith 0:2a53a4c3238c 27 * This file is part of the lwIP TCP/IP stack.
lorcansmith 0:2a53a4c3238c 28 *
lorcansmith 0:2a53a4c3238c 29 * Author: Adam Dunkels <adam@sics.se>
lorcansmith 0:2a53a4c3238c 30 *
lorcansmith 0:2a53a4c3238c 31 */
lorcansmith 0:2a53a4c3238c 32 #ifndef __LWIP_MEM_H__
lorcansmith 0:2a53a4c3238c 33 #define __LWIP_MEM_H__
lorcansmith 0:2a53a4c3238c 34
lorcansmith 0:2a53a4c3238c 35 #include "lwip/opt.h"
lorcansmith 0:2a53a4c3238c 36
lorcansmith 0:2a53a4c3238c 37 #ifdef __cplusplus
lorcansmith 0:2a53a4c3238c 38 extern "C" {
lorcansmith 0:2a53a4c3238c 39 #endif
lorcansmith 0:2a53a4c3238c 40
lorcansmith 0:2a53a4c3238c 41 #if MEM_LIBC_MALLOC
lorcansmith 0:2a53a4c3238c 42
lorcansmith 0:2a53a4c3238c 43 #include <stddef.h> /* for size_t */
lorcansmith 0:2a53a4c3238c 44
lorcansmith 0:2a53a4c3238c 45 typedef size_t mem_size_t;
lorcansmith 0:2a53a4c3238c 46
lorcansmith 0:2a53a4c3238c 47 /* aliases for C library malloc() */
lorcansmith 0:2a53a4c3238c 48 #define mem_init()
lorcansmith 0:2a53a4c3238c 49 /* in case C library malloc() needs extra protection,
lorcansmith 0:2a53a4c3238c 50 * allow these defines to be overridden.
lorcansmith 0:2a53a4c3238c 51 */
lorcansmith 0:2a53a4c3238c 52 #ifndef mem_free
lorcansmith 0:2a53a4c3238c 53 #define mem_free free
lorcansmith 0:2a53a4c3238c 54 #endif
lorcansmith 0:2a53a4c3238c 55 #ifndef mem_malloc
lorcansmith 0:2a53a4c3238c 56 #define mem_malloc malloc
lorcansmith 0:2a53a4c3238c 57 #endif
lorcansmith 0:2a53a4c3238c 58 #ifndef mem_calloc
lorcansmith 0:2a53a4c3238c 59 #define mem_calloc calloc
lorcansmith 0:2a53a4c3238c 60 #endif
lorcansmith 0:2a53a4c3238c 61 /* Since there is no C library allocation function to shrink memory without
lorcansmith 0:2a53a4c3238c 62 moving it, define this to nothing. */
lorcansmith 0:2a53a4c3238c 63 #ifndef mem_trim
lorcansmith 0:2a53a4c3238c 64 #define mem_trim(mem, size) (mem)
lorcansmith 0:2a53a4c3238c 65 #endif
lorcansmith 0:2a53a4c3238c 66 #else /* MEM_LIBC_MALLOC */
lorcansmith 0:2a53a4c3238c 67
lorcansmith 0:2a53a4c3238c 68 /* MEM_SIZE would have to be aligned, but using 64000 here instead of
lorcansmith 0:2a53a4c3238c 69 * 65535 leaves some room for alignment...
lorcansmith 0:2a53a4c3238c 70 */
lorcansmith 0:2a53a4c3238c 71 #if MEM_SIZE > 64000l
lorcansmith 0:2a53a4c3238c 72 typedef u32_t mem_size_t;
lorcansmith 0:2a53a4c3238c 73 #define MEM_SIZE_F U32_F
lorcansmith 0:2a53a4c3238c 74 #else
lorcansmith 0:2a53a4c3238c 75 typedef u16_t mem_size_t;
lorcansmith 0:2a53a4c3238c 76 #define MEM_SIZE_F U16_F
lorcansmith 0:2a53a4c3238c 77 #endif /* MEM_SIZE > 64000 */
lorcansmith 0:2a53a4c3238c 78
lorcansmith 0:2a53a4c3238c 79 #if MEM_USE_POOLS
lorcansmith 0:2a53a4c3238c 80 /** mem_init is not used when using pools instead of a heap */
lorcansmith 0:2a53a4c3238c 81 #define mem_init()
lorcansmith 0:2a53a4c3238c 82 /** mem_trim is not used when using pools instead of a heap:
lorcansmith 0:2a53a4c3238c 83 we can't free part of a pool element and don't want to copy the rest */
lorcansmith 0:2a53a4c3238c 84 #define mem_trim(mem, size) (mem)
lorcansmith 0:2a53a4c3238c 85 #else /* MEM_USE_POOLS */
lorcansmith 0:2a53a4c3238c 86 /* lwIP alternative malloc */
lorcansmith 0:2a53a4c3238c 87 void mem_init(void);
lorcansmith 0:2a53a4c3238c 88 void *mem_trim(void *mem, mem_size_t size);
lorcansmith 0:2a53a4c3238c 89 #endif /* MEM_USE_POOLS */
lorcansmith 0:2a53a4c3238c 90 void *mem_malloc(mem_size_t size);
lorcansmith 0:2a53a4c3238c 91 void *mem_calloc(mem_size_t count, mem_size_t size);
lorcansmith 0:2a53a4c3238c 92 void mem_free(void *mem);
lorcansmith 0:2a53a4c3238c 93 #endif /* MEM_LIBC_MALLOC */
lorcansmith 0:2a53a4c3238c 94
lorcansmith 0:2a53a4c3238c 95 /** Calculate memory size for an aligned buffer - returns the next highest
lorcansmith 0:2a53a4c3238c 96 * multiple of MEM_ALIGNMENT (e.g. LWIP_MEM_ALIGN_SIZE(3) and
lorcansmith 0:2a53a4c3238c 97 * LWIP_MEM_ALIGN_SIZE(4) will both yield 4 for MEM_ALIGNMENT == 4).
lorcansmith 0:2a53a4c3238c 98 */
lorcansmith 0:2a53a4c3238c 99 #ifndef LWIP_MEM_ALIGN_SIZE
lorcansmith 0:2a53a4c3238c 100 #define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1) & ~(MEM_ALIGNMENT-1))
lorcansmith 0:2a53a4c3238c 101 #endif
lorcansmith 0:2a53a4c3238c 102
lorcansmith 0:2a53a4c3238c 103 /** Calculate safe memory size for an aligned buffer when using an unaligned
lorcansmith 0:2a53a4c3238c 104 * type as storage. This includes a safety-margin on (MEM_ALIGNMENT - 1) at the
lorcansmith 0:2a53a4c3238c 105 * start (e.g. if buffer is u8_t[] and actual data will be u32_t*)
lorcansmith 0:2a53a4c3238c 106 */
lorcansmith 0:2a53a4c3238c 107 #ifndef LWIP_MEM_ALIGN_BUFFER
lorcansmith 0:2a53a4c3238c 108 #define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1))
lorcansmith 0:2a53a4c3238c 109 #endif
lorcansmith 0:2a53a4c3238c 110
lorcansmith 0:2a53a4c3238c 111 /** Align a memory pointer to the alignment defined by MEM_ALIGNMENT
lorcansmith 0:2a53a4c3238c 112 * so that ADDR % MEM_ALIGNMENT == 0
lorcansmith 0:2a53a4c3238c 113 */
lorcansmith 0:2a53a4c3238c 114 #ifndef LWIP_MEM_ALIGN
lorcansmith 0:2a53a4c3238c 115 #define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
lorcansmith 0:2a53a4c3238c 116 #endif
lorcansmith 0:2a53a4c3238c 117
lorcansmith 0:2a53a4c3238c 118 #ifdef __cplusplus
lorcansmith 0:2a53a4c3238c 119 }
lorcansmith 0:2a53a4c3238c 120 #endif
lorcansmith 0:2a53a4c3238c 121
lorcansmith 0:2a53a4c3238c 122 #endif /* __LWIP_MEM_H__ */