From 2d67fe65655c1d14d0aa7ba71253de31da591583 Mon Sep 17 00:00:00 2001 From: Bright Pan Date: Fri, 23 Jan 2015 13:27:52 +0800 Subject: [PATCH] [Driver/ringbuffer]: Fix put_force bug OXape reports: http://www.rt-thread.org/phpBB3/topic3939.html driver/ringbuffer: when data length is bigger than space length for rb, the read_index in rb is not update. When length > space, update the read_index, the bug can be fix, and works fine. --- components/drivers/src/ringbuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/components/drivers/src/ringbuffer.c b/components/drivers/src/ringbuffer.c index 6212b10258..8c2705ceb1 100644 --- a/components/drivers/src/ringbuffer.c +++ b/components/drivers/src/ringbuffer.c @@ -100,13 +100,13 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint16_t length) { - enum rt_ringbuffer_state old_state; + rt_uint16_t space_length; RT_ASSERT(rb != RT_NULL); - old_state = rt_ringbuffer_status(rb); + space_length = rt_ringbuffer_space_len(rb); - if (length > rb->buffer_size) + if (length > space_length) length = rb->buffer_size; if (rb->buffer_size - rb->write_index > length) @@ -117,7 +117,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, * length of data in current mirror */ rb->write_index += length; - if (old_state == RT_RINGBUFFER_FULL) + if (length > space_length) rb->read_index = rb->write_index; return length; @@ -134,7 +134,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, rb->write_mirror = ~rb->write_mirror; rb->write_index = length - (rb->buffer_size - rb->write_index); - if (old_state == RT_RINGBUFFER_FULL) + if (length > space_length) { rb->read_mirror = ~rb->read_mirror; rb->read_index = rb->write_index;