ringbuff.h

00001 
00007 #ifndef RINGBUFF_H
00008 #define RINGBUFF_H
00009 
00010 #ifndef CTL_SERIAL_H
00011 #include "ctl/serial.h"
00012 #endif
00013 
00014 typedef struct RingBuff
00015 {
00016     const uint8* buff;  /* Start of buffer */
00017     const uint8* end;   /* End of buffer */
00018     uint8* head;    /* Beginning of data in buffer */
00019     uint8* tail;    /* End of data in buffer */
00020 } RingBuff;
00021 
00022 /*
00023  * Init RingBuff
00024  */
00025 void    RingBuff_Init( RingBuff* self, void* buff, size_t size );
00026 
00030 #define RingBuff_Reset(rb)  { (rb)->tail = (rb)->head = (uint8*)(rb)->buff; }
00031 
00035 #define RingBuff_Total(rb)  ( (rb)->end - (rb)->buff )
00036 
00040 #define RingBuff_IsEmpty(rb)    ( (rb)->head == (rb)->tail )
00041 
00047 #define RingBuff_Remain(rb) ((rb)->tail - (rb)->head)
00048 
00054 #define RingBuff_Free(rb) (RingBuff_Total(rb)-RingBuff_Remain(rb))
00055 
00056 /*
00057  * Put or peek bytes directly in buffer
00058  * Efficient, but dangerous for sloppy coders
00059  */
00060 bool RingBuff_Space( RingBuff* self, uint8** buff, size_t count );
00061 bool RingBuff_Add( RingBuff* self, uint8** buff, size_t count );
00062 bool RingBuff_CopyTo( RingBuff* self, const void* buff, size_t count );
00063 
00064 bool RingBuff_Peek( RingBuff* self, const uint8** buff, size_t count );
00065 bool RingBuff_Consume( RingBuff* self, size_t count );
00066 bool RingBuff_Pop( RingBuff* self, const uint8** buff, size_t count );
00067 bool RingBuff_CopyFrom( RingBuff* self, void* buff, size_t count );
00068 
00069 /*
00070  * Interface with serial data and balance of ctl code generators
00071  */
00072 bool    RingBuff_AddSerial( RingBuff* self, ctl_serial* serial, size_t reserve );
00073 bool    RingBuff_PeekSerial( RingBuff* self, ctl_serial* serial );
00074 bool    RingBuff_PopSerial( RingBuff* self, ctl_serial* serial );
00075 
00076 #endif /* RINGBUFF_H */
00077 

Generated on Fri Jan 2 15:28:34 2009 for Squat by  doxygen 1.5.6