/** ##########################################################################
**     Filename  : queue_entity.h
**     Project   :
**     Module    :
**     Processor :
**     Version   : 1.2
**     Compiler  :
**     Date/Time :
**     Abstract  :
**     Contents  :
**     Note      :  消息隊列
          順序循環消息隊列   ----  溢出丟棄
            約定:1.隊列尾指針為實際末尾無素的下一位置.   2.浪費一個元素空間,以"隊列頭指
              針在隊列尾指針的下一位置(指環狀的下一位置)上作為隊列呈"滿"狀態的標誌.
              seq為空循環隊列的判定條件為:頭尾重合      seq.front==seq.rear
              seq為滿循環隊列的判定條件為:隊尾趕上隊頭  (seq.rear+1)%MAXSIZE==seq.front
              注: 申請的隊列空間,buf至少2個.
          注: 定義隊列緩存時;可以多加一個地址緩存;但是記住在調用queue_init函數時;參數length的值就是隊列緩存大小值;
**
**     (c) Copyright dmdz Co.,Ltd
**  --------------------------------------------------------------------------
**               R E V I S I O N   H I S T O R Y
**  --------------------------------------------------------------------------
**  Date       Ver   Author             Description

**  -20230602-  --V1.2--  --mingyea---  --修改--

** #########################################################################*/
#ifndef QUEUE_ENTITY__H
#define QUEUE_ENTITY__H

/*lint -e749 */ /* 枚舉 not referenced*/
/*lint -e750 */ /* 宏 not referenced*/
/*lint -e751 */ /* 變量 not referenced*/
/*lint -e752 */ /* 函數 not referenced*/
/*lint -e753 */ /* 枚舉 not referenced*/
/*lint -e754 */ /* 結構體成員 not referenced*/

/*---------------------------------------------------------------------------
- I N C L U D E   F I L E S
----------------------------------------------------------------------------*/
#include "common_types.h"
#include "queue_entity_cfg.h"

/*---------------------------------------------------------------------------
- D E F I N E S / M A C R O S
----------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
- T Y P E   D E F I N I T I O N S
----------------------------------------------------------------------------*/
typedef enum
{
	QUEUE_ERRO = 0u,
	QUEUE_OK = !QUEUE_ERRO
}QUEUE_OPERATE_FLAG_E;

typedef enum
{
	QUEUE_FALSE = 0u,
	QUEUE_TRUE = !QUEUE_FALSE
}QUEUE_RIGHT_FLAG_E;


typedef enum
{
	QUEUE_MINUS = 0u,  /* 元素減少發送次數 */
	QUEUE_DEL = !QUEUE_MINUS     /* 元素直接刪除 */
}QUEUE_DEL_FLAG_E;

typedef u8 sequential_queue_elem;


typedef struct
{
	u16 length;  /*隊列長度*/
	sequential_queue_elem *base; /*數據*/
	u8 unit_sizes;  /*元素的字節長度*/
	u16 front;  /*頭指針*/
	u16 rear;   /*尾指針*/
}sequential_queue_s;

/*---------------------------------------------------------------------------
- G L O B A L   V A R I A B L E S
- only configuration table allowed here,variables are not allowed!
----------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
- C O N S T A N T S
----------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------
- F U N C T I O N   P R O T O T Y P E
----------------------------------------------------------------------------*/
void queue_init(sequential_queue_s *seq, sequential_queue_elem *pdata, u8 length , u8 unit_sizes);
void queue_clear(sequential_queue_s *seq);
QUEUE_RIGHT_FLAG_E queue_get_empty(sequential_queue_s seq);
u16 queue_get_length(sequential_queue_s seq);
QUEUE_OPERATE_FLAG_E queue_get_head(sequential_queue_s *seq,sequential_queue_elem *element);
QUEUE_OPERATE_FLAG_E queue_add_element(sequential_queue_s *seq,const sequential_queue_elem *element);
QUEUE_OPERATE_FLAG_E queue_del_element(sequential_queue_s *seq,sequential_queue_elem *element);



#if 0


QUEUE_OPERATE_FLAG_E queue_del_one_element_by_flag(sequential_queue_s *seq,u16 i,sequential_queue_elem *element,QUEUE_DEL_FLAG_E fdo);
QUEUE_OPERATE_FLAG_E queue_del_one_element(sequential_queue_s *seq,u16 i,sequential_queue_elem *element);
QUEUE_OPERATE_FLAG_E queue_get_element(sequential_queue_s seq,u8 i ,sequential_queue_elem *element);

#endif





#endif /* QUEUE_ENTITY__H */

/* [] END OF FILE */
