15 #include <constants.h> 24 #include <basictypes.h> 28 typedef struct pool_buffer *PoolPtr;
29 typedef volatile PoolPtr VPoolPtr;
39 #define BS_PHY_BCAST 1 41 #define BS_IP_LOCAL_NET 4 43 #define BS_PHY_802_3 0x10 46 struct pool_buffer :
public OS_FIFO_EL
49 uint32_t PreSentinal[16];
54 vuint32_t dwTimeFraction;
56 uint8_t bBuffer_state;
59 uint8_t bInterfaceNumber;
60 uint8_t bAlignmentPad[6];
61 uint8_t pData[ETHER_BUFFER_SIZE];
62 uint8_t bPostAlignmentPad[3];
63 uint32_t PostSentinal[16];
73 inline uint8_t OSPoolFifoPost(
OS_FIFO *pFifo, PoolPtr pToPost)
75 return pFifo->
Post(pToPost);
78 inline uint8_t OSPoolFifoPostFirst(
OS_FIFO *pFifo, PoolPtr pToPost)
83 inline PoolPtr OSPoolFifoPend(
OS_FIFO *pFifo, uint16_t timeout)
85 return static_cast<PoolPtr
>(pFifo->
Pend(timeout));
88 inline PoolPtr OSPoolFifoPendNoWait(
OS_FIFO *pFifo)
90 return static_cast<PoolPtr
>(pFifo->
PendNoWait());
97 void ShowBuffers_Web(
int sockfd);
98 PoolPtr GetBufferX(PCSTR file,
int line);
99 #define GetBuffer() GetBufferX(__FILE__, __LINE__) 101 PoolPtr GetFastBufferX(PCSTR file,
int line);
102 #define GetFastBuffer() GetFastBufferX(__FILE__, __LINE__) 104 #define GetFastBuffer() GetBufferX(__FILE__, __LINE__) 106 void FreeBufferX(PoolPtr nbuf, PCSTR file,
int line);
107 #define FreeBuffer(x) FreeBufferX(x, __FILE__, __LINE__) 109 void ChangeOwnerX(PoolPtr nbuf, PCSTR file,
int line);
110 #define ChangeOwner(x) ChangeOwnerX(x, __FILE__, __LINE__) 114 PoolPtr GetFastBuffer();
116 #define GetFastBuffer() GetBuffer() 118 void FreeBuffer(PoolPtr nbuf);
119 #define ChangeOwner(x) 122 #ifdef BUFFER_DIAG_LOG 124 #define LOG_DEST 0x0A010103 // 10.1.1.3 125 #define SET_LOG_DEST \ 127 extern IPADDR4 SysLogAddress; \ 128 SysLogAddress = LOG_DEST; \ 131 #define BuffLog_Get(p) SysLogVia(LOG_INTF, "GET - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__) 132 #define BuffLog_Free(p) SysLogVia(LOG_INTF, "FREE - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__) 133 #define BuffLog_Write(p) SysLogVia(LOG_INTF, "WRITE - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__) 134 #define BuffLog_Read(p) SysLogVia(LOG_INTF, "READ - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__) 136 #define BuffLog_Get(p) 137 #define BuffLog_Free(p) 138 #define BuffLog_Write(p) 139 #define BuffLog_Read(p) 144 void IncUsageCount(PoolPtr pp);
183 uint16_t m_wElements;
184 void InsertHead(PoolPtr buffer);
185 void InsertTail(PoolPtr buffer);
186 void InsertBefore(PoolPtr buf2insert, PoolPtr b4buffer);
187 void InsertAfter(PoolPtr buf2insert, PoolPtr after_buffer);
188 void Remove(PoolPtr buffer);
189 PoolPtr RemoveHead();
190 PoolPtr RemoveTail();
197 uint16_t GetCount() {
return m_wElements; };
204 class fifo_buffer_storage
211 uint8_t m_Segments_Stored;
212 uint8_t m_MaxSegments;
213 uint32_t m_startOffset;
214 uint32_t m_maxChunkLen;
215 bool m_checksumWrites;
219 uint8_t *GetWritePtr(uint32_t *remLen);
220 void WriteDone(uint32_t bytesCopied);
222 uint8_t *GetReadPtr(uint32_t *remLen);
223 void ReadDone(uint32_t bytesCopied);
230 fifo_buffer_storage &m_fifo;
236 WriteBufPtr(fifo_buffer_storage &fifo) : m_fifo(fifo), copied(0)
238 m_fifo.m_critical_section.Enter();
239 pBuf = m_fifo.GetWritePtr(&bufLen);
243 m_fifo.WriteDone(copied);
244 m_fifo.m_critical_section.Leave();
247 inline uint8_t *buf() {
return pBuf + copied; }
248 inline uint32_t len() {
return bufLen - copied; }
249 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
255 fifo_buffer_storage &m_fifo;
261 ReadBufPtr(fifo_buffer_storage &fifo) : m_fifo(fifo), copied(0)
263 m_fifo.m_critical_section.Enter();
264 pBuf = m_fifo.GetReadPtr(&bufLen);
268 m_fifo.ReadDone(copied);
269 m_fifo.m_critical_section.Leave();
272 inline uint8_t *buf() {
return pBuf + copied; }
273 inline uint32_t len() {
return bufLen - copied; }
274 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
277 friend class WriteBufPtr;
278 friend class ReadBufPtr;
280 uint32_t LongSpaceAvail();
283 uint16_t SpaceAvail();
285 uint16_t SpaceUsed();
289 int ReadData(puint8_t pCopyTo,
int max_bytes);
294 int ReadDatawSum(puint8_t pCopyTo,
int max_bytes, uint32_t &csum);
297 int SkipData(
int skip);
299 int ReadTerminatedData(puint8_t pCopyTo,
int max_bytes, uint8_t term_char);
302 int PushBuffer(PoolPtr pp,
int dataLen,
int startOffset);
303 PoolPtr PullBuffer(uint32_t &csum);
304 inline PoolPtr PeekBuffer() {
return m_Head; }
305 void SetFifoLock(
bool locked);
309 int WriteData(puint8_t pCopyFrom,
int num_bytes);
320 fifo_buffer_storage(uint8_t max_buffers = 0, uint8_t use_fromisr = 1);
321 ~fifo_buffer_storage();
324 void Reset(uint8_t max_buffers);
326 void SetMaxBuffers(uint8_t max_buffers);
327 inline void SetMaxChunkLen(uint32_t maxStorage)
329 m_maxChunkLen = (maxStorage > (ETHER_BUFFER_SIZE - m_startOffset)) ? (ETHER_BUFFER_SIZE - m_startOffset) : maxStorage;
331 inline void SetStartOffset(uint32_t offset)
333 m_startOffset = offset;
334 SetMaxChunkLen(m_maxChunkLen);
336 inline void SetWriteChecksum(
bool summingOn) { m_checksumWrites = summingOn; }
339 void Init(uint8_t max_buffers, uint8_t use_fromisr = 1);
340 } __attribute__((packed));
347 SMPoolPtr() { m_pp = GetBuffer(); }
348 SMPoolPtr(
const PoolPtr pp) { m_pp = pp; }
349 SMPoolPtr(
const SMPoolPtr &pp) { m_pp = pp.m_pp; }
352 if (m_pp) { FreeBuffer(m_pp); }
355 inline const SMPoolPtr &operator=(
const PoolPtr pp)
360 inline const SMPoolPtr &operator=(
const SMPoolPtr &pp)
365 inline pool_buffer &operator*() {
return *m_pp; }
366 inline PoolPtr &operator->() {
return m_pp; }
NetBurner Real-Time Operating System API.
A FIFO is used to pass structures from one task to another. Note: Structures to be passed must have a...
Definition: nbrtos.h:736
OS_FIFO_EL * PendNoWait(uint8_t &result)
Checks to see if a structure has been posted to a FIFO, but does not wait.
Definition: nbrtos.cpp:1294
OS_FIFO_EL * Pend(uint32_t timeoutTicks, uint8_t &result)
This function pends on a FIFO for a specified number of ticks.
Definition: nbrtos.cpp:1254
uint8_t Post(OS_FIFO_EL *pToPost)
This function posts to a FIFO object.
Definition: nbrtos.cpp:1318
uint8_t PostFirst(OS_FIFO_EL *pToPost)
This function is identical to Post(), but the element posted is put on the beginning of the FIFO list...
Definition: nbrtos.cpp:1341
uint16_t GetFreeCount()
Returns the number of free buffers in the system. Buffers are used for both serial and network interf...
Definition: buffers.cpp:519
void FreeBufferList(PoolPtr nbuf)
FreeBufferList Frees a linked list of pool buffers. The buffers must be linked by the pNextFifo_El Po...
Definition: buffers.cpp:433
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition: nbrtos.h:893
void WriteData(int fd, const char *c, int siz)
Definition: gifCompress.cpp:142
void ShowBuffer(PoolPtr p)
Prints a pool buffer to stdout.
Definition: buffers.cpp:705