diff options
| author | Meco Man <[email protected]> | 2020-12-14 15:33:53 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-14 15:33:53 +0800 |
| commit | 5f6d3298eeadb59a2d946c18e95f0d59a6558063 (patch) | |
| tree | 837c41518f14d2fa99342a5d4d3f9e6b32c94f0b /components/drivers/src/ringbuffer.c | |
| parent | 3634621815b4145c786cff2e22cfeae5b108e94f (diff) | |
| parent | 57ddea482f3c3e24f47461565d7b119fdff8de93 (diff) | |
Merge pull request #4 from RT-Thread/master
update
Diffstat (limited to 'components/drivers/src/ringbuffer.c')
| -rw-r--r-- | components/drivers/src/ringbuffer.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index c6a491a7cc..88afd19506 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -194,6 +194,40 @@ rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, RTM_EXPORT(rt_ringbuffer_get); /** + * peak data from ring buffer + */ +rt_size_t rt_ringbuffer_peak(struct rt_ringbuffer *rb, rt_uint8_t **ptr) +{ + RT_ASSERT(rb != RT_NULL); + + *ptr = RT_NULL; + + /* whether has enough data */ + rt_size_t size = rt_ringbuffer_data_len(rb); + + /* no data */ + if (size == 0) + return 0; + + *ptr = &rb->buffer_ptr[rb->read_index]; + + if(rb->buffer_size - rb->read_index > size) + { + rb->read_index += size; + return size; + } + + size = rb->buffer_size - rb->read_index; + + /* we are going into the other side of the mirror */ + rb->read_mirror = ~rb->read_mirror; + rb->read_index = 0; + + return size; +} +RTM_EXPORT(rt_ringbuffer_peak); + +/** * put a character into ring buffer */ rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch) |
