V1

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
lemniskata
Date:
Thu Jun 13 20:00:31 2013 +0000
Revision:
11:c9233fe7de67
Parent:
0:51ac1d130fd4
V1

Who changed what in which revision?

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