29#include <basictypes.h>
58#define BS_IP_LOCAL_NET 4
60#define BS_PHY_802_3 0x10
62#define BS_DBG_LOG 0x80
66#define BUFFER_DIAG_WORD_COUNT 4
68#define BUFFER_DIAG_WORD_COUNT 0
71#define BUF_PREDATA_SENTINAL_LEN (8)
72#define BUF_PREDATA_PADLEN 8
73#define BUF_POSTDATA_PADLEN 3
74#define BUF_POSTDATA_SENTINAL_LEN (11 - BUFFER_DIAG_WORD_COUNT)
76#define BUF_PREDATA_SENTINAL_LEN (8)
77#define BUF_PREDATA_PADLEN 6
78#define BUF_POSTDATA_PADLEN 3
79#define BUF_POSTDATA_SENTINAL_LEN (12 - BUFFER_DIAG_WORD_COUNT)
92 uint32_t PreSentinal[BUF_PREDATA_SENTINAL_LEN];
103 uint8_t bAlignmentPad[BUF_PREDATA_PADLEN];
105 uint8_t bPostAlignmentPad[BUF_POSTDATA_PADLEN];
106 uint32_t PostSentinal[BUF_POSTDATA_SENTINAL_LEN];
118 return pFifo->
Post(pToPost);
121inline uint8_t OSPoolFifoPostFirst(
OS_FIFO *pFifo,
PoolPtr pToPost)
146void ShowBuffers_Web(
int sockfd);
155PoolPtr GetBufferX(PCSTR file,
int line);
156#define GetBuffer() GetBufferX(__FILE__, __LINE__)
166PoolPtr GetFastBufferX(PCSTR file,
int line);
167#define GetFastBuffer() GetFastBufferX(__FILE__, __LINE__)
169#define GetFastBuffer() GetBufferX(__FILE__, __LINE__)
178void FreeBufferX(
PoolPtr nbuf, PCSTR file,
int line);
179#define FreeBuffer(x) FreeBufferX(x, __FILE__, __LINE__)
181void ChangeOwnerX(
PoolPtr nbuf, PCSTR file,
int line);
182#define ChangeOwner(x) ChangeOwnerX(x, __FILE__, __LINE__)
209#define GetFastBuffer() GetBuffer()
223#define ChangeOwner(x)
226#ifdef BUFFER_DIAG_LOG
228extern uint32_t bufLogID;
229#define LOG_DEST AsciiToIp("10.1.1.3")
230#define SET_LOG_DEST \
232 extern IPADDR SysLogAddress; \
233 SysLogAddress = LOG_DEST; \
236#define BuffLog_GetFmt "%0.8lu) GET - P: %p, L: %0.4d, F: %s\r\n"
237#define BuffLog_FreeFmt "%0.8lu) FREE - P: %p, L: %0.4d, F: %s\r\n"
238#define BuffLog_GetLF(p, l, f) SysLogVia(LOG_INTF, BuffLog_GetFmt, bufLogID++, p, l, f)
239#define BuffLog_FreeLF(p, l, f) SysLogVia(LOG_INTF, BuffLog_FreeFmt, bufLogID++, p, l, f)
240#define BuffLog_Get(p) BuffLog_GetLF(p, __LINE__, __FILE__)
241#define BuffLog_Free(p) BuffLog_FreeLF(p, __LINE__, __FILE__)
242#define BuffLog_Write(p) SysLogVia(LOG_INTF, "WRITE - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__)
243#define BuffLog_Read(p) SysLogVia(LOG_INTF, "READ - P: %p, L: %0.4d, F: %s\r\n", p, __LINE__, __FILE__)
245#define BuffLog_Get(p)
246#define BuffLog_Free(p)
247#define BuffLog_Write(p)
248#define BuffLog_Read(p)
301#ifdef BUFFER_WATERMARK
309uint16_t GetMinFreeCount();
318uint16_t GetMaxFreeCount();
353#ifdef BUFFER_WATERMARK
354 uint16_t m_wMaxElements;
355 uint16_t m_wMinElements;
408#ifdef BUFFER_WATERMARK
420#ifdef BUFFER_WATERMARK
425 uint16_t GetMaxCount() {
return m_wMaxElements; };
431 uint16_t GetMinCount() {
return m_wMinElements; };
449 uint32_t m_startOffset;
450 uint32_t m_maxChunkLen;
451 uint8_t m_Segments_Stored;
452 uint8_t m_MaxSegments;
453 bool m_checksumWrites;
454 uint8_t m_buffer_pool;
458 uint8_t *GetWritePtr(uint32_t *remLen);
459 void WriteDone(uint32_t bytesCopied);
461 uint8_t *GetReadPtr(uint32_t *remLen);
462 void ReadDone(uint32_t bytesCopied);
482 m_fifo.m_critical_section.
Enter();
483 pBuf = m_fifo.GetWritePtr(&bufLen);
487 m_fifo.WriteDone(copied);
488 m_fifo.m_critical_section.
Leave();
491 inline uint8_t *buf() {
return pBuf + copied; }
492 inline uint32_t len() {
return bufLen - copied; }
493 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
512 m_fifo.m_critical_section.
Enter();
513 pBuf = m_fifo.GetReadPtr(&bufLen);
517 m_fifo.ReadDone(copied);
518 m_fifo.m_critical_section.
Leave();
521 inline uint8_t *buf() {
return pBuf + copied; }
522 inline uint32_t len() {
return bufLen - copied; }
523 void ByteCopyDone(uint32_t bytesCopied) { copied += (bytesCopied <= (bufLen - copied)) ? bytesCopied : (bufLen - copied); }
540 : m_fifo(rhs.m_fifo), pCurrPP(rhs.pCurrPP), peekPtr(rhs.peekPtr), locked(
false)
544 m_fifo.m_critical_section.
Enter();
554 m_fifo.m_critical_section.
Enter();
556 pCurrPP = m_fifo.m_Head;
557 if (pCurrPP) { peekPtr = pCurrPP->
pAsBytePtr; }
568 operator uint16_t()
const;
569 operator uint32_t()
const;
573 return ((&m_fifo == &(rhs.m_fifo)) && (pCurrPP == rhs.pCurrPP) && (peekPtr == rhs.peekPtr));
575 bool operator!=(
const PeekIterator &rhs) {
return !(*
this == rhs); }
582 uint32_t LongSpaceAvail();
611 int ReadDatawSum(puint8_t pCopyTo,
int max_bytes, uint32_t &csum);
613 int SkipData(
int skip);
615 int ReadTerminatedData(puint8_t pCopyTo,
int max_bytes, uint8_t term_char);
618 int PushBuffer(
PoolPtr pp,
int dataLen,
int startOffset);
620 PoolPtr PullBuffer(uint32_t &csum);
621 inline PoolPtr PeekBuffer() {
return m_Head; }
622 void SetFifoLock(
bool locked);
677 void SetMaxBuffers(uint8_t max_buffers);
678 inline void SetMaxChunkLen(uint32_t maxStorage)
682 inline void SetStartOffset(uint32_t offset)
684 m_startOffset = offset;
685 SetMaxChunkLen(m_maxChunkLen);
687 inline uint32_t GetMaxBuffers() {
return m_MaxSegments; }
688 inline uint32_t GetMaxChunkLen() {
return m_maxChunkLen; }
689 inline uint32_t GetStartOffset() {
return m_startOffset; }
690 inline void SetWriteChecksum(
bool summingOn) { m_checksumWrites = summingOn; }
691 inline uint32_t GetMinimumFullSize(
int maxSegments = -1)
694 maxSegments = m_MaxSegments;
695 return (m_maxChunkLen * (maxSegments-1))+1;
698 void Init(uint8_t max_buffers, uint8_t use_fromisr = 1, uint8_t use_fast_buffs = 1);
699} __attribute__((packed));
752 inline PoolPtr &operator->() {
return m_pp; }
753 explicit operator PoolPtr() {
return m_pp; }
754 inline bool operator!() {
return !m_pp; }
Smart pointer wrapper for automatic buffer management.
Definition buffers.h:708
SMPoolPtr(const PoolPtr pp)
Constructor from existing buffer pointer.
Definition buffers.h:725
SMPoolPtr()
Constructor - automatically allocates a buffer.
Definition buffers.h:715
~SMPoolPtr()
Destructor - automatically frees the buffer.
Definition buffers.h:732
TickTimeout objects are used to facilitate sequential function calls with timeout parameters that nee...
Definition nbrtos.h:168
Doubly-linked list management for buffers.
Definition buffers.h:349
PoolPtr RemoveHead()
Remove and return the head buffer.
void InsertAfter(PoolPtr buf2insert, PoolPtr after_buffer)
Insert buffer after specified buffer in list.
uint16_t GetCount()
Get current number of buffers in the list.
Definition buffers.h:419
void Remove(PoolPtr buffer)
Remove specified buffer from the list.
void InsertHead(PoolPtr buffer)
Insert buffer at the head of the list.
PoolPtr RemoveTail()
Remove and return the tail buffer.
void InsertTail(PoolPtr buffer)
Insert buffer at the tail of the list.
uint16_t m_wElements
Current number of elements in list.
Definition buffers.h:357
PoolPtr m_Head
First buffer in the list.
Definition buffers.h:351
void InsertBefore(PoolPtr buf2insert, PoolPtr b4buffer)
Insert buffer before specified buffer in list.
PoolPtr m_Tail
Last buffer in the list.
Definition buffers.h:352
Iterator for non-destructive examination of buffered data.
Definition buffers.h:532
RAII accessor for reading from buffer storage.
Definition buffers.h:502
RAII accessor for writing to buffer storage.
Definition buffers.h:472
FIFO buffer storage using linked pool buffers.
Definition buffers.h:443
BOOL Empty()
Check if buffer is empty.
~fifo_buffer_storage()
Destructor - frees all allocated buffers.
uint8_t PeekData(int idx=-1)
Peek at data without removing it.
fifo_buffer_storage(uint8_t max_buffers=0, uint8_t use_fromisr=1, uint8_t use_fast_buffs=1)
Constructor.
BOOL Full()
Check if buffer is full.
void Reset(uint8_t max_buffers)
Reset buffer storage and free all data.
PeekIterator Peek_Begin()
Get iterator for beginning of buffered data.
int ReadData(puint8_t pCopyTo, int max_bytes)
Read data from the buffer.
uint16_t SpaceAvail()
Get number of bytes available for writing.
PeekIterator Peek_End()
Get iterator for end of buffered data.
int WriteData(puint8_t pCopyFrom, int num_bytes)
Write data to the buffer.
uint16_t SpaceUsed()
Get number of bytes currently stored.
NetBurner System Constants.
PoolPtr GetFastBuffer()
Allocate a software buffer, preferring the fast memory pool.
void FreeBuffer(PoolPtr nbuf)
Free a buffer and return it to the unused pool.
void ShowBuffer(PoolPtr p)
Display buffer contents and state information.
void InitBuffers()
Initialize the buffer system.
PoolPtr GetBuffer()
Allocate a software buffer for general use.
uint16_t GetFreeCount()
Returns the number of free buffers in the system. Buffers are used for both serial and network interf...
void IncUsageCount(PoolPtr pp)
Increment the usage count of a buffer.
void FreeBufferList(PoolPtr nbuf)
Free a linked list of buffers.
#define ETHER_BUFFER_SIZE
Definition constants.h:64
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:1110
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:993
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:909
puint8_t pAsBytePtr
Next OS_FIFO element data byte pointer.
Definition nbrtos.h:918
Main buffer structure for network and serial communication.
Definition buffers.h:90
uint8_t bInterfaceNumber
Network interface number.
Definition buffers.h:102
uint8_t pData[ETHER_BUFFER_SIZE]
Buffer data payload (1548 bytes)
Definition buffers.h:104
vuint32_t dwTimeFraction
Fractional timestamp component.
Definition buffers.h:97
vuint16_t usedsize
Number of bytes currently used in pData.
Definition buffers.h:98
VPoolPtr pPoolNext
Pointer to next buffer in linked list.
Definition buffers.h:94
VPoolPtr pPoolPrev
Pointer to previous buffer in linked list.
Definition buffers.h:95
uint8_t bBufferFlag
Buffer state flags (BS_* values)
Definition buffers.h:100
vuint32_t dwTime
Timestamp or checksum storage.
Definition buffers.h:96
uint8_t bUsageCount
Reference count for shared buffers.
Definition buffers.h:101
uint8_t bBuffer_state
Buffer ownership state (BO_* values)
Definition buffers.h:99