aboutsummaryrefslogtreecommitdiffstats
path: root/os/kernel/include/chmboxes.h
diff options
context:
space:
mode:
Diffstat (limited to 'os/kernel/include/chmboxes.h')
-rw-r--r--os/kernel/include/chmboxes.h149
1 files changed, 93 insertions, 56 deletions
diff --git a/os/kernel/include/chmboxes.h b/os/kernel/include/chmboxes.h
index 388ef07a6..6cb903e82 100644
--- a/os/kernel/include/chmboxes.h
+++ b/os/kernel/include/chmboxes.h
@@ -31,13 +31,26 @@
#if CH_USE_MAILBOXES || defined(__DOXYGEN__)
-/*
- * Module dependencies check.
- */
+/*===========================================================================*/
+/* Module constants. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Module pre-compile time settings. */
+/*===========================================================================*/
+
+/*===========================================================================*/
+/* Derived constants and error checks. */
+/*===========================================================================*/
+
#if !CH_USE_SEMAPHORES
#error "CH_USE_MAILBOXES requires CH_USE_SEMAPHORES"
#endif
+/*===========================================================================*/
+/* Module data structures and types. */
+/*===========================================================================*/
+
/**
* @brief Structure representing a mailbox object.
*/
@@ -52,39 +65,79 @@ typedef struct {
@p semaphore_t. */
semaphore_t mb_emptysem; /**< @brief Empty counter
@p semaphore_t. */
-} Mailbox;
+} mailbox_t;
+
+/*===========================================================================*/
+/* Module macros. */
+/*===========================================================================*/
+
+/**
+ * @brief Data part of a static mailbox initializer.
+ * @details This macro should be used when statically initializing a
+ * mailbox that is part of a bigger structure.
+ *
+ * @param[in] name the name of the mailbox variable
+ * @param[in] buffer pointer to the mailbox buffer area
+ * @param[in] size size of the mailbox buffer area
+ */
+#define _MAILBOX_DATA(name, buffer, size) { \
+ (msg_t *)(buffer), \
+ (msg_t *)(buffer) + size, \
+ (msg_t *)(buffer), \
+ (msg_t *)(buffer), \
+ _SEMAPHORE_DATA(name.mb_fullsem, 0), \
+ _SEMAPHORE_DATA(name.mb_emptysem, size), \
+}
+
+/**
+ * @brief Static mailbox initializer.
+ * @details Statically initialized mailboxes require no explicit
+ * initialization using @p chMBInit().
+ *
+ * @param[in] name the name of the mailbox variable
+ * @param[in] buffer pointer to the mailbox buffer area
+ * @param[in] size size of the mailbox buffer area
+ */
+#define MAILBOX_DECL(name, buffer, size) \
+ mailbox_t name = _MAILBOX_DATA(name, buffer, size)
+
+/*===========================================================================*/
+/* External declarations. */
+/*===========================================================================*/
#ifdef __cplusplus
extern "C" {
#endif
- void chMBInit(Mailbox *mbp, msg_t *buf, cnt_t n);
- void chMBReset(Mailbox *mbp);
- msg_t chMBPost(Mailbox *mbp, msg_t msg, systime_t timeout);
- msg_t chMBPostS(Mailbox *mbp, msg_t msg, systime_t timeout);
- msg_t chMBPostI(Mailbox *mbp, msg_t msg);
- msg_t chMBPostAhead(Mailbox *mbp, msg_t msg, systime_t timeout);
- msg_t chMBPostAheadS(Mailbox *mbp, msg_t msg, systime_t timeout);
- msg_t chMBPostAheadI(Mailbox *mbp, msg_t msg);
- msg_t chMBFetch(Mailbox *mbp, msg_t *msgp, systime_t timeout);
- msg_t chMBFetchS(Mailbox *mbp, msg_t *msgp, systime_t timeout);
- msg_t chMBFetchI(Mailbox *mbp, msg_t *msgp);
+ void chMBInit(mailbox_t *mbp, msg_t *buf, cnt_t n);
+ void chMBReset(mailbox_t *mbp);
+ msg_t chMBPost(mailbox_t *mbp, msg_t msg, systime_t timeout);
+ msg_t chMBPostS(mailbox_t *mbp, msg_t msg, systime_t timeout);
+ msg_t chMBPostI(mailbox_t *mbp, msg_t msg);
+ msg_t chMBPostAhead(mailbox_t *mbp, msg_t msg, systime_t timeout);
+ msg_t chMBPostAheadS(mailbox_t *mbp, msg_t msg, systime_t timeout);
+ msg_t chMBPostAheadI(mailbox_t *mbp, msg_t msg);
+ msg_t chMBFetch(mailbox_t *mbp, msg_t *msgp, systime_t timeout);
+ msg_t chMBFetchS(mailbox_t *mbp, msg_t *msgp, systime_t timeout);
+ msg_t chMBFetchI(mailbox_t *mbp, msg_t *msgp);
#ifdef __cplusplus
}
#endif
-/**
- * @name Macro Functions
- * @{
- */
+/*===========================================================================*/
+/* Module inline functions. */
+/*===========================================================================*/
+
/**
* @brief Returns the mailbox buffer size.
*
- * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] mbp the pointer to an initialized mailbox_t object
*
* @iclass
*/
-#define chMBSizeI(mbp) \
- ((mbp)->mb_top - (mbp)->mb_buffer)
+static inline size_t chMBSizeI(mailbox_t *mbp) {
+
+ return (size_t)(mbp->mb_top - mbp->mb_buffer);
+}
/**
* @brief Returns the number of free message slots into a mailbox.
@@ -93,12 +146,17 @@ extern "C" {
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*
- * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] mbp the pointer to an initialized mailbox_t object
* @return The number of empty message slots.
*
* @iclass
*/
-#define chMBGetFreeCountI(mbp) chSemGetCounterI(&(mbp)->mb_emptysem)
+static inline cnt_t chMBGetFreeCountI(mailbox_t *mbp) {
+
+ chDbgCheckClassI();
+
+ return chSemGetCounterI(&mbp->mb_emptysem);
+}
/**
* @brief Returns the number of used message slots into a mailbox.
@@ -107,12 +165,17 @@ extern "C" {
* @note The returned value can be less than zero when there are waiting
* threads on the internal semaphore.
*
- * @param[in] mbp the pointer to an initialized Mailbox object
+ * @param[in] mbp the pointer to an initialized mailbox_t object
* @return The number of queued messages.
*
* @iclass
*/
-#define chMBGetUsedCountI(mbp) chSemGetCounterI(&(mbp)->mb_fullsem)
+static inline cnt_t chMBGetUsedCountI(mailbox_t *mbp) {
+
+ chDbgCheckClassI();
+
+ return chSemGetCounterI(&mbp->mb_fullsem);
+}
/**
* @brief Returns the next message in the queue without removing it.
@@ -123,38 +186,12 @@ extern "C" {
*
* @iclass
*/
-#define chMBPeekI(mbp) (*(mbp)->mb_rdptr)
-/** @} */
+static inline cnt_t chMBPeekI(mailbox_t *mbp) {
-/**
- * @brief Data part of a static mailbox initializer.
- * @details This macro should be used when statically initializing a
- * mailbox that is part of a bigger structure.
- *
- * @param[in] name the name of the mailbox variable
- * @param[in] buffer pointer to the mailbox buffer area
- * @param[in] size size of the mailbox buffer area
- */
-#define _MAILBOX_DATA(name, buffer, size) { \
- (msg_t *)(buffer), \
- (msg_t *)(buffer) + size, \
- (msg_t *)(buffer), \
- (msg_t *)(buffer), \
- _SEMAPHORE_DATA(name.mb_fullsem, 0), \
- _SEMAPHORE_DATA(name.mb_emptysem, size), \
-}
+ chDbgCheckClassI();
-/**
- * @brief Static mailbox initializer.
- * @details Statically initialized mailboxes require no explicit
- * initialization using @p chMBInit().
- *
- * @param[in] name the name of the mailbox variable
- * @param[in] buffer pointer to the mailbox buffer area
- * @param[in] size size of the mailbox buffer area
- */
-#define MAILBOX_DECL(name, buffer, size) \
- Mailbox name = _MAILBOX_DATA(name, buffer, size)
+ return *mbp->mb_rdptr;
+}
#endif /* CH_USE_MAILBOXES */