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