Initial commit of files
This commit is contained in:
112
include/bytequeue.h
Normal file
112
include/bytequeue.h
Normal file
@ -0,0 +1,112 @@
|
||||
/*****************************************************************************
|
||||
* Copyright (C) 2008
|
||||
* ProbeStar Telematics, LLC
|
||||
* All Rights Reserved. Proprietary and Confidential.
|
||||
*============================================================================
|
||||
* BYTE Queue
|
||||
*****************************************************************************/
|
||||
|
||||
/* prevent multiple inclusions */
|
||||
#ifndef __EMBEDDED_BYTEQUEUE__
|
||||
#define __EMBEDDED_BYTEQUEUE__
|
||||
|
||||
/*****************************************************************************
|
||||
* includes
|
||||
*****************************************************************************/
|
||||
|
||||
#include "embtypes.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* defines
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* macros
|
||||
*****************************************************************************/
|
||||
|
||||
#define _QueuePut(Q,D) \
|
||||
{ \
|
||||
*((Q).pbyBuf+((Q).byFront++)) = (D); \
|
||||
(Q).byCount++; \
|
||||
if ( (Q).byFront == (Q).bySize ) \
|
||||
(Q).byFront = 0; \
|
||||
}
|
||||
|
||||
#define _QueueUnput(Q) \
|
||||
{ \
|
||||
if ( (Q).byFront == 0 ) \
|
||||
(Q).byFront = (Q).bySize; \
|
||||
*((Q).pbyBuf+(--(Q).byFront)) = (0); \
|
||||
(Q).byCount--; \
|
||||
}
|
||||
|
||||
#define _QueueGet(Q,D) \
|
||||
{ \
|
||||
(D) = *((Q).pbyBuf+((Q).byRear++)); \
|
||||
(Q).byCount--; \
|
||||
if ( (Q).byRear == (Q).bySize ) \
|
||||
(Q).byRear = 0; \
|
||||
}
|
||||
|
||||
#define _QueueUnget(Q,D) \
|
||||
{ \
|
||||
if ( (Q).byRear == 0 ) \
|
||||
(Q).byRear = (Q).bySize; \
|
||||
*((Q).pbyBuf+(--(Q).byRear)) = (D); \
|
||||
(Q).byCount++; \
|
||||
}
|
||||
|
||||
#define _QueueAlloc(Q,B,N) (Q).pbyBuf=(B);(Q).bySize=(N)
|
||||
#define _QueueClear(Q) (Q).byCount=(Q).byFront=(Q).byRear=0
|
||||
#define _QueueCount(Q) (Q).byCount
|
||||
#define _QueueSize(Q) (Q).bySize
|
||||
#define _QueueEmpty(Q) ((Q).byCount==0)
|
||||
#define _QueueFull(Q) ((Q).byCount>=(Q).bySize)
|
||||
|
||||
#define QueueCount(Q) (Q)->byCount
|
||||
#define QueueSize(Q) (Q)->bySize
|
||||
#define QueueEmpty(Q) ((Q)->byCount==0)
|
||||
#define QueueFull(Q) ((Q)->byCount>=(Q)->bySize)
|
||||
|
||||
/*****************************************************************************
|
||||
* structs & typedefs
|
||||
*****************************************************************************/
|
||||
|
||||
typedef struct _Queue {
|
||||
BYTE byCount;
|
||||
BYTE byFront;
|
||||
BYTE byRear;
|
||||
BYTE bySize;
|
||||
BYTE *pbyBuf;
|
||||
} Queue;
|
||||
|
||||
/*****************************************************************************
|
||||
* global constants
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* global variables
|
||||
*****************************************************************************/
|
||||
|
||||
/*****************************************************************************
|
||||
* C function prototypes
|
||||
*****************************************************************************/
|
||||
/* export C functions to C++ */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void QueueAlloc( Queue *pQ, BYTE *pbyData, BYTE bySize );
|
||||
void QueueClear( Queue *pQ );
|
||||
|
||||
BYTE QueueGet( Queue *pQ, BYTE *pbyData );
|
||||
BYTE QueuePut( Queue *pQ, BYTE *pbyData );
|
||||
|
||||
BYTE QueueUnget( Queue *pQ, BYTE byData );
|
||||
BYTE QueueUnput( Queue *pQ );
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user