diff options
| -rw-r--r-- | demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile | 6 | ||||
| -rw-r--r-- | os/various/cpp_wrappers/ch.cpp | 70 | ||||
| -rw-r--r-- | os/various/cpp_wrappers/ch.hpp | 138 | 
3 files changed, 94 insertions, 120 deletions
| diff --git a/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile b/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile index 7360b53c2..8d16de8c1 100644 --- a/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile +++ b/demos/STM32/RT-STM32F407-DISCOVERY-G++/Makefile @@ -88,6 +88,7 @@ include $(CHIBIOS)/os/hal/osal/rt/osal.mk  include $(CHIBIOS)/os/rt/rt.mk  include $(CHIBIOS)/os/rt/ports/ARMCMx/compilers/GCC/mk/port_stm32f4xx.mk  include $(CHIBIOS)/test/rt/test.mk +include $(CHIBIOS)/os/various/cpp_wrappers/chcpp.mk  # Define linker script file here  LDSCRIPT= $(PORTLD)/STM32F407xG.ld @@ -108,9 +109,8 @@ CSRC = $(PORTSRC) \  # C++ sources that can be compiled in ARM or THUMB mode depending on the global  # setting. -CPPSRC = main.cpp \ -         $(CHIBIOS)/os/various/cpp_wrappers/ch.cpp \ -         $(CHIBIOS)/os/various/cpp_wrappers/syscalls_cpp.cpp \ +CPPSRC = $(CHCPPSRC) \ +         main.cpp  # C sources to be compiled in ARM mode regardless of the global setting.  # NOTE: Mixing ARM and THUMB mode enables the -mthumb-interwork compiler diff --git a/os/various/cpp_wrappers/ch.cpp b/os/various/cpp_wrappers/ch.cpp index d6f4ca0c1..fc9bd8e9a 100644 --- a/os/various/cpp_wrappers/ch.cpp +++ b/os/various/cpp_wrappers/ch.cpp @@ -745,76 +745,6 @@ namespace chibios_rt {    }
  #endif /* CH_CFG_USE_QUEUES */
 -#if CH_CFG_USE_MAILBOXES
 -  /*------------------------------------------------------------------------*
 -   * chibios_rt::Mailbox                                                    *
 -   *------------------------------------------------------------------------*/
 -  Mailbox::Mailbox(msg_t *buf, cnt_t n) {
 -
 -    chMBObjectInit(&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);
 -  }
 -
 -  cnt_t Mailbox::getFreeCountI(void) {
 -
 -    return chMBGetFreeCountI(&mb);
 -  }
 -
 -  cnt_t Mailbox::getUsedCountI(void) {
 -
 -    return chMBGetUsedCountI(&mb);
 -  }
 -#endif /* CH_CFG_USE_MAILBOXES */
 -
  #if CH_CFG_USE_MEMPOOLS
    /*------------------------------------------------------------------------*
     * chibios_rt::MemoryPool                                                 *
 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 */
 | 
