diff options
author | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-10-29 15:31:22 +0000 |
---|---|---|
committer | Giovanni Di Sirio <gdisirio@gmail.com> | 2017-10-29 15:31:22 +0000 |
commit | 00969133d278e36593d1b88513935b2e78ef2517 (patch) | |
tree | 55d43ff0cab73f08d883f9aaaf3aef967e44c9cb /os/hal/src | |
parent | a8f7a7bd427294f96647529a7f0bfb3918eb6918 (diff) | |
download | ChibiOS-00969133d278e36593d1b88513935b2e78ef2517.tar.gz ChibiOS-00969133d278e36593d1b88513935b2e78ef2517.tar.bz2 ChibiOS-00969133d278e36593d1b88513935b2e78ef2517.zip |
HAL queues rework, not finished.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10906 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/src')
-rw-r--r-- | os/hal/src/hal_queues.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/os/hal/src/hal_queues.c b/os/hal/src/hal_queues.c index 66e8a89cd..a4f363541 100644 --- a/os/hal/src/hal_queues.c +++ b/os/hal/src/hal_queues.c @@ -35,8 +35,126 @@ * @{
*/
+#include <string.h>
+
#include "hal.h"
+/*===========================================================================*/
+/* Driver local definitions. */
+/*===========================================================================*/
+
+/**
+ * @brief Non-blocking input queue read.
+ * @details The function reads data from an input queue into a buffer. The
+ * operation completes when the specified amount of data has been
+ * transferred or when the input queue has been emptied.
+ *
+ * @param[in] iqp pointer to an @p input_queue_t structure
+ * @param[out] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred, the
+ * value 0 is reserved
+ * @return The number of bytes effectively transferred.
+ *
+ * @notapi
+ */
+static size_t iq_read(input_queue_t *iqp, uint8_t *bp, size_t n) {
+ size_t s1, s2;
+
+ osalDbgCheck(n > 0U);
+
+ /* Number of bytes that can be read in a single atomic operation.*/
+ if (n > iqGetFullI(iqp)) {
+ n = iqGetFullI(iqp);
+ }
+
+ /* Number of bytes before buffer limit.*/
+ s1 = iqp->q_top - iqp->q_rdptr;
+ if (n < s1) {
+ memcpy((void *)bp, (void *)iqp->q_rdptr, n);
+ iqp->q_rdptr += n;
+ }
+ else if (n > s1) {
+ memcpy((void *)bp, (void *)iqp->q_rdptr, s1);
+ s2 = n - s1;
+ bp += s1;
+ memcpy((void *)bp, (void *)iqp->q_buffer, s2);
+ iqp->q_rdptr = iqp->q_buffer + s2;
+ }
+ else { /* n == s1 */
+ memcpy((void *)bp, (void *)iqp->q_rdptr, n);
+ iqp->q_rdptr = iqp->q_buffer;
+ }
+
+ iqp->q_counter -= n;
+ return n;
+}
+
+/**
+ * @brief Non-blocking output queue write.
+ * @details The function writes data from a buffer to an output queue. The
+ * operation completes when the specified amount of data has been
+ * transferred or when the output queue has been filled.
+ *
+ * @param[in] oqp pointer to an @p output_queue_t structure
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred, the
+ * value 0 is reserved
+ * @return The number of bytes effectively transferred.
+ *
+ * @notapi
+ */
+static size_t oq_write(output_queue_t *oqp, const uint8_t *bp, size_t n) {
+ size_t s1, s2;
+
+ osalDbgCheck(n > 0U);
+
+ /* Number of bytes that can be written in a single atomic operation.*/
+ if (n > oqGetEmptyI(oqp)) {
+ n = oqGetEmptyI(oqp);
+ }
+
+ /* Number of bytes before buffer limit.*/
+ s1 = oqp->q_top - oqp->q_wrptr;
+ if (n < s1) {
+ memcpy((void *)oqp->q_wrptr, (void *)bp, n);
+ oqp->q_wrptr += n;
+ }
+ else if (n > s1) {
+ memcpy((void *)oqp->q_wrptr, (void *)bp, s1);
+ s2 = n - s1;
+ bp += s1;
+ memcpy((void *)oqp->q_buffer, (void *)bp, s2);
+ oqp->q_wrptr = oqp->q_buffer + s2;
+ }
+ else { /* n == s1 */
+ memcpy((void *)oqp->q_wrptr, (void *)bp, n);
+ oqp->q_wrptr = oqp->q_buffer;
+ }
+
+ oqp->q_counter -= n;
+ return n;
+}
+
+/*===========================================================================*/
+/* Driver exported variables. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local variables and types. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver local functions. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver interrupt handlers. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Driver exported functions. */
+/*===========================================================================*/
+
/**
* @brief Initializes an input queue.
* @details A Semaphore is internally initialized and works as a counter of
|