Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_circularBufferStd.h
Go to the documentation of this file.
1 
15  /*********************************************************************
16  * @section nz_circularBufferStd_lic Software License Agreement
17  *
18  * The software supplied herewith is owned by Modtronix Engineering, and is
19  * protected under applicable copyright laws. The software supplied herewith is
20  * intended and supplied to you, the Company customer, for use solely and
21  * exclusively on products manufactured by Modtronix Engineering. The code may
22  * be modified and can be used free of charge for commercial and non commercial
23  * applications. All rights are reserved. Any use in violation of the foregoing
24  * restrictions may subject the user to criminal sanctions under applicable laws,
25  * as well as to civil liability for the breach of the terms and conditions of this license.
26  *
27  * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
28  * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
29  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
30  * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
31  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
32  **********************************************************************
33  * File History
34  *
35  * 2010-11-10, David H. (DH):
36  * - Initial version
37  *********************************************************************/
38 #ifndef NZ_CIRCULAR_BUFFER_STD_H
39 #define NZ_CIRCULAR_BUFFER_STD_H
40 
41 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_STD)
42 
43 #if defined(NZ_CIRCULAR_BUFFER_PWR2_H)
44 #error "Can not include both nz_circularBufferPwr2.h AND nz_circularBufferStd.h! Only included the one corresponding to the *.c file used in project!"
45 #endif
46 
47 #if defined(THIS_IS_NZ_CIRCULAR_BUFFER_PWR2_C)
48 #error "Can not include nz_circularBufferStd.h in nz_circularBufferPwr2.c! For some reason MPLAB X keeps adding it! Remove nz_circularBufferStd.h from nz_circularBufferPwr2.c!"
49 #endif
50 
51 #define BUF_SYNC_CHAR 0xC5
52 
53 #include "nz_circularBuffer.h"
54 
55 
61 #if !defined(CIRBUF_OPTIMIZE_SIZE)
62 #define cbufEmpty(pBuf) {(pBuf)->get = (pBuf)->put; /*Don't update put, only GET*/}
63 //#define cbufEmpty(pBuf) {(pBuf)->get = (pBuf)->put = 0;}
64 #endif
65 
66 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
67 
68 #define cbufEmpty_MACRO(pBuf) {(pBuf)->get = (pBuf)->put; /*Don't update put, only GET*/}
69 #else
70 #define cbufEmpty_MACRO cbufEmpty
71 #endif
72 
73 
81 #if !defined(CIRBUF_OPTIMIZE_SIZE)
82 #define cbufIsEmpty(pBuf) ((pBuf)->get == (pBuf)->put)
83 #endif
84 
85 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
86 
87 #define cbufIsEmpty_MACRO(pBuf) ((pBuf)->get == (pBuf)->put)
88 #else
89 #define cbufIsEmpty_MACRO cbufIsEmpty
90 #endif
91 
92 
93 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
94 
95 #define cbufIsFull_MACRO(pBuf) ( ((pBuf)->put==(pBuf)->maxOffset) ? ((pBuf)->get==0) : (((pBuf)->put+1)==(pBuf)->get) )
96 #else
97 #define cbufIsFull_MACRO cbufIsFull
98 #endif
99 
107 #define cbufHasData(pBuf) (cbufIsEmpty(pBuf)==0)
108 #define cbufHasData_MACRO(pBuf) ((pBuf)->get != (pBuf)->put)
109 
110 
111 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
112 
113 #define cbufHasSpace_MACRO(pBuf) ( ((pBuf)->put==(pBuf)->maxOffset) ? ((pBuf)->get!=0) : (((pBuf)->put+1)!=(pBuf)->get) )
114 #else
115 #define cbufHasSpace_MACRO(pBuf) (cbufIsFull(pBuf)==0)
116 #endif
117 
118 
119 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
120 
121 #define cbufGetCount_MACRO(pBuf) ( ((pBuf)->put>=(pBuf)->get) ? ((pBuf)->put-(pBuf)->get) : (((pBuf)->put+(pBuf)->maxOffset+1)-(pBuf)->get) )
122 #else
123 #define cbufGetCount_MACRO cbufGetCount
124 #endif
125 
126 
127 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
128 
129 #define cbufGetFree_MACRO(pBuf) ( ((pBuf)->put < (pBuf)->get) ? ((pBuf)->get-(pBuf)->put-1) : (((pBuf)->get + (pBuf)->maxOffset) - (pBuf)->put) )
130 #else
131 #define cbufGetFree_MACRO cbufGetFree
132 #endif
133 
134 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
135 
136 #define cbufGetFormat_MACRO(pBuf) ((pBuf)->flagTF.format)
137 #else
138 #define cbufGetFormat_MACRO cbufGetFormat
139 #endif
140 
141 
142 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
143 
144 #define cbufGetType_MACRO(pBuf) ((pBuf)->flagTF.type)
145 #else
146 #define cbufGetType_MACRO cbufGetType
147 #endif
148 
149 
163 #if !defined(CIRBUF_OPTIMIZE_SIZE)
164 #define cbufPeekByte(pBuf) ( (pBuf)->buf[(pBuf)->get] )
165 #endif
166 
167 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
168 
169 #define cbufPeekByte_MACRO(pBuf) ( (pBuf)->buf[(pBuf)->get] )
170 #else
171 #define cbufPeekByte_MACRO cbufPeekByte
172 #endif
173 
174 
185 #if !defined(CIRBUF_OPTIMIZE_SIZE)
186  #define cbufRemoveByte(pBuf) ( (pBuf)->get = (((pBuf)->get==(pBuf)->maxOffset) ? 0 : ((pBuf)->get+1)) )
187 #endif
188 
189 
190 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS) && !defined(cbufRemoveByte_MACRO)
191 
192 #define cbufRemoveByte_MACRO(pBuf) ( (pBuf)->get = (((pBuf)->get==(pBuf)->maxOffset) ? 0 : ((pBuf)->get+1)) )
193 #else
194 #define cbufRemoveByte_MACRO cbufRemoveByte
195 #endif
196 
197 
198 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
199 
216 #define cbufGetByte_MACRO(pBuf) ((pBuf)->buf[ (pBuf)->get ]); ( (pBuf)->get = (((pBuf)->get==(pBuf)->maxOffset) ? 0 : ((pBuf)->get+1)) )
217 #else
218 #define cbufGetByte_MACRO cbufGetByte
219 #endif
220 
221 
222 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
223 
224 #define cbufGetRdArrSize_MACRO(pBuf) (((pBuf)->put < (pBuf)->get) ? (((pBuf)->maxOffset + 1) - (pBuf)->get) : ((pBuf)->put - (pBuf)->get))
225 #else
226 #define cbufGetRdArrSize_MACRO cbufGetRdArrSize
227 #endif
228 
229 
237 #define cbufGetRdArr(pBuf) ( (BYTE*) &((pBuf)->buf[(pBuf)->get]) )
238 
239 
251 #if !defined(CIRBUF_OPTIMIZE_SIZE)
252 #define cbufPutByteNoCheck(pBuf, b) {(pBuf)->buf[(pBuf)->put] = (b); /* Write byte to buf */ (pBuf)->put = (((pBuf)->put==(pBuf)->maxOffset) ? 0 : ((pBuf)->put+1));}
253 #endif
254 #if defined(CIRBUF_USE_PUTBYTE_FOR_PUTBYTENOCHECK)
255 #define cbufPutByteNoCheck(pBuf, b) cbufPutByte(pBuf, b)
256 #endif
257 
258 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
259 
260 #define cbufPutByteNoCheck_MACRO(pBuf, b) {(pBuf)->buf[(pBuf)->put] = (b); /* Write byte to buf */ (pBuf)->put = (((pBuf)->put==(pBuf)->maxOffset) ? 0 : ((pBuf)->put+1));}
261 #else
262 #define cbufPutByteNoCheck_MACRO cbufPutByteNoCheck
263 #endif
264 
265 
276 #define cbufGetWrArr(pBuf) ( (BYTE*) &((pBuf)->buf[(pBuf)->put]) )
277 
278 
286 #define cbufGetError(pBuf) ((pBuf)->flags.bErrorFull)
287 
288 
294 #define cbufClearError(pBuf) ((pBuf)->flags.bErrorFull = 0)
295 
296 
306 #define cbufIsPacket(pBuf) (pBuf->flagBits.bPacket==TRUE)
307 
308 
321 #define cbufIsPacketLarge(pBuf) (pBuf->flagBits.bPacketLarge==TRUE)
322 
323 #endif //#if defined(CIRBUF_USE_CIRCULAR_BUFFER_STD)
324 #endif //#ifndef NZ_CIRCULAR_BUFFER_STD_H