From 22e44605b62e47e2852522658b42adef02e98db3 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 10 Feb 2016 20:11:19 -0800 Subject: [PATCH] Hide baseband queue code inside baseband "API". --- firmware/application/Makefile | 1 + firmware/application/ais_app.cpp | 14 +--- firmware/application/baseband_api.cpp | 105 ++++++++++++++++++++++++ firmware/application/baseband_api.hpp | 63 ++++++++++++++ firmware/application/ert_app.cpp | 14 +--- firmware/application/m4_startup.cpp | 5 +- firmware/application/receiver_model.cpp | 84 ++----------------- firmware/application/receiver_model.hpp | 2 - firmware/application/tpms_app.cpp | 14 +--- firmware/application/ui_spectrum.cpp | 15 +--- 10 files changed, 195 insertions(+), 122 deletions(-) create mode 100644 firmware/application/baseband_api.cpp create mode 100644 firmware/application/baseband_api.hpp diff --git a/firmware/application/Makefile b/firmware/application/Makefile index c3d347ef7..ca1be09a2 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -127,6 +127,7 @@ CPPSRC = main.cpp \ hackrf_hal.cpp \ portapack.cpp \ portapack_shared_memory.cpp \ + baseband_api.cpp \ portapack_persistent_memory.cpp \ portapack_io.cpp \ i2c_pp.cpp \ diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index cc0973575..1d5113096 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -25,8 +25,7 @@ #include "string_format.hpp" -#include "portapack_shared_memory.hpp" -using namespace portapack; +#include "baseband_api.hpp" #include @@ -352,12 +351,11 @@ AISAppView::AISAppView(NavigationView&) { 1, }); - BasebandConfigurationMessage message { { + baseband::start({ .mode = 3, .sampling_rate = sampling_rate, .decimation_factor = 1, - } }; - shared_memory.baseband_queue.push(message); + }); options_channel.on_change = [this](size_t, OptionsField::value_t v) { this->on_frequency_changed(v); @@ -373,11 +371,7 @@ AISAppView::AISAppView(NavigationView&) { } AISAppView::~AISAppView() { - shared_memory.baseband_queue.push_and_wait( - BasebandConfigurationMessage { - .configuration = { }, - } - ); + baseband::stop(); radio::disable(); EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket); diff --git a/firmware/application/baseband_api.cpp b/firmware/application/baseband_api.cpp new file mode 100644 index 000000000..3c87682ba --- /dev/null +++ b/firmware/application/baseband_api.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "baseband_api.hpp" + +#include "audio.hpp" +#include "dsp_iir_config.hpp" + +#include "portapack_shared_memory.hpp" + +namespace baseband { + +void AMConfig::apply() const { + const AMConfigureMessage message { + taps_6k0_decim_0, + taps_6k0_decim_1, + taps_6k0_decim_2, + channel, + modulation, + audio_12k_hpf_300hz_config + }; + shared_memory.baseband_queue.push(message); + audio::set_rate(audio::Rate::Hz_12000); +} + +void NBFMConfig::apply() const { + const NBFMConfigureMessage message { + decim_0, + decim_1, + channel, + 2, + deviation, + audio_24k_hpf_300hz_config, + audio_24k_deemph_300_6_config + }; + shared_memory.baseband_queue.push(message); + audio::set_rate(audio::Rate::Hz_24000); +} + +void WFMConfig::apply() const { + const WFMConfigureMessage message { + taps_200k_wfm_decim_0, + taps_200k_wfm_decim_1, + taps_64_lp_156_198, + 75000, + audio_48k_hpf_30hz_config, + audio_48k_deemph_2122_6_config + }; + shared_memory.baseband_queue.push(message); + audio::set_rate(audio::Rate::Hz_48000); +} + +void start(BasebandConfiguration configuration) { + BasebandConfigurationMessage message { configuration }; + shared_memory.baseband_queue.push(message); +} + +void stop() { + shared_memory.baseband_queue.push_and_wait( + BasebandConfigurationMessage { + .configuration = { }, + } + ); +} + +void shutdown() { + ShutdownMessage shutdown_message; + shared_memory.baseband_queue.push(shutdown_message); +} + +void spectrum_streaming_start() { + shared_memory.baseband_queue.push_and_wait( + SpectrumStreamingConfigMessage { + SpectrumStreamingConfigMessage::Mode::Running + } + ); +} + +void spectrum_streaming_stop() { + shared_memory.baseband_queue.push_and_wait( + SpectrumStreamingConfigMessage { + SpectrumStreamingConfigMessage::Mode::Stopped + } + ); +} + +} /* namespace baseband */ diff --git a/firmware/application/baseband_api.hpp b/firmware/application/baseband_api.hpp new file mode 100644 index 000000000..15959142f --- /dev/null +++ b/firmware/application/baseband_api.hpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 Jared Boone, ShareBrained Technology, Inc. + * + * This file is part of PortaPack. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __BASEBAND_API_H__ +#define __BASEBAND_API_H__ + +#include "message.hpp" + +#include "dsp_fir_taps.hpp" + +#include + +namespace baseband { + +struct AMConfig { + const fir_taps_complex<64> channel; + const AMConfigureMessage::Modulation modulation; + + void apply() const; +}; + +struct NBFMConfig { + const fir_taps_real<24> decim_0; + const fir_taps_real<32> decim_1; + const fir_taps_real<32> channel; + const size_t deviation; + + void apply() const; +}; + +struct WFMConfig { + void apply() const; +}; + +void start(BasebandConfiguration configuration); +void stop(); + +void shutdown(); + +void spectrum_streaming_start(); +void spectrum_streaming_stop(); + +} /* namespace baseband */ + +#endif/*__BASEBAND_API_H__*/ diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index b555bca4e..6ad67d965 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -23,8 +23,7 @@ #include "event_m0.hpp" -#include "portapack_shared_memory.hpp" -using namespace portapack; +#include "baseband_api.hpp" #include "manchester.hpp" @@ -140,20 +139,15 @@ ERTAppView::ERTAppView(NavigationView&) { 1, }); - BasebandConfigurationMessage message { { + baseband::start({ .mode = 6, .sampling_rate = sampling_rate, .decimation_factor = 1, - } }; - shared_memory.baseband_queue.push(message); + }); } ERTAppView::~ERTAppView() { - shared_memory.baseband_queue.push_and_wait( - BasebandConfigurationMessage { - .configuration = { }, - } - ); + baseband::stop(); radio::disable(); EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket); diff --git a/firmware/application/m4_startup.cpp b/firmware/application/m4_startup.cpp index 6b9df47b4..2313b4939 100644 --- a/firmware/application/m4_startup.cpp +++ b/firmware/application/m4_startup.cpp @@ -24,7 +24,7 @@ #include "hal.h" #include "message.hpp" -#include "portapack_shared_memory.hpp" +#include "baseband_api.hpp" #include @@ -49,6 +49,5 @@ void m4_init(const portapack::spi_flash::region_t from, const portapack::memory: } void m4_request_shutdown() { - ShutdownMessage shutdown_message; - shared_memory.baseband_queue.push(shutdown_message); + baseband::shutdown(); } diff --git a/firmware/application/receiver_model.cpp b/firmware/application/receiver_model.cpp index 7edd6f249..cf8607b83 100644 --- a/firmware/application/receiver_model.cpp +++ b/firmware/application/receiver_model.cpp @@ -21,7 +21,8 @@ #include "receiver_model.hpp" -#include "portapack_shared_memory.hpp" +#include "baseband_api.hpp" + #include "portapack_persistent_memory.hpp" using namespace portapack; @@ -34,79 +35,19 @@ using namespace portapack; namespace { -struct AMConfig { - const fir_taps_complex<64> channel; - const AMConfigureMessage::Modulation modulation; - - void apply() const; -}; - -struct NBFMConfig { - const fir_taps_real<24> decim_0; - const fir_taps_real<32> decim_1; - const fir_taps_real<32> channel; - const size_t deviation; - - void apply() const; -}; - -struct WFMConfig { - void apply() const; -}; - -void AMConfig::apply() const { - const AMConfigureMessage message { - taps_6k0_decim_0, - taps_6k0_decim_1, - taps_6k0_decim_2, - channel, - modulation, - audio_12k_hpf_300hz_config - }; - shared_memory.baseband_queue.push(message); - audio::set_rate(audio::Rate::Hz_12000); -} - -void NBFMConfig::apply() const { - const NBFMConfigureMessage message { - decim_0, - decim_1, - channel, - 2, - deviation, - audio_24k_hpf_300hz_config, - audio_24k_deemph_300_6_config - }; - shared_memory.baseband_queue.push(message); - audio::set_rate(audio::Rate::Hz_24000); -} - -void WFMConfig::apply() const { - const WFMConfigureMessage message { - taps_200k_wfm_decim_0, - taps_200k_wfm_decim_1, - taps_64_lp_156_198, - 75000, - audio_48k_hpf_30hz_config, - audio_48k_deemph_2122_6_config - }; - shared_memory.baseband_queue.push(message); - audio::set_rate(audio::Rate::Hz_48000); -} - -static constexpr std::array am_configs { { +static constexpr std::array am_configs { { { taps_6k0_dsb_channel, AMConfigureMessage::Modulation::DSB }, { taps_2k8_usb_channel, AMConfigureMessage::Modulation::SSB }, { taps_2k8_lsb_channel, AMConfigureMessage::Modulation::SSB }, } }; -static constexpr std::array nbfm_configs { { +static constexpr std::array nbfm_configs { { { taps_4k25_decim_0, taps_4k25_decim_1, taps_4k25_channel, 2500 }, { taps_11k0_decim_0, taps_11k0_decim_1, taps_11k0_channel, 2500 }, { taps_16k0_decim_0, taps_16k0_decim_1, taps_16k0_channel, 5000 }, } }; -static constexpr std::array wfm_configs { { +static constexpr std::array wfm_configs { { { }, } }; @@ -210,18 +151,10 @@ void ReceiverModel::enable() { update_headphone_volume(); } -void ReceiverModel::baseband_disable() { - shared_memory.baseband_queue.push_and_wait( - BasebandConfigurationMessage { - .configuration = { }, - } - ); -} - void ReceiverModel::disable() { enabled_ = false; update_antenna_bias(); - baseband_disable(); + baseband::stop(); // TODO: Responsibility for enabling/disabling the radio is muddy. // Some happens in ReceiverModel, some inside radio namespace. @@ -292,14 +225,13 @@ void ReceiverModel::update_baseband_configuration() { // protocols that need quick RX/TX turn-around. // Disabling baseband while changing sampling rates seems like a good idea... - baseband_disable(); + baseband::stop(); radio::set_baseband_rate(sampling_rate() * baseband_oversampling()); update_tuning_frequency(); radio::set_baseband_decimation_by(baseband_oversampling()); - BasebandConfigurationMessage message { baseband_configuration }; - shared_memory.baseband_queue.push(message); + baseband::start(baseband_configuration); } void ReceiverModel::update_headphone_volume() { diff --git a/firmware/application/receiver_model.hpp b/firmware/application/receiver_model.hpp index 159706e09..48839f327 100644 --- a/firmware/application/receiver_model.hpp +++ b/firmware/application/receiver_model.hpp @@ -116,8 +116,6 @@ private: void update_am_configuration(); void update_nbfm_configuration(); void update_wfm_configuration(); - - void baseband_disable(); }; #endif/*__RECEIVER_MODEL_H__*/ diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index f580eaf94..55ef0811c 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -23,8 +23,7 @@ #include "event_m0.hpp" -#include "portapack_shared_memory.hpp" -using namespace portapack; +#include "baseband_api.hpp" #include "string_format.hpp" @@ -247,20 +246,15 @@ TPMSAppView::TPMSAppView(NavigationView&) { 1, }); - BasebandConfigurationMessage message { { + baseband::start({ .mode = 5, .sampling_rate = sampling_rate, .decimation_factor = 1, - } }; - shared_memory.baseband_queue.push(message); + }); } TPMSAppView::~TPMSAppView() { - shared_memory.baseband_queue.push_and_wait( - BasebandConfigurationMessage { - .configuration = { }, - } - ); + baseband::stop(); radio::disable(); EventDispatcher::message_map().unregister_handler(Message::ID::TPMSPacket); diff --git a/firmware/application/ui_spectrum.cpp b/firmware/application/ui_spectrum.cpp index 27e7da43b..4362db679 100644 --- a/firmware/application/ui_spectrum.cpp +++ b/firmware/application/ui_spectrum.cpp @@ -26,9 +26,10 @@ #include "spectrum_color_lut.hpp" #include "portapack.hpp" -#include "portapack_shared_memory.hpp" using namespace portapack; +#include "baseband_api.hpp" + #include "string_format.hpp" #include @@ -251,19 +252,11 @@ void WaterfallWidget::on_show() { } ); - shared_memory.baseband_queue.push_and_wait( - SpectrumStreamingConfigMessage { - SpectrumStreamingConfigMessage::Mode::Running - } - ); + baseband::spectrum_streaming_start(); } void WaterfallWidget::on_hide() { - shared_memory.baseband_queue.push_and_wait( - SpectrumStreamingConfigMessage { - SpectrumStreamingConfigMessage::Mode::Stopped - } - ); + baseband::spectrum_streaming_stop(); EventDispatcher::message_map().unregister_handler(Message::ID::DisplayFrameSync); EventDispatcher::message_map().unregister_handler(Message::ID::ChannelSpectrumConfig);