diff --git a/firmware/common/message_queue.cpp b/firmware/common/message_queue.cpp index 40705a93..54e9a233 100644 --- a/firmware/common/message_queue.cpp +++ b/firmware/common/message_queue.cpp @@ -20,33 +20,3 @@ */ #include "message_queue.hpp" - -#include "ch.h" -#include "lpc43xx_cpp.hpp" - -using namespace lpc43xx; - -bool MessageQueue::push(const void* const buf, const size_t len) { - const auto result = fifo.in_r(buf, len); - const bool success = (result == len); - if( success ) { - signal(); - } - return success; -} - -size_t MessageQueue::pop(void* const buf, const size_t len) { - return fifo.out_r(buf, len); -} - -#if defined(LPC43XX_M0) -void MessageQueue::signal() { - creg::m0apptxevent::assert(); -} -#endif - -#if defined(LPC43XX_M4) -void MessageQueue::signal() { - creg::m4txevent::assert(); -} -#endif diff --git a/firmware/common/message_queue.hpp b/firmware/common/message_queue.hpp index 400ecdea..814ec007 100644 --- a/firmware/common/message_queue.hpp +++ b/firmware/common/message_queue.hpp @@ -27,6 +27,10 @@ #include "message.hpp" #include "fifo.hpp" +#include "lpc43xx_cpp.hpp" +using namespace lpc43xx; + +template class MessageQueue { public: template @@ -37,7 +41,9 @@ public: return push(&message, sizeof(message)); } - size_t pop(void* const buf, const size_t len); + size_t pop(void* const buf, const size_t len) { + return fifo.out_r(buf, len); + } size_t len() const { return fifo.len(); @@ -48,11 +54,29 @@ public: } private: - FIFO fifo; + FIFO fifo; - bool push(const void* const buf, const size_t len); + bool push(const void* const buf, const size_t len) { + const auto result = fifo.in_r(buf, len); + const bool success = (result == len); + if( success ) { + signal(); + } + return success; + } - void signal(); + +#if defined(LPC43XX_M0) + void signal() { + creg::m0apptxevent::assert(); + } +#endif + +#if defined(LPC43XX_M4) + void signal() { + creg::m4txevent::assert(); + } +#endif }; #endif/*__MESSAGE_QUEUE_H__*/ diff --git a/firmware/common/portapack_shared_memory.hpp b/firmware/common/portapack_shared_memory.hpp index c4ae6aab..a0fd7010 100644 --- a/firmware/common/portapack_shared_memory.hpp +++ b/firmware/common/portapack_shared_memory.hpp @@ -32,8 +32,8 @@ struct TouchADCFrame { /* NOTE: These structures must be located in the same location in both M4 and M0 binaries */ struct SharedMemory { - MessageQueue baseband_queue; - MessageQueue application_queue; + MessageQueue<12> baseband_queue; + MessageQueue<11> application_queue; // TODO: M0 should directly configure and control DMA channel that is // acquiring ADC samples. @@ -44,8 +44,8 @@ extern SharedMemory& shared_memory; #if defined(LPC43XX_M0) inline void init_message_queues() { - new (&shared_memory.baseband_queue) MessageQueue(); - new (&shared_memory.application_queue) MessageQueue(); + new (&shared_memory.baseband_queue) MessageQueue<12>(); + new (&shared_memory.application_queue) MessageQueue<11>(); } #endif