Dependencies:   mbed

Committer:
slowness
Date:
Tue Sep 06 18:10:36 2011 +0000
Revision:
0:cd4c47744fa1

        

Who changed what in which revision?

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