From 0647f26707236598c424d43307340e3531506313 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 10 Jan 2016 10:23:39 -0800 Subject: [PATCH] Move SGPIO configuration and control to baseband firmware. Addresses long-standing and annoying bug where SGPIO DMA channel would not disable -- and not configure cleanly next time it was needed. My theory is that the DMA channel couldn't disable until it got a request from the peripheral, and sometimes the peripheral was disabled before that last request. Anyway, the baseband firmware should control the SGPIO, methinks, despite the impact on baseband code size. --- firmware/application/Makefile | 1 - firmware/application/radio.cpp | 13 ------------- firmware/application/radio.hpp | 2 -- firmware/application/receiver_model.cpp | 4 ---- firmware/baseband/Makefile | 1 + firmware/baseband/baseband_thread.cpp | 7 +++++++ 6 files changed, 8 insertions(+), 20 deletions(-) diff --git a/firmware/application/Makefile b/firmware/application/Makefile index ab0e616c..ce6da9dc 100755 --- a/firmware/application/Makefile +++ b/firmware/application/Makefile @@ -135,7 +135,6 @@ CPPSRC = main.cpp \ wm8731.cpp \ radio.cpp \ baseband_cpld.cpp \ - baseband_sgpio.cpp \ tuning.cpp \ rf_path.cpp \ rffc507x.cpp \ diff --git a/firmware/application/radio.cpp b/firmware/application/radio.cpp index 97463663..cdaced34 100644 --- a/firmware/application/radio.cpp +++ b/firmware/application/radio.cpp @@ -24,7 +24,6 @@ #include "rf_path.hpp" #include "max5864.hpp" #include "baseband_cpld.hpp" -#include "baseband_sgpio.hpp" #include "portapack_shared_memory.hpp" #include "tuning.hpp" @@ -90,7 +89,6 @@ rffc507x::RFFC507x first_if; max2837::MAX2837 second_if { ssp1_target_max2837 }; static max5864::MAX5864 baseband_codec { ssp1_target_max5864 }; static baseband::CPLD baseband_cpld; -static baseband::SGPIO baseband_sgpio; static rf::Direction direction { rf::Direction::Receive }; @@ -100,7 +98,6 @@ void init() { second_if.init(); baseband_codec.init(); baseband_cpld.init(); - baseband_sgpio.init(); } void set_direction(const rf::Direction new_direction) { @@ -112,7 +109,6 @@ void set_direction(const rf::Direction new_direction) { rf_path.set_direction(direction); baseband_codec.set_mode((direction == rf::Direction::Transmit) ? max5864::Mode::Transmit : max5864::Mode::Receive); - baseband_sgpio.configure((direction == rf::Direction::Transmit) ? baseband::Direction::Transmit : baseband::Direction::Receive); } bool set_tuning_frequency(const rf::Frequency frequency) { @@ -156,16 +152,7 @@ void set_baseband_decimation_by(const size_t n) { baseband_cpld.set_decimation_by(n); } -void streaming_enable() { - baseband_sgpio.streaming_enable(); -} - -void streaming_disable() { - baseband_sgpio.streaming_disable(); -} - void disable() { - baseband_sgpio.streaming_disable(); baseband_codec.set_mode(max5864::Mode::Shutdown); second_if.set_mode(max2837::Mode::Standby); first_if.disable(); diff --git a/firmware/application/radio.hpp b/firmware/application/radio.hpp index c796963d..0513c17c 100644 --- a/firmware/application/radio.hpp +++ b/firmware/application/radio.hpp @@ -43,8 +43,6 @@ void set_sampling_frequency(const uint32_t frequency); void set_baseband_filter_bandwidth(const uint32_t bandwidth_minimum); void set_baseband_decimation_by(const size_t n); -void streaming_enable(); -void streaming_disable(); void disable(); extern rffc507x::RFFC507x first_if; diff --git a/firmware/application/receiver_model.cpp b/firmware/application/receiver_model.cpp index f068f24d..6d44e7ec 100644 --- a/firmware/application/receiver_model.cpp +++ b/firmware/application/receiver_model.cpp @@ -118,7 +118,6 @@ void ReceiverModel::enable() { update_vga(); update_baseband_bandwidth(); update_baseband_configuration(); - radio::streaming_enable(); update_headphone_volume(); } @@ -168,7 +167,6 @@ void ReceiverModel::set_baseband_configuration(const BasebandConfiguration confi } void ReceiverModel::update_baseband_configuration() { - radio::streaming_disable(); clock_manager.set_sampling_frequency(sampling_rate() * baseband_oversampling()); update_tuning_frequency(); @@ -176,8 +174,6 @@ void ReceiverModel::update_baseband_configuration() { BasebandConfigurationMessage message { baseband_configuration }; shared_memory.baseband_queue.push(message); - - radio::streaming_enable(); } void ReceiverModel::update_headphone_volume() { diff --git a/firmware/baseband/Makefile b/firmware/baseband/Makefile index 27608c43..6f107e3a 100755 --- a/firmware/baseband/Makefile +++ b/firmware/baseband/Makefile @@ -127,6 +127,7 @@ CPPSRC = main.cpp \ event.cpp \ gpdma.cpp \ baseband_dma.cpp \ + baseband_sgpio.cpp \ portapack_shared_memory.cpp \ baseband_thread.cpp \ baseband_processor.cpp \ diff --git a/firmware/baseband/baseband_thread.cpp b/firmware/baseband/baseband_thread.cpp index d1a2e30c..92b968f5 100644 --- a/firmware/baseband/baseband_thread.cpp +++ b/firmware/baseband/baseband_thread.cpp @@ -25,6 +25,7 @@ #include "baseband.hpp" #include "baseband_stats_collector.hpp" +#include "baseband_sgpio.hpp" #include "baseband_dma.hpp" #include "rssi.hpp" @@ -42,6 +43,8 @@ #include +static baseband::SGPIO baseband_sgpio; + WORKING_AREA(baseband_thread_wa, 4096); Thread* BasebandThread::start(const tprio_t priority) { @@ -79,6 +82,7 @@ void BasebandThread::on_message(const Message* const message) { } void BasebandThread::run() { + baseband_sgpio.init(); baseband::dma::init(); const auto baseband_buffer = new std::array(); @@ -136,6 +140,7 @@ void BasebandThread::disable() { if( baseband_processor ) { i2s::i2s0::tx_mute(); baseband::dma::disable(); + baseband_sgpio.streaming_disable(); rf::rssi::stop(); } } @@ -145,6 +150,8 @@ void BasebandThread::enable() { if( direction() == baseband::Direction::Receive ) { rf::rssi::start(); } + baseband_sgpio.configure(direction()); baseband::dma::enable(direction()); + baseband_sgpio.streaming_enable(); } }