aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
Diffstat (limited to 'os')
-rw-r--r--os/lib/include/chlib.h7
-rw-r--r--os/lib/include/chmboxes.h10
-rw-r--r--os/lib/include/chpipes.h210
3 files changed, 222 insertions, 5 deletions
diff --git a/os/lib/include/chlib.h b/os/lib/include/chlib.h
index f398e1000..6a1944e53 100644
--- a/os/lib/include/chlib.h
+++ b/os/lib/include/chlib.h
@@ -121,11 +121,13 @@
#undef CH_CFG_USE_HEAP
#undef CH_CFG_USE_MEMPOOLS
#undef CH_CFG_USE_OBJ_FIFOS
+#undef CH_CFG_USE_PIPES
#define CH_CFG_USE_MEMCORE FALSE
#define CH_CFG_USE_HEAP FALSE
#define CH_CFG_USE_MEMPOOLS FALSE
#define CH_CFG_USE_OBJ_FIFOS FALSE
+#define CH_CFG_USE_PIPES FALSE
#endif /* (CH_CUSTOMER_LIC_LIB == FALSE) || \
(CH_LICENSE_FEATURES == CH_FEATURES_BASIC) */
@@ -155,6 +157,10 @@
#error "CH_CFG_USE_OBJ_FIFOS not defined in chlibconf.h"
#endif
+//#if !defined(CH_CFG_USE_PIPES)
+//#error "CH_CFG_USE_PIPES not defined in chlibconf.h"
+//#endif
+
/* Objects factory options checks.*/
#if !defined(CH_CFG_USE_FACTORY)
#error "CH_CFG_USE_FACTORY not defined in chlibconf.h"
@@ -207,6 +213,7 @@
#include "chheap.h"
#include "chmempools.h"
#include "chfifo.h"
+//#include "chpipes.h"
#include "chfactory.h"
#endif /* CHLIB_H */
diff --git a/os/lib/include/chmboxes.h b/os/lib/include/chmboxes.h
index 65e811e60..eeff68751 100644
--- a/os/lib/include/chmboxes.h
+++ b/os/lib/include/chmboxes.h
@@ -128,7 +128,7 @@ extern "C" {
/**
* @brief Returns the mailbox buffer size as number of messages.
*
- * @param[in] mbp the pointer to an initialized mailbox_t object
+ * @param[in] mbp the pointer to an initialized @p mailbox_t object
* @return The size of the mailbox.
*
* @iclass
@@ -144,7 +144,7 @@ static inline size_t chMBGetSizeI(const mailbox_t *mbp) {
/**
* @brief Returns the number of used message slots into a mailbox.
*
- * @param[in] mbp the pointer to an initialized mailbox_t object
+ * @param[in] mbp the pointer to an initialized @p mailbox_t object
* @return The number of queued messages.
*
* @iclass
@@ -159,7 +159,7 @@ static inline size_t chMBGetUsedCountI(const mailbox_t *mbp) {
/**
* @brief Returns the number of free message slots into a mailbox.
*
- * @param[in] mbp the pointer to an initialized mailbox_t object
+ * @param[in] mbp the pointer to an initialized @p mailbox_t object
* @return The number of empty message slots.
*
* @iclass
@@ -178,7 +178,7 @@ static inline size_t chMBGetFreeCountI(const mailbox_t *mbp) {
* to use @p chMBGetFullCountI() and then use this macro, all within
* a lock state.
*
- * @param[in] mbp the pointer to an initialized mailbox_t object
+ * @param[in] mbp the pointer to an initialized @p mailbox_t object
* @return The next message in queue.
*
* @iclass
@@ -193,7 +193,7 @@ static inline msg_t chMBPeekI(const mailbox_t *mbp) {
/**
* @brief Terminates the reset state.
*
- * @param[in] mbp the pointer to an initialized mailbox_t object
+ * @param[in] mbp the pointer to an initialized @p mailbox_t object
*
* @xclass
*/
diff --git a/os/lib/include/chpipes.h b/os/lib/include/chpipes.h
new file mode 100644
index 000000000..197aa9199
--- /dev/null
+++ b/os/lib/include/chpipes.h
@@ -0,0 +1,210 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
+
+ This file is part of ChibiOS.
+
+ ChibiOS is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * @file chpipes.h
+ * @brief Pipes macros and structures.
+ *
+ * @addtogroup pipes
+ * @{
+ */
+
+#ifndef CHPIPES_H
+#define CHPIPES_H
+
+#if (CH_CFG_USE_PIPES == TRUE) || defined(__DOXYGEN__)
+
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
+/**
+ * @brief Structure representing a pipe object.
+ */
+typedef struct {
+ uint8_t *buffer; /**< @brief Pointer to the pipe
+ buffer. */
+ uint8_t *top; /**< @brief Pointer to the location
+ after the buffer. */
+ uint8_t *wrptr; /**< @brief Write pointer. */
+ uint8_t *rdptr; /**< @brief Read pointer. */
+ size_t cnt; /**< @brief Messages in queue. */
+ bool reset; /**< @brief True if in reset state. */
+ threads_queue_t qw; /**< @brief Queued writers. */
+ threads_queue_t qr; /**< @brief Queued readers. */
+} pipe_t;
+
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Data part of a static pipe initializer.
+ * @details This macro should be used when statically initializing a
+ * pipe that is part of a bigger structure.
+ *
+ * @param[in] name the name of the pipe variable
+ * @param[in] buffer pointer to the pipe buffer array of @p uint8_t
+ * @param[in] size number of @p uint8_t elements in the buffer array
+ */
+#define _PIPE_DATA(name, buffer, size) { \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer) + size, \
+ (uint8_t *)(buffer), \
+ (uint8_t *)(buffer), \
+ (size_t)0, \
+ false, \
+ _THREADS_QUEUE_DATA(name.qw), \
+ _THREADS_QUEUE_DATA(name.qr), \
+}
+
+/**
+ * @brief Static pipe initializer.
+ * @details Statically initialized pipes require no explicit
+ * initialization using @p chPipeObjectInit().
+ *
+ * @param[in] name the name of the pipe variable
+ * @param[in] buffer pointer to the pipe buffer array of @p uint8_t
+ * @param[in] size number of @p uint8_t elements in the buffer array
+ */
+#define PIPE_DECL(name, buffer, size) \
+ pipe_t name = _PIPE_DATA(name, buffer, size)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ void chPipeObjectInit(pipe_t *pp, uint8_t *buf, size_t n);
+ void chPipeReset(pipe_t *pp);
+ void chPipeResetI(pipe_t *pp);
+ size_t chPipeReadI(pipe_t *pp, uint8_t *bp, size_t n);
+ size_t chPipeReadTimeoutS(pipe_t *pp, uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ size_t chPipeReadTimeout(pipe_t *pp, uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ size_t chPipeWriteI(pipe_t *pp, const uint8_t *bp, size_t n);
+ size_t chPipeWriteTimeoutS(pipe_t *pp, const uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+ size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
+ size_t n, sysinterval_t timeout);
+#ifdef __cplusplus
+}
+#endif
+
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
+
+/**
+ * @brief Returns the pipe buffer size as number of bytes.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ * @return The size of the pipe.
+ *
+ * @iclass
+ */
+static inline size_t chPipeGetSizeI(const pipe_t *pp) {
+
+ /*lint -save -e9033 [10.8] Perfectly safe pointers
+ arithmetic.*/
+ return (size_t)(pp->top - pp->buffer);
+ /*lint -restore*/
+}
+
+/**
+ * @brief Returns the number of used byte slots into a pipe.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ * @return The number of queued bytes.
+ *
+ * @iclass
+ */
+static inline size_t chPipeGetUsedCountI(const pipe_t *pp) {
+
+ chDbgCheckClassI();
+
+ return pp->cnt;
+}
+
+/**
+ * @brief Returns the number of free byte slots into a pipe.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ * @return The number of empty byte slots.
+ *
+ * @iclass
+ */
+static inline size_t chPipeGetFreeCountI(const pipe_t *pp) {
+
+ chDbgCheckClassI();
+
+ return chPipeGetSizeI(pp) - chPipeGetUsedCountI(pp);
+}
+
+/**
+ * @brief Returns the next byte in the queue without removing it.
+ * @pre A byte must be present in the queue for this function to work
+ * or it would return garbage. The correct way to use this macro is
+ * to use @p chPipeGetFullCountI() and then use this macro, all within
+ * a lock state.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ * @return The next byte in queue.
+ *
+ * @iclass
+ */
+static inline uint8_t chPipePeekI(const pipe_t *pp) {
+
+ chDbgCheckClassI();
+
+ return *pp->rdptr;
+}
+
+/**
+ * @brief Terminates the reset state.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ *
+ * @xclass
+ */
+static inline void chPipeResumeX(pipe_t *pp) {
+
+ pp->reset = false;
+}
+
+#endif /* CH_CFG_USE_PIPES == TRUE */
+
+#endif /* CHPIPES_H */
+
+/** @} */