ChibiOS  21.6.0
nil/include/chmsg.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014,
3  2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio.
4 
5  This file is part of ChibiOS.
6 
7  ChibiOS is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation version 3 of the License.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file nil/include/chmsg.h
22  * @brief Nil RTOS synchronous messages header file.
23  *
24  * @addtogroup NIL_MESSAGES
25  * @{
26  */
27 
28 #ifndef CHMSG_H
29 #define CHMSG_H
30 
31 #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
32 
33 /*===========================================================================*/
34 /* Module constants. */
35 /*===========================================================================*/
36 
37 /*===========================================================================*/
38 /* Module pre-compile time settings. */
39 /*===========================================================================*/
40 
41 /*===========================================================================*/
42 /* Derived constants and error checks. */
43 /*===========================================================================*/
44 
45 /*===========================================================================*/
46 /* Module data structures and types. */
47 /*===========================================================================*/
48 
49 /*===========================================================================*/
50 /* Module macros. */
51 /*===========================================================================*/
52 
53 /**
54  * @name Macro Functions
55  * @{
56  */
57 /**
58  * @brief Suspends the thread and waits for an incoming message.
59  * @post After receiving a message the function @p chMsgGet() must be
60  * called in order to retrieve the message and then @p chMsgRelease()
61  * must be invoked in order to acknowledge the reception and send
62  * the answer.
63  * @note If the message is a pointer then you can assume that the data
64  * pointed by the message is stable until you invoke @p chMsgRelease()
65  * because the sending thread is suspended until then.
66  * @note The reference counter of the sender thread is not increased, the
67  * returned pointer is a temporary reference.
68  *
69  * @return A pointer to the thread carrying the message.
70  *
71  * @sclass
72  */
73 #define chMsgWaitS() chMsgWaitTimeoutS(TIME_INFINITE)
74 
75 /**
76  * @brief Returns the message carried by the specified thread.
77  * @pre This function must be invoked immediately after exiting a call
78  * to @p chMsgWait().
79  *
80  * @param[in] tp pointer to the thread
81  * @return The message carried by the sender.
82  *
83  * @api
84  */
85 #define chMsgGet(tp) ((tp)->sntmsg)
86 
87 /**
88  * @brief Releases the thread waiting on top of the messages queue.
89  * @pre Invoke this function only after a message has been received
90  * using @p chMsgWait().
91  *
92  * @param[in] tp pointer to the thread
93  * @param[in] msg message to be returned to the sender
94  *
95  * @sclass
96  */
97 #define chMsgReleaseS(tp, msg) do { \
98  (void) chSchReadyI(tp, msg); \
99  chSchRescheduleS(); \
100  } while (false)
101 /** @} */
102 
103 /*===========================================================================*/
104 /* External declarations. */
105 /*===========================================================================*/
106 
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110  msg_t chMsgSend(thread_t *tp, msg_t msg);
111  thread_t *chMsgWait(void);
114  void chMsgRelease(thread_t *tp, msg_t msg);
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif /* CH_CFG_USE_MESSAGES == TRUE */
120 
121 #endif /* CHMSG_H */
122 
123 /** @} */
msg_t
int32_t msg_t
Definition: chearly.h:88
chMsgWait
thread_t * chMsgWait(void)
Suspends the thread and waits for an incoming message.
Definition: nil/src/chmsg.c:100
ch_thread
Structure representing a thread.
Definition: chobjects.h:156
chMsgSend
msg_t chMsgSend(thread_t *tp, msg_t msg)
Sends a message to the specified thread.
Definition: rt/src/chmsg.c:81
chMsgRelease
void chMsgRelease(thread_t *tp, msg_t msg)
Releases a sender thread specifying a response message.
Definition: rt/src/chmsg.c:208
sysinterval_t
uint64_t sysinterval_t
Type of time interval.
Definition: chtime.h:119
chMsgWaitTimeoutS
thread_t * chMsgWaitTimeoutS(sysinterval_t timeout)
Suspends the thread and waits for an incoming message or a timeout to occur.
Definition: rt/src/chmsg.c:152
chMsgWaitTimeout
thread_t * chMsgWaitTimeout(sysinterval_t timeout)
Suspends the thread and waits for an incoming message or a timeout to occur.
Definition: nil/src/chmsg.c:133