Committer:
mbed714
Date:
Sat Sep 18 23:05:49 2010 +0000
Revision:
0:d616ece2d859

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed714 0:d616ece2d859 1 /*
mbed714 0:d616ece2d859 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
mbed714 0:d616ece2d859 3 * All rights reserved.
mbed714 0:d616ece2d859 4 *
mbed714 0:d616ece2d859 5 * Redistribution and use in source and binary forms, with or without modification,
mbed714 0:d616ece2d859 6 * are permitted provided that the following conditions are met:
mbed714 0:d616ece2d859 7 *
mbed714 0:d616ece2d859 8 * 1. Redistributions of source code must retain the above copyright notice,
mbed714 0:d616ece2d859 9 * this list of conditions and the following disclaimer.
mbed714 0:d616ece2d859 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed714 0:d616ece2d859 11 * this list of conditions and the following disclaimer in the documentation
mbed714 0:d616ece2d859 12 * and/or other materials provided with the distribution.
mbed714 0:d616ece2d859 13 * 3. The name of the author may not be used to endorse or promote products
mbed714 0:d616ece2d859 14 * derived from this software without specific prior written permission.
mbed714 0:d616ece2d859 15 *
mbed714 0:d616ece2d859 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
mbed714 0:d616ece2d859 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
mbed714 0:d616ece2d859 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
mbed714 0:d616ece2d859 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
mbed714 0:d616ece2d859 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
mbed714 0:d616ece2d859 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed714 0:d616ece2d859 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed714 0:d616ece2d859 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
mbed714 0:d616ece2d859 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
mbed714 0:d616ece2d859 25 * OF SUCH DAMAGE.
mbed714 0:d616ece2d859 26 *
mbed714 0:d616ece2d859 27 * This file is part of the lwIP TCP/IP stack.
mbed714 0:d616ece2d859 28 *
mbed714 0:d616ece2d859 29 * Author: Adam Dunkels <adam@sics.se>
mbed714 0:d616ece2d859 30 *
mbed714 0:d616ece2d859 31 */
mbed714 0:d616ece2d859 32
mbed714 0:d616ece2d859 33 #ifndef __LWIP_MEMP_H__
mbed714 0:d616ece2d859 34 #define __LWIP_MEMP_H__
mbed714 0:d616ece2d859 35
mbed714 0:d616ece2d859 36 #include "lwip/opt.h"
mbed714 0:d616ece2d859 37
mbed714 0:d616ece2d859 38 #ifdef __cplusplus
mbed714 0:d616ece2d859 39 extern "C" {
mbed714 0:d616ece2d859 40 #endif
mbed714 0:d616ece2d859 41
mbed714 0:d616ece2d859 42 /* Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end */
mbed714 0:d616ece2d859 43 typedef enum {
mbed714 0:d616ece2d859 44 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
mbed714 0:d616ece2d859 45 #include "lwip/memp_std.h"
mbed714 0:d616ece2d859 46 MEMP_MAX
mbed714 0:d616ece2d859 47 } memp_t;
mbed714 0:d616ece2d859 48
mbed714 0:d616ece2d859 49 #if MEM_USE_POOLS
mbed714 0:d616ece2d859 50 /* Use a helper type to get the start and end of the user "memory pools" for mem_malloc */
mbed714 0:d616ece2d859 51 typedef enum {
mbed714 0:d616ece2d859 52 /* Get the first (via:
mbed714 0:d616ece2d859 53 MEMP_POOL_HELPER_START = ((u8_t) 1*MEMP_POOL_A + 0*MEMP_POOL_B + 0*MEMP_POOL_C + 0)*/
mbed714 0:d616ece2d859 54 MEMP_POOL_HELPER_FIRST = ((u8_t)
mbed714 0:d616ece2d859 55 #define LWIP_MEMPOOL(name,num,size,desc)
mbed714 0:d616ece2d859 56 #define LWIP_MALLOC_MEMPOOL_START 1
mbed714 0:d616ece2d859 57 #define LWIP_MALLOC_MEMPOOL(num, size) * MEMP_POOL_##size + 0
mbed714 0:d616ece2d859 58 #define LWIP_MALLOC_MEMPOOL_END
mbed714 0:d616ece2d859 59 #include "lwip/memp_std.h"
mbed714 0:d616ece2d859 60 ) ,
mbed714 0:d616ece2d859 61 /* Get the last (via:
mbed714 0:d616ece2d859 62 MEMP_POOL_HELPER_END = ((u8_t) 0 + MEMP_POOL_A*0 + MEMP_POOL_B*0 + MEMP_POOL_C*1) */
mbed714 0:d616ece2d859 63 MEMP_POOL_HELPER_LAST = ((u8_t)
mbed714 0:d616ece2d859 64 #define LWIP_MEMPOOL(name,num,size,desc)
mbed714 0:d616ece2d859 65 #define LWIP_MALLOC_MEMPOOL_START
mbed714 0:d616ece2d859 66 #define LWIP_MALLOC_MEMPOOL(num, size) 0 + MEMP_POOL_##size *
mbed714 0:d616ece2d859 67 #define LWIP_MALLOC_MEMPOOL_END 1
mbed714 0:d616ece2d859 68 #include "lwip/memp_std.h"
mbed714 0:d616ece2d859 69 )
mbed714 0:d616ece2d859 70 } memp_pool_helper_t;
mbed714 0:d616ece2d859 71
mbed714 0:d616ece2d859 72 /* The actual start and stop values are here (cast them over)
mbed714 0:d616ece2d859 73 We use this helper type and these defines so we can avoid using const memp_t values */
mbed714 0:d616ece2d859 74 #define MEMP_POOL_FIRST ((memp_t) MEMP_POOL_HELPER_FIRST)
mbed714 0:d616ece2d859 75 #define MEMP_POOL_LAST ((memp_t) MEMP_POOL_HELPER_LAST)
mbed714 0:d616ece2d859 76 #endif /* MEM_USE_POOLS */
mbed714 0:d616ece2d859 77
mbed714 0:d616ece2d859 78 #if MEMP_MEM_MALLOC || MEM_USE_POOLS
mbed714 0:d616ece2d859 79 extern const u16_t memp_sizes[MEMP_MAX];
mbed714 0:d616ece2d859 80 #endif /* MEMP_MEM_MALLOC || MEM_USE_POOLS */
mbed714 0:d616ece2d859 81
mbed714 0:d616ece2d859 82 #if MEMP_MEM_MALLOC
mbed714 0:d616ece2d859 83
mbed714 0:d616ece2d859 84 #include "mem.h"
mbed714 0:d616ece2d859 85
mbed714 0:d616ece2d859 86 #define memp_init()
mbed714 0:d616ece2d859 87 #define memp_malloc(type) mem_malloc(memp_sizes[type])
mbed714 0:d616ece2d859 88 #define memp_free(type, mem) mem_free(mem)
mbed714 0:d616ece2d859 89
mbed714 0:d616ece2d859 90 #else /* MEMP_MEM_MALLOC */
mbed714 0:d616ece2d859 91
mbed714 0:d616ece2d859 92 #if MEM_USE_POOLS
mbed714 0:d616ece2d859 93 /** This structure is used to save the pool one element came from. */
mbed714 0:d616ece2d859 94 struct memp_malloc_helper
mbed714 0:d616ece2d859 95 {
mbed714 0:d616ece2d859 96 memp_t poolnr;
mbed714 0:d616ece2d859 97 };
mbed714 0:d616ece2d859 98 #endif /* MEM_USE_POOLS */
mbed714 0:d616ece2d859 99
mbed714 0:d616ece2d859 100 void memp_init(void);
mbed714 0:d616ece2d859 101
mbed714 0:d616ece2d859 102 #if MEMP_OVERFLOW_CHECK
mbed714 0:d616ece2d859 103 void *memp_malloc_fn(memp_t type, const char* file, const int line);
mbed714 0:d616ece2d859 104 #define memp_malloc(t) memp_malloc_fn((t), __FILE__, __LINE__)
mbed714 0:d616ece2d859 105 #else
mbed714 0:d616ece2d859 106 void *memp_malloc(memp_t type);
mbed714 0:d616ece2d859 107 #endif
mbed714 0:d616ece2d859 108 void memp_free(memp_t type, void *mem);
mbed714 0:d616ece2d859 109
mbed714 0:d616ece2d859 110 #endif /* MEMP_MEM_MALLOC */
mbed714 0:d616ece2d859 111
mbed714 0:d616ece2d859 112 #ifdef __cplusplus
mbed714 0:d616ece2d859 113 }
mbed714 0:d616ece2d859 114 #endif
mbed714 0:d616ece2d859 115
mbed714 0:d616ece2d859 116 #endif /* __LWIP_MEMP_H__ */