From a10028c175769e8d7a03c1f0f963b878a83deac1 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 20 Dec 2015 10:39:36 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8621 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/src/hal_buffers.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'os') diff --git a/os/hal/src/hal_buffers.c b/os/hal/src/hal_buffers.c index 286f3cf50..fe23c5ba1 100644 --- a/os/hal/src/hal_buffers.c +++ b/os/hal/src/hal_buffers.c @@ -127,9 +127,12 @@ void ibqPostBufferI(io_buffers_queue_t *ibqp, size_t size) { /** * @brief Gets the next filled buffer from the queue. * @note The function always returns the same buffer if called repeatedly. + * @post After calling the function the fields @p ptr and @p top are set + * at beginning and end of the buffer data or @NULL if the queue + * is empty. * * @param[out] ibqp pointer to the @p input_buffers_queue_t object - * @return A pointer to the next buffer to be filled. + * @return A pointer to filled buffer area. * @retval NULL if the queue is empty. * * @iclass @@ -139,10 +142,14 @@ uint8_t *ibqGetFullBufferI(input_buffers_queue_t *ibqp) { osalDbgCheckClassI(); if (ibqIsEmptyI(ibqp)) { + ibqp->ptr = NULL; + ibqp->top = NULL; return NULL; } - return ibqp->brdptr + sizeof (size_t); + ibqp->ptr = ibqp->brdptr + sizeof (size_t); + ibqp->top = ibqp->ptr + *((size_t *)ibqp->brdptr); + return ibqp->brdptr; } /** @@ -199,7 +206,7 @@ msg_t ibqGetTimeout(input_buffers_queue_t *ibqp, systime_t timeout) { if (msg < MSG_OK) { return msg; } - ibqp->ptr = ibqGetFullBufferI(ibqp); + (void) ibqGetFullBufferI(ibqp); } /* Next byte from the buffer.*/ -- cgit v1.2.3