📄 ring_buffer.h
字号:
/**
* \file ring_buffer.h
* \brief Ring (circular) buffer API.
*
* A ring (circular) buffer implementation for use in the
* serial port driver.
*
* To avoid the use of malloc to dynamically allocate the
* ring-buffer structure and its internal buffer, the
* initialization routine takes a previously allocated
* ring-buffer structure and data buffer. For example, the
* serial port driver structure contains a ring buffer
* for transmit and another for receive.
*/
#ifndef RING_BUFFER_H
#define RING_BUFFER_H
#include <stdint.h>
/* Ring-buffer state */
typedef struct ring_buffer {
uint32_t wr;
uint32_t rd;
uint32_t count;
uint32_t size;
uint8_t *data;
} ring_buffer_t;
/* Initialize a statically allocated ring buffer with a
* statically allocated data buffer data[size];
*/
void ring_buffer_init(
uint32_t size,
uint8_t *data,
ring_buffer_t *buf);
/* Remove a character from the ring buffer
* (returns -1 on empty)
*/
int32_t ring_buffer_remove(
ring_buffer_t *buf);
/* Add a character to the ring buffer
* (returns -1 on full)
*/
int32_t ring_buffer_add(
ring_buffer_t *buf,
int8_t ch);
/* Number of characters in the buffer */
uint32_t ring_buffer_count(
ring_buffer_t *buf);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -