aboutsummaryrefslogtreecommitdiffstats
path: root/os/various/cpp_wrappers/ch.hpp
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-09-11 08:36:13 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2014-09-11 08:36:13 +0000
commit7e5f127c41b8fb167e6dfb834a4a39bb8cc35bbf (patch)
tree99dfd14ee62ca90aa9c39da8f7bf3f4684e47f50 /os/various/cpp_wrappers/ch.hpp
parent05f8c30707338157d66beff3c28cbdb79b0646aa (diff)
downloadChibiOS-7e5f127c41b8fb167e6dfb834a4a39bb8cc35bbf.tar.gz
ChibiOS-7e5f127c41b8fb167e6dfb834a4a39bb8cc35bbf.tar.bz2
ChibiOS-7e5f127c41b8fb167e6dfb834a4a39bb8cc35bbf.zip
[CPP wrappers] Base mailbox class now strongly typed and template based.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@7260 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/various/cpp_wrappers/ch.hpp')
-rw-r--r--os/various/cpp_wrappers/ch.hpp138
1 files changed, 91 insertions, 47 deletions
diff --git a/os/various/cpp_wrappers/ch.hpp b/os/various/cpp_wrappers/ch.hpp
index a7fd44df9..2c2a82fb0 100644
--- a/os/various/cpp_wrappers/ch.hpp
+++ b/os/various/cpp_wrappers/ch.hpp
@@ -1843,10 +1843,14 @@ namespace chibios_rt {
* chibios_rt::Mailbox *
*------------------------------------------------------------------------*/
/**
- * @brief Class encapsulating a mailbox.
+ * @brief Base mailbox class.
+ *
+ * @param T type of objects that mailbox able to handle
*/
- class Mailbox {
+ template <typename T>
+ class MailboxBase {
public:
+
/**
* @brief Embedded @p ::Mailbox structure.
*/
@@ -1862,7 +1866,11 @@ namespace chibios_rt {
*
* @init
*/
- Mailbox(msg_t *buf, cnt_t n);
+ MailboxBase(msg_t *buf, cnt_t n) {
+ /* static_assert(sizeof(msg_t) >= sizeof(T),
+ "You can not pass objects bigger than msg_t"); */
+ chMBObjectInit(&mb, buf, n);
+ }
/**
* @brief Resets a Mailbox object.
@@ -1871,7 +1879,10 @@ namespace chibios_rt {
*
* @api
*/
- void reset(void);
+ void reset(void) {
+
+ chMBReset(&mb);
+ }
/**
* @brief Posts a message into a mailbox.
@@ -1885,13 +1896,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @api
*/
- msg_t post(msg_t msg, systime_t time);
+ msg_t post(T msg, systime_t time) {
+
+ return chMBPost(&mb, reinterpret_cast<msg_t>(msg), time);
+ }
/**
* @brief Posts a message into a mailbox.
@@ -1905,13 +1919,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @sclass
*/
- msg_t postS(msg_t msg, systime_t time);
+ msg_t postS(T msg, systime_t time) {
+
+ return chMBPostS(&mb, reinterpret_cast<msg_t>(msg), time);
+ }
/**
* @brief Posts a message into a mailbox.
@@ -1920,13 +1937,16 @@ namespace chibios_rt {
*
* @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
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_TIMEOUT if the mailbox is full and the message cannot be
* posted.
*
* @iclass
*/
- msg_t postI(msg_t msg);
+ msg_t postI(T msg) {
+
+ return chMBPostI(&mb, reinterpret_cast<msg_t>(msg));
+ }
/**
* @brief Posts an high priority message into a mailbox.
@@ -1940,13 +1960,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @api
*/
- msg_t postAhead(msg_t msg, systime_t time);
+ msg_t postAhead(T msg, systime_t time) {
+
+ return chMBPostAhead(&mb, reinterpret_cast<msg_t>(msg), time);
+ }
/**
* @brief Posts an high priority message into a mailbox.
@@ -1960,13 +1983,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @sclass
*/
- msg_t postAheadS(msg_t msg, systime_t time);
+ msg_t postAheadS(T msg, systime_t time) {
+
+ return chMBPostAheadS(&mb, reinterpret_cast<msg_t>(msg), time);
+ }
/**
* @brief Posts an high priority message into a mailbox.
@@ -1975,13 +2001,16 @@ namespace chibios_rt {
*
* @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
+ * @retval MSG_OK if a message has been correctly posted.
+ * @retval MSG_TIMEOUT if the mailbox is full and the message cannot be
* posted.
*
* @iclass
*/
- msg_t postAheadI(msg_t msg);
+ msg_t postAheadI(T msg) {
+
+ return chMBPostAheadI(&mb, reinterpret_cast<msg_t>(msg));
+ }
/**
* @brief Retrieves a message from a mailbox.
@@ -1995,13 +2024,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly fetched.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @api
*/
- msg_t fetch(msg_t *msgp, systime_t time);
+ msg_t fetch(T *msgp, systime_t time) {
+
+ return chMBFetch(&mb, reinterpret_cast<msg_t*>(msgp), time);
+ }
/**
* @brief Retrieves a message from a mailbox.
@@ -2015,13 +2047,16 @@ namespace chibios_rt {
* - @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.
+ * @retval MSG_OK if a message has been correctly fetched.
+ * @retval MSG_RESET if the mailbox has been reset while waiting.
+ * @retval MSG_TIMEOUT if the operation has timed out.
*
* @sclass
*/
- msg_t fetchS(msg_t *msgp, systime_t time);
+ msg_t fetchS(T *msgp, systime_t time) {
+
+ return chMBFetchS(&mb, reinterpret_cast<msg_t*>(msgp), time);
+ }
/**
* @brief Retrieves a message from a mailbox.
@@ -2031,13 +2066,16 @@ namespace chibios_rt {
* @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
+ * @retval MSG_OK if a message has been correctly fetched.
+ * @retval MSG_TIMEOUT if the mailbox is empty and a message cannot be
* fetched.
*
* @iclass
*/
- msg_t fetchI(msg_t *msgp);
+ msg_t fetchI(T *msgp) {
+
+ return chMBFetchI(&mb, reinterpret_cast<msg_t*>(msgp));
+ }
/**
* @brief Returns the number of free message slots into a mailbox.
@@ -2050,7 +2088,10 @@ namespace chibios_rt {
*
* @iclass
*/
- cnt_t getFreeCountI(void);
+ cnt_t getFreeCountI(void) {
+
+ return chMBGetFreeCountI(&mb);
+ }
/**
* @brief Returns the number of used message slots into a mailbox.
@@ -2063,30 +2104,33 @@ namespace chibios_rt {
*
* @iclass
*/
- cnt_t getUsedCountI(void);
+ cnt_t getUsedCountI(void) {
+
+ return chMBGetUsedCountI(&mb);
+ }
};
/*------------------------------------------------------------------------*
- * chibios_rt::MailboxBuffer *
+ * chibios_rt::Mailbox *
*------------------------------------------------------------------------*/
/**
- * @brief Template class encapsulating a mailbox and its messages buffer.
+ * @brief Template class encapsulating a mailbox and its messages buffer.
*
- * @param N size of the mailbox
+ * @param N length of the mailbox buffer
*/
- template <int N>
- class MailboxBuffer : public Mailbox {
+ template <typename T, int N>
+ class Mailbox : public MailboxBase<T> {
private:
msg_t mb_buf[N];
public:
/**
- * @brief BufferMailbox constructor.
+ * @brief Mailbox constructor.
*
* @init
*/
- MailboxBuffer(void) : Mailbox(mb_buf,
- (cnt_t)(sizeof mb_buf / sizeof (msg_t))) {
+ Mailbox(void) :
+ MailboxBase<T>(mb_buf, (cnt_t)(sizeof mb_buf / sizeof (msg_t))) {
}
};
#endif /* CH_CFG_USE_MAILBOXES */