2009-08-16 13:07:24 +00:00
|
|
|
/*
|
2016-03-18 10:29:35 +00:00
|
|
|
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
This file is part of ChibiOS.
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is free software; you can redistribute it and/or modify
|
2009-08-16 13:07:24 +00:00
|
|
|
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.
|
|
|
|
|
2015-01-11 13:45:54 +00:00
|
|
|
ChibiOS is distributed in the hope that it will be useful,
|
2009-08-16 13:07:24 +00:00
|
|
|
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
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2016-03-23 18:43:19 +00:00
|
|
|
#ifndef CHMSG_H
|
|
|
|
#define CHMSG_H
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2015-03-05 21:28:51 +00:00
|
|
|
#if (CH_CFG_USE_MESSAGES == TRUE) || 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();
|
|
|
|
|
2016-02-16 10:07:00 +00:00
|
|
|
return (bool)(tp->msgqueue.next != (thread_t *)&tp->msgqueue);
|
2013-07-19 14:51:35 +00:00
|
|
|
}
|
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) {
|
|
|
|
|
2016-02-16 10:07:00 +00:00
|
|
|
chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state");
|
2016-01-07 10:12:42 +00:00
|
|
|
|
2016-02-16 10:07:00 +00:00
|
|
|
return tp->u.sentmsg;
|
2013-07-19 14:51:35 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-03-05 21:28:51 +00:00
|
|
|
#endif /* CH_CFG_USE_MESSAGES == TRUE */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
2016-03-23 18:43:19 +00:00
|
|
|
#endif /* CHMSG_H */
|
2009-08-16 13:07:24 +00:00
|
|
|
|
|
|
|
/** @} */
|