From a1534ccb61d616ad15a69a668fe26466a87d76a9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 2 Jan 2011 14:01:18 +0000 Subject: New queues APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2571 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chqueues.c | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'os/kernel/src') diff --git a/os/kernel/src/chqueues.c b/os/kernel/src/chqueues.c index 87a82acf2..4a195fa9b 100644 --- a/os/kernel/src/chqueues.c +++ b/os/kernel/src/chqueues.c @@ -69,6 +69,22 @@ void chIQInit(InputQueue *iqp, uint8_t *bp, size_t size, qnotify_t infy) { chSemInit(&iqp->q_sem, 0); } +/** + * @brief Returns the filled space into an input queue. + * + * @param[in] iqp pointer to an @p InputQueue structure + * + * @iclass + */ +size_t chIQGetFullI(InputQueue *iqp) { + cnt_t cnt; + + cnt = chQSpaceI(iqp); + if (cnt < 0) + return 0; + return (size_t)cnt; +} + /** * @brief Resets an input queue. * @details All the data in the input queue is erased and lost, any waiting @@ -136,7 +152,7 @@ msg_t chIQGetTimeout(InputQueue *iqp, systime_t time) { chSysLock(); if (iqp->q_notify) - iqp->q_notify(); + iqp->q_notify(iqp); if ((msg = chSemWaitTimeoutS(&iqp->q_sem, time)) < RDY_OK) { chSysUnlock(); @@ -185,7 +201,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, while (TRUE) { if (chIQIsEmptyI(iqp)) { if (nfy) - nfy(); + nfy(iqp); if ((chSemWaitTimeoutS(&iqp->q_sem, time) != RDY_OK)) { chSysUnlock(); return r; @@ -201,7 +217,7 @@ size_t chIQReadTimeout(InputQueue *iqp, uint8_t *bp, if (--n == 0) { chSysLock(); if (nfy) - nfy(); + nfy(iqp); chSysUnlock(); return r; } @@ -232,6 +248,22 @@ void chOQInit(OutputQueue *oqp, uint8_t *bp, size_t size, qnotify_t onfy) { chSemInit(&oqp->q_sem, (cnt_t)size); } +/** + * @brief Returns the filled space into an output queue. + * + * @param[in] oqp pointer to an @p OutputQueue structure + * + * @iclass + */ +size_t chOQGetFullI(OutputQueue *oqp) { + cnt_t cnt; + + cnt = chQSpaceI(oqp); + if (cnt < 0) + return chQSizeI(oqp); + return chQSizeI(oqp) - (size_t)cnt; +} + /** * @brief Resets an output queue. * @details All the data in the output queue is erased and lost, any waiting @@ -282,7 +314,7 @@ msg_t chOQPutTimeout(OutputQueue *oqp, uint8_t b, systime_t time) { oqp->q_wrptr = oqp->q_buffer; if (oqp->q_notify) - oqp->q_notify(); + oqp->q_notify(oqp); chSysUnlock(); return Q_OK; @@ -346,7 +378,7 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, while (TRUE) { if (chOQIsFullI(oqp)) { if (nfy) - nfy(); + nfy(oqp); if ((chSemWaitTimeoutS(&oqp->q_sem, time) != RDY_OK)) { chSysUnlock(); return w; @@ -362,7 +394,7 @@ size_t chOQWriteTimeout(OutputQueue *oqp, const uint8_t *bp, if (--n == 0) { chSysLock(); if (nfy) - nfy(); + nfy(oqp); chSysUnlock(); return w; } -- cgit v1.2.3