From f81ca1be704585918bcb42e78a970bb1fefb2650 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Wed, 23 Dec 2015 10:46:59 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8633 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_buffers.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'os/hal/src/hal_buffers.c') diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c index cd052912f..2f47cd649 100644 --- a/os/hal/src/hal_buffers.c +++ b/os/hal/src/hal_buffers.c @@ -127,13 +127,15 @@ uint8_t *ibqGetEmptyBufferI(input_buffers_queue_t *ibqp) { * @brief Posts a new filled buffer to the queue. * * @param[in] ibqp pointer to the @p input_buffers_queue_t object - * @param[in] size used size of the buffer + * @param[in] size used size of the buffer, cannot be zero * * @iclass */ void ibqPostFullBufferI(input_buffers_queue_t *ibqp, size_t size) { osalDbgCheckClassI(); + + osalDbgCheck(size > 0); osalDbgAssert(!ibqIsFullI(ibqp), "buffers queue full"); /* Writing size field in the buffer.*/ @@ -256,6 +258,7 @@ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout) { if (ibqp->ptr == NULL) { msg = ibqGetFullBufferTimeout(ibqp, timeout); if (msg != MSG_OK) { + ibqp->accessed = false; return msg; } } @@ -340,16 +343,14 @@ size_t ibqReadTimeout(input_buffers_queue_t *ibqp, uint8_t *bp, memcpy(bp, ibqp->ptr, size); /* Updating the pointers and the counter.*/ - r += size; - bp += size; + r += size; + bp += size; + ibqp->ptr += size; /* Has the current data buffer been finished? if so then release it.*/ if (ibqp->ptr >= ibqp->top) { ibqReleaseEmptyBuffer(ibqp); } - else { - ibqp->ptr += size; - } } ibqp->accessed = false; @@ -656,16 +657,14 @@ size_t obqWriteTimeout(output_buffers_queue_t *obqp, const uint8_t *bp, memcpy(obqp->ptr, bp, size); /* Updating the pointers and the counter.*/ - r += size; - bp += size; + r += size; + bp += size; + obqp->ptr += size; /* Has the current data buffer been finished? if so then release it.*/ if (obqp->ptr >= obqp->top) { obqPostFullBuffer(obqp, obqp->bsize - sizeof (size_t)); } - else { - obqp->ptr += size; - } } obqp->accessed = false; -- cgit v1.2.3