mppt/Drivers/RingQueue2/ring_queue2.h

46 lines
1.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* ring_queue.h
*
* Created on: 2024年6月21日
* Author: psx
*/
#ifndef DRIVERS_RINGQUEUE_RING_QUEUE2_H_
#define DRIVERS_RINGQUEUE_RING_QUEUE2_H_
//#define RING_QUEUE_DEBUG //定义本宏会打印RingQueue的调试信息
//typedef unsigned char RQ_ElementType2;//元素类型
typedef uint16_t RQ_ElementType2;//元素类型
typedef struct _ring_queue2
{
RQ_ElementType2 *elems;
int size;
volatile int front, rear;
}RingQueue2;
//初始化队列,需传入保存队列状态的结构q队列使用的buffer和buffer大小
int InitRingQueue2(RingQueue2 *q, RQ_ElementType2 *buff, int size);
#define RingQueueFull2(q) (((q)->rear+1) % (q)->size == (q)->front)
#define RingQueueEmpty2(q) ((q)->front == (q)->rear)
//遍历队列,
//消费者使用故对生产者可能修改的rear先读取缓存
int ShowRingQueue2(RingQueue2 *q);
//向队尾插入元素e
int InRingQueue2(RingQueue2 *q,RQ_ElementType2 e);
//从队首删除元素
int OutRingQueue2(RingQueue2 *q, RQ_ElementType2 *e);
//队列中的元素个数
int RingQueueLength2(RingQueue2 *q);
#endif /* DRIVERS_RINGQUEUE_RING_QUEUE_H_ */