From ef83e007f110af0c1c9dd3874fc0b84f982960c9 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Thu, 22 Mar 2018 08:25:37 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11834 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/lib/src/chpipes.c | 105 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 40 deletions(-) (limited to 'os/lib/src') 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 @@ -41,6 +41,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 */ /** @} */ -- cgit v1.2.3