From 25ddb1c801f06a3be7171e20dcfd46d11a75f112 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 19 Jul 2013 14:51:35 +0000 Subject: First cleanup pass finished, queues and streams not yet removed. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@5999 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmboxes.c | 70 +++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 24 deletions(-) (limited to 'os/kernel/src/chmboxes.c') diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 6f09a8d26..16f303daf 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -53,16 +53,38 @@ #include "ch.h" #if CH_USE_MAILBOXES || defined(__DOXYGEN__) + +/*===========================================================================*/ +/* Module exported variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local types. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local variables. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module local functions. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Module exported functions. */ +/*===========================================================================*/ + /** - * @brief Initializes a Mailbox object. + * @brief Initializes a @p mailbox_t object. * - * @param[out] mbp the pointer to the Mailbox structure to be initialized + * @param[out] mbp the pointer to the @p mailbox_t structure to be + * initialized * @param[in] buf pointer to the messages buffer as an array of @p msg_t * @param[in] n number of elements in the buffer array * * @init */ -void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) { +void chMBInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); @@ -73,15 +95,15 @@ void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n) { } /** - * @brief Resets a Mailbox object. + * @brief Resets a @p mailbox_t object. * @details All the waiting threads are resumed with status @p RDY_RESET and * the queued messages are lost. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * * @api */ -void chMBReset(Mailbox *mbp) { +void chMBReset(mailbox_t *mbp) { chDbgCheck(mbp != NULL, "chMBReset"); @@ -98,7 +120,7 @@ void chMBReset(Mailbox *mbp) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -112,7 +134,7 @@ void chMBReset(Mailbox *mbp) { * * @api */ -msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chSysLock(); @@ -126,7 +148,7 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -140,7 +162,7 @@ msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t time) { * * @sclass */ -msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -162,7 +184,7 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. @@ -171,7 +193,7 @@ msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t time) { * * @iclass */ -msg_t chMBPostI(Mailbox *mbp, msg_t msg) { +msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL, "chMBPostI"); @@ -191,7 +213,7 @@ msg_t chMBPostI(Mailbox *mbp, msg_t msg) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -205,7 +227,7 @@ msg_t chMBPostI(Mailbox *mbp, msg_t msg) { * * @api */ -msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chSysLock(); @@ -219,7 +241,7 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { * @details The invoking thread waits until a empty slot in the mailbox becomes * available or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -233,7 +255,7 @@ msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t time) { * * @sclass */ -msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { +msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -255,7 +277,7 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is full. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[in] msg the message to be posted on the mailbox * @return The operation status. * @retval RDY_OK if a message has been correctly posted. @@ -264,7 +286,7 @@ msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t time) { * * @iclass */ -msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { +msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); chDbgCheck(mbp != NULL, "chMBPostAheadI"); @@ -284,7 +306,7 @@ msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { * @details The invoking thread waits until a message is posted in the mailbox * or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -298,7 +320,7 @@ msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg) { * * @api */ -msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { +msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chSysLock(); @@ -312,7 +334,7 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { * @details The invoking thread waits until a message is posted in the mailbox * or the specified time runs out. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @param[in] time the number of ticks before the operation timeouts, * the following special values are allowed: @@ -326,7 +348,7 @@ msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t time) { * * @sclass */ -msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { +msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); @@ -348,7 +370,7 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { * @details This variant is non-blocking, the function returns a timeout * condition if the queue is empty. * - * @param[in] mbp the pointer to an initialized Mailbox object + * @param[in] mbp the pointer to an initialized @p mailbox_t object * @param[out] msgp pointer to a message variable for the received message * @return The operation status. * @retval RDY_OK if a message has been correctly fetched. @@ -357,7 +379,7 @@ msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t time) { * * @iclass */ -msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp) { +msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI"); -- cgit v1.2.3 From 390ed322cb8f40cb9250021cde5f48acb928d291 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 07:24:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6001 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmboxes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chmboxes.c') diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 16f303daf..b1a4fb963 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -84,14 +84,14 @@ * * @init */ -void chMBInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { +void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; mbp->mb_top = &buf[n]; - chSemInit(&mbp->mb_emptysem, n); - chSemInit(&mbp->mb_fullsem, 0); + chSemObjectInit(&mbp->mb_emptysem, n); + chSemObjectInit(&mbp->mb_fullsem, 0); } /** -- cgit v1.2.3 From 49d71a01abeefa000a4cd7a556052d826b096d49 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 20 Jul 2013 10:12:44 +0000 Subject: Renamed or added prefix to all hernel configuration options. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6010 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmboxes.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'os/kernel/src/chmboxes.c') diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index b1a4fb963..2a6e6fae8 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -45,14 +45,14 @@ * example) from the posting side and free it on the fetching side. * Another approach is to set a "done" flag into the structure pointed * by the message. - * @pre In order to use the mailboxes APIs the @p CH_USE_MAILBOXES option + * @pre In order to use the mailboxes APIs the @p CH_CFG_USE_MAILBOXES option * must be enabled in @p chconf.h. * @{ */ #include "ch.h" -#if CH_USE_MAILBOXES || defined(__DOXYGEN__) +#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) /*===========================================================================*/ /* Module exported variables. */ @@ -393,6 +393,6 @@ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chSemSignalI(&mbp->mb_emptysem); return RDY_OK; } -#endif /* CH_USE_MAILBOXES */ +#endif /* CH_CFG_USE_MAILBOXES */ /** @} */ -- cgit v1.2.3 From eb7a1a15b23341693864c6fc13ac5eab5c1d6122 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:50:32 +0000 Subject: Removed 2nd parameter to assertion and check macros. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6122 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmboxes.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'os/kernel/src/chmboxes.c') diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c index 2a6e6fae8..003c779ec 100644 --- a/os/kernel/src/chmboxes.c +++ b/os/kernel/src/chmboxes.c @@ -86,7 +86,7 @@ */ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { - chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0), "chMBInit"); + chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; mbp->mb_top = &buf[n]; @@ -105,7 +105,7 @@ void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { */ void chMBReset(mailbox_t *mbp) { - chDbgCheck(mbp != NULL, "chMBReset"); + chDbgCheck(mbp != NULL); chSysLock(); mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; @@ -166,7 +166,7 @@ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck(mbp != NULL, "chMBPostS"); + chDbgCheck(mbp != NULL); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { @@ -196,7 +196,7 @@ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); - chDbgCheck(mbp != NULL, "chMBPostI"); + chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; @@ -259,7 +259,7 @@ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck(mbp != NULL, "chMBPostAheadS"); + chDbgCheck(mbp != NULL); rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); if (rdymsg == RDY_OK) { @@ -289,7 +289,7 @@ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { chDbgCheckClassI(); - chDbgCheck(mbp != NULL, "chMBPostAheadI"); + chDbgCheck(mbp != NULL); if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) return RDY_TIMEOUT; @@ -352,7 +352,7 @@ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t rdymsg; chDbgCheckClassS(); - chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchS"); + chDbgCheck((mbp != NULL) && (msgp != NULL)); rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); if (rdymsg == RDY_OK) { @@ -382,7 +382,7 @@ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { chDbgCheckClassI(); - chDbgCheck((mbp != NULL) && (msgp != NULL), "chMBFetchI"); + chDbgCheck((mbp != NULL) && (msgp != NULL)); if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) return RDY_TIMEOUT; -- cgit v1.2.3 From a1435e018bfc9919cb76b1356509ecc883767fb4 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 10 Aug 2013 14:51:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/kernel_3_dev@6123 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmboxes.c | 398 ----------------------------------------------- 1 file changed, 398 deletions(-) delete mode 100644 os/kernel/src/chmboxes.c (limited to 'os/kernel/src/chmboxes.c') diff --git a/os/kernel/src/chmboxes.c b/os/kernel/src/chmboxes.c deleted file mode 100644 index 003c779ec..000000000 --- a/os/kernel/src/chmboxes.c +++ /dev/null @@ -1,398 +0,0 @@ -/* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012,2013 Giovanni Di Sirio. - - This file is part of ChibiOS/RT. - - ChibiOS/RT 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/RT 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 . -*/ - -/** - * @file chmboxes.c - * @brief Mailboxes code. - * - * @addtogroup mailboxes - * @details Asynchronous messages. - *

