Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start audio DMA only in apps that use audio #1982

Merged
merged 3 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions firmware/baseband/audio_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -194,29 +186,45 @@ 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();
}

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
Expand Down
5 changes: 2 additions & 3 deletions firmware/baseband/audio_dma.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 1 addition & 7 deletions firmware/baseband/baseband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions firmware/baseband/proc_afskrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_am_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "proc_am_audio.hpp"

#include "audio_output.hpp"
#include "audio_dma.hpp"

#include "event_m4.hpp"

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions firmware/baseband/proc_aprsrx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "proc_aprsrx.hpp"
#include "portapack_shared_memory.hpp"

#include "audio_dma.hpp"

#include "event_m4.hpp"

#include "stdio.h"
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_audiotx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "portapack_shared_memory.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <cstdint>

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_mictx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "sine_table_int8.hpp"
#include "tonesets.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <cstdint>

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions firmware/baseband/proc_nfm_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "sine_table_int8.hpp"
#include "portapack_shared_memory.hpp"

#include "audio_dma.hpp"

#include "event_m4.hpp"

#include <cstdint>
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_pocsag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "dsp_iir_config.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_pocsag2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "proc_pocsag2.hpp"

#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <algorithm>
#include <cmath>
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_sonde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_tones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "proc_tones.hpp"
#include "sine_table_int8.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <cstdint>

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_wfm_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "audio_output.hpp"
#include "dsp_fft.hpp"
#include "event_m4.hpp"
#include "audio_dma.hpp"

#include <cstdint>

Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions firmware/baseband/proc_wideband_spectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*/

#include "proc_wideband_spectrum.hpp"
#include "audio_dma.hpp"

#include "event_m4.hpp"

Expand Down Expand Up @@ -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;
Expand Down
Loading