aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/hal_queues.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/src/hal_queues.c')
-rw-r--r--os/hal/src/hal_queues.c113
1 files changed, 67 insertions, 46 deletions
diff --git a/os/hal/src/hal_queues.c b/os/hal/src/hal_queues.c
index 9d4c6d330..d825674ec 100644
--- a/os/hal/src/hal_queues.c
+++ b/os/hal/src/hal_queues.c
@@ -40,7 +40,8 @@
#include "hal.h"
-#if !defined(_CHIBIOS_RT_) || !CH_CFG_USE_QUEUES || defined(__DOXYGEN__)
+#if !defined(_CHIBIOS_RT_) || (CH_CFG_USE_QUEUES == FALSE) || \
+ defined(__DOXYGEN__)
/**
* @brief Initializes an input queue.
@@ -62,7 +63,9 @@ void iqObjectInit(input_queue_t *iqp, uint8_t *bp, size_t size,
osalThreadQueueObjectInit(&iqp->q_waiting);
iqp->q_counter = 0;
- iqp->q_buffer = iqp->q_rdptr = iqp->q_wrptr = bp;
+ iqp->q_buffer = bp;
+ iqp->q_rdptr = bp;
+ iqp->q_wrptr = bp;
iqp->q_top = bp + size;
iqp->q_notify = infy;
iqp->q_link = link;
@@ -83,7 +86,8 @@ void iqResetI(input_queue_t *iqp) {
osalDbgCheckClassI();
- iqp->q_rdptr = iqp->q_wrptr = iqp->q_buffer;
+ iqp->q_rdptr = iqp->q_buffer;
+ iqp->q_wrptr = iqp->q_buffer;
iqp->q_counter = 0;
osalThreadDequeueAllI(&iqp->q_waiting, Q_RESET);
}
@@ -105,13 +109,15 @@ msg_t iqPutI(input_queue_t *iqp, uint8_t b) {
osalDbgCheckClassI();
- if (iqIsFullI(iqp))
+ if (iqIsFullI(iqp)) {
return Q_FULL;
+ }
iqp->q_counter++;
*iqp->q_wrptr++ = b;
- if (iqp->q_wrptr >= iqp->q_top)
+ if (iqp->q_wrptr >= iqp->q_top) {
iqp->q_wrptr = iqp->q_buffer;
+ }
osalThreadDequeueNextI(&iqp->q_waiting, Q_OK);
@@ -127,7 +133,7 @@ msg_t iqPutI(input_queue_t *iqp, uint8_t b) {
* buffer or before entering the state @p THD_STATE_WTQUEUE.
*
* @param[in] iqp pointer to an @p input_queue_t structure
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -138,16 +144,17 @@ msg_t iqPutI(input_queue_t *iqp, uint8_t b) {
*
* @api
*/
-msg_t iqGetTimeout(input_queue_t *iqp, systime_t time) {
+msg_t iqGetTimeout(input_queue_t *iqp, systime_t timeout) {
uint8_t b;
osalSysLock();
- if (iqp->q_notify)
+ if (iqp->q_notify != NULL) {
iqp->q_notify(iqp);
+ }
while (iqIsEmptyI(iqp)) {
- msg_t msg;
- if ((msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, time)) < Q_OK) {
+ msg_t msg = osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout);
+ if (msg < Q_OK) {
osalSysUnlock();
return msg;
}
@@ -155,11 +162,12 @@ msg_t iqGetTimeout(input_queue_t *iqp, systime_t time) {
iqp->q_counter--;
b = *iqp->q_rdptr++;
- if (iqp->q_rdptr >= iqp->q_top)
+ if (iqp->q_rdptr >= iqp->q_top) {
iqp->q_rdptr = iqp->q_buffer;
-
+ }
osalSysUnlock();
- return b;
+
+ return (msg_t)b;
}
/**
@@ -177,7 +185,7 @@ msg_t iqGetTimeout(input_queue_t *iqp, systime_t time) {
* @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred, the
* value 0 is reserved
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -187,19 +195,20 @@ msg_t iqGetTimeout(input_queue_t *iqp, systime_t time) {
* @api
*/
size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
- size_t n, systime_t time) {
+ size_t n, systime_t timeout) {
qnotify_t nfy = iqp->q_notify;
size_t r = 0;
- osalDbgCheck(n > 0);
+ osalDbgCheck(n > 0U);
osalSysLock();
- while (TRUE) {
- if (nfy)
+ while (true) {
+ if (nfy != NULL) {
nfy(iqp);
+ }
while (iqIsEmptyI(iqp)) {
- if (osalThreadEnqueueTimeoutS(&iqp->q_waiting, time) != Q_OK) {
+ if (osalThreadEnqueueTimeoutS(&iqp->q_waiting, timeout) != Q_OK) {
osalSysUnlock();
return r;
}
@@ -207,13 +216,15 @@ size_t iqReadTimeout(input_queue_t *iqp, uint8_t *bp,
iqp->q_counter--;
*bp++ = *iqp->q_rdptr++;
- if (iqp->q_rdptr >= iqp->q_top)
+ if (iqp->q_rdptr >= iqp->q_top) {
iqp->q_rdptr = iqp->q_buffer;
-
+ }
osalSysUnlock(); /* Gives a preemption chance in a controlled point.*/
+
r++;
- if (--n == 0)
+ if (--n == 0U) {
return r;
+ }
osalSysLock();
}
@@ -239,7 +250,9 @@ void oqObjectInit(output_queue_t *oqp, uint8_t *bp, size_t size,
osalThreadQueueObjectInit(&oqp->q_waiting);
oqp->q_counter = size;
- oqp->q_buffer = oqp->q_rdptr = oqp->q_wrptr = bp;
+ oqp->q_buffer = bp;
+ oqp->q_rdptr = bp;
+ oqp->q_wrptr = bp;
oqp->q_top = bp + size;
oqp->q_notify = onfy;
oqp->q_link = link;
@@ -260,8 +273,9 @@ void oqResetI(output_queue_t *oqp) {
osalDbgCheckClassI();
- oqp->q_rdptr = oqp->q_wrptr = oqp->q_buffer;
- oqp->q_counter = qSizeI(oqp);
+ oqp->q_rdptr = oqp->q_buffer;
+ oqp->q_wrptr = oqp->q_buffer;
+ oqp->q_counter = qSizeX(oqp);
osalThreadDequeueAllI(&oqp->q_waiting, Q_RESET);
}
@@ -275,7 +289,7 @@ void oqResetI(output_queue_t *oqp) {
*
* @param[in] oqp pointer to an @p output_queue_t structure
* @param[in] b the byte value to be written in the queue
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -287,13 +301,12 @@ void oqResetI(output_queue_t *oqp) {
*
* @api
*/
-msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) {
+msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t timeout) {
osalSysLock();
while (oqIsFullI(oqp)) {
- msg_t msg;
-
- if ((msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, time)) < Q_OK) {
+ msg_t msg = osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout);
+ if (msg < Q_OK) {
osalSysUnlock();
return msg;
}
@@ -301,13 +314,15 @@ msg_t oqPutTimeout(output_queue_t *oqp, uint8_t b, systime_t time) {
oqp->q_counter--;
*oqp->q_wrptr++ = b;
- if (oqp->q_wrptr >= oqp->q_top)
+ if (oqp->q_wrptr >= oqp->q_top) {
oqp->q_wrptr = oqp->q_buffer;
+ }
- if (oqp->q_notify)
+ if (oqp->q_notify != NULL) {
oqp->q_notify(oqp);
-
+ }
osalSysUnlock();
+
return Q_OK;
}
@@ -326,17 +341,19 @@ msg_t oqGetI(output_queue_t *oqp) {
osalDbgCheckClassI();
- if (oqIsEmptyI(oqp))
+ if (oqIsEmptyI(oqp)) {
return Q_EMPTY;
+ }
oqp->q_counter++;
b = *oqp->q_rdptr++;
- if (oqp->q_rdptr >= oqp->q_top)
+ if (oqp->q_rdptr >= oqp->q_top) {
oqp->q_rdptr = oqp->q_buffer;
+ }
osalThreadDequeueNextI(&oqp->q_waiting, Q_OK);
- return b;
+ return (msg_t)b;
}
/**
@@ -354,7 +371,7 @@ msg_t oqGetI(output_queue_t *oqp) {
* @param[out] bp pointer to the data buffer
* @param[in] n the maximum amount of data to be transferred, the
* value 0 is reserved
- * @param[in] time the number of ticks before the operation timeouts,
+ * @param[in] timeout the number of ticks before the operation timeouts,
* the following special values are allowed:
* - @a TIME_IMMEDIATE immediate timeout.
* - @a TIME_INFINITE no timeout.
@@ -364,36 +381,40 @@ msg_t oqGetI(output_queue_t *oqp) {
* @api
*/
size_t oqWriteTimeout(output_queue_t *oqp, const uint8_t *bp,
- size_t n, systime_t time) {
+ size_t n, systime_t timeout) {
qnotify_t nfy = oqp->q_notify;
size_t w = 0;
- osalDbgCheck(n > 0);
+ osalDbgCheck(n > 0U);
osalSysLock();
- while (TRUE) {
+ while (true) {
while (oqIsFullI(oqp)) {
- if (osalThreadEnqueueTimeoutS(&oqp->q_waiting, time) != Q_OK) {
+ if (osalThreadEnqueueTimeoutS(&oqp->q_waiting, timeout) != Q_OK) {
osalSysUnlock();
return w;
}
}
oqp->q_counter--;
*oqp->q_wrptr++ = *bp++;
- if (oqp->q_wrptr >= oqp->q_top)
+ if (oqp->q_wrptr >= oqp->q_top) {
oqp->q_wrptr = oqp->q_buffer;
+ }
- if (nfy)
+ if (nfy != NULL) {
nfy(oqp);
-
+ }
osalSysUnlock(); /* Gives a preemption chance in a controlled point.*/
+
w++;
- if (--n == 0)
+ if (--n == 0U) {
return w;
+ }
+
osalSysLock();
}
}
-#endif /* !defined(_CHIBIOS_RT_) || !CH_USE_QUEUES */
+#endif /* !defined(_CHIBIOS_RT_) || (CH_USE_QUEUES == FALSE) */
/** @} */