From 74c8429f75f8249241f0558f289cd54d196b61dc Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 25 Jun 2016 10:57:16 -0700 Subject: [PATCH] Take processor as argument to BasebandThread. Remove lots of dependency on specific processors. Reduce state by removing processor switching from BasebandThread. --- firmware/baseband/baseband_thread.cpp | 60 ++++----------------------- firmware/baseband/baseband_thread.hpp | 15 +++---- 2 files changed, 14 insertions(+), 61 deletions(-) diff --git a/firmware/baseband/baseband_thread.cpp b/firmware/baseband/baseband_thread.cpp index 0f575ad6..0784d9bd 100644 --- a/firmware/baseband/baseband_thread.cpp +++ b/firmware/baseband/baseband_thread.cpp @@ -31,15 +31,6 @@ #include "i2s.hpp" using namespace lpc43xx; -#include "proc_am_audio.hpp" -#include "proc_nfm_audio.hpp" -#include "proc_wfm_audio.hpp" -#include "proc_ais.hpp" -#include "proc_wideband_spectrum.hpp" -#include "proc_tpms.hpp" -#include "proc_ert.hpp" -#include "proc_capture.hpp" - #include "portapack_shared_memory.hpp" #include @@ -50,7 +41,13 @@ WORKING_AREA(baseband_thread_wa, 4096); Thread* BasebandThread::thread = nullptr; -BasebandThread::BasebandThread(const tprio_t priority) { +BasebandThread::BasebandThread( + uint32_t sampling_rate, + BasebandProcessor* const baseband_processor, + const tprio_t priority +) : baseband_processor { baseband_processor }, + sampling_rate { sampling_rate } +{ thread = chThdCreateStatic(baseband_thread_wa, sizeof(baseband_thread_wa), priority, ThreadBase::fn, this @@ -63,33 +60,6 @@ BasebandThread::~BasebandThread() { thread = nullptr; } -void BasebandThread::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; -} - -void BasebandThread::on_message(const Message* const message) { - if( message->id == Message::ID::BasebandConfiguration ) { - set_configuration(reinterpret_cast(message)->configuration); - } else { - if( baseband_processor ) { - baseband_processor->on_message(message); - } - } -} - void BasebandThread::run() { baseband_sgpio.init(); baseband::dma::init(); @@ -110,7 +80,7 @@ void BasebandThread::run() { const auto buffer_tmp = baseband::dma::wait_for_rx_buffer(); if( buffer_tmp ) { buffer_c8_t buffer { - buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate + buffer_tmp.p, buffer_tmp.count, sampling_rate }; if( baseband_processor ) { @@ -123,17 +93,3 @@ void BasebandThread::run() { baseband::dma::disable(); baseband_sgpio.streaming_disable(); } - -BasebandProcessor* BasebandThread::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(); - case 7: return new CaptureProcessor(); - default: return nullptr; - } -} diff --git a/firmware/baseband/baseband_thread.hpp b/firmware/baseband/baseband_thread.hpp index ce09a51b..3263b4f1 100644 --- a/firmware/baseband/baseband_thread.hpp +++ b/firmware/baseband/baseband_thread.hpp @@ -30,10 +30,12 @@ class BasebandThread : public ThreadBase { public: - BasebandThread(const tprio_t priority); + BasebandThread( + uint32_t sampling_rate, + BasebandProcessor* const baseband_processor, + const tprio_t priority + ); ~BasebandThread(); - - void on_message(const Message* const message); // This getter should die, it's just here to leak information to code that // isn't in the right place to begin with. @@ -45,14 +47,9 @@ private: static Thread* thread; BasebandProcessor* baseband_processor { nullptr }; - - BasebandConfiguration baseband_configuration; + uint32_t sampling_rate; void run() override; - - BasebandProcessor* create_processor(const int32_t mode); - - void set_configuration(const BasebandConfiguration& new_configuration); }; #endif/*__BASEBAND_THREAD_H__*/