ChibiOS/RT
2.6.0
chmsg.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012,2013 Giovanni Di Sirio.
00004 
00005     This file is part of ChibiOS/RT.
00006 
00007     ChibiOS/RT is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ChibiOS/RT is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 
00020                                       ---
00021 
00022     A special exception to the GPL can be applied should you wish to distribute
00023     a combined work that includes ChibiOS/RT, without being obliged to provide
00024     the source code for any proprietary components. See the file exception.txt
00025     for full details of how and when the exception can be applied.
00026 */
00027 
00028 /**
00029  * @file    chmsg.h
00030  * @brief   Messages macros and structures.
00031  *
00032  * @addtogroup messages
00033  * @{
00034  */
00035 
00036 #ifndef _CHMSG_H_
00037 #define _CHMSG_H_
00038 
00039 #if CH_USE_MESSAGES || defined(__DOXYGEN__)
00040 
00041 /**
00042  * @name    Macro Functions
00043  * @{
00044  */
00045 /**
00046  * @brief   Evaluates to TRUE if the thread has pending messages.
00047  *
00048  * @iclass
00049  */
00050 #define chMsgIsPendingI(tp) \
00051         ((tp)->p_msgqueue.p_next != (Thread *)&(tp)->p_msgqueue)
00052 
00053 /**
00054  * @brief   Returns the message carried by the specified thread.
00055  * @pre     This function must be invoked immediately after exiting a call
00056  *          to @p chMsgWait().
00057  *
00058  * @param[in] tp        pointer to the thread
00059  * @return              The message carried by the sender.
00060  *
00061  * @api
00062  */
00063 #define chMsgGet(tp) ((tp)->p_msg)
00064 
00065 /**
00066  * @brief   Releases the thread waiting on top of the messages queue.
00067  * @pre     Invoke this function only after a message has been received
00068  *          using @p chMsgWait().
00069  *
00070  * @param[in] tp        pointer to the thread
00071  * @param[in] msg       message to be returned to the sender
00072  *
00073  * @sclass
00074  */
00075 #define chMsgReleaseS(tp, msg) chSchWakeupS(tp, msg)
00076 /** @} */
00077 
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081   msg_t chMsgSend(Thread *tp, msg_t msg);
00082   Thread * chMsgWait(void);
00083   void chMsgRelease(Thread *tp, msg_t msg);
00084 #ifdef __cplusplus
00085 }
00086 #endif
00087 
00088 #endif /* CH_USE_MESSAGES */
00089 
00090 #endif /* _CHMSG_H_ */
00091 
00092 /** @} */