82 lines
2.6 KiB
C
82 lines
2.6 KiB
C
/*****************************************************************************
|
|
* Copyright (C) 2004-2005
|
|
* ProbeStar Telematics, LLC
|
|
* All Rights Reserved. Proprietary and Confidential.
|
|
*============================================================================
|
|
* BYTE Stack
|
|
*****************************************************************************/
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __EMBEDDED_BYTESTACK__
|
|
#define __EMBEDDED_BYTESTACK__
|
|
|
|
/*****************************************************************************
|
|
* includes
|
|
*****************************************************************************/
|
|
|
|
#include "embtypes.h"
|
|
|
|
/*****************************************************************************
|
|
* defines
|
|
*****************************************************************************/
|
|
|
|
/*****************************************************************************
|
|
* macros
|
|
*****************************************************************************/
|
|
|
|
#define _StackPush(S,D) \
|
|
if ( (S).byCount < (S).bySize ) \
|
|
*((S).pbyBuf+((S).byCount++)) = (D);
|
|
|
|
#define _StackPop(S) ((S).byCount ? *((S).pbyBuf+(--(S).byCount)) : 0)
|
|
|
|
#define _StackAlloc(S,B,N) (S).pbyBuf=(B);(S).bySize=(N)
|
|
#define _StackClear(S) (S).byCount=0
|
|
#define _StackCount(S) (S).byCount
|
|
#define _StackSize(S) (S).bySize
|
|
#define _StackEmpty(S) ((S).byCount==0)
|
|
#define _StackFull(S) ((S).byCount>=(S).bySize)
|
|
|
|
#define StackClear(S) (S)->byCount=0
|
|
#define StackCount(S) (S)->byCount
|
|
#define StackSize(S) (S)->bySize
|
|
#define StackEmpty(S) ((S)->byCount==0)
|
|
#define StackFull(S) ((S)->byCount>=(S)->bySize)
|
|
|
|
/*****************************************************************************
|
|
* structs & typedefs
|
|
*****************************************************************************/
|
|
|
|
typedef struct _Stack {
|
|
BYTE byCount;
|
|
BYTE bySize;
|
|
BYTE *pbyBuf;
|
|
} Stack;
|
|
|
|
/*****************************************************************************
|
|
* global constants
|
|
*****************************************************************************/
|
|
|
|
/*****************************************************************************
|
|
* global variables
|
|
*****************************************************************************/
|
|
|
|
/*****************************************************************************
|
|
* C function prototypes
|
|
*****************************************************************************/
|
|
/* export C functions to C++ */
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
void StackAlloc( Stack *pS, BYTE *pbyBuf, BYTE bySize );
|
|
|
|
BYTE StackPush( Stack *pS, BYTE *pbyData );
|
|
BYTE StackPop( Stack *pS, BYTE *pbyData );
|
|
|
|
#ifdef __cpluscplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|