#include "hal_board.h"
//*********************************************************************************************************
void QueueInit(QueueDef *pdI_Queue, QueueCfgPrmtDef *pdI_Prmt) {
pdI_Queue->rear = 0;
pdI_Queue->front = pdI_Queue->rear;
pdI_Queue->count = 0;
pdI_Queue->elemSize = pdI_Prmt->elemSize;
pdI_Queue->queueCnt = pdI_Prmt->queueCnt;
pdI_Queue->pdat = pdI_Prmt->paddr;
}
//*********************************************************************************************************
QueueResult QueueIn(QueueDef *pdI_Queue, void *pvI_Dat) {
if ((pdI_Queue->front == pdI_Queue->rear) && (pdI_Queue->count == pdI_Queue->queueCnt)) {
return _QueueFull;
} else {
u8 *operatAddr = (u8 *)pdI_Queue->pdat;
operatAddr += pdI_Queue->rear * pdI_Queue->elemSize;
memcpyEX(operatAddr, pvI_Dat, pdI_Queue->elemSize);
pdI_Queue->rear = (pdI_Queue->rear + 1) % pdI_Queue->queueCnt;
pdI_Queue->count = pdI_Queue->count + 1;
return _QueueOperateOk;
}
}
//*********************************************************************************************************
QueueResult QueueOut(QueueDef *pdI_Queue, void *pvI_Dat) {
if ((pdI_Queue->front == pdI_Queue->rear) && (pdI_Queue->count == 0)) {
return _QueueEmpty;
} else {
u8 *operatAddr = (u8 *)pdI_Queue->pdat;
operatAddr += pdI_Queue->front * pdI_Queue->elemSize;
memcpyEX(pvI_Dat, operatAddr, pdI_Queue->elemSize);
pdI_Queue->front = (pdI_Queue->front + 1) % pdI_Queue->queueCnt;
pdI_Queue->count = pdI_Queue->count - 1;
return _QueueOperateOk;
}
}
//*********************************************************************************************************
#ifdef __TEST_DATA_FIFO
//*********************************************************************************************************
typedef struct {
u8 e1;
u16 e2;
u32 e3;
}ElemTypeDef;
//*********************************************************************************************************
void data_fifo_test(void){
QueueDef MyQueue;
ElemTypeDef MyQueueData[10];
ElemTypeDef sh;
QueueCfgPrmtDef prmt;
u8 i;
prmt.elemSize = sizeof(ElemTypeDef);
prmt.queueCnt = sizeof(MyQueueData) / sizeof(ElemTypeDef);
prmt.paddr = (u8*)MyQueueData;
QueueInit(&MyQueue, &prmt);
while (1) {
for (i = 0; i < 20; i++){
if (QueueIn(&MyQueue, &sh) == _QueueFull) break;
}
for (i = 0; i < 20; i++){
if (QueueOut(&MyQueue, &sh) == _QueueEmpty) break;
}
}
}
#endif
//*********************************************************************************************************
- 1
- 2
- 3
前往页