diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-01-02 15:00:20 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-01-02 15:00:20 +0000 |
commit | f0526e72d81b13f115ffd6dcbca5620f62b14d2f (patch) | |
tree | e5ca28ef151a3f571948b46f6966baae81a0e7a2 /os/various | |
parent | 04db761f7e787b9f920aa2c264b6133d1b1815ff (diff) | |
download | ChibiOS-f0526e72d81b13f115ffd6dcbca5620f62b14d2f.tar.gz ChibiOS-f0526e72d81b13f115ffd6dcbca5620f62b14d2f.tar.bz2 ChibiOS-f0526e72d81b13f115ffd6dcbca5620f62b14d2f.zip |
Added mailboxes to the C++ wrapper.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5018 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/various')
-rw-r--r-- | os/various/cpp_wrappers/ch.cpp | 61 | ||||
-rw-r--r-- | os/various/cpp_wrappers/ch.hpp | 231 |
2 files changed, 288 insertions, 4 deletions
diff --git a/os/various/cpp_wrappers/ch.cpp b/os/various/cpp_wrappers/ch.cpp index d6dd61ff7..b6270d8ba 100644 --- a/os/various/cpp_wrappers/ch.cpp +++ b/os/various/cpp_wrappers/ch.cpp @@ -510,6 +510,67 @@ namespace chibios_rt { chEvtBroadcastFlagsI(&ev_source, flags);
}
#endif /* CH_USE_EVENTS */
+
+#if CH_USE_MAILBOXES || defined(__DOXYGEN__)
+ /*------------------------------------------------------------------------*
+ * chibios_rt::Mailbox *
+ *------------------------------------------------------------------------*/
+ Mailbox::Mailbox(msg_t *buf, cnt_t n) {
+
+ chMBInit(&mb, buf, n);
+ }
+
+ void Mailbox::reset(void) {
+
+ chMBReset(&mb);
+ }
+
+ msg_t Mailbox::post(msg_t msg, systime_t time) {
+
+ return chMBPost(&mb, msg, time);
+ }
+
+ msg_t Mailbox::postS(msg_t msg, systime_t time) {
+
+ return chMBPostS(&mb, msg, time);
+ }
+
+ msg_t Mailbox::postI(msg_t msg) {
+
+ return chMBPostI(&mb, msg);
+ }
+
+ msg_t Mailbox::postAhead(msg_t msg, systime_t time) {
+
+ return chMBPostAhead(&mb, msg, time);
+ }
+
+ msg_t Mailbox::postAheadS(msg_t msg, systime_t time) {
+
+ return chMBPostAheadS(&mb, msg, time);
+ }
+
+ msg_t Mailbox::postAheadI(msg_t msg) {
+
+ return chMBPostAheadI(&mb, msg);
+ }
+
+ msg_t Mailbox::fetch(msg_t *msgp, systime_t time) {
+
+ return chMBFetch(&mb, msgp, time);
+ }
+
+ msg_t Mailbox::fetchS(msg_t *msgp, systime_t time) {
+
+ return chMBFetchS(&mb, msgp, time);
+ }
+
+ msg_t Mailbox::fetchI(msg_t *msgp) {
+
+ return chMBFetchI(&mb, msgp);
+ }
+
+#endif /* CH_USE_MAILBOXES */
}
/** @} */
diff --git a/os/various/cpp_wrappers/ch.hpp b/os/various/cpp_wrappers/ch.hpp index a1928e852..b660a319b 100644 --- a/os/various/cpp_wrappers/ch.hpp +++ b/os/various/cpp_wrappers/ch.hpp @@ -106,7 +106,7 @@ namespace chibios_rt { /**
* @brief Embedded @p VirtualTimer structure.
*/
- struct ::VirtualTimer timer_ref;
+ ::VirtualTimer timer_ref;
/**
* @brief Enables a virtual timer.
@@ -720,7 +720,7 @@ namespace chibios_rt { /**
* @brief Embedded @p ::Semaphore structure.
*/
- struct ::Semaphore sem;
+ ::Semaphore sem;
/**
* @brief Semaphore constructor.
@@ -906,7 +906,7 @@ namespace chibios_rt { /**
* @brief Embedded @p ::Mutex structure.
*/
- struct ::Mutex mutex;
+ ::Mutex mutex;
/**
* @brief Mutex object constructor.
@@ -983,7 +983,7 @@ namespace chibios_rt { /**
* @brief Embedded @p ::CondVar structure.
*/
- struct ::CondVar condvar;
+ ::CondVar condvar;
/**
* @brief CondVar object constructor.
@@ -1192,6 +1192,229 @@ namespace chibios_rt { void broadcastFlagsI(flagsmask_t flags);
};
#endif /* CH_USE_EVENTS */
+
+#if CH_USE_MAILBOXES || defined(__DOXYGEN__)
+ /*------------------------------------------------------------------------*
+ * chibios_rt::Mailbox *
+ *------------------------------------------------------------------------*/
+ class Mailbox {
+ public:
+ /**
+ * @brief Embedded @p ::Mailbox structure.
+ */
+ ::Mailbox mb;
+
+ /**
+ * @brief Mailbox constructor.
+ * @details The embedded @p ::Mailbox structure is initialized.
+ *
+ * @param[in] buf pointer to the messages buffer as an array of
+ * @p msg_t
+ * @param[in] n number of elements in the buffer array
+ *
+ * @api
+ */
+ Mailbox(msg_t *buf, cnt_t n);
+
+ /**
+ * @brief Resets a Mailbox object.
+ * @details All the waiting threads are resumed with status @p RDY_RESET and
+ * the queued messages are lost.
+ *
+ * @api
+ */
+ void reset(void);
+
+ /**
+ * @brief Posts a message into a mailbox.
+ * @details The invoking thread waits until a empty slot in the mailbox becomes
+ * available or the specified time runs out.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @api
+ */
+ msg_t post(msg_t msg, systime_t time);
+
+ /**
+ * @brief Posts a message into a mailbox.
+ * @details The invoking thread waits until a empty slot in the mailbox becomes
+ * available or the specified time runs out.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @sclass
+ */
+ msg_t postS(msg_t msg, systime_t time);
+
+ /**
+ * @brief Posts a message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+ msg_t postI(msg_t msg);
+
+ /**
+ * @brief Posts an high priority message into a mailbox.
+ * @details The invoking thread waits until a empty slot in the mailbox becomes
+ * available or the specified time runs out.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @api
+ */
+ msg_t postAhead(msg_t msg, systime_t time);
+
+ /**
+ * @brief Posts an high priority message into a mailbox.
+ * @details The invoking thread waits until a empty slot in the mailbox becomes
+ * available or the specified time runs out.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @sclass
+ */
+ msg_t postAheadS(msg_t msg, systime_t time);
+
+ /**
+ * @brief Posts an high priority message into a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is full.
+ *
+ * @param[in] msg the message to be posted on the mailbox
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly posted.
+ * @retval RDY_TIMEOUT if the mailbox is full and the message cannot be
+ * posted.
+ *
+ * @iclass
+ */
+ msg_t postAheadI(msg_t msg);
+
+ /**
+ * @brief Retrieves a message from a mailbox.
+ * @details The invoking thread waits until a message is posted in the mailbox
+ * or the specified time runs out.
+ *
+ * @param[out] msgp pointer to a message variable for the received message
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly fetched.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @api
+ */
+ msg_t fetch(msg_t *msgp, systime_t time);
+
+ /**
+ * @brief Retrieves a message from a mailbox.
+ * @details The invoking thread waits until a message is posted in the mailbox
+ * or the specified time runs out.
+ *
+ * @param[out] msgp pointer to a message variable for the received message
+ * @param[in] time the number of ticks before the operation timeouts,
+ * the following special values are allowed:
+ * - @a TIME_IMMEDIATE immediate timeout.
+ * - @a TIME_INFINITE no timeout.
+ * .
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly fetched.
+ * @retval RDY_RESET if the mailbox has been reset while waiting.
+ * @retval RDY_TIMEOUT if the operation has timed out.
+ *
+ * @sclass
+ */
+ msg_t fetchS(msg_t *msgp, systime_t time);
+
+ /**
+ * @brief Retrieves a message from a mailbox.
+ * @details This variant is non-blocking, the function returns a timeout
+ * condition if the queue is empty.
+ *
+ * @param[out] msgp pointer to a message variable for the received message
+ * @return The operation status.
+ * @retval RDY_OK if a message has been correctly fetched.
+ * @retval RDY_TIMEOUT if the mailbox is empty and a message cannot be
+ * fetched.
+ *
+ * @iclass
+ */
+ msg_t fetchI(msg_t *msgp);
+ };
+
+ /*------------------------------------------------------------------------*
+ * chibios_rt::MailboxBuffer *
+ *------------------------------------------------------------------------*/
+ /**
+ * @brief Template class encapsulating a mailbox with its messages buffer.
+ *
+ * @param N size of the mailbox
+ */
+ template <int N>
+ class MailboxBuffer : public Mailbox {
+ private:
+ msg_t mb_buf[N];
+
+ public:
+ /**
+ * @brief BufferMailbox constructor.
+ *
+ * @api
+ */
+ MailboxBuffer(void) : Mailbox(mb_buf,
+ (cnt_t)(sizeof mb_buf / sizeof (msg_t))) {
+ }
+ };
+#endif /* CH_USE_MAILBOXES */
}
#endif /* _CH_HPP_ */
|