#ifndef __QUEUE_H
#define __QUEUE_H
#include "stdio.h"

#define MAX_QSIZE (60u) /* 最大队列长度 */

typedef unsigned long long u64;

typedef struct
{
    struct
    {
        uint8_t ide;
        uint8_t rtr;
        uint8_t dlc;
    } reg;
    union
    {
        uint32_t r;
        struct
        {
            uint8_t sa : 8;
            uint8_t ps : 8;
            uint8_t pf : 8;
            uint8_t dp : 1;
            uint8_t r  : 1;
            uint8_t p  : 3;
        } b;
    } id;
    union
    {
        uint8_t  u8_buf[8];
        uint16_t u16_buf[4];
        uint32_t u32_buf[2];
        u64      u64_buf;
    } data;
} pdu_tag, *p_pdu_tag;

typedef struct
{
    uint8_t  buf[8];
    uint32_t can_id;
} CanData_TypeDef;

typedef struct
{
    uint16_t head;
    uint16_t tail;
    uint16_t count;
    pdu_tag  can_message[MAX_QSIZE];
} can_queue_tag, *p_can_queue_tag;

typedef enum
{
    Q_OK,
    Q_ERR,
    Q_FULL,
    Q_EMPTY,
} QUEUE_STATUS;

extern can_queue_tag can_tx_queue;
extern can_queue_tag can_rx_queue;

void         queue_init(p_can_queue_tag);  // 初始化队列
uint8_t      queue_empty(p_can_queue_tag); // 查询队列是否为空
uint8_t      queue_full(p_can_queue_tag);
uint8_t      get_head(can_queue_tag *p_queue, pdu_tag *data); // 获取对头数据
QUEUE_STATUS en_queue(p_can_queue_tag, pdu_tag);              // 队列插入数据
QUEUE_STATUS de_queue(p_can_queue_tag, p_pdu_tag);
#endif
