提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file : MyQueue.h |
|
4 |
* @brief : Header for MyQueue.c file. |
|
5 |
* This file contains the common defines of the application. |
|
6 |
****************************************************************************** |
|
7 |
*/ |
|
8 |
#ifndef __MYQUEUE_H__ |
|
9 |
#define __MYQUEUE_H__ |
|
10 |
|
|
11 |
typedef struct |
|
12 |
{ |
|
13 |
unsigned char * buf1; |
|
14 |
int Caps; |
|
15 |
volatile int wp; //Write Pointor |
|
16 |
volatile int rp; //Read Pointor |
|
17 |
// volatile int DataSize; |
|
18 |
volatile int RecvBytes; |
|
19 |
volatile int bFull; |
|
20 |
volatile int bEmpty; |
|
21 |
volatile int state; |
|
22 |
|
|
23 |
}stMyQueue,* pMyQueue; |
|
24 |
|
|
25 |
int initQueue(pMyQueue theQueue, void * pBuf, int nSize); |
|
26 |
int EmptyQueue(stMyQueue * theQueue); |
|
27 |
static __inline int GetCap(pMyQueue theQueue) |
|
28 |
{ |
|
29 |
return theQueue->Caps; |
|
30 |
} |
|
31 |
static __inline int GetDataLen(pMyQueue theQueue) |
|
32 |
{ |
|
33 |
int size=theQueue->wp -theQueue->rp; |
|
34 |
if (theQueue->bFull) |
|
35 |
{ |
|
36 |
return theQueue->Caps; |
|
37 |
}else if (theQueue->bEmpty) |
|
38 |
{ |
|
39 |
return 0; |
|
40 |
}else if (size >0 ) |
|
41 |
{ |
|
42 |
return size; |
|
43 |
}else if (size < 0) |
|
44 |
{ |
|
45 |
return size + theQueue->Caps; |
|
46 |
} else |
|
47 |
{ |
|
48 |
return 0; |
|
49 |
} |
|
50 |
} |
|
51 |
static __inline int GetLeftRoom(pMyQueue theQueue) |
|
52 |
{ |
|
53 |
return (theQueue->Caps - GetDataLen(theQueue)); |
|
54 |
} |
|
55 |
static __inline int IsFull(pMyQueue theQueue) |
|
56 |
{ |
|
57 |
return (theQueue->bFull); |
|
58 |
} |
|
59 |
static __inline int IsEmpty(pMyQueue theQueue) |
|
60 |
{ |
|
61 |
return (theQueue->bEmpty); |
|
62 |
} |
|
63 |
|
|
64 |
int GetContinueEmptyRoom(pMyQueue theQueue); |
|
65 |
int GetContinueData(pMyQueue theQueue); |
|
66 |
static __inline unsigned char * GetReadBuffer(pMyQueue theQueue) |
|
67 |
{ |
|
68 |
return theQueue->buf1+theQueue->rp; |
|
69 |
} |
|
70 |
static __inline unsigned char * GetWriteBuffer(pMyQueue theQueue) |
|
71 |
{ |
|
72 |
return theQueue->buf1+theQueue->wp; |
|
73 |
} |
|
74 |
int AddSpace(pMyQueue theQueue, int nSize); |
|
75 |
int DelData(pMyQueue theQueue, int nSize); |
|
76 |
|
|
77 |
int CopyData(pMyQueue theQueue, void * pData, int nSize); |
|
78 |
|
|
79 |
int PushIn(pMyQueue theQueue, void * pData, int nSize); |
|
80 |
int PopOut(pMyQueue theQueue, void * pData, int nSize); |
|
81 |
|
|
82 |
int PushOne(pMyQueue theQueue, unsigned char ch); |
|
83 |
int PopOne(pMyQueue theQueue); |
|
84 |
|
|
85 |
#endif /* __MYQUEUE_H__ */ |