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