Operation mode

- * A mailbox is an asynchronous communication mechanism.
- * Operations defined for mailboxes: - * - Post: Posts a message on the mailbox in FIFO order. - * - Post Ahead: Posts a message on the mailbox with urgent - * priority. - * - Fetch: A message is fetched from the mailbox and removed - * from the queue. - * - Reset: The mailbox is emptied and all the stored messages - * are lost. - * . - * A message is a variable of type msg_t that is guaranteed to have - * the same size of and be compatible with (data) pointers (anyway an - * explicit cast is needed). - * If larger messages need to be exchanged then a pointer to a - * structure can be posted in the mailbox but the posting side has - * no predefined way to know when the message has been processed. A - * possible approach is to allocate memory (from a memory pool for - * example) from the posting side and free it on the fetching side. - * Another approach is to set a "done" flag into the structure pointed - * by the message. - * @pre In order to use the mailboxes APIs the @p CH_CFG_USE_MAILBOXES option - * must be enabled in @p chconf.h. - * @{ - */ - -#include "ch.h" - -#if CH_CFG_USE_MAILBOXES || defined(__DOXYGEN__) - -/*===========================================================================*/ -/* Module exported variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local types. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local variables. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module local functions. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Module exported functions. */ -/*===========================================================================*/ - -/** - * @brief Initializes a @p mailbox_t object. - * - * @param[out] mbp the pointer to the @p mailbox_t structure to be - * initialized - * @param[in] buf pointer to the messages buffer as an array of @p msg_t - * @param[in] n number of elements in the buffer array - * - * @init - */ -void chMBObjectInit(mailbox_t *mbp, msg_t *buf, cnt_t n) { - - chDbgCheck((mbp != NULL) && (buf != NULL) && (n > 0)); - - mbp->mb_buffer = mbp->mb_wrptr = mbp->mb_rdptr = buf; - mbp->mb_top = &buf[n]; - chSemObjectInit(&mbp->mb_emptysem, n); - chSemObjectInit(&mbp->mb_fullsem, 0); -} - -/** - * @brief Resets a @p mailbox_t object. - * @details All the waiting threads are resumed with status @p RDY_RESET and - * the queued messages are lost. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * - * @api - */ -void chMBReset(mailbox_t *mbp) { - - chDbgCheck(mbp != NULL); - - chSysLock(); - mbp->mb_wrptr = mbp->mb_rdptr = mbp->mb_buffer; - chSemResetI(&mbp->mb_emptysem, mbp->mb_top - mbp->mb_buffer); - chSemResetI(&mbp->mb_fullsem, 0); - chSchRescheduleS(); - chSysUnlock(); -} - -/** - * @brief Posts a message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBPostS(mbp, msg, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Posts a message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck(mbp != NULL); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); - if (rdymsg == RDY_OK) { - *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) - mbp->mb_wrptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_fullsem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Posts a message into a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is full. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be - * posted. - * - * @iclass - */ -msg_t chMBPostI(mailbox_t *mbp, msg_t msg) { - - chDbgCheckClassI(); - chDbgCheck(mbp != NULL); - - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_emptysem); - *mbp->mb_wrptr++ = msg; - if (mbp->mb_wrptr >= mbp->mb_top) - mbp->mb_wrptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_fullsem); - return RDY_OK; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBPostAheadS(mbp, msg, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details The invoking thread waits until a empty slot in the mailbox becomes - * available or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck(mbp != NULL); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_emptysem, time); - if (rdymsg == RDY_OK) { - if (--mbp->mb_rdptr < mbp->mb_buffer) - mbp->mb_rdptr = mbp->mb_top - 1; - *mbp->mb_rdptr = msg; - chSemSignalI(&mbp->mb_fullsem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Posts an high priority message into a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is full. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[in] msg the message to be posted on the mailbox - * @return The operation status. - * @retval RDY_OK if a message has been correctly posted. - * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be - * posted. - * - * @iclass - */ -msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg) { - - chDbgCheckClassI(); - chDbgCheck(mbp != NULL); - - if (chSemGetCounterI(&mbp->mb_emptysem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_emptysem); - if (--mbp->mb_rdptr < mbp->mb_buffer) - mbp->mb_rdptr = mbp->mb_top - 1; - *mbp->mb_rdptr = msg; - chSemSignalI(&mbp->mb_fullsem); - return RDY_OK; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details The invoking thread waits until a message is posted in the mailbox - * or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @api - */ -msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t time) { - msg_t rdymsg; - - chSysLock(); - rdymsg = chMBFetchS(mbp, msgp, time); - chSysUnlock(); - return rdymsg; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details The invoking thread waits until a message is posted in the mailbox - * or the specified time runs out. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @param[in] time 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 operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_RESET if the mailbox has been reset while waiting. - * @retval RDY_TIMEOUT if the operation has timed out. - * - * @sclass - */ -msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t time) { - msg_t rdymsg; - - chDbgCheckClassS(); - chDbgCheck((mbp != NULL) && (msgp != NULL)); - - rdymsg = chSemWaitTimeoutS(&mbp->mb_fullsem, time); - if (rdymsg == RDY_OK) { - *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) - mbp->mb_rdptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_emptysem); - chSchRescheduleS(); - } - return rdymsg; -} - -/** - * @brief Retrieves a message from a mailbox. - * @details This variant is non-blocking, the function returns a timeout - * condition if the queue is empty. - * - * @param[in] mbp the pointer to an initialized @p mailbox_t object - * @param[out] msgp pointer to a message variable for the received message - * @return The operation status. - * @retval RDY_OK if a message has been correctly fetched. - * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be - * fetched. - * - * @iclass - */ -msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp) { - - chDbgCheckClassI(); - chDbgCheck((mbp != NULL) && (msgp != NULL)); - - if (chSemGetCounterI(&mbp->mb_fullsem) <= 0) - return RDY_TIMEOUT; - chSemFastWaitI(&mbp->mb_fullsem); - *msgp = *mbp->mb_rdptr++; - if (mbp->mb_rdptr >= mbp->mb_top) - mbp->mb_rdptr = mbp->mb_buffer; - chSemSignalI(&mbp->mb_emptysem); - return RDY_OK; -} -#endif /* CH_CFG_USE_MAILBOXES */ - -/** @} */ -- cgit v1.2.3