12楼说得正确,我写的也有问题,加volatile更正
#ifndef _COMMON_DATA_STRUCTRUE #define _COMMON_DATA_STRUCTRUE
typedef struct _COMMONF_QUE { unsigned char *pBuf; volatile unsigned short len; unsigned short head; unsigned short tail; unsigned short maxLen; }COMMON_QUE2;
void InitCommQue(COMMON_QUE2 *pCommDataStru,unsigned char *ppBuf1,unsigned maxLen1); unsigned char GetCommQueHdStatus(COMMON_QUE2 *pCommDataStru); unsigned char GetCommQueTlStatus(COMMON_QUE2 *pCommDataStru); void RefreshCommQueHead(COMMON_QUE2 *pCommDataStru); void RefreshCommQueTail(COMMON_QUE2 *pCommDataStru);
#endif
#include "common_data_structure.h"
void InitCommQue(COMMON_QUE2 *pCommDataStru,unsigned char *ppBuf1,unsigned maxLen1) { pCommDataStru ->pBuf = pBuf1; pCommDataStru ->maxLen = maxLen1; }
unsigned char GetCommQueHdStatus(COMMON_QUE2 *pCommDataStru) { if(pCommDataStru ->len < pCommDataStru ->maxLen) return 1; else return 0; }
unsigned char GetCommQueTlStatus(COMMON_QUE2 *pCommDataStru) { if(pCommDataStru ->len > 0) return 1; else return 0; }
void RefreshCommQueHead(COMMON_QUE2 *pCommDataStru) { if(pCommDataStru ->head == pCommDataStru ->maxLen -1) pCommDataStru ->head = 0; else pCommDataStru ->head ++;
pCommDataStru ->len++; }
void RefreshCommQueTail(COMMON_QUE2 *pCommDataStru) { if(pCommDataStru ->tail == pCommDataStru ->maxLen -1) pCommDataStru ->tail = 0; else pCommDataStru ->tail ++;
pCommDataStru ->len--; } |
|