From bbff6eecc2567d09e94505953e77da76a8b7564a Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:35:07 -0500 Subject: [PATCH 1/3] Start audio DMA only in apps that use audio --- firmware/baseband/audio_dma.cpp | 38 +++++++++++--------- firmware/baseband/audio_dma.hpp | 5 ++- firmware/baseband/baseband.cpp | 8 +---- firmware/baseband/proc_afskrx.cpp | 4 +++ firmware/baseband/proc_am_audio.cpp | 3 ++ firmware/baseband/proc_aprsrx.cpp | 4 +++ firmware/baseband/proc_audiotx.cpp | 3 ++ firmware/baseband/proc_mictx.cpp | 3 ++ firmware/baseband/proc_nfm_audio.cpp | 4 +++ firmware/baseband/proc_pocsag.cpp | 3 ++ firmware/baseband/proc_pocsag2.cpp | 3 ++ firmware/baseband/proc_sonde.cpp | 3 ++ firmware/baseband/proc_tones.cpp | 3 ++ firmware/baseband/proc_wfm_audio.cpp | 3 ++ firmware/baseband/proc_wideband_spectrum.cpp | 3 ++ 15 files changed, 63 insertions(+), 27 deletions(-) diff --git a/firmware/baseband/audio_dma.cpp b/firmware/baseband/audio_dma.cpp index f493fd939..0df474dcf 100644 --- a/firmware/baseband/audio_dma.cpp +++ b/firmware/baseband/audio_dma.cpp @@ -162,14 +162,6 @@ static void rx_error() { disable(); } -void init() { - gpdma_channel_i2s0_tx.set_handlers(tx_transfer_complete, tx_error); - gpdma_channel_i2s0_rx.set_handlers(rx_transfer_complete, rx_error); - - // LPC_GPDMA->SYNC |= (1 << gpdma_rx_peripheral); - // LPC_GPDMA->SYNC |= (1 << gpdma_tx_peripheral); -} - static void configure_tx() { const auto peripheral = reinterpret_cast(&LPC_I2S0->TXFIFO); const auto control_value = control_tx(transfer_bytes); @@ -194,22 +186,34 @@ static void configure_rx() { } } -void configure() { - configure_tx(); - configure_rx(); +static void enable_tx() { + const auto gpdma_config_tx = config_tx(); + gpdma_channel_i2s0_tx.configure(lli_tx_loop[0], gpdma_config_tx); + gpdma_channel_i2s0_tx.enable(); } -void enable() { - const auto gpdma_config_tx = config_tx(); +static void enable_rx() { const auto gpdma_config_rx = config_rx(); - - gpdma_channel_i2s0_tx.configure(lli_tx_loop[0], gpdma_config_tx); gpdma_channel_i2s0_rx.configure(lli_rx_loop[0], gpdma_config_rx); - - gpdma_channel_i2s0_tx.enable(); gpdma_channel_i2s0_rx.enable(); } +void init_audio_out() { + gpdma_channel_i2s0_tx.set_handlers(tx_transfer_complete, tx_error); + // LPC_GPDMA->SYNC |= (1 << gpdma_tx_peripheral); + configure_tx(); + enable_tx(); + nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); +} + +void init_audio_in() { + gpdma_channel_i2s0_rx.set_handlers(rx_transfer_complete, rx_error); + // LPC_GPDMA->SYNC |= (1 << gpdma_rx_peripheral); + configure_rx(); + enable_rx(); + nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); +} + void disable() { gpdma_channel_i2s0_tx.disable(); gpdma_channel_i2s0_rx.disable(); diff --git a/firmware/baseband/audio_dma.hpp b/firmware/baseband/audio_dma.hpp index 8634de820..41573524f 100644 --- a/firmware/baseband/audio_dma.hpp +++ b/firmware/baseband/audio_dma.hpp @@ -43,9 +43,8 @@ using buffer_t = buffer_t; namespace dma { -void init(); -void configure(); -void enable(); +void init_audio_in(); +void init_audio_out(); void disable(); void shrink_tx_buffer(bool shrink); diff --git a/firmware/baseband/baseband.cpp b/firmware/baseband/baseband.cpp index 5de5ec464..aac665fd0 100644 --- a/firmware/baseband/baseband.cpp +++ b/firmware/baseband/baseband.cpp @@ -28,14 +28,8 @@ #include "gpdma.hpp" -#include "audio_dma.hpp" - static void init() { - audio::dma::init(); - audio::dma::configure(); - audio::dma::enable(); - - nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); + // Audio DMA initialization was moved to baseband proc's that actually use DMA audio, to save memory. } static void halt() { diff --git a/firmware/baseband/proc_afskrx.cpp b/firmware/baseband/proc_afskrx.cpp index 27b1b4616..804518ece 100644 --- a/firmware/baseband/proc_afskrx.cpp +++ b/firmware/baseband/proc_afskrx.cpp @@ -23,6 +23,8 @@ #include "proc_afskrx.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" void AFSKRxProcessor::execute(const buffer_c8_t& buffer) { @@ -181,6 +183,8 @@ void AFSKRxProcessor::configure(const AFSKRxConfigureMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_am_audio.cpp b/firmware/baseband/proc_am_audio.cpp index 160356303..a1304c464 100644 --- a/firmware/baseband/proc_am_audio.cpp +++ b/firmware/baseband/proc_am_audio.cpp @@ -22,6 +22,7 @@ #include "proc_am_audio.hpp" #include "audio_output.hpp" +#include "audio_dma.hpp" #include "event_m4.hpp" @@ -112,6 +113,8 @@ void NarrowbandAMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_aprsrx.cpp b/firmware/baseband/proc_aprsrx.cpp index 616bbb417..60b048b02 100644 --- a/firmware/baseband/proc_aprsrx.cpp +++ b/firmware/baseband/proc_aprsrx.cpp @@ -23,6 +23,8 @@ #include "proc_aprsrx.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" #include "stdio.h" @@ -244,6 +246,8 @@ void APRSRxProcessor::configure(const APRSRxConfigureMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_audiotx.cpp b/firmware/baseband/proc_audiotx.cpp index d7991ccec..b8d70660a 100644 --- a/firmware/baseband/proc_audiotx.cpp +++ b/firmware/baseband/proc_audiotx.cpp @@ -24,6 +24,7 @@ #include "portapack_shared_memory.hpp" #include "sine_table_int8.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -139,6 +140,8 @@ void AudioTXProcessor::sample_rate_config(const SampleRateConfigMessage& message } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_mictx.cpp b/firmware/baseband/proc_mictx.cpp index be37c9c9f..9f0d37718 100644 --- a/firmware/baseband/proc_mictx.cpp +++ b/firmware/baseband/proc_mictx.cpp @@ -25,6 +25,7 @@ #include "sine_table_int8.hpp" #include "tonesets.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -167,6 +168,8 @@ void MicTXProcessor::on_message(const Message* const msg) { } int main() { + audio::dma::init_audio_in(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_nfm_audio.cpp b/firmware/baseband/proc_nfm_audio.cpp index 6b4e61352..47e1f7d41 100644 --- a/firmware/baseband/proc_nfm_audio.cpp +++ b/firmware/baseband/proc_nfm_audio.cpp @@ -24,6 +24,8 @@ #include "sine_table_int8.hpp" #include "portapack_shared_memory.hpp" +#include "audio_dma.hpp" + #include "event_m4.hpp" #include @@ -174,6 +176,8 @@ void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_pocsag.cpp b/firmware/baseband/proc_pocsag.cpp index 0101b7485..b05abd495 100644 --- a/firmware/baseband/proc_pocsag.cpp +++ b/firmware/baseband/proc_pocsag.cpp @@ -27,6 +27,7 @@ #include "dsp_iir_config.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include #include @@ -530,6 +531,8 @@ uint32_t POCSAGProcessor::getRate() const { // // ==================================================================== int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_pocsag2.cpp b/firmware/baseband/proc_pocsag2.cpp index 15c157389..1170a520b 100644 --- a/firmware/baseband/proc_pocsag2.cpp +++ b/firmware/baseband/proc_pocsag2.cpp @@ -26,6 +26,7 @@ #include "proc_pocsag2.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include #include @@ -416,6 +417,8 @@ void POCSAGProcessor::send_packet() { /* main **************************************************/ int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_sonde.cpp b/firmware/baseband/proc_sonde.cpp index 1477c3573..7c145ed3b 100644 --- a/firmware/baseband/proc_sonde.cpp +++ b/firmware/baseband/proc_sonde.cpp @@ -27,6 +27,7 @@ #include "event_m4.hpp" #include "audio_output.hpp" +#include "audio_dma.hpp" SondeProcessor::SondeProcessor() { decim_0.configure(taps_11k0_decim_0.taps); @@ -141,6 +142,8 @@ void SondeProcessor::pitch_rssi_config(const PitchRSSIConfigureMessage& message) } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); diff --git a/firmware/baseband/proc_tones.cpp b/firmware/baseband/proc_tones.cpp index 1af4bc473..f59c554b1 100644 --- a/firmware/baseband/proc_tones.cpp +++ b/firmware/baseband/proc_tones.cpp @@ -23,6 +23,7 @@ #include "proc_tones.hpp" #include "sine_table_int8.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -154,6 +155,8 @@ void TonesProcessor::on_message(const Message* const p) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_wfm_audio.cpp b/firmware/baseband/proc_wfm_audio.cpp index f6a3cb39d..7a59c73fa 100644 --- a/firmware/baseband/proc_wfm_audio.cpp +++ b/firmware/baseband/proc_wfm_audio.cpp @@ -26,6 +26,7 @@ #include "audio_output.hpp" #include "dsp_fft.hpp" #include "event_m4.hpp" +#include "audio_dma.hpp" #include @@ -188,6 +189,8 @@ void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) { } int main() { + audio::dma::init_audio_out(); + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; diff --git a/firmware/baseband/proc_wideband_spectrum.cpp b/firmware/baseband/proc_wideband_spectrum.cpp index a7377b0b8..35aef2ee6 100644 --- a/firmware/baseband/proc_wideband_spectrum.cpp +++ b/firmware/baseband/proc_wideband_spectrum.cpp @@ -20,6 +20,7 @@ */ #include "proc_wideband_spectrum.hpp" +#include "audio_dma.hpp" #include "event_m4.hpp" @@ -82,6 +83,8 @@ void WidebandSpectrum::on_message(const Message* const msg) { } int main() { + audio::dma::init_audio_out(); // for AudioRX app (enables audio output while this baseband image is running) + EventDispatcher event_dispatcher{std::make_unique()}; event_dispatcher.run(); return 0; From 6f4639d7edf7bc3254dd829a6bb83e1c1e1fa5a1 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:49:05 -0500 Subject: [PATCH 2/3] Rename main.cpp to main.cpp.unused --- firmware/baseband/{main.cpp => main.cpp.unused} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename firmware/baseband/{main.cpp => main.cpp.unused} (100%) diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp.unused similarity index 100% rename from firmware/baseband/main.cpp rename to firmware/baseband/main.cpp.unused From 6ee2d23b0f93e0c73ce43a1bad786e4a44264af9 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Wed, 13 Mar 2024 00:20:28 -0500 Subject: [PATCH 3/3] shrink_tx_buffer fix for transfers_per_buffer==1 scenario --- firmware/baseband/audio_dma.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/firmware/baseband/audio_dma.cpp b/firmware/baseband/audio_dma.cpp index 0df474dcf..356faea3b 100644 --- a/firmware/baseband/audio_dma.cpp +++ b/firmware/baseband/audio_dma.cpp @@ -221,6 +221,10 @@ void disable() { void shrink_tx_buffer(bool shrink) { single_tx_buffer = shrink; + + if (transfers_per_buffer == 1) + return; + if (single_tx_buffer) lli_tx_loop[0].lli = lli_pointer(&lli_tx_loop[0]); else