Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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