chmsg.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
  3. This file is part of ChibiOS.
  4. ChibiOS is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. ChibiOS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /**
  16. * @file chmsg.h
  17. * @brief Messages macros and structures.
  18. *
  19. * @addtogroup messages
  20. * @{
  21. */
  22. #ifndef CHMSG_H
  23. #define CHMSG_H
  24. #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__)
  25. /*===========================================================================*/
  26. /* Module constants. */
  27. /*===========================================================================*/
  28. /*===========================================================================*/
  29. /* Module pre-compile time settings. */
  30. /*===========================================================================*/
  31. /*===========================================================================*/
  32. /* Derived constants and error checks. */
  33. /*===========================================================================*/
  34. /*===========================================================================*/
  35. /* Module data structures and types. */
  36. /*===========================================================================*/
  37. /*===========================================================================*/
  38. /* Module macros. */
  39. /*===========================================================================*/
  40. /*===========================================================================*/
  41. /* External declarations. */
  42. /*===========================================================================*/
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. msg_t chMsgSend(thread_t *tp, msg_t msg);
  47. thread_t * chMsgWait(void);
  48. void chMsgRelease(thread_t *tp, msg_t msg);
  49. #ifdef __cplusplus
  50. }
  51. #endif
  52. /*===========================================================================*/
  53. /* External declarations. */
  54. /*===========================================================================*/
  55. /**
  56. * @brief Evaluates to @p true if the thread has pending messages.
  57. *
  58. * @param[in] tp pointer to the thread
  59. * @return The pending messages status.
  60. *
  61. * @iclass
  62. */
  63. static inline bool chMsgIsPendingI(thread_t *tp) {
  64. chDbgCheckClassI();
  65. return (bool)(tp->msgqueue.next != (thread_t *)&tp->msgqueue);
  66. }
  67. /**
  68. * @brief Returns the message carried by the specified thread.
  69. * @pre This function must be invoked immediately after exiting a call
  70. * to @p chMsgWait().
  71. *
  72. * @param[in] tp pointer to the thread
  73. * @return The message carried by the sender.
  74. *
  75. * @api
  76. */
  77. static inline msg_t chMsgGet(thread_t *tp) {
  78. chDbgAssert(tp->state == CH_STATE_SNDMSG, "invalid state");
  79. return tp->u.sentmsg;
  80. }
  81. /**
  82. * @brief Releases the thread waiting on top of the messages queue.
  83. * @pre Invoke this function only after a message has been received
  84. * using @p chMsgWait().
  85. *
  86. * @param[in] tp pointer to the thread
  87. * @param[in] msg message to be returned to the sender
  88. *
  89. * @sclass
  90. */
  91. static inline void chMsgReleaseS(thread_t *tp, msg_t msg) {
  92. chDbgCheckClassS();
  93. chSchWakeupS(tp, msg);
  94. }
  95. #endif /* CH_CFG_USE_MESSAGES == TRUE */
  96. #endif /* CHMSG_H */
  97. /** @} */