Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_circularBufferPwr2.h
Go to the documentation of this file.
1 
16  /*********************************************************************
17  * @section nz_circularBufferPwr2_lic Software License Agreement
18  *
19  * The software supplied herewith is owned by Modtronix Engineering, and is
20  * protected under applicable copyright laws. The software supplied herewith is
21  * intended and supplied to you, the Company customer, for use solely and
22  * exclusively on products manufactured by Modtronix Engineering. The code may
23  * be modified and can be used free of charge for commercial and non commercial
24  * applications. All rights are reserved. Any use in violation of the foregoing
25  * restrictions may subject the user to criminal sanctions under applicable laws,
26  * as well as to civil liability for the breach of the terms and conditions of this license.
27  *
28  * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
29  * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
31  * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
32  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
33  **********************************************************************
34  * File History
35  *
36  * 2010-11-10, David H. (DH):
37  * - Initial version
38  *********************************************************************/
39 #ifndef NZ_CIRCULAR_BUFFER_PWR2_H
40 #define NZ_CIRCULAR_BUFFER_PWR2_H
41 
42 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
43 
44 #if defined(NZ_CIRCULAR_BUFFER_STD_H)
45 #error "Can not include both nz_circularBufferPwr2.h AND nz_circularBufferStd.h! Only included the one corresponding to the *.c file used in project!"
46 #endif
47 
48 #if defined(THIS_IS_NZ_CIRCULAR_BUFFER_STD_C)
49 #error "Can not include nz_circularBufferPwr2.h in nz_circularBufferStd.c! For some reason MPLAB X keeps adding it! Remove nz_circularBufferPwr2.h from nz_circularBufferStd.c!"
50 #endif
51 
52 #include "nz_circularBuffer.h"
53 
54 #ifndef __INLINE_FUNCTION__
55 #define __INLINE_FUNCTION__ extern inline __attribute__((always_inline))
56 #endif
57 
58 
64 #if !defined(CIRBUF_OPTIMIZE_SIZE)
65 #define cbufEmpty(pBuf) {(pBuf)->get = (pBuf)->put; /*Don't update put, only GET*/}
66 //#define cbufEmpty(pBuf) {(pBuf)->get = (pBuf)->put = 0;}
67 #endif
68 
69 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
70 
71 #define cbufEmpty_MACRO(pBuf) {(pBuf)->get = (pBuf)->put; /*Don't update put, only GET*/}
72 #else
73 #define cbufEmpty_MACRO cbufEmpty
74 #endif
75 
76 
84 #if !defined(CIRBUF_OPTIMIZE_SIZE)
85 #define cbufIsEmpty(pBuf) ((pBuf)->get == (pBuf)->put)
86 #endif
87 
88 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
89 
90 #define cbufIsEmpty_MACRO(pBuf) ((pBuf)->get == (pBuf)->put)
91 #else
92 #define cbufIsEmpty_MACRO cbufIsEmpty
93 #endif
94 
95 
96 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
97 
98 #define cbufIsFull_MACRO(pBuf) ( (((pBuf)->put+1) & (pBuf)->maxOffset) == (pBuf)->get)
99 #else
100 #define cbufIsFull_MACRO cbufIsFull
101 #endif
102 
103 
111 #define cbufHasData(pBuf) (cbufIsEmpty(pBuf)==0)
112 #define cbufHasData_MACRO(pBuf) ((pBuf)->get != (pBuf)->put)
113 
114 
115 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
116 
117 #define cbufHasSpace_MACRO(pBuf) ( (((pBuf)->put+1) & (pBuf)->maxOffset) != (pBuf)->get)
118 #else
119 #define cbufHasSpace_MACRO(pBuf) (cbufIsFull(pBuf)==0)
120 #endif
121 
122 
123 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
124 
125 #define cbufGetCount_MACRO(pBuf) ( ((pBuf)->put - (pBuf)->get) & (pBuf)->maxOffset)
126 #else
127 #define cbufGetCount_MACRO cbufGetCount
128 #endif
129 
130 
131 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
132 
133 #define cbufGetFree_MACRO(pBuf) ( ((pBuf)->get - (pBuf)->put - 1) & (pBuf)->maxOffset)
134 #else
135 #define cbufGetFree_MACRO cbufGetFree
136 #endif
137 
138 
139 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
140 
141 #define cbufGetFormat_MACRO(pBuf) ((pBuf)->flagTF.format)
142 #else
143 #define cbufGetFormat_MACRO cbufGetFormat
144 #endif
145 
146 
147 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
148 
149 #define cbufGetType_MACRO(pBuf) ((pBuf)->flagTF.type)
150 #else
151 #define cbufGetType_MACRO cbufGetType
152 #endif
153 
154 
168 #if !defined(CIRBUF_OPTIMIZE_SIZE)
169 #define cbufPeekByte(pBuf) ( (pBuf)->buf[(pBuf)->get] )
170 #endif
171 
172 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
173 
174 #define cbufPeekByte_MACRO(pBuf) ( (pBuf)->buf[(pBuf)->get] )
175 #else
176 #define cbufPeekByte_MACRO cbufPeekByte
177 #endif
178 
179 
197 #if !defined(CIRBUF_OPTIMIZE_SIZE)
198 #define cbufPeekByteAt(pBuf, offset) ((pBuf)->buf[ (((pBuf)->get + (offset)) & (pBuf)->maxOffset) ])
199 #endif
200 
201 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
202 
203 #define cbufPeekByteAt_MACRO(pBuf, offset) ((pBuf)->buf[ (((pBuf)->get + (offset)) & (pBuf)->maxOffset) ])
204 #else
205 #define cbufPeekByteAt_MACRO cbufPeekByteAt
206 #endif
207 
208 
209 
220 #if !defined(CIRBUF_OPTIMIZE_SIZE)
221 #define cbufRemoveByte(pBuf) ( (pBuf)->get = (((pBuf)->get + 1) & (pBuf)->maxOffset) )
222 #endif
223 
224 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
225 
226 #define cbufRemoveByte_MACRO(pBuf) ( (pBuf)->get = (((pBuf)->get + 1) & (pBuf)->maxOffset) )
227 #else
228 #define cbufRemoveByte_MACRO cbufRemoveByte
229 #endif
230 
231 
245 #if !defined(CIRBUF_OPTIMIZE_SIZE)
246 #define cbufRemoveBytes(pBuf, n) {(pBuf)->get = (((pBuf)->get + (n)) & (pBuf)->maxOffset); }
247 #endif
248 
249 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
250 
251 #define cbufRemoveBytes_MACRO(pBuf, n) {(pBuf)->get = (((pBuf)->get + (n)) & (pBuf)->maxOffset); }
252 #else
253 #define cbufRemoveBytes_MACRO cbufRemoveBytes
254 #endif
255 
256 
257 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
258 
275 #define cbufGetByte_MACRO(pBuf) ((pBuf)->buf[ (pBuf)->get ]); ( (pBuf)->get = (((pBuf)->get + 1) & (pBuf)->maxOffset) )
276 #else
277 #define cbufGetByte_MACRO cbufGetByte
278 #endif
279 
280 
304 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
305 
306 #define cbufGetRdArrSize_MACRO(pBuf) (((pBuf)->put < (pBuf)->get) ? (((pBuf)->maxOffset + 1) - (pBuf)->get) : ((pBuf)->put - (pBuf)->get))
307 #else
308 #define cbufGetRdArrSize_MACRO cbufGetRdArrSize
309 #endif
310 
311 
319 #define cbufGetRdArr(pBuf) ( (BYTE*) &((pBuf)->buf[(pBuf)->get]) )
320 
321 
333 #if !defined(CIRBUF_OPTIMIZE_SIZE)
334 #define cbufPutByteNoCheck(pBuf, b) {(pBuf)->buf[(pBuf)->put] = (b); /* Write byte to buf */ (pBuf)->put = (((pBuf)->put + 1) & (pBuf)->maxOffset);}
335 #endif
336 #if defined(CIRBUF_USE_PUTBYTE_FOR_PUTBYTENOCHECK)
337 #define cbufPutByteNoCheck(pBuf, b) cbufPutByte(pBuf, b)
338 #endif
339 
340 #if !defined(CIRBUF_DISABLE_ALL_MACRO_FUNCTIONS)
341 
342 #define cbufPutByteNoCheck_MACRO(pBuf, b) {(pBuf)->buf[(pBuf)->put] = (b); /* Write byte to buf */ (pBuf)->put = (((pBuf)->put + 1) & (pBuf)->maxOffset);}
343 #else
344 #define cbufPutByteNoCheck_MACRO cbufPutByteNoCheck
345 #endif
346 
347 
358 #define cbufGetWrArr(pBuf) ( (BYTE*) &((pBuf)->buf[(pBuf)->put]) )
359 
360 
370 #define cbufUpdatePut(pBuf, n) {(pBuf)->put = (((pBuf)->put + (n)) & (pBuf)->maxOffset); }
371 
372 
380 #define cbufGetError(pBuf) ((pBuf)->flags.bErrorFull)
381 
382 
388 #define cbufClearError(pBuf) ((pBuf)->flags.bErrorFull = 0)
389 
390 
400 #define cbufIsPacket(pBuf) (pBuf->flagBits.bPacket==TRUE)
401 
402 
415 #define cbufIsPacketLarge(pBuf) (pBuf->flagBits.bPacketLarge==TRUE)
416 
417 #endif //#if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
418 #endif //#ifndef NZ_CIRCULAR_BUFFER_PWR2_H