diff --git a/firmware/application/capture_thread.hpp b/firmware/application/capture_thread.hpp index d9977da0..357c7720 100644 --- a/firmware/application/capture_thread.hpp +++ b/firmware/application/capture_thread.hpp @@ -37,21 +37,28 @@ using namespace hackrf::one; class StreamOutput { public: - StreamOutput( - ) : fifo { reinterpret_cast*>(shared_memory.FIFO_HACK) } - { + StreamOutput() { + shared_memory.baseband_queue.push_and_wait( + CaptureConfigMessage { &config } + ); + } + + ~StreamOutput() { + shared_memory.baseband_queue.push_and_wait( + CaptureConfigMessage { nullptr } + ); } size_t available() { - return fifo->len(); + return config.fifo->len(); } size_t read(void* const data, const size_t length) { - return fifo->out(reinterpret_cast(data), length); + return config.fifo->out(reinterpret_cast(data), length); } private: - FIFO* const fifo; + CaptureConfig config; }; class CaptureThread { @@ -66,21 +73,25 @@ public: } ~CaptureThread() { - chThdTerminate(thread); - chEvtSignal(thread, EVT_FIFO_HIGHWATER); - const auto success = chThdWait(thread); + const auto thread_tmp = thread; - if( !success ) { - led_tx.on(); + if( thread_tmp ) { + thread = nullptr; + chThdTerminate(thread_tmp); + chEvtSignal(thread_tmp, EVT_FIFO_HIGHWATER); + const auto success = chThdWait(thread_tmp); + + if( !success ) { + led_tx.on(); + } } } static void check_fifo_isr() { - if( (shared_memory.FIFO_HACK != nullptr) && (thread != nullptr) ) { - auto fifo = reinterpret_cast*>(shared_memory.FIFO_HACK); - if( fifo->len() >= write_size ) { - chEvtSignalI(thread, EVT_FIFO_HIGHWATER); - } + // TODO: Prevent over-signalling by transmitting a set of + // flags from the baseband core. + if( thread ) { + chEvtSignalI(thread, EVT_FIFO_HIGHWATER); } } diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 28aaeb50..2ed05b18 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -255,6 +255,4 @@ void EventDispatcher::init_message_queues() { new (&shared_memory.application_queue) MessageQueue( shared_memory.application_queue_data, SharedMemory::application_queue_k ); - - shared_memory.FIFO_HACK = nullptr; } diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index 0a4b5faf..9af3295e 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -63,6 +63,10 @@ void NarrowbandAMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::CaptureConfig: + capture_config(*reinterpret_cast(message)); + break; + default: break; } @@ -93,3 +97,11 @@ void NarrowbandAMAudio::configure(const AMConfigureMessage& message) { configured = true; } + +void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) { + if( message.config ) { + audio_output.set_stream(std::make_unique(14, *message.config)); + } else { + audio_output.set_stream(nullptr); + } +} diff --git a/firmware/baseband/proc_am_audio.hpp b/firmware/baseband/proc_am_audio.hpp index af94c416..051f1703 100644 --- a/firmware/baseband/proc_am_audio.hpp +++ b/firmware/baseband/proc_am_audio.hpp @@ -72,6 +72,7 @@ private: bool configured { false }; void configure(const AMConfigureMessage& message); + void capture_config(const CaptureConfigMessage& message); buffer_f32_t demodulate(const buffer_c16_t& channel); }; diff --git a/firmware/baseband/proc_capture.cpp b/firmware/baseband/proc_capture.cpp index e061e524..e0b0455a 100644 --- a/firmware/baseband/proc_capture.cpp +++ b/firmware/baseband/proc_capture.cpp @@ -44,8 +44,6 @@ CaptureProcessor::CaptureProcessor() { spectrum_samples = 0; channel_spectrum.set_decimation_factor(1); - - stream = std::make_unique(15); } void CaptureProcessor::execute(const buffer_c8_t& buffer) { @@ -76,7 +74,19 @@ void CaptureProcessor::on_message(const Message* const message) { channel_spectrum.on_message(message); break; + case Message::ID::CaptureConfig: + capture_config(*reinterpret_cast(message)); + break; + default: break; } } + +void CaptureProcessor::capture_config(const CaptureConfigMessage& message) { + if( message.config ) { + stream = std::make_unique(15, *message.config); + } else { + stream.reset(); + } +} diff --git a/firmware/baseband/proc_capture.hpp b/firmware/baseband/proc_capture.hpp index 9a8ee0f4..e975d99c 100644 --- a/firmware/baseband/proc_capture.hpp +++ b/firmware/baseband/proc_capture.hpp @@ -61,6 +61,8 @@ private: SpectrumCollector channel_spectrum; size_t spectrum_interval_samples = 0; size_t spectrum_samples = 0; + + void capture_config(const CaptureConfigMessage& message); }; #endif/*__PROC_CAPTURE_HPP__*/ diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 3fd546b9..bdf4421a 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -53,6 +53,10 @@ void NarrowbandFMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::CaptureConfig: + capture_config(*reinterpret_cast(message)); + break; + default: break; } @@ -81,3 +85,11 @@ void NarrowbandFMAudio::configure(const NBFMConfigureMessage& message) { configured = true; } + +void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) { + if( message.config ) { + audio_output.set_stream(std::make_unique(14, *message.config)); + } else { + audio_output.set_stream(nullptr); + } +} diff --git a/firmware/baseband/proc_nfm_audio.hpp b/firmware/baseband/proc_nfm_audio.hpp index dbae4f5f..164e0b45 100644 --- a/firmware/baseband/proc_nfm_audio.hpp +++ b/firmware/baseband/proc_nfm_audio.hpp @@ -66,6 +66,7 @@ private: bool configured { false }; void configure(const NBFMConfigureMessage& message); + void capture_config(const CaptureConfigMessage& message); }; #endif/*__PROC_NFM_AUDIO_H__*/ diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index 4246a555..c6f1e116 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -81,6 +81,10 @@ void WidebandFMAudio::on_message(const Message* const message) { configure(*reinterpret_cast(message)); break; + case Message::ID::CaptureConfig: + capture_config(*reinterpret_cast(message)); + break; + default: break; } @@ -110,3 +114,11 @@ void WidebandFMAudio::configure(const WFMConfigureMessage& message) { configured = true; } + +void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) { + if( message.config ) { + audio_output.set_stream(std::make_unique(15, *message.config)); + } else { + audio_output.set_stream(nullptr); + } +} diff --git a/firmware/baseband/proc_wfm_audio.hpp b/firmware/baseband/proc_wfm_audio.hpp index 15f5bf36..9752f90a 100644 --- a/firmware/baseband/proc_wfm_audio.hpp +++ b/firmware/baseband/proc_wfm_audio.hpp @@ -68,6 +68,7 @@ private: bool configured { false }; void configure(const WFMConfigureMessage& message); + void capture_config(const CaptureConfigMessage& message); }; #endif/*__PROC_WFM_AUDIO_H__*/ diff --git a/firmware/baseband/stream_input.hpp b/firmware/baseband/stream_input.hpp index 1b1ec552..e8221477 100644 --- a/firmware/baseband/stream_input.hpp +++ b/firmware/baseband/stream_input.hpp @@ -32,18 +32,12 @@ class StreamInput { public: - StreamInput(const size_t K) : + StreamInput(const size_t K, CaptureConfig& config) : K { K }, data { std::make_unique(1UL << K) }, fifo { data.get(), K } { - // TODO: Send stream creation message. - shared_memory.FIFO_HACK = &fifo; - } - - ~StreamInput() { - // TODO: Send stream distruction message. - shared_memory.FIFO_HACK = nullptr; + config.fifo = &fifo; } size_t write(const void* const data, const size_t length) { diff --git a/firmware/common/portapack_shared_memory.hpp b/firmware/common/portapack_shared_memory.hpp index 612a3b27..b7b97f39 100644 --- a/firmware/common/portapack_shared_memory.hpp +++ b/firmware/common/portapack_shared_memory.hpp @@ -40,7 +40,6 @@ struct SharedMemory { uint8_t baseband_queue_data[1 << baseband_queue_k]; MessageQueue application_queue; uint8_t application_queue_data[1 << application_queue_k]; - void* FIFO_HACK; // TODO: M0 should directly configure and control DMA channel that is // acquiring ADC samples.