Start audio DMA only in apps that use audio (#1982)

* Start audio DMA only in apps that use audio
* Rename main.cpp to main.cpp.unuse
* shrink_tx_buffer fix for transfers_per_buffer==1 scenario
This commit is contained in:
Mark Thompson 2024-03-13 10:07:44 -05:00 committed by GitHub
parent 3c489e1a81
commit 0b2d5f75cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 67 additions and 27 deletions

View File

@ -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<uint32_t>(&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();
@ -217,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

View File

@ -43,9 +43,8 @@ using buffer_t = buffer_t<sample_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);

View File

@ -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() {

View File

@ -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<AFSKRxProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -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<NarrowbandAMAudio>()};
event_dispatcher.run();
return 0;

View File

@ -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<APRSRxProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -24,6 +24,7 @@
#include "portapack_shared_memory.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <cstdint>
@ -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<AudioTXProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -25,6 +25,7 @@
#include "sine_table_int8.hpp"
#include "tonesets.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <cstdint>
@ -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<MicTXProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -24,6 +24,8 @@
#include "sine_table_int8.hpp"
#include "portapack_shared_memory.hpp"
#include "audio_dma.hpp"
#include "event_m4.hpp"
#include <cstdint>
@ -174,6 +176,8 @@ void NarrowbandFMAudio::capture_config(const CaptureConfigMessage& message) {
}
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<NarrowbandFMAudio>()};
event_dispatcher.run();
return 0;

View File

@ -27,6 +27,7 @@
#include "dsp_iir_config.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <algorithm>
#include <cmath>
@ -530,6 +531,8 @@ uint32_t POCSAGProcessor::getRate() const {
//
// ====================================================================
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<POCSAGProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -26,6 +26,7 @@
#include "proc_pocsag2.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <algorithm>
#include <cmath>
@ -416,6 +417,8 @@ void POCSAGProcessor::send_packet() {
/* main **************************************************/
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<POCSAGProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -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<SondeProcessor>()};
event_dispatcher.run();

View File

@ -23,6 +23,7 @@
#include "proc_tones.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <cstdint>
@ -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<TonesProcessor>()};
event_dispatcher.run();
return 0;

View File

@ -26,6 +26,7 @@
#include "audio_output.hpp"
#include "dsp_fft.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"
#include <cstdint>
@ -188,6 +189,8 @@ void WidebandFMAudio::capture_config(const CaptureConfigMessage& message) {
}
int main() {
audio::dma::init_audio_out();
EventDispatcher event_dispatcher{std::make_unique<WidebandFMAudio>()};
event_dispatcher.run();
return 0;

View File

@ -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<WidebandSpectrum>()};
event_dispatcher.run();
return 0;