lpc1768

Committer:
jh1cdv00
Date:
Tue Jan 27 01:38:19 2015 +0000
Revision:
0:f35dada1dac1
lpc1768

Who changed what in which revision?

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