/** ****************************************************************************** * @file : MyQueue.h * @brief : Header for MyQueue.c file. * This file contains the common defines of the application. ****************************************************************************** */ #ifndef __MYQUEUE_H__ #define __MYQUEUE_H__ typedef struct { unsigned char * buf1; int Caps; volatile int wp; //Write Pointor volatile int rp; //Read Pointor // volatile int DataSize; volatile int RecvBytes; volatile int bFull; volatile int bEmpty; volatile int state; }stMyQueue,* pMyQueue; int initQueue(pMyQueue theQueue, void * pBuf, int nSize); int EmptyQueue(stMyQueue * theQueue); static __inline int GetCap(pMyQueue theQueue) { return theQueue->Caps; } static __inline int GetDataLen(pMyQueue theQueue) { int size=theQueue->wp -theQueue->rp; if (theQueue->bFull) { return theQueue->Caps; }else if (theQueue->bEmpty) { return 0; }else if (size >0 ) { return size; }else if (size < 0) { return size + theQueue->Caps; } else { return 0; } } static __inline int GetLeftRoom(pMyQueue theQueue) { return (theQueue->Caps - GetDataLen(theQueue)); } static __inline int IsFull(pMyQueue theQueue) { return (theQueue->bFull); } static __inline int IsEmpty(pMyQueue theQueue) { return (theQueue->bEmpty); } int GetContinueEmptyRoom(pMyQueue theQueue); int GetContinueData(pMyQueue theQueue); static __inline unsigned char * GetReadBuffer(pMyQueue theQueue) { return theQueue->buf1+theQueue->rp; } static __inline unsigned char * GetWriteBuffer(pMyQueue theQueue) { return theQueue->buf1+theQueue->wp; } int AddSpace(pMyQueue theQueue, int nSize); int DelData(pMyQueue theQueue, int nSize); int CopyData(pMyQueue theQueue, void * pData, int nSize); int PushIn(pMyQueue theQueue, void * pData, int nSize); int PopOut(pMyQueue theQueue, void * pData, int nSize); int PushOne(pMyQueue theQueue, unsigned char ch); int PopOne(pMyQueue theQueue); #endif /* __MYQUEUE_H__ */