Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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