29#include <basictypes.h>
33typedef struct pool_buffer *PoolPtr;
34typedef volatile PoolPtr VPoolPtr;
46#define BS_IP_LOCAL_NET 4
48#define BS_PHY_802_3 0x10
50#define BS_DBG_LOG 0x80
53#define BUFFER_DIAG_WORD_COUNT 4
55#define BUFFER_DIAG_WORD_COUNT 0
58#define BUF_PREDATA_SENTINAL_LEN (8)
59#define BUF_PREDATA_PADLEN 8
60#define BUF_POSTDATA_PADLEN 3
61#define BUF_POSTDATA_SENTINAL_LEN (11 - BUFFER_DIAG_WORD_COUNT)
63#define BUF_PREDATA_SENTINAL_LEN (8)
64#define BUF_PREDATA_PADLEN 6
65#define BUF_POSTDATA_PADLEN 3
66#define BUF_POSTDATA_SENTINAL_LEN (12 - BUFFER_DIAG_WORD_COUNT)
72 uint32_t PreSentinal[BUF_PREDATA_SENTINAL_LEN];
77 vuint32_t dwTimeFraction;
79 uint8_t bBuffer_state;
82 uint8_t bInterfaceNumber;
83 uint8_t bAlignmentPad[BUF_PREDATA_PADLEN];
85 uint8_t bPostAlignmentPad[BUF_POSTDATA_PADLEN];
86 uint32_t PostSentinal[BUF_POSTDATA_SENTINAL_LEN];
96inline uint8_t OSPoolFifoPost(
OS_FIFO *pFifo, PoolPtr pToPost)
98 return pFifo->
Post(pToPost);
101inline uint8_t OSPoolFifoPostFirst(
OS_FIFO *pFifo, PoolPtr pToPost)
106inline PoolPtr OSPoolFifoPend(
OS_FIFO *pFifo, uint16_t timeout)
108 return static_cast<PoolPtr
>(pFifo->
Pend(timeout));
113 return static_cast<PoolPtr
>(pFifo->
Pend(timeout));
117inline PoolPtr OSPoolFifoPendNoWait(
OS_FIFO *pFifo)
119 return static_cast<PoolPtr
>(pFifo->
PendNoWait());
126void ShowBuffers_Web(
int sockfd);
127PoolPtr GetBufferX(PCSTR file,
int line);
128#define GetBuffer() GetBufferX(__FILE__, __LINE__)
130PoolPtr GetFastBufferX(PCSTR file,
int line);
131#define GetFastBuffer() GetFastBufferX(__FILE__, __LINE__)
133#define GetFastBuffer() GetBufferX(__FILE__, __LINE__)
135void FreeBufferX(PoolPtr nbuf, PCSTR file,
int line);
136#define FreeBuffer(x) FreeBufferX(x, __FILE__, __LINE__)
138void ChangeOwnerX(PoolPtr nbuf, PCSTR file,
int line);
139#define ChangeOwner(x) ChangeOwnerX(x, __FILE__, __LINE__)
143PoolPtr GetFastBuffer();
145#define GetFastBuffer() GetBuffer()
147void FreeBuffer(PoolPtr nbuf);
148#define ChangeOwner(x)
151#ifdef BUFFER_DIAG_LOG
153extern uint32_t bufLogID;
154#define LOG_DEST AsciiToIp("10.1.1.3")
155#define SET_LOG_DEST \
157 extern IPADDR SysLogAddress; \
158 SysLogAddress = LOG_DEST; \
161#define BuffLog_GetFmt "%0.8lu) GET - P: %p, L: %0.4d, F: %s\r\n"
162#define BuffLog_FreeFmt "%0.8lu) FREE - P: %p, L: %0.4d, F: %s\r\n"
163#define BuffLog_GetLF(p, l, f) SysLogVia(LOG_INTF, BuffLog_GetFmt, bufLogID++, p, l, f)
164#define BuffLog_FreeLF(p, l, f) SysLogVia(LOG_INTF, BuffLog_FreeFmt, bufLogID++, p, l, f)
165#define BuffLog_Get(p) BuffLog_GetLF(p, __LINE__, __FILE__)
166#define BuffLog_Free(p) BuffLog_FreeLF(p, __LINE__, __FILE__)
167#define BuffLog_Write(p) SysLogVia(LOG_INTF, "WRITE - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__)
168#define BuffLog_Read(p) SysLogVia(LOG_INTF, "READ - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__)
170#define BuffLog_Get(p)
171#define BuffLog_Free(p)
172#define BuffLog_Write(p)
173#define BuffLog_Read(p)
176void FreeBufferList(PoolPtr nbuf);
178void IncUsageCount(PoolPtr pp);
206#ifdef BUFFER_WATERMARK
207uint16_t GetMinFreeCount();
208uint16_t GetMaxFreeCount();
224#ifdef BUFFER_WATERMARK
225 uint16_t m_wMaxElements;
226 uint16_t m_wMinElements;
228 uint16_t m_wElements;
229 void InsertHead(PoolPtr buffer);
230 void InsertTail(PoolPtr buffer);
231 void InsertBefore(PoolPtr buf2insert, PoolPtr b4buffer);
232 void InsertAfter(PoolPtr buf2insert, PoolPtr after_buffer);
233 void Remove(PoolPtr buffer);
234 PoolPtr RemoveHead();
235 PoolPtr RemoveTail();
241#ifdef BUFFER_WATERMARK
247 uint16_t GetCount() {
return m_wElements; };
248#ifdef BUFFER_WATERMARK
249 uint16_t GetMaxCount() {
return m_wMaxElements; };
250 uint16_t GetMinCount() {
return m_wMinElements; };
258class fifo_buffer_storage
265 uint32_t m_startOffset;
266 uint32_t m_maxChunkLen;
267 uint8_t m_Segments_Stored;
268 uint8_t m_MaxSegments;
269 bool m_checksumWrites;
270 uint8_t m_buffer_pool;
274 uint8_t *GetWritePtr(uint32_t *remLen);
275 void WriteDone(uint32_t bytesCopied);
277 uint8_t *GetReadPtr(uint32_t *remLen);
278 void ReadDone(uint32_t bytesCopied);
285 fifo_buffer_storage &m_fifo;
291 WriteBufPtr(fifo_buffer_storage &fifo) : m_fifo(fifo), copied(0)
293 m_fifo.m_critical_section.
Enter();
294 pBuf = m_fifo.GetWritePtr(&bufLen);
298 m_fifo.WriteDone(copied);
299 m_fifo.m_critical_section.
Leave();
302 inline uint8_t *buf() {
return pBuf + copied; }
303 inline uint32_t len() {
return bufLen - copied; }
304 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
310 fifo_buffer_storage &m_fifo;
316 ReadBufPtr(fifo_buffer_storage &fifo) : m_fifo(fifo), copied(0)
318 m_fifo.m_critical_section.
Enter();
319 pBuf = m_fifo.GetReadPtr(&bufLen);
323 m_fifo.ReadDone(copied);
324 m_fifo.m_critical_section.
Leave();
327 inline uint8_t *buf() {
return pBuf + copied; }
328 inline uint32_t len() {
return bufLen - copied; }
329 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
334 fifo_buffer_storage &m_fifo;
339 PeekIterator(
const PeekIterator &rhs)
340 : m_fifo(rhs.m_fifo), pCurrPP(rhs.pCurrPP), peekPtr(rhs.peekPtr), locked(false)
344 m_fifo.m_critical_section.
Enter();
350 PeekIterator(fifo_buffer_storage &fifo,
bool begin =
true) : m_fifo(fifo), pCurrPP(NULL), peekPtr(NULL), locked(false)
354 m_fifo.m_critical_section.
Enter();
356 pCurrPP = m_fifo.m_Head;
357 if (pCurrPP) { peekPtr = pCurrPP->
pAsBytePtr; }
360 ~PeekIterator() {
if (locked) m_fifo.m_critical_section.
Leave(); }
362 PeekIterator &operator++();
363 PeekIterator operator++(
int);
365 int32_t operator-(
const PeekIterator &rhs);
366 PeekIterator &operator+=(
int);
368 operator uint16_t()
const;
369 operator uint32_t()
const;
371 inline bool operator==(
const PeekIterator &rhs)
373 return ((&m_fifo == &(rhs.m_fifo)) && (pCurrPP == rhs.pCurrPP) && (peekPtr == rhs.peekPtr));
375 bool operator!=(
const PeekIterator &rhs) {
return !(*
this == rhs); }
378 friend class WriteBufPtr;
379 friend class ReadBufPtr;
380 friend class PeekIterator;
382 uint32_t LongSpaceAvail();
385 uint16_t SpaceAvail();
387 uint16_t SpaceUsed();
391 int ReadData(puint8_t pCopyTo,
int max_bytes);
394 uint8_t PeekData(
int idx = -1);
396 int ReadDatawSum(puint8_t pCopyTo,
int max_bytes, uint32_t &csum);
399 int SkipData(
int skip);
401 int ReadTerminatedData(puint8_t pCopyTo,
int max_bytes, uint8_t term_char);
404 int PushBuffer(PoolPtr pp,
int dataLen,
int startOffset);
405 PoolPtr PullBuffer();
406 PoolPtr PullBuffer(uint32_t &csum);
407 inline PoolPtr PeekBuffer() {
return m_Head; }
408 void SetFifoLock(
bool locked);
412 int WriteData(puint8_t pCopyFrom,
int num_bytes);
417 PeekIterator Peek_Begin();
418 PeekIterator Peek_End();
427 fifo_buffer_storage(uint8_t max_buffers = 0, uint8_t use_fromisr = 1, uint8_t use_fast_buffs = 1);
428 ~fifo_buffer_storage();
431 void Reset(uint8_t max_buffers);
433 void SetMaxBuffers(uint8_t max_buffers);
434 inline void SetMaxChunkLen(uint32_t maxStorage)
438 inline void SetStartOffset(uint32_t offset)
440 m_startOffset = offset;
441 SetMaxChunkLen(m_maxChunkLen);
443 inline uint32_t GetMaxBuffers() {
return m_MaxSegments; }
444 inline uint32_t GetMaxChunkLen() {
return m_maxChunkLen; }
445 inline uint32_t GetStartOffset() {
return m_startOffset; }
446 inline void SetWriteChecksum(
bool summingOn) { m_checksumWrites = summingOn; }
447 inline uint32_t GetMinimumFullSize(
int maxSegments = -1)
450 maxSegments = m_MaxSegments;
451 return (m_maxChunkLen * (maxSegments-1))+1;
455 void Init(uint8_t max_buffers, uint8_t use_fromisr = 1, uint8_t use_fast_buffs = 1);
456} __attribute__((packed));
468 SMPoolPtr(
const PoolPtr pp) { m_pp = pp; }
469 SMPoolPtr(
const SMPoolPtr &pp) { m_pp = pp.m_pp; }
479 inline const SMPoolPtr &operator=(
const PoolPtr pp)
484 inline const SMPoolPtr &operator=(
const SMPoolPtr &pp)
489 inline pool_buffer &operator*() {
return *m_pp; }
490 inline PoolPtr &operator->() {
return m_pp; }
491 explicit operator PoolPtr() {
return m_pp; }
void WriteData(int fd, const char *c, int siz)
Definition JSON/DemoNetBurner/src/gifCompress.cpp:142
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:157
void ShowBuffer(PoolPtr p)
Prints a pool buffer to stdout.
uint16_t GetFreeCount()
Returns the number of free buffers in the system. Buffers are used for both serial and network interf...
#define ETHER_BUFFER_SIZE
Definition nbrtos/include/constants.h:54
NetBurner System Constants.
NetBurner Real-Time Operating System (NBRTOS) API.
An OS_CRIT object is used to establish critical sections of code that can only be run by one task at ...
Definition nbrtos.h:1084
uint8_t Enter(TickTimeout &t)
Request to Enter/Claim the critical section.
uint8_t Leave()
Release the critical section.
OS_FIFO_EL * PendNoWait(uint8_t &result)
Attempts to pend a structure to the FIFO, but does not wait.
uint8_t PostFirst(OS_FIFO_EL *pToPost)
Post a message to the head of the FIFO.
OS_FIFO_EL * Pend(uint32_t timeoutTicks, uint8_t &result)
Wait the specified number of time ticks for some other task to post to the FIFO.
Definition nbrtos.h:968
uint8_t Post(OS_FIFO_EL *pToPost)
Post a message to the next available location in the FIFO.
OS_FIFO element definition.
Definition nbrtos.h:884
puint8_t pAsBytePtr
Next OS_FIFO element data byte pointer.
Definition nbrtos.h:893