From 1ea7355d85e316aadfd90468b3e808bb3dc95ee9 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 16 Aug 2009 13:07:24 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1073 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 os/kernel/src/chmsg.c (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c new file mode 100644 index 000000000..393ab8dad --- /dev/null +++ b/os/kernel/src/chmsg.c @@ -0,0 +1,125 @@ +/* + ChibiOS/RT - Copyright (C) 2006-2007 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 chmsg.c + * @brief Messages code. + * @addtogroup Messages + * @{ + */ + +#include + +#if CH_USE_MESSAGES + +#if CH_USE_MESSAGES_PRIORITY +#define msg_insert(tp, qp) prio_insert(tp, qp) +#else +#define msg_insert(tp, qp) queue_insert(tp, qp) +#endif + +/** + * @brief Sends a message to the specified thread. + * @details The sender is stopped until the receiver executes a + * @p chMsgRelease()after receiving the message. + * + * @param[in] tp the pointer to the thread + * @param[in] msg the message + * @return The return message from @p chMsgRelease(). + */ +msg_t chMsgSend(Thread *tp, msg_t msg) { + + chDbgCheck(tp != NULL, "chMsgSend"); + + chSysLock(); + msg_insert(currp, &tp->p_msgqueue); + currp->p_msg = msg; + currp->p_wtthdp = tp; + if (tp->p_state == PRWTMSG) + chSchReadyI(tp); + chSchGoSleepS(PRSNDMSG); + msg = currp->p_rdymsg; + chSysUnlock(); + return msg; +} + +/** + * @brief Suspends the thread and waits for an incoming message. + * + * @return The pointer to the message structure. Note, it is always the + * message associated to the thread on the top of the messages queue. + * @note You can assume that the data contained in the message is stable until + * you invoke @p chMsgRelease() because the sending thread is + * suspended until then. + */ +msg_t chMsgWait(void) { + msg_t msg; + + chSysLock(); + if (!chMsgIsPendingI(currp)) + chSchGoSleepS(PRWTMSG); + msg = chMsgGetI(currp); + chSysUnlock(); + return msg; +} + +/** + * @brief Returns the next message in the queue. + * + * @return The pointer to the message structure. Note, it is always the + * message associated to the thread on the top of the messages queue. + * If the queue is empty then @p NULL is returned. + * @note You can assume that the data pointed by the message is stable until + * you invoke @p chMsgRelease() because the sending thread is + * suspended until then. Always remember that the message data is not + * copied between the sender and the receiver, just a pointer is passed. + */ +msg_t chMsgGet(void) { + msg_t msg; + + chSysLock(); + msg = chMsgIsPendingI(currp) ? chMsgGetI(currp) : (msg_t)NULL; + chSysUnlock(); + return msg; +} + +/** + * @brief Releases the thread waiting on top of the messages queue. + * + * @param[in] msg the message returned to the message sender + * @note You can call this function only if there is a message already in the + * queue else the result will be unpredictable (a crash most likely). + * Exiting from the @p chMsgWait() ensures you have at least one + * message in the queue so it is not a big deal.
+ * The condition is only tested in debug mode in order to make this code + * as fast as possible. + */ +void chMsgRelease(msg_t msg) { + + chSysLock(); + chDbgAssert(chMsgIsPendingI(currp), + "chMsgRelease(), #1", + "no message pending"); + chSchWakeupS(fifo_remove(&currp->p_msgqueue), msg); + chSysUnlock(); +} + +#endif /* CH_USE_MESSAGES */ + +/** @} */ -- cgit v1.2.3 From 397ccffac55ffd139d0e3e82add83e51413c1347 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 30 Aug 2009 06:59:43 +0000 Subject: Documentation reorganization. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1133 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 393ab8dad..6f1be5c47 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -20,7 +20,7 @@ /** * @file chmsg.c * @brief Messages code. - * @addtogroup Messages + * @addtogroup messages * @{ */ -- cgit v1.2.3 From bdb7f4ab20bd3daf261ab93dfe733e0ff11dca0f Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 8 Dec 2009 17:37:49 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1397 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 6f1be5c47..e3c82ec5a 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -24,7 +24,7 @@ * @{ */ -#include +#include "ch.h" #if CH_USE_MESSAGES -- cgit v1.2.3 From 7bd8164f8ff6ffd0a9458d44e18097582adae201 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jan 2010 14:39:34 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1532 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index e3c82ec5a..577e82693 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -50,11 +50,11 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { chSysLock(); msg_insert(currp, &tp->p_msgqueue); currp->p_msg = msg; - currp->p_wtthdp = tp; - if (tp->p_state == PRWTMSG) + currp->p_u.wtobjp = tp; + if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); - chSchGoSleepS(PRSNDMSG); - msg = currp->p_rdymsg; + chSchGoSleepS(THD_STATE_SNDMSG); + msg = currp->p_u.rdymsg; chSysUnlock(); return msg; } @@ -73,7 +73,7 @@ msg_t chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) - chSchGoSleepS(PRWTMSG); + chSchGoSleepS(THD_STATE_WTMSG); msg = chMsgGetI(currp); chSysUnlock(); return msg; -- cgit v1.2.3 From 85016e2a2622a64719e8baa58dd493b6b99aa793 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jan 2010 20:45:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1534 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 577e82693..2f5a7a127 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -48,9 +48,9 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { chDbgCheck(tp != NULL, "chMsgSend"); chSysLock(); - msg_insert(currp, &tp->p_msgqueue); currp->p_msg = msg; - currp->p_u.wtobjp = tp; + currp->p_u.wtobjp = &tp->p_msgqueue; + msg_insert(currp, &tp->p_msgqueue); if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); chSchGoSleepS(THD_STATE_SNDMSG); -- cgit v1.2.3 From 8cdf2dba5b8113538f2c7c8c7728cc868398d636 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 20 Jan 2010 21:08:28 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1535 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 2f5a7a127..6c0c6a81a 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -44,17 +44,18 @@ * @return The return message from @p chMsgRelease(). */ msg_t chMsgSend(Thread *tp, msg_t msg) { + Thread *ctp = currp; chDbgCheck(tp != NULL, "chMsgSend"); chSysLock(); - currp->p_msg = msg; - currp->p_u.wtobjp = &tp->p_msgqueue; - msg_insert(currp, &tp->p_msgqueue); + ctp->p_msg = msg; + ctp->p_u.wtobjp = &tp->p_msgqueue; + msg_insert(ctp, &tp->p_msgqueue); if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); chSchGoSleepS(THD_STATE_SNDMSG); - msg = currp->p_u.rdymsg; + msg = ctp->p_u.rdymsg; chSysUnlock(); return msg; } -- cgit v1.2.3 From f17db1931e95f5ebb42f557b6eead2bf1320db5a Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Feb 2010 10:55:53 +0000 Subject: Reformatted doxygen tags into the kernel sources to make them more readable. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1567 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 60 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 28 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 6c0c6a81a..9b6afd950 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -18,8 +18,9 @@ */ /** - * @file chmsg.c - * @brief Messages code. + * @file chmsg.c + * @brief Messages code. + * * @addtogroup messages * @{ */ @@ -35,13 +36,13 @@ #endif /** - * @brief Sends a message to the specified thread. + * @brief Sends a message to the specified thread. * @details The sender is stopped until the receiver executes a * @p chMsgRelease()after receiving the message. * - * @param[in] tp the pointer to the thread - * @param[in] msg the message - * @return The return message from @p chMsgRelease(). + * @param[in] tp the pointer to the thread + * @param[in] msg the message + * @return The answer message from @p chMsgRelease(). */ msg_t chMsgSend(Thread *tp, msg_t msg) { Thread *ctp = currp; @@ -61,13 +62,14 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { } /** - * @brief Suspends the thread and waits for an incoming message. + * @brief Suspends the thread and waits for an incoming message. + * @note You can assume that the data contained in the message is stable + * until you invoke @p chMsgRelease() because the sending thread is + * suspended until then. * - * @return The pointer to the message structure. Note, it is always the - * message associated to the thread on the top of the messages queue. - * @note You can assume that the data contained in the message is stable until - * you invoke @p chMsgRelease() because the sending thread is - * suspended until then. + * @return The pointer to the message structure. Note, it is + * always the message associated to the thread on the + * top of the messages queue. */ msg_t chMsgWait(void) { msg_t msg; @@ -81,15 +83,17 @@ msg_t chMsgWait(void) { } /** - * @brief Returns the next message in the queue. + * @brief Returns the next message in the queue. + * @note You can assume that the data pointed by the message is stable until + * you invoke @p chMsgRelease() because the sending thread is + * suspended until then. Always remember that the message data is not + * copied between the sender and the receiver, just a pointer is + * passed. * - * @return The pointer to the message structure. Note, it is always the - * message associated to the thread on the top of the messages queue. - * If the queue is empty then @p NULL is returned. - * @note You can assume that the data pointed by the message is stable until - * you invoke @p chMsgRelease() because the sending thread is - * suspended until then. Always remember that the message data is not - * copied between the sender and the receiver, just a pointer is passed. + * @return The pointer to the message structure. Note, it is + * always the message associated to the thread on the + * top of the messages queue. + * @retval NULL if the queue is empty. */ msg_t chMsgGet(void) { msg_t msg; @@ -101,15 +105,15 @@ msg_t chMsgGet(void) { } /** - * @brief Releases the thread waiting on top of the messages queue. + * @brief Releases the thread waiting on top of the messages queue. + * @note You can call this function only if there is a message already in + * the queue else the result will be unpredictable (a crash most likely). + * Exiting from the @p chMsgWait() ensures you have at least one + * message in the queue so it is not a big deal.
+ * The condition is only tested in debug mode in order to make this + * code as fast as possible. * - * @param[in] msg the message returned to the message sender - * @note You can call this function only if there is a message already in the - * queue else the result will be unpredictable (a crash most likely). - * Exiting from the @p chMsgWait() ensures you have at least one - * message in the queue so it is not a big deal.
- * The condition is only tested in debug mode in order to make this code - * as fast as possible. + * @param[in] msg the message returned to the message sender */ void chMsgRelease(msg_t msg) { -- cgit v1.2.3 From 157b6f9695e7f72f2d54b231c19cb4045710ed01 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 21 Feb 2010 07:24:53 +0000 Subject: Updated license dates. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1646 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 9b6afd950..411c5fed3 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -1,5 +1,5 @@ /* - ChibiOS/RT - Copyright (C) 2006-2007 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From b69948bc4883423fde36e63e2ef5d2d16f7ec71c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 5 Mar 2010 19:01:12 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1713 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 411c5fed3..5030ac809 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -77,7 +77,8 @@ msg_t chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) chSchGoSleepS(THD_STATE_WTMSG); - msg = chMsgGetI(currp); +/* msg = chMsgGetI(currp);*/ + msg = chMsgGetI((volatile Thread *)currp); /* Temporary hack.*/ chSysUnlock(); return msg; } -- cgit v1.2.3 From 755c42b99afb7f68428bf43bd31b3ce407cc8f13 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 6 Mar 2010 09:08:30 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1718 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 5030ac809..1e89aa0a3 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -77,8 +77,11 @@ msg_t chMsgWait(void) { chSysLock(); if (!chMsgIsPendingI(currp)) chSchGoSleepS(THD_STATE_WTMSG); -/* msg = chMsgGetI(currp);*/ +#if defined(CH_ARCHITECTURE_STM8) msg = chMsgGetI((volatile Thread *)currp); /* Temporary hack.*/ +#else + msg = chMsgGetI(currp); +#endif chSysUnlock(); return msg; } -- cgit v1.2.3 From ad3d21e81592481539a56e93234f5bf1fa2c0504 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 16 Mar 2010 19:36:21 +0000 Subject: Documentation reorganization. Moved the description from kernel.dox into the source code for ease of editing and reference. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1746 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 1e89aa0a3..96bf61452 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -22,6 +22,22 @@ * @brief Messages code. * * @addtogroup messages + * @details Synchronous inter-thread messages APIs and services. + *

Operation Mode

+ * Synchronous messages are an easy to use and fast IPC mechanism, + * threads can both act as message servers and/or message clients, + * the mechanism allows data to be carried in both directions. Note + * that messages are not copied between the client and server threads + * but just a pointer passed so the exchange is very time + * efficient.
+ * Messages are usually processed in FIFO order but it is possible to + * process them in priority order by enabling the + * @p CH_USE_MESSAGES_PRIORITY option in @p chconf.h.
+ * Applications do not need to allocate buffers for synchronous + * message queues, the mechanism just requires two extra pointers in + * the @p Thread structure (the message queue header).
+ * In order to use the Messages APIs the @p CH_USE_MESSAGES option + * must be enabled in @p chconf.h. * @{ */ -- cgit v1.2.3 From 9ffea7e261ec4016d788abbbf7c4a6d3a78e0a04 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 18 Sep 2010 06:48:56 +0000 Subject: Documentation improvements, renamed some event APIs. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2179 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 48 ++++++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 26 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 96bf61452..09acf7b42 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -30,20 +30,22 @@ * that messages are not copied between the client and server threads * but just a pointer passed so the exchange is very time * efficient.
+ * Messages are scalar data types of type @p msg_t that are guaranteed + * to be size compatible with data pointers. Note that on some + * architectures function pointers can be larger that @p msg_t.
* Messages are usually processed in FIFO order but it is possible to * process them in priority order by enabling the * @p CH_USE_MESSAGES_PRIORITY option in @p chconf.h.
- * Applications do not need to allocate buffers for synchronous - * message queues, the mechanism just requires two extra pointers in - * the @p Thread structure (the message queue header).
- * In order to use the Messages APIs the @p CH_USE_MESSAGES option + * @pre In order to use the message APIs the @p CH_USE_MESSAGES option * must be enabled in @p chconf.h. + * @post Enabling messages requires 6-12 (depending on the architecture) + * extra bytes in the @p Thread structure. * @{ */ #include "ch.h" -#if CH_USE_MESSAGES +#if CH_USE_MESSAGES || defined(__DOXYGEN__) #if CH_USE_MESSAGES_PRIORITY #define msg_insert(tp, qp) prio_insert(tp, qp) @@ -79,13 +81,13 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { /** * @brief Suspends the thread and waits for an incoming message. - * @note You can assume that the data contained in the message is stable - * until you invoke @p chMsgRelease() because the sending thread is - * suspended until then. + * @post After receiving a message the function @p chMsgRelease() must be + * invoked in order to acknowledge the reception and send the answer. + * @note If the message is a pointer then you can assume that the data + * pointed by the message is stable until you invoke @p chMsgRelease() + * because the sending thread is suspended until then. * - * @return The pointer to the message structure. Note, it is - * always the message associated to the thread on the - * top of the messages queue. + * @return The message. */ msg_t chMsgWait(void) { msg_t msg; @@ -104,16 +106,14 @@ msg_t chMsgWait(void) { /** * @brief Returns the next message in the queue. - * @note You can assume that the data pointed by the message is stable until - * you invoke @p chMsgRelease() because the sending thread is - * suspended until then. Always remember that the message data is not - * copied between the sender and the receiver, just a pointer is - * passed. + * @post After receiving a message the function @p chMsgRelease() must be + * invoked in order to acknowledge the reception and send the answer. + * @note If the message is a pointer then you can assume that the data + * pointed by the message is stable until you invoke @p chMsgRelease() + * because the sending thread is suspended until then. * - * @return The pointer to the message structure. Note, it is - * always the message associated to the thread on the - * top of the messages queue. - * @retval NULL if the queue is empty. + * @return The message. + * @retval 0 if the queue is empty. */ msg_t chMsgGet(void) { msg_t msg; @@ -126,12 +126,8 @@ msg_t chMsgGet(void) { /** * @brief Releases the thread waiting on top of the messages queue. - * @note You can call this function only if there is a message already in - * the queue else the result will be unpredictable (a crash most likely). - * Exiting from the @p chMsgWait() ensures you have at least one - * message in the queue so it is not a big deal.
- * The condition is only tested in debug mode in order to make this - * code as fast as possible. + * @pre Invoke this function only after a message has been received + * using @p chMsgWait() or @p chMsgGet(). * * @param[in] msg the message returned to the message sender */ -- cgit v1.2.3 From 07351222e6d0b6b3dcd4f50ecb18bc09e7402d1c Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 21 Sep 2010 10:22:06 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2184 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 09acf7b42..c3b4848b0 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -61,6 +61,8 @@ * @param[in] tp the pointer to the thread * @param[in] msg the message * @return The answer message from @p chMsgRelease(). + * + * @api */ msg_t chMsgSend(Thread *tp, msg_t msg) { Thread *ctp = currp; @@ -88,6 +90,8 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { * because the sending thread is suspended until then. * * @return The message. + * + * @api */ msg_t chMsgWait(void) { msg_t msg; @@ -114,6 +118,8 @@ msg_t chMsgWait(void) { * * @return The message. * @retval 0 if the queue is empty. + * + * @api */ msg_t chMsgGet(void) { msg_t msg; @@ -130,6 +136,8 @@ msg_t chMsgGet(void) { * using @p chMsgWait() or @p chMsgGet(). * * @param[in] msg the message returned to the message sender + * + * @api */ void chMsgRelease(msg_t msg) { -- cgit v1.2.3 From 6f6e1a6401eda000dce198150937c7919b4c9855 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Wed, 23 Feb 2011 18:59:39 +0000 Subject: Improved messages subsystem. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2759 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 59 ++++++++++++++++----------------------------------- 1 file changed, 18 insertions(+), 41 deletions(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index c3b4848b0..d4199bbb0 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -75,7 +75,7 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { msg_insert(ctp, &tp->p_msgqueue); if (tp->p_state == THD_STATE_WTMSG) chSchReadyI(tp); - chSchGoSleepS(THD_STATE_SNDMSG); + chSchGoSleepS(THD_STATE_SNDMSGQ); msg = ctp->p_u.rdymsg; chSysUnlock(); return msg; @@ -83,69 +83,46 @@ msg_t chMsgSend(Thread *tp, msg_t msg) { /** * @brief Suspends the thread and waits for an incoming message. - * @post After receiving a message the function @p chMsgRelease() must be - * invoked in order to acknowledge the reception and send the answer. + * @post After receiving a message the function @p chMsgGet() must be + * called in order to retrieve the message and then @p chMsgRelease() + * must be invoked in order to acknowledge the reception and send + * the answer. * @note If the message is a pointer then you can assume that the data * pointed by the message is stable until you invoke @p chMsgRelease() * because the sending thread is suspended until then. * - * @return The message. + * @return A reference to the thread carrying the message. * * @api */ -msg_t chMsgWait(void) { - msg_t msg; +Thread *chMsgWait(void) { + Thread *tp; chSysLock(); if (!chMsgIsPendingI(currp)) chSchGoSleepS(THD_STATE_WTMSG); -#if defined(CH_ARCHITECTURE_STM8) - msg = chMsgGetI((volatile Thread *)currp); /* Temporary hack.*/ -#else - msg = chMsgGetI(currp); -#endif + tp = fifo_remove(&currp->p_msgqueue); + tp->p_state = THD_STATE_SNDMSG; chSysUnlock(); - return msg; -} - -/** - * @brief Returns the next message in the queue. - * @post After receiving a message the function @p chMsgRelease() must be - * invoked in order to acknowledge the reception and send the answer. - * @note If the message is a pointer then you can assume that the data - * pointed by the message is stable until you invoke @p chMsgRelease() - * because the sending thread is suspended until then. - * - * @return The message. - * @retval 0 if the queue is empty. - * - * @api - */ -msg_t chMsgGet(void) { - msg_t msg; - - chSysLock(); - msg = chMsgIsPendingI(currp) ? chMsgGetI(currp) : (msg_t)NULL; - chSysUnlock(); - return msg; + return tp; } /** * @brief Releases the thread waiting on top of the messages queue. * @pre Invoke this function only after a message has been received - * using @p chMsgWait() or @p chMsgGet(). + * using @p chMsgWait(). * - * @param[in] msg the message returned to the message sender + * @param[in] tp pointer to the thread + * @param[in] msg message to be returned to the sender * * @api */ -void chMsgRelease(msg_t msg) { +void chMsgRelease(Thread *tp, msg_t msg) { chSysLock(); - chDbgAssert(chMsgIsPendingI(currp), - "chMsgRelease(), #1", - "no message pending"); - chSchWakeupS(fifo_remove(&currp->p_msgqueue), msg); + chDbgAssert(tp->p_state == THD_STATE_SNDMSG, + "chMsgRelease(), #1", "invalid state"); + chMsgReleaseS(tp, msg); chSysUnlock(); } -- cgit v1.2.3 From e7e79a6ccb4f3e320b2b8b7bad1b14d65218641d Mon Sep 17 00:00:00 2001 From: gdisirio Date: Fri, 18 Mar 2011 18:38:08 +0000 Subject: License updated. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2827 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index d4199bbb0..5002a892a 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -1,5 +1,6 @@ /* - ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. + ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, + 2011 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From c9be79def630f153b0b2d28e905939c15743f989 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Tue, 23 Aug 2011 10:09:08 +0000 Subject: Kernel documentation fixes and improvements. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3251 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 5002a892a..403df1580 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -109,7 +109,7 @@ Thread *chMsgWait(void) { } /** - * @brief Releases the thread waiting on top of the messages queue. + * @brief Releases a sender thread specifying a response message. * @pre Invoke this function only after a message has been received * using @p chMsgWait(). * -- cgit v1.2.3 From de5dcbba856524599a8f06d3a9bdbf1b01db44c2 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 21 Jan 2012 14:29:42 +0000 Subject: License text updated with new year. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3846 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 403df1580..50814ef9c 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011 Giovanni Di Sirio. + 2011,2012 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3 From 184a71345c6a36a9a8664eda8fbcc3ea728267a8 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sat, 2 Feb 2013 10:58:09 +0000 Subject: Updated license years. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5102 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/kernel/src/chmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'os/kernel/src/chmsg.c') diff --git a/os/kernel/src/chmsg.c b/os/kernel/src/chmsg.c index 50814ef9c..ad97da79c 100644 --- a/os/kernel/src/chmsg.c +++ b/os/kernel/src/chmsg.c @@ -1,6 +1,6 @@ /* ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, - 2011,2012 Giovanni Di Sirio. + 2011,2012,2013 Giovanni Di Sirio. This file is part of ChibiOS/RT. -- cgit v1.2.3