From 9742a058e91faa171bfb7be9e908e260eb8ee5c2 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 20 Aug 2015 17:56:19 -0700 Subject: [PATCH] Move event loop into dispatcher, provide a way to exit. --- firmware/baseband/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index cf680bd3..48009a1e 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -704,6 +704,17 @@ public: return message_map; } + void run() { + while(is_running) { + const auto events = wait(); + dispatch(events); + } + } + + void request_stop() { + is_running = false; + } + eventmask_t wait() { return chEvtWaitAny(ALL_EVENTS); } @@ -721,6 +732,8 @@ public: private: MessageHandlerMap message_map; + bool is_running = true; + void handle_baseband_queue() { while( !shared_memory.baseband_queue.is_empty() ) { std::array message_buffer; @@ -853,10 +866,7 @@ int main(void) { ); //baseband::dma::allocate(4, 2048); - while(true) { - const auto events = event_dispatcher.wait(); - event_dispatcher.dispatch(events); - } - + event_dispatcher.run(); + return 0; }