From 82f367dfeaa5eb6c46210458957d0b029399301f Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 10 Dec 2015 14:41:07 -0800 Subject: [PATCH] Move code into BasebandThread. --- firmware/baseband/main.cpp | 89 +++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index bd2c458ab..66ce0320b 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -102,6 +102,8 @@ private: const char* const name; }; +static constexpr auto direction = baseband::Direction::Receive; + class BasebandThread : public ThreadBase { public: BasebandThread( @@ -116,6 +118,23 @@ public: ); } + void set_configuration(const BasebandConfiguration& new_configuration) { + if( new_configuration.mode != baseband_configuration.mode ) { + disable(); + + // TODO: Timing problem around disabling DMA and nulling and deleting old processor + auto old_p = baseband_processor; + baseband_processor = nullptr; + delete old_p; + + baseband_processor = create_processor(new_configuration.mode); + + enable(); + } + + baseband_configuration = new_configuration; + } + Thread* thread_main { nullptr }; Thread* thread_rssi { nullptr }; BasebandProcessor* baseband_processor { nullptr }; @@ -151,6 +170,36 @@ private: ); } } + + BasebandProcessor* create_processor(const int32_t mode) { + switch(mode) { + case 0: return new NarrowbandAMAudio(); + case 1: return new NarrowbandFMAudio(); + case 2: return new WidebandFMAudio(); + case 3: return new AISProcessor(); + case 4: return new WidebandSpectrum(); + case 5: return new TPMSProcessor(); + case 6: return new ERTProcessor(); + default: return nullptr; + } + } + + void disable() { + if( baseband_processor ) { + i2s::i2s0::tx_mute(); + baseband::dma::disable(); + rf::rssi::stop(); + } + } + + void enable() { + if( baseband_processor ) { + if( direction == baseband::Direction::Receive ) { + rf::rssi::start(); + } + baseband::dma::enable(direction); + } + } }; class RSSIThread : public ThreadBase { @@ -319,21 +368,6 @@ private: } }; -static constexpr auto direction = baseband::Direction::Receive; - -static BasebandProcessor* create_processor(const int32_t mode) { - switch(mode) { - case 0: return new NarrowbandAMAudio(); - case 1: return new NarrowbandFMAudio(); - case 2: return new WidebandFMAudio(); - case 3: return new AISProcessor(); - case 4: return new WidebandSpectrum(); - case 5: return new TPMSProcessor(); - case 6: return new ERTProcessor(); - default: return nullptr; - } -} - int main(void) { init(); @@ -346,30 +380,7 @@ int main(void) { message_handlers.register_handler(Message::ID::BasebandConfiguration, [&message_handlers](const Message* const p) { auto message = reinterpret_cast(p); - if( message->configuration.mode != baseband_thread.baseband_configuration.mode ) { - - if( baseband_thread.baseband_processor ) { - i2s::i2s0::tx_mute(); - baseband::dma::disable(); - rf::rssi::stop(); - } - - // TODO: Timing problem around disabling DMA and nulling and deleting old processor - auto old_p = baseband_thread.baseband_processor; - baseband_thread.baseband_processor = nullptr; - delete old_p; - - baseband_thread.baseband_processor = create_processor(message->configuration.mode); - - if( baseband_thread.baseband_processor ) { - if( direction == baseband::Direction::Receive ) { - rf::rssi::start(); - } - baseband::dma::enable(direction); - } - } - - baseband_thread.baseband_configuration = message->configuration; + baseband_thread.set_configuration(message->configuration); } );