ChibiOS/RT  6.0.3
chmsg.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
3 
4  This file is part of ChibiOS.
5 
6  ChibiOS is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
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 chmsg.h
22  * @brief Messages macros and structures.
23  *
24  * @addtogroup 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 /* External declarations. */
55 /*===========================================================================*/
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60  msg_t chMsgSend(thread_t *tp, msg_t msg);
61  thread_t * chMsgWait(void);
62  void chMsgRelease(thread_t *tp, msg_t msg);
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 /*===========================================================================*/
68 /* External declarations. */
69 /*===========================================================================*/
70 
71 /**
72  * @brief Evaluates to @p true if the thread has pending messages.
73  *
74  * @param[in] tp pointer to the thread
75  * @return The pending messages status.
76  *
77  * @iclass
78  */
79 static inline bool chMsgIsPendingI(thread_t *tp) {
80 
82 
83  return (bool)(tp->msgqueue.next != (thread_t *)&tp->msgqueue);
84 }
85 
86 /**
87  * @brief Returns the message carried by the specified thread.
88  * @pre This function must be invoked immediately after exiting a call
89  * to @p chMsgWait().
90  *
91  * @param[in] tp pointer to the thread
92  * @return The message carried by the sender.
93  *
94  * @api
95  */
96 static inline msg_t chMsgGet(thread_t *tp) {
97 
98  chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state");
99 
100  return tp->u.sentmsg;
101 }
102 
103 /**
104  * @brief Releases the thread waiting on top of the messages queue.
105  * @pre Invoke this function only after a message has been received
106  * using @p chMsgWait().
107  *
108  * @param[in] tp pointer to the thread
109  * @param[in] msg message to be returned to the sender
110  *
111  * @sclass
112  */
113 static inline void chMsgReleaseS(thread_t *tp, msg_t msg) {
114 
116 
117  chSchWakeupS(tp, msg);
118 }
119 
120 #endif /* CH_CFG_USE_MESSAGES == TRUE */
121 
122 #endif /* CHMSG_H */
123 
124 /** @} */
#define CH_STATE_SNDMSG
Sent a message, waiting answer.
Definition: chschd.h:82
static void chMsgReleaseS(thread_t *tp, msg_t msg)
Releases the thread waiting on top of the messages queue.
Definition: chmsg.h:113
threads_queue_t msgqueue
Messages queue.
Definition: chschd.h:281
static msg_t chMsgGet(thread_t *tp)
Returns the message carried by the specified thread.
Definition: chmsg.h:96
thread_t * next
Next in the list/queue.
Definition: chschd.h:143
msg_t chMsgSend(thread_t *tp, msg_t msg)
Sends a message to the specified thread.
Definition: chmsg.c:87
msg_t sentmsg
Thread sent message.
Definition: chschd.h:242
static bool chMsgIsPendingI(thread_t *tp)
Evaluates to true if the thread has pending messages.
Definition: chmsg.h:79
thread_t * chMsgWait(void)
Suspends the thread and waits for an incoming message.
Definition: chmsg.c:121
void chMsgRelease(thread_t *tp, msg_t msg)
Releases a sender thread specifying a response message.
Definition: chmsg.c:145
tstate_t state
Current thread state.
Definition: chschd.h:180
union ch_thread::@0 u
State-specific fields.
void chDbgCheckClassI(void)
I-class functions context check.
Definition: chdebug.c:233
void chSchWakeupS(thread_t *ntp, msg_t msg)
Wakes up a thread.
Definition: chschd.c:412
#define chDbgAssert(c, r)
Condition assertion.
Definition: chdebug.h:127
void chDbgCheckClassS(void)
S-class functions context check.
Definition: chdebug.c:248
Structure representing a thread.
Definition: chschd.h:153