Embed:
(wiki syntax)
Show/hide line numbers
net_mem.h
Go to the documentation of this file.
00001 /** 00002 * @file net_mem.h 00003 * @brief Memory management 00004 * 00005 * @section License 00006 * 00007 * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved. 00008 * 00009 * This file is part of CycloneTCP Open. 00010 * 00011 * This program is free software; you can redistribute it and/or 00012 * modify it under the terms of the GNU General Public License 00013 * as published by the Free Software Foundation; either version 2 00014 * of the License, or (at your option) any later version. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software Foundation, 00023 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00024 * 00025 * @author Oryx Embedded SARL (www.oryx-embedded.com) 00026 * @version 1.7.6 00027 **/ 00028 00029 #ifndef _NET_MEM_H 00030 #define _NET_MEM_H 00031 00032 //Dependencies 00033 #include "net_config.h" 00034 #include "os_port.h" 00035 #include "error.h" 00036 00037 //Deprecated properties 00038 #ifdef MEM_POOL_SUPPORT 00039 #warning MEM_POOL_SUPPORT property is deprecated. NET_MEM_POOL_SUPPORT should be used instead. 00040 #define NET_MEM_POOL_SUPPORT MEM_POOL_SUPPORT 00041 #endif 00042 00043 #ifdef MEM_POOL_BUFFER_COUNT 00044 #warning MEM_POOL_BUFFER_COUNT property is deprecated. NET_MEM_POOL_BUFFER_COUNT should be used instead. 00045 #define NET_MEM_POOL_BUFFER_COUNT MEM_POOL_BUFFER_COUNT 00046 #endif 00047 00048 #ifdef MEM_POOL_BUFFER_SIZE 00049 #warning MEM_POOL_BUFFER_SIZE property is deprecated. NET_MEM_POOL_BUFFER_SIZE should be used instead. 00050 #define NET_MEM_POOL_BUFFER_SIZE MEM_POOL_BUFFER_SIZE 00051 #endif 00052 00053 //Use fixed-size blocks allocation? 00054 #ifndef NET_MEM_POOL_SUPPORT 00055 #define NET_MEM_POOL_SUPPORT DISABLED 00056 #elif (NET_MEM_POOL_SUPPORT != ENABLED && NET_MEM_POOL_SUPPORT != DISABLED) 00057 #error NET_MEM_POOL_SUPPORT parameter is not valid 00058 #endif 00059 00060 //Number of buffers available 00061 #ifndef NET_MEM_POOL_BUFFER_COUNT 00062 #define NET_MEM_POOL_BUFFER_COUNT 32 00063 #elif (NET_MEM_POOL_BUFFER_COUNT < 1) 00064 #error NET_MEM_POOL_BUFFER_COUNT parameter is not valid 00065 #endif 00066 00067 //Size of the buffers 00068 #ifndef NET_MEM_POOL_BUFFER_SIZE 00069 #define NET_MEM_POOL_BUFFER_SIZE 1536 00070 #elif (NET_MEM_POOL_BUFFER_SIZE < 128) 00071 #error NET_MEM_POOL_BUFFER_SIZE parameter is not valid 00072 #endif 00073 00074 //Size of the header part of the buffer 00075 #define CHUNKED_BUFFER_HEADER_SIZE (sizeof(NetBuffer) + MAX_CHUNK_COUNT * sizeof(ChunkDesc)) 00076 00077 //Helper macro for defining a buffer 00078 #define N(size) (((size) + NET_MEM_POOL_BUFFER_SIZE - 1) / NET_MEM_POOL_BUFFER_SIZE) 00079 00080 00081 /** 00082 * @brief Structure describing a chunk of data 00083 **/ 00084 00085 typedef struct 00086 { 00087 void *address; 00088 uint16_t length; 00089 uint16_t size; 00090 } ChunkDesc; 00091 00092 00093 /** 00094 * @brief Structure describing a buffer that spans multiple chunks 00095 **/ 00096 00097 typedef struct 00098 { 00099 uint_t chunkCount; 00100 uint_t maxChunkCount; 00101 ChunkDesc chunk[]; 00102 } NetBuffer; 00103 00104 00105 typedef struct 00106 { 00107 uint_t chunkCount; 00108 uint_t maxChunkCount; 00109 ChunkDesc chunk[1]; 00110 } NetBuffer1; 00111 00112 00113 //Memory management functions 00114 error_t memPoolInit(void); 00115 void *memPoolAlloc(size_t size); 00116 void memPoolFree(void *p); 00117 void memPoolGetStats(uint_t *currentUsage, uint_t *maxUsage, uint_t *size); 00118 00119 NetBuffer *netBufferAlloc(size_t length); 00120 void netBufferFree(NetBuffer *buffer); 00121 00122 size_t netBufferGetLength(const NetBuffer *buffer); 00123 error_t netBufferSetLength(NetBuffer *buffer, size_t length); 00124 00125 void *netBufferAt(const NetBuffer *buffer, size_t offset); 00126 00127 error_t netBufferConcat(NetBuffer *dest, 00128 const NetBuffer *src, size_t srcOffset, size_t length); 00129 00130 error_t netBufferCopy(NetBuffer *dest, size_t destOffset, 00131 const NetBuffer *src, size_t srcOffset, size_t length); 00132 00133 error_t netBufferAppend(NetBuffer *dest, const void *src, size_t length); 00134 00135 size_t netBufferWrite(NetBuffer *dest, 00136 size_t destOffset, const void *src, size_t length); 00137 00138 size_t netBufferRead(void *dest, const NetBuffer *src, 00139 size_t srcOffset, size_t length); 00140 00141 #endif 00142
Generated on Tue Jul 12 2022 17:10:15 by
