X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9b29d1dc5045b74516e0ddd3ffcc200ef8ad9bff..fc92f9969c1fcc2f952f0bd6d09a309a9b3ce02f:/Projects/XPLAINBridge/Lib/LightweightRingBuff.h diff --git a/Projects/XPLAINBridge/Lib/LightweightRingBuff.h b/Projects/XPLAINBridge/Lib/LightweightRingBuff.h index 16e890c07..8026cef64 100644 --- a/Projects/XPLAINBridge/Lib/LightweightRingBuff.h +++ b/Projects/XPLAINBridge/Lib/LightweightRingBuff.h @@ -41,10 +41,10 @@ #include /* Defines: */ - /** Size of each ring buffer, in bytes */ + /** Size of each ring buffer, in bytes. */ #define BUFFER_SIZE 128 - /** Type of data to store into the buffer */ + /** Type of data to store into the buffer. */ #define RingBuff_Data_t uint8_t /* Type Defines: */ @@ -53,13 +53,15 @@ RingBuff_Data_t Buffer[BUFFER_SIZE]; RingBuff_Data_t* In; RingBuff_Data_t* Out; + uint8_t Count; } RingBuff_t; /* Inline Functions: */ static inline void RingBuffer_InitBuffer(RingBuff_t* const Buffer) { Buffer->In = Buffer->Buffer; - Buffer->Out = Buffer->Buffer; + Buffer->Out = Buffer->Buffer; + Buffer->Count = 0; } static inline void RingBuffer_Insert(RingBuff_t* const Buffer, RingBuff_Data_t Data) @@ -68,6 +70,8 @@ if (++Buffer->In == &Buffer->Buffer[BUFFER_SIZE]) Buffer->In = Buffer->Buffer; + + Buffer->Count++; } static inline RingBuff_Data_t RingBuffer_Remove(RingBuff_t* const Buffer) @@ -77,12 +81,9 @@ if (++Buffer->Out == &Buffer->Buffer[BUFFER_SIZE]) Buffer->Out = Buffer->Buffer; - return Data; - } + Buffer->Count--; - static inline bool RingBuffer_Empty(RingBuff_t* const Buffer) - { - return (Buffer->In == Buffer->Out); + return Data; } #endif