2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2014-07-26 09:06:28 +00:00
|
|
|
2011,2012,2013,2014 Giovanni Di Sirio.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-27 08:54:22 +00:00
|
|
|
* @file chmsg.h
|
2010-02-06 12:31:09 +00:00
|
|
|
* @brief Messages macros and structures.
|
|
|
|
*
|
2009-08-30 06:59:43 +00:00
|
|
|
* @addtogroup messages
|
2009-08-16 13:07:24 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#ifndef _CHMSG_H_
|
|
|
|
#define _CHMSG_H_
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-07-20 10:12:44 +00:00
|
|
|
#if CH_CFG_USE_MESSAGES || defined(__DOXYGEN__)
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* Module macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
msg_t chMsgSend(thread_t *tp, msg_t msg);
|
|
|
|
thread_t * chMsgWait(void);
|
|
|
|
void chMsgRelease(thread_t *tp, msg_t msg);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-08-16 13:07:24 +00:00
|
|
|
/**
|
2013-07-20 07:24:12 +00:00
|
|
|
* @brief Evaluates to @p true if the thread has pending messages.
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
2014-12-11 15:12:21 +00:00
|
|
|
* @param[in] tp pointer to the thread
|
|
|
|
* @return The pending messages status.
|
|
|
|
*
|
2010-09-21 10:22:06 +00:00
|
|
|
* @iclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline bool chMsgIsPendingI(thread_t *tp) {
|
|
|
|
|
|
|
|
chDbgCheckClassI();
|
|
|
|
|
|
|
|
return (bool)(tp->p_msgqueue.p_next != (thread_t *)&tp->p_msgqueue);
|
|
|
|
}
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/**
|
2011-02-23 18:59:39 +00:00
|
|
|
* @brief Returns the message carried by the specified thread.
|
|
|
|
* @pre This function must be invoked immediately after exiting a call
|
|
|
|
* to @p chMsgWait().
|
2010-09-21 10:22:06 +00:00
|
|
|
*
|
2011-02-23 18:59:39 +00:00
|
|
|
* @param[in] tp pointer to the thread
|
|
|
|
* @return The message carried by the sender.
|
|
|
|
*
|
|
|
|
* @api
|
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline msg_t chMsgGet(thread_t *tp) {
|
|
|
|
|
|
|
|
return tp->p_msg;
|
|
|
|
}
|
2011-02-23 18:59:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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().
|
|
|
|
*
|
|
|
|
* @param[in] tp pointer to the thread
|
|
|
|
* @param[in] msg message to be returned to the sender
|
|
|
|
*
|
|
|
|
* @sclass
|
2009-08-16 13:07:24 +00:00
|
|
|
*/
|
2013-07-19 14:51:35 +00:00
|
|
|
static inline void chMsgReleaseS(thread_t *tp, msg_t msg) {
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2013-07-19 14:51:35 +00:00
|
|
|
chDbgCheckClassS();
|
|
|
|
|
|
|
|
chSchWakeupS(tp, msg);
|
2009-08-16 13:07:24 +00:00
|
|
|
}
|
|
|
|
|
2013-07-20 10:12:44 +00:00
|
|
|
#endif /* CH_CFG_USE_MESSAGES */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2010-02-27 08:54:22 +00:00
|
|
|
#endif /* _CHMSG_H_ */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/** @} */
|