Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
e158d48d
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
e158d48d
编写于
10月 15, 2018
作者:
B
Bernard Xiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[license] Fix the bad license replace.
上级
20bc91d2
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
79 deletion
+8
-79
components/drivers/include/ipc/ringbuffer.h
components/drivers/include/ipc/ringbuffer.h
+8
-79
未找到文件。
components/drivers/include/ipc/ringbuffer.h
浏览文件 @
e158d48d
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*/
#ifndef RINGBUFFER_H__
#ifndef RINGBUFFER_H__
#define RINGBUFFER_H__
#define RINGBUFFER_H__
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
#endif
#endif
#include <rtthread.h>
#include <rtthread.h>
/* ring buffer */
/* ring buffer */
struct
rt_ringbuffer
struct
rt_ringbuffer
{
{
rt_uint8_t
*
buffer_ptr
;
rt_uint8_t
*
buffer_ptr
;
/* use the msb of the {read,write}_index as mirror bit. You can see this as
/* use the msb of the {read,write}_index as mirror bit. You can see this as
* if the buffer adds a virtual mirror and the pointers point either to the
* if the buffer adds a virtual mirror and the pointers point either to the
* normal or to the mirrored buffer. If the write_index has the same value
* normal or to the mirrored buffer. If the write_index has the same value
* with the read_index, but in a different mirror, the buffer is full.
* with the read_index, but in a different mirror, the buffer is full.
* While if the write_index and the read_index are the same and within the
* While if the write_index and the read_index are the same and within the
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
*
*
* mirror = 0 mirror = 1
* mirror = 0 mirror = 1
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* read_idx-^ write_idx-^
* read_idx-^ write_idx-^
*
*
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
* read_idx-^ ^-write_idx
* read_idx-^ ^-write_idx
*
*
* The tradeoff is we could only use 32KiB of buffer for 16 bit of index.
* The tradeoff is we could only use 32KiB of buffer for 16 bit of index.
* But it should be enough for most of the cases.
* But it should be enough for most of the cases.
*
*
* Ref: http://en.wikipedia.org/wiki/Circular_buffer#Mirroring */
* Ref: http://en.wikipedia.org/wiki/Circular_buffer#Mirroring */
rt_uint16_t
read_mirror
:
1
;
rt_uint16_t
read_mirror
:
1
;
rt_uint16_t
read_index
:
15
;
rt_uint16_t
read_index
:
15
;
rt_uint16_t
write_mirror
:
1
;
rt_uint16_t
write_mirror
:
1
;
rt_uint16_t
write_index
:
15
;
rt_uint16_t
write_index
:
15
;
/* as we use msb of index as mirror bit, the size should be signed and
/* as we use msb of index as mirror bit, the size should be signed and
* could only be positive. */
*
could
only
be
positive
.
*/
rt_int16_t
buffer_size
;
rt_int16_t
buffer_size
;
};
};
enum
rt_ringbuffer_state
enum
rt_ringbuffer_state
{
{
RT_RINGBUFFER_EMPTY
,
RT_RINGBUFFER_EMPTY
,
RT_RINGBUFFER_FULL
,
RT_RINGBUFFER_FULL
,
/* half full is neither full nor empty */
/* half full is neither full nor empty */
RT_RINGBUFFER_HALFFULL
,
RT_RINGBUFFER_HALFFULL
,
};
};
/**
/**
* RingBuffer for DeviceDriver
* RingBuffer for DeviceDriver
*
*
* Please note that the ring buffer implementation of RT-Thread
* Please note that the ring buffer implementation of RT-Thread
* has no thread wait or resume feature.
* has no thread wait or resume feature.
*/
*/
void
rt_ringbuffer_init
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
pool
,
rt_int16_t
size
);
void
rt_ringbuffer_init
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
pool
,
rt_int16_t
size
);
void
rt_ringbuffer_reset
(
struct
rt_ringbuffer
*
rb
);
void
rt_ringbuffer_reset
(
struct
rt_ringbuffer
*
rb
);
rt_size_t
rt_ringbuffer_put
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_put
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_put_force
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_put_force
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_putchar
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
ch
);
rt_size_t
rt_ringbuffer_putchar
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
ch
);
rt_size_t
rt_ringbuffer_putchar_force
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
ch
);
rt_size_t
rt_ringbuffer_putchar_force
(
struct
rt_ringbuffer
*
rb
,
const
rt_uint8_t
ch
);
rt_size_t
rt_ringbuffer_get
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_get
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
ptr
,
rt_uint16_t
length
);
rt_size_t
rt_ringbuffer_getchar
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
ch
);
rt_size_t
rt_ringbuffer_getchar
(
struct
rt_ringbuffer
*
rb
,
rt_uint8_t
*
ch
);
rt_size_t
rt_ringbuffer_data_len
(
struct
rt_ringbuffer
*
rb
);
rt_size_t
rt_ringbuffer_data_len
(
struct
rt_ringbuffer
*
rb
);
#ifdef RT_USING_HEAP
#ifdef RT_USING_HEAP
struct
rt_ringbuffer
*
rt_ringbuffer_create
(
rt_uint16_t
length
);
struct
rt_ringbuffer
*
rt_ringbuffer_create
(
rt_uint16_t
length
);
void
rt_ringbuffer_destroy
(
struct
rt_ringbuffer
*
rb
);
void
rt_ringbuffer_destroy
(
struct
rt_ringbuffer
*
rb
);
#endif
#endif
rt_inline
rt_uint16_t
rt_ringbuffer_get_size
(
struct
rt_ringbuffer
*
rb
)
rt_inline
rt_uint16_t
rt_ringbuffer_get_size
(
struct
rt_ringbuffer
*
rb
)
{
{
RT_ASSERT
(
rb
!=
RT_NULL
);
RT_ASSERT
(
rb
!=
RT_NULL
);
return
rb
->
buffer_size
;
return
rb
->
buffer_size
;
}
}
/** return the size of empty space in rb */
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录