Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Committer:
mamezu
Date:
Thu Dec 09 01:33:56 2010 +0000
Revision:
0:0f6c82fcde82

        

Who changed what in which revision?

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