mikroSDK Reference Manual
net_mem.h
Go to the documentation of this file.
1
31#ifndef _NET_MEM_H
32#define _NET_MEM_H
33
34//Dependencies
35#include "net_config.h"
36#include "os_port.h"
37#include "error.h"
38
39//Use fixed-size blocks allocation?
40#ifndef NET_MEM_POOL_SUPPORT
41 #define NET_MEM_POOL_SUPPORT DISABLED
42#elif (NET_MEM_POOL_SUPPORT != ENABLED && NET_MEM_POOL_SUPPORT != DISABLED)
43 #error NET_MEM_POOL_SUPPORT parameter is not valid
44#endif
45
46//Number of buffers available
47#ifndef NET_MEM_POOL_BUFFER_COUNT
48 #define NET_MEM_POOL_BUFFER_COUNT 32
49#elif (NET_MEM_POOL_BUFFER_COUNT < 1)
50 #error NET_MEM_POOL_BUFFER_COUNT parameter is not valid
51#endif
52
53//Size of the buffers
54#ifndef NET_MEM_POOL_BUFFER_SIZE
55 #define NET_MEM_POOL_BUFFER_SIZE 1536
56#elif (NET_MEM_POOL_BUFFER_SIZE < 128)
57 #error NET_MEM_POOL_BUFFER_SIZE parameter is not valid
58#endif
59
60//Size of the header part of the buffer
61#define CHUNKED_BUFFER_HEADER_SIZE (sizeof(NetBuffer) + MAX_CHUNK_COUNT * sizeof(ChunkDesc))
62
63//Helper macro for defining a buffer
64#define N(size) (((size) + NET_MEM_POOL_BUFFER_SIZE - 1) / NET_MEM_POOL_BUFFER_SIZE)
65
66//C++ guard
67#ifdef __cplusplus
68extern "C" {
69#endif
70
71
76typedef struct
77{
78 void *address;
79 uint16_t length;
80 uint16_t size;
81} ChunkDesc;
82
83
88typedef struct
89{
90 uint_t chunkCount;
91 uint_t maxChunkCount;
92 ChunkDesc chunk[];
93} NetBuffer;
94
95
96typedef struct
97{
98 uint_t chunkCount;
99 uint_t maxChunkCount;
100 ChunkDesc chunk[1];
101} NetBuffer1;
102
103
104//Memory management functions
105error_t memPoolInit(void);
106void *memPoolAlloc(size_t size);
107void memPoolFree(void *p);
108void memPoolGetStats(uint_t *currentUsage, uint_t *maxUsage, uint_t *size);
109
110NetBuffer *netBufferAlloc(size_t length);
111void netBufferFree(NetBuffer *buffer);
112
113size_t netBufferGetLength(const NetBuffer *buffer);
114error_t netBufferSetLength(NetBuffer *buffer, size_t length);
115
116void *netBufferAt(const NetBuffer *buffer, size_t offset);
117
118error_t netBufferConcat(NetBuffer *dest,
119 const NetBuffer *src, size_t srcOffset, size_t length);
120
121error_t netBufferCopy(NetBuffer *dest, size_t destOffset,
122 const NetBuffer *src, size_t srcOffset, size_t length);
123
124error_t netBufferAppend(NetBuffer *dest, const void *src, size_t length);
125
126size_t netBufferWrite(NetBuffer *dest,
127 size_t destOffset, const void *src, size_t length);
128
129size_t netBufferRead(void *dest, const NetBuffer *src,
130 size_t srcOffset, size_t length);
131
132//C++ guard
133#ifdef __cplusplus
134}
135#endif
136
137#endif
Error codes description.
error_t
Error codes.
Definition error.h:43
CycloneTCP configuration file.
RTOS abstraction layer.
Structure describing a chunk of data.
Definition net_mem.h:77
Definition net_mem.h:97
Structure describing a buffer that spans multiple chunks.
Definition net_mem.h:89