aboutsummaryrefslogtreecommitdiffstats
path: root/os/lib
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2018-03-22 08:25:37 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2018-03-22 08:25:37 +0000
commitef83e007f110af0c1c9dd3874fc0b84f982960c9 (patch)
tree21878527850578ba7eba81b60d4ba4767045bdca /os/lib
parenta28b3e44ca453a85740bd9bdb23b95bd3d4c4f6b (diff)
downloadChibiOS-ef83e007f110af0c1c9dd3874fc0b84f982960c9.tar.gz
ChibiOS-ef83e007f110af0c1c9dd3874fc0b84f982960c9.tar.bz2
ChibiOS-ef83e007f110af0c1c9dd3874fc0b84f982960c9.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11834 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'os/lib')
-rw-r--r--os/lib/include/chmemheaps.h2
-rw-r--r--os/lib/include/chpipes.h29
-rw-r--r--os/lib/src/chpipes.c105
3 files changed, 87 insertions, 49 deletions
diff --git a/os/lib/include/chmemheaps.h b/os/lib/include/chmemheaps.h
index 59248a89e..c0ebcbb99 100644
--- a/os/lib/include/chmemheaps.h
+++ b/os/lib/include/chmemheaps.h
@@ -97,7 +97,7 @@ struct memory_heap {
memgetfunc2_t provider; /**< @brief Memory blocks provider for
this heap. */
heap_header_t header; /**< @brief Free blocks list header. */
-#if CH_CFG_USE_MUTEXES == TRUE
+#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
mutex_t mtx; /**< @brief Heap access mutex. */
#else
semaphore_t sem; /**< @brief Heap access semaphore. */
diff --git a/os/lib/include/chpipes.h b/os/lib/include/chpipes.h
index 197aa9199..9e91614c4 100644
--- a/os/lib/include/chpipes.h
+++ b/os/lib/include/chpipes.h
@@ -60,6 +60,11 @@ typedef struct {
bool reset; /**< @brief True if in reset state. */
threads_queue_t qw; /**< @brief Queued writers. */
threads_queue_t qr; /**< @brief Queued readers. */
+#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
+ mutex_t mtx; /**< @brief Heap access mutex. */
+#else
+ semaphore_t sem; /**< @brief Heap access semaphore. */
+#endif
} pipe_t;
/*===========================================================================*/
@@ -75,6 +80,19 @@ typedef struct {
* @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
*/
+#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
+#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), \
+ _MUTEX_DATA(name.mtx), \
+}
+#else /* CH_CFG_USE_MUTEXES == FALSE */
#define _PIPE_DATA(name, buffer, size) { \
(uint8_t *)(buffer), \
(uint8_t *)(buffer) + size, \
@@ -84,7 +102,9 @@ typedef struct {
false, \
_THREADS_QUEUE_DATA(name.qw), \
_THREADS_QUEUE_DATA(name.qr), \
+ _SEMAPHORE_DATA(name.sem, (cnt_t)1), \
}
+#endif /* CH_CFG_USE_MUTEXES == FALSE */
/**
* @brief Static pipe initializer.
@@ -107,17 +127,10 @@ 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 chPipeWriteTimeout(pipe_t *pp, const 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
diff --git a/os/lib/src/chpipes.c b/os/lib/src/chpipes.c
index 74a45e121..05b47f369 100644
--- a/os/lib/src/chpipes.c
+++ b/os/lib/src/chpipes.c
@@ -42,6 +42,21 @@
#if (CH_CFG_USE_PIPES == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/
+/* Module local definitions. */
+/*===========================================================================*/
+
+/*
+ * Defaults on the best synchronization mechanism available.
+ */
+#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
+#define P_LOCK(p) chMtxLock(&(p)->mtx)
+#define P_UNLOCK(p) chMtxUnlock(&(p)->mtx)
+#else
+#define P_LOCK(p) (void) chSemWait(&(p)->sem)
+#define P_UNLOCK(p) chSemSignal(&(p)->sem)
+#endif
+
+/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
@@ -97,67 +112,77 @@ void chPipeObjectInit(pipe_t *pp, uint8_t *buf, size_t n) {
*
* @api
*/
-void chPipeReset(mailbox_t *mbp) {
+void chPipeReset(pipe_t *pp) {
+
+ chDbgCheck(pp != NULL);
+ P_LOCK(pp);
chSysLock();
- chMBResetI(mbp);
+ pipe_t->wrptr = pipe_t->buffer;
+ pipe_t->rdptr = pipe_t->buffer;
+ pipe_t->cnt = (size_t)0;
+ pipe_t->reset = true;
+ chThdDequeueAllI(&pipe_t->qw, MSG_RESET);
+ chThdDequeueAllI(&pipe_t->qr, MSG_RESET);
chSchRescheduleS();
chSysUnlock();
+ P_UNLOCK();
}
/**
- * @brief Resets a @p pipe_t object.
- * @details All the waiting threads are resumed with status @p MSG_RESET and
- * the queued data is lost.
- * @post The pipe is in reset state, all operations will fail and
- * return @p MSG_RESET until the mailbox is enabled again using
- * @p chPipeResumeX().
+ * @brief Pipe write with timeout.
+ * @details The function writes data from a buffer to a pipe. The
+ * operation completes when the specified amount of data has been
+ * transferred or after the specified timeout or if the pipe has
+ * been reset.
*
* @param[in] pp the pointer to an initialized @p pipe_t object
+ * @param[in] bp pointer to the data buffer
+ * @param[in] n the maximum amount of data to be transferred, the
+ * value 0 is reserved
+ * @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.
+ * .
+ * @return The number of bytes effectively transferred.
+ * @retval MSG_RESET if the mailbox has been reset.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @api
*/
-void chPipeResetI(pipe_t *pp) {
-
- chDbgCheckClassI();
- chDbgCheck(pipe_t != NULL);
-
- pipe_t->wrptr = pipe_t->buffer;
- pipe_t->rdptr = pipe_t->buffer;
- pipe_t->cnt = (size_t)0;
- pipe_t->reset = true;
- chThdDequeueAllI(&pipe_t->qw, MSG_RESET);
- chThdDequeueAllI(&pipe_t->qr, MSG_RESET);
-}
-
-size_t chPipeReadI(pipe_t *pp, uint8_t *bp, size_t n) {
-
-}
-
-size_t chPipeReadTimeoutS(pipe_t *pp, uint8_t *bp,
+size_t chPipeWriteTimeout(pipe_t *pp, const uint8_t *bp,
size_t n, sysinterval_t timeout) {
}
+/**
+ * @brief Pipe read with timeout.
+ * @details The function reads data from a pipe into a buffer. The
+ * operation completes when the specified amount of data has been
+ * transferred or after the specified timeout or if the pipe has
+ * been reset.
+ *
+ * @param[in] pp the pointer to an initialized @p pipe_t object
+ * @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] 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.
+ * .
+ * @return The number of bytes effectively transferred.
+ * @retval MSG_RESET if the mailbox has been reset.
+ * @retval MSG_TIMEOUT if the operation has timed out.
+ *
+ * @api
+ */
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) {
-
-}
-
#endif /* CH_CFG_USE_MAILBOXES == TRUE */
/** @} */