1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "queue.h"
- void InitQueue(SqQueue *Q)
- {
- Q->front = Q->rear = 0;
- }
- INT8U IsQueueEmpty(const SqQueue *Q)
- {
- if (Q->front == Q->rear)
- return TRUE;
- else
- return FALSE;
- }
- INT16U QueueLength(SqQueue Q)
- {
- return (Q.rear - Q.front + MAX_QSIZE) % MAX_QSIZE;
- }
- INT8U GetHead(SqQueue *Q, CanData_TypeDef *e)
- {
- if (Q->front == Q->rear)
- return ERROR;
- *e = Q->CanBuf[Q->front];
- Q->front = (Q->front + 1) % MAX_QSIZE;
- return SUCCESS;
- }
- INT8U InsertQueue(SqQueue *Q, CanData_TypeDef e)
- {
- if ((Q->rear + 1) % MAX_QSIZE == Q->front)
- return ERROR;
- Q->CanBuf[Q->rear] = e;
- Q->rear = (Q->rear + 1) % MAX_QSIZE;
- return SUCCESS;
- }
|