2025-05-21 11:31:07 +08:00

76 lines
2.4 KiB
C

/******************************************************************************
Copyright @2024 - 2044 Shenzhen dcenzix Technology Ltd.
******************************************************************************
@file cola_fifo.h
@brief
@author xiexiongwu
@version V1.0
@date 2024年5月29日
******************************************************************************/
/*----------------------------------------------*
* 包含头文件 *
*----------------------------------------------*/
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#ifndef COLA_FIFO_H__
#define COLA_FIFO_H__
/*----------------------------------------------*
* 结构体定义 *
*----------------------------------------------*/
/**@brief A FIFO instance structure.
* @details Keeps track of which bytes to read and write next.
* Also, it keeps the information about which memory is allocated for the buffer
* and its size. This structure must be initialized by app_fifo_init() before use.
*/
typedef struct
{
uint8_t * p_buf; /**< Pointer to FIFO buffer memory. */
uint16_t buf_size; /**< Read/write index mask. Also used for size checking. */
volatile uint16_t read_pos; /**< Next read position in the FIFO buffer. */
volatile uint16_t write_pos; /**< Next write position in the FIFO buffer. */
} cola_fifo_t;
/*----------------------------------------------*
* 函数原型说明 *
*----------------------------------------------*/
#ifdef __cplusplus
extern "C" {
#endif
bool cola_fifo_init(cola_fifo_t *p_fifo, uint8_t *p_buf, uint16_t buf_size);
bool cola_fifo_put(cola_fifo_t *p_fifo, uint8_t byte);
bool cola_fifo_get(cola_fifo_t *p_fifo, uint8_t *p_byte);
bool cola_fifo_peek(cola_fifo_t *p_fifo, uint8_t *p_byte_array, uint32_t p_size, uint32_t p_offset);
void cola_fifo_flush(cola_fifo_t *p_fifo);
void cola_fifo_remove(cola_fifo_t *p_fifo, uint32_t p_offset);
bool cola_fifo_read(cola_fifo_t * p_fifo, uint8_t * p_byte_array, uint32_t p_size);
bool cola_fifo_write(cola_fifo_t * p_fifo, const uint8_t * p_byte_array, uint32_t p_size);
//uint32_t cola_fifo_avail(cola_fifo_t *p_fifo);
uint32_t cola_fifo_length(cola_fifo_t * p_fifo);
#ifdef __cplusplus
}
#endif
#endif // APP_FIFO_H__
/** @} */