Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_circularBuffer.h
Go to the documentation of this file.
1 
294 // Circular Buffer - documentation module
305 #ifndef NZ_CIRCULARBUFFER_H
306 #define NZ_CIRCULARBUFFER_H
307 
308 
310 // Default values if none are defined
312 
313 //If no circular buffers are defined, define CIRBUF_USE_CIRCULAR_BUFFER_PWR2
314 #if !defined(CIRBUF_USE_CIRCULAR_BUFFER_STD) && !defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
315 #define CIRBUF_USE_CIRCULAR_BUFFER_PWR2 //Use nz_circularBufferPwr2
316 #endif
317 
318 
319 //Defines minimum size allowed for a circular buffer. Default is 8
320 #if !defined(CIRBUF_MIN_SIZE)
321 #define CIRBUF_MIN_SIZE 8
322 #endif
323 
332 //#define CIRBUF_DISABLE_CONTIGUOUS_PACKETS
333 
334 
335 //Default Escape Character
336 #if !defined(CIRBUF_ESC_CHAR)
337 #define CIRBUF_ESC_CHAR '^'
338 #endif
339 
340 
341 
343 // Buffer Type Defines
345 
350 #define CIRBUF_TYPE_STREAMING 0x0000
351 
362 #define CIRBUF_TYPE_PACKET 0x0001
363 
379 #define CIRBUF_TYPE_LARGE_PACKET 0x0003
380 
381 #define CIRBUF_FLAGS_POWER2 0x0020
382 
383 
384 
386 // Byffer Format Defines
388 
390 #define CIRBUF_FORMAT_NONE 0x0000
391 #define BUFFORMAT_NONE 0
392 
394 #define CIRBUF_FORMAT_ASCII 0x0004
395 #define BUFFORMAT_ASCII 1
396 
402 #define CIRBUF_FORMAT_ASCII_ESC 0x0008
403 #define BUFFORMAT_ASCII_ESC 2
404 
406 #define CIRBUF_FORMAT_BIN 0x000C
407 #define BUFFORMAT_BIN 3
408 
409 
417 #define CIRBUF_FORMAT_BIN_ESC 0x0010
418 #define BUFFORMAT_BIN_ESC 4
419 
420 
421 //CIRBUF is defined in nz_netcruzer.h
428 //typedef struct __attribute__((aligned(2), packed)) _CIRBUF
429 typedef struct __attribute__((__packed__)) _CIRBUF
430 {
431  WORD put; //Put Pointer(offset) for Buffer, a value from 0-(bufSize)
432  WORD get; //Get Pointer(offset) for Buffer, a value from 0-(bufSize)
433  BYTE* buf; //Pointer to start of buffer.
434  WORD maxOffset; //Max value offset can have = usable buffer size. Actual buffer size is maxOffset+1 (because put=get is used to indicate empty buffer)
435  //When buffer size is power of 2, this is also the mask used for updating put and get offsets.
436  union {
437  struct
438  {
439  unsigned int bPacket : 1;
440  unsigned int bPacketLarge : 1;
441  unsigned int format : 3;
442  unsigned int bSizePower2 : 1;
443  unsigned int fill6_7 : 2;
444  unsigned int fill8_15 : 8;
445  } flagBits;
446  struct
447  {
448  unsigned int type : 2;
449  unsigned int format : 3;
450  unsigned int fill : 11;
451  } flagTF; //Type and Format
452  struct {
453  unsigned int val : 5;
454  unsigned int fill5_7 : 3;
455  unsigned int fill : 8;
456  } typeFormat; //Type and Format
457  struct
458  {
459  BYTE LB;
460  BYTE HB;
461  } flagBytes;
462  WORD flagVal;
463  };
464 } CIRBUF;
465 
466 
467 
469 // Function Prototypes
471 
485 void cbufInitDefault(CIRBUF* pBuf, BYTE* bufArray, WORD size);
486 
487 
503 void cbufInit(CIRBUF* pBuf, BYTE* bufArray, WORD size, BYTE typeFormat);
504 
505 
510 void cbufTask(void);
511 
512 
523 void cbufSetTypeAndFormat(CIRBUF* pBuf, BYTE typeFormat);
524 
525 
535 void cbufEmpty(CIRBUF* pBuf);
536 
537 
545 BOOL cbufIsEmpty(CIRBUF* pBuf);
546 
547 
556 BOOL cbufIsFull(CIRBUF* pBuf);
557 
558 
566 BOOL cbufHasData(CIRBUF* pBuf);
567 
568 
578 #define cbufHasSpace(pBuf) (cbufIsFull(pBuf)==0)
579 
580 
590 WORD cbufGetCount(CIRBUF* pBuf);
591 
592 
606 WORD cbufGetFree(CIRBUF* pBuf);
607 
608 
616 BYTE cbufGetFormat(CIRBUF* pBuf);
617 
618 
626 BYTE cbufGetType(CIRBUF* pBuf);
627 
628 
645 WORD cbufGetEscapedSizeRequired(CIRBUF* pBuf, BYTE* buf, WORD size);
646 
647 
656 #define cbufGetEscapeCharacter(pBuf) (CIRBUF_ESC_CHAR)
657 
658 
672 BYTE cbufPeekByte(CIRBUF* pBuf);
673 
674 
692 BYTE cbufPeekByteAt(CIRBUF* pBuf, WORD offset);
693 
694 
720 BYTE cbufPeekEscapedByte(CIRBUF* pBuf, BYTE* b);
721 
722 
738 WORD cbufFindByte(CIRBUF* pBuf, WORD offset, BYTE value);
739 
740 
752 void cbufRemoveByte(CIRBUF* pBuf);
753 
754 
768 void cbufRemoveBytes(CIRBUF* pBuf, WORD n);
769 
770 
783 void cbufRemovePutByte(CIRBUF* pBuf);
784 
785 
797 BYTE cbufGetByte(CIRBUF* pBuf);
798 
799 
816 BYTE cbufGetByte_MACRO(CIRBUF* pBuf);
817 
818 
819 
842 BYTE cbufGetEscapedByte(CIRBUF* pBuf, BYTE* b);
843 
844 
868 WORD cbufGetString(CIRBUF* pBuf, BYTE* pDstArr, WORD size);
869 
870 
885 WORD cbufGetArray(CIRBUF* pBuf, BYTE* pDstArr, WORD size);
886 
887 
927 WORD cbufGetArrayTillByte(CIRBUF* pBuf, BYTE* pDstArr, BYTE value, WORD size);
928 
929 
953 WORD cbufGetRdArrSize(CIRBUF* pBuf);
954 
955 
963 BYTE* cbufGetRdArr(CIRBUF* pBuf);
964 
965 
980 BYTE cbufPutByte(CIRBUF* pBuf, BYTE b);
981 
982 
994 void cbufPutByteNoCheck(CIRBUF* pBuf, BYTE b);
995 
996 
1012 BYTE cbufPutWord(CIRBUF* pBuf, WORD w);
1013 
1014 
1030 BYTE cbufPutByteAscii(CIRBUF* pBuf, BYTE b);
1031 
1032 
1049 BYTE cbufPutByteAsciiHex(CIRBUF* pBuf, BYTE b);
1050 
1051 
1067 BYTE cbufPutWordAscii(CIRBUF* pBuf, WORD w);
1068 
1069 
1086 BYTE cbufPutWordAsciiHex(CIRBUF* pBuf, WORD w);
1087 
1088 
1114 BYTE cbufShaddowPutByte(CIRBUF* pBuf, BYTE b, WORD putShaddow);
1115 
1116 
1124 void cbufShaddowPutCommit(CIRBUF* pBuf, WORD putShaddow);
1125 
1126 
1141 BYTE cbufPutControlChar(CIRBUF* pBuf, BYTE b);
1142 
1143 
1162 BYTE cbufPutEscapedByte(CIRBUF* pBuf, BYTE b);
1163 
1164 
1180 WORD cbufPutString(CIRBUF* pBuf, const char * s);
1181 
1182 
1187 #define ASCIIESC_ADD_S_AND_P 0x0001
1188 
1189 
1240 WORD cbufPutAsciiEscString(CIRBUF* cbufDst, CIRBUF* cbufSrc, const char* pStrSrc, WORD flags);
1241 
1242 
1257 WORD cbufPutStringWait(CIRBUF* pBuf, const char * s);
1258 
1259 
1272 WORD cbufPutArray(CIRBUF* pBuf, const BYTE* pSrcArr, WORD size);
1273 
1274 
1291 WORD cbufPutArrayWait(CIRBUF* pBuf, const BYTE* pSrcArr, WORD size);
1292 
1293 
1307 WORD cbufMove(CIRBUF* pBufSrc, CIRBUF* pBufDst);
1308 
1309 
1333 WORD cbufGetWrArrSize(CIRBUF* pBuf);
1334 
1335 
1346 BYTE* cbufGetWrArr(CIRBUF* pBuf);
1347 
1348 
1358 void cbufUpdatePut(CIRBUF* pBuf, WORD n);
1359 
1360 
1368 BOOL cbufGetError(CIRBUF* pBuf);
1369 
1370 
1376 void cbufClearError(CIRBUF* pBuf);
1377 
1378 
1388 BOOL cbufIsPacket(CIRBUF* pBuf);
1389 
1390 
1403 BOOL cbufIsPacketLarge(CIRBUF* pBuf);
1404 
1405 
1415 WORD cbufHasWholePacket(CIRBUF* pBuf);
1416 
1417 
1433 WORD cbufPacketStrcmp(CIRBUF* pBuf, const char* str);
1434 
1435 
1450 WORD cbufGetFreeForPacket(CIRBUF* pBuf);
1451 
1452 
1474 WORD cbufGetContiguousPacket(CIRBUF* pBuf, BYTE** ppData);
1475 
1476 
1496 WORD cbufGetPacketDataSize(CIRBUF* pBuf);
1497 
1498 
1511 BYTE cbufPeekPacketByte(CIRBUF* pBuf);
1512 
1513 
1530 WORD cbufPeekPacketDataSize(CIRBUF* pBuf);
1531 
1532 
1557 WORD cbufPutPacket(CIRBUF* pBuf, const BYTE* pSrcArr, WORD size);
1558 
1559 
1569 void cbufRemovePacket(CIRBUF* pBuf);
1570 
1571 
1573 // Include cirbuf implementation include files
1574 
1575 #if !defined(CIRBUF_USE_CIRCULAR_BUFFER_STD) && !defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
1576 //Use nz_circularBufferStd by default if projdefs.h does not define a circular buffer
1577 #define CIRBUF_USE_CIRCULAR_BUFFER_STD
1578 #endif
1579 
1580 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_STD)
1581  #if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
1582  #error "Configured to use multiple Circular Buffers! Only one can be used! Ensure only one CIRBUF_USE_XXX macro is defined (projdefs.h), and it matches circular buffer *.c file included with project!"
1583  #endif
1584  #include "nz_circularBufferStd.h"
1585 #endif
1586 
1587 #if defined(CIRBUF_USE_CIRCULAR_BUFFER_PWR2)
1588  #if defined(CIRBUF_USE_CIRCULAR_BUFFER_STD)
1589  #error "Configured to use multiple Circular Buffers! Only one can be used! Ensure only one CIRBUF_USE_XXX macro is defined (projdefs.h), and it matches circular buffer *.c file included with project!"
1590  #endif
1591  #include "nz_circularBufferPwr2.h"
1592 #endif
1593 
1594 #endif /* NZ_CIRCULARBUFFER_H */
1595