提交 | 用户 | 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 |
|
842bb6
|
11 |
#pragma anon_unions |
483170
|
12 |
typedef struct |
Q |
13 |
{ |
|
14 |
unsigned char * buf1; |
842bb6
|
15 |
short Caps; |
Q |
16 |
volatile short wp; //Write Pointor |
|
17 |
volatile short rp; //Read Pointor |
483170
|
18 |
// volatile int DataSize; |
842bb6
|
19 |
// volatile short RecvBytes; |
Q |
20 |
union{ |
|
21 |
volatile unsigned char state; |
|
22 |
struct{ |
|
23 |
volatile unsigned char bFull:1; |
|
24 |
volatile unsigned char bEmpty:1; |
|
25 |
}; |
|
26 |
}; |
483170
|
27 |
|
Q |
28 |
}stMyQueue,* pMyQueue; |
|
29 |
|
|
30 |
int initQueue(pMyQueue theQueue, void * pBuf, int nSize); |
|
31 |
int EmptyQueue(stMyQueue * theQueue); |
|
32 |
static __inline int GetCap(pMyQueue theQueue) |
|
33 |
{ |
|
34 |
return theQueue->Caps; |
|
35 |
} |
|
36 |
static __inline int GetDataLen(pMyQueue theQueue) |
|
37 |
{ |
842bb6
|
38 |
int size=theQueue->wp - theQueue->rp; |
483170
|
39 |
if (theQueue->bFull) |
Q |
40 |
{ |
|
41 |
return theQueue->Caps; |
|
42 |
}else if (theQueue->bEmpty) |
|
43 |
{ |
|
44 |
return 0; |
|
45 |
}else if (size >0 ) |
|
46 |
{ |
|
47 |
return size; |
|
48 |
}else if (size < 0) |
|
49 |
{ |
|
50 |
return size + theQueue->Caps; |
|
51 |
} else |
|
52 |
{ |
|
53 |
return 0; |
|
54 |
} |
|
55 |
} |
|
56 |
static __inline int GetLeftRoom(pMyQueue theQueue) |
|
57 |
{ |
|
58 |
return (theQueue->Caps - GetDataLen(theQueue)); |
|
59 |
} |
|
60 |
static __inline int IsFull(pMyQueue theQueue) |
|
61 |
{ |
|
62 |
return (theQueue->bFull); |
|
63 |
} |
|
64 |
static __inline int IsEmpty(pMyQueue theQueue) |
|
65 |
{ |
|
66 |
return (theQueue->bEmpty); |
|
67 |
} |
|
68 |
|
|
69 |
int GetContinueEmptyRoom(pMyQueue theQueue); |
|
70 |
int GetContinueData(pMyQueue theQueue); |
|
71 |
static __inline unsigned char * GetReadBuffer(pMyQueue theQueue) |
|
72 |
{ |
|
73 |
return theQueue->buf1+theQueue->rp; |
|
74 |
} |
|
75 |
static __inline unsigned char * GetWriteBuffer(pMyQueue theQueue) |
|
76 |
{ |
|
77 |
return theQueue->buf1+theQueue->wp; |
|
78 |
} |
|
79 |
int AddSpace(pMyQueue theQueue, int nSize); |
|
80 |
int DelData(pMyQueue theQueue, int nSize); |
|
81 |
|
|
82 |
int CopyData(pMyQueue theQueue, void * pData, int nSize); |
|
83 |
|
|
84 |
int PushIn(pMyQueue theQueue, void * pData, int nSize); |
|
85 |
int PopOut(pMyQueue theQueue, void * pData, int nSize); |
|
86 |
|
|
87 |
int PushOne(pMyQueue theQueue, unsigned char ch); |
|
88 |
int PopOne(pMyQueue theQueue); |
|
89 |
|
|
90 |
#endif /* __MYQUEUE_H__ */ |