Simplify app->baseband message handling.

No need for a FIFO when all messages are intended to be synchronous.
This commit is contained in:
Jared Boone 2016-06-24 14:16:45 -07:00
parent 61325e4696
commit d41c6ee36a
4 changed files with 37 additions and 36 deletions

View File

@ -30,6 +30,14 @@
namespace baseband { namespace baseband {
static void send_message(const Message* const message) {
// If message is only sent by this function via one thread, no need to check if
// another message is present before setting new message.
shared_memory.baseband_message = message;
creg::m0apptxevent::assert();
while(shared_memory.baseband_message);
}
void AMConfig::apply() const { void AMConfig::apply() const {
const AMConfigureMessage message { const AMConfigureMessage message {
taps_6k0_decim_0, taps_6k0_decim_0,
@ -39,7 +47,7 @@ void AMConfig::apply() const {
modulation, modulation,
audio_12k_hpf_300hz_config audio_12k_hpf_300hz_config
}; };
shared_memory.baseband_queue.push_and_wait(message); send_message(&message);
audio::set_rate(audio::Rate::Hz_12000); audio::set_rate(audio::Rate::Hz_12000);
} }
@ -53,7 +61,7 @@ void NBFMConfig::apply() const {
audio_24k_hpf_300hz_config, audio_24k_hpf_300hz_config,
audio_24k_deemph_300_6_config audio_24k_deemph_300_6_config
}; };
shared_memory.baseband_queue.push_and_wait(message); send_message(&message);
audio::set_rate(audio::Rate::Hz_24000); audio::set_rate(audio::Rate::Hz_24000);
} }
@ -66,21 +74,20 @@ void WFMConfig::apply() const {
audio_48k_hpf_30hz_config, audio_48k_hpf_30hz_config,
audio_48k_deemph_2122_6_config audio_48k_deemph_2122_6_config
}; };
shared_memory.baseband_queue.push_and_wait(message); send_message(&message);
audio::set_rate(audio::Rate::Hz_48000); audio::set_rate(audio::Rate::Hz_48000);
} }
void start(BasebandConfiguration configuration) { void start(BasebandConfiguration configuration) {
BasebandConfigurationMessage message { configuration }; BasebandConfigurationMessage message { configuration };
shared_memory.baseband_queue.push_and_wait(message); send_message(&message);
} }
void stop() { void stop() {
shared_memory.baseband_queue.push_and_wait( BasebandConfigurationMessage message {
BasebandConfigurationMessage {
.configuration = { }, .configuration = { },
} };
); send_message(&message);
} }
void run_image(const portapack::spi_flash::region_t image_region) { void run_image(const portapack::spi_flash::region_t image_region) {
@ -92,36 +99,32 @@ void run_image(const portapack::spi_flash::region_t image_region) {
void shutdown() { void shutdown() {
creg::m4txevent::disable(); creg::m4txevent::disable();
ShutdownMessage shutdown_message; ShutdownMessage message;
shared_memory.baseband_queue.push_and_wait(shutdown_message); send_message(&message);
} }
void spectrum_streaming_start() { void spectrum_streaming_start() {
shared_memory.baseband_queue.push_and_wait( SpectrumStreamingConfigMessage message {
SpectrumStreamingConfigMessage {
SpectrumStreamingConfigMessage::Mode::Running SpectrumStreamingConfigMessage::Mode::Running
} };
); send_message(&message);
} }
void spectrum_streaming_stop() { void spectrum_streaming_stop() {
shared_memory.baseband_queue.push_and_wait( SpectrumStreamingConfigMessage message {
SpectrumStreamingConfigMessage {
SpectrumStreamingConfigMessage::Mode::Stopped SpectrumStreamingConfigMessage::Mode::Stopped
} };
); send_message(&message);
} }
void capture_start(CaptureConfig* const config) { void capture_start(CaptureConfig* const config) {
shared_memory.baseband_queue.push_and_wait( CaptureConfigMessage message { config };
CaptureConfigMessage { config } send_message(&message);
);
} }
void capture_stop() { void capture_stop() {
shared_memory.baseband_queue.push_and_wait( CaptureConfigMessage message { nullptr };
CaptureConfigMessage { nullptr } send_message(&message);
);
} }
} /* namespace baseband */ } /* namespace baseband */

View File

@ -284,9 +284,7 @@ void EventDispatcher::event_bubble_encoder(const ui::EncoderEvent event) {
} }
void EventDispatcher::init_message_queues() { void EventDispatcher::init_message_queues() {
new (&shared_memory.baseband_queue) MessageQueue( shared_memory.baseband_message = nullptr;
shared_memory.baseband_queue_data, SharedMemory::baseband_queue_k
);
new (&shared_memory.application_queue) MessageQueue( new (&shared_memory.application_queue) MessageQueue(
shared_memory.application_queue_data, SharedMemory::application_queue_k shared_memory.application_queue_data, SharedMemory::application_queue_k
); );

View File

@ -87,9 +87,11 @@ void EventDispatcher::dispatch(const eventmask_t events) {
} }
void EventDispatcher::handle_baseband_queue() { void EventDispatcher::handle_baseband_queue() {
shared_memory.baseband_queue.handle([this](Message* const message) { const auto message = shared_memory.baseband_message;
this->on_message(message); if( message ) {
}); on_message(message);
shared_memory.baseband_message = nullptr;
}
} }
void EventDispatcher::on_message(const Message* const message) { void EventDispatcher::on_message(const Message* const message) {

View File

@ -33,14 +33,12 @@ struct TouchADCFrame {
/* NOTE: These structures must be located in the same location in both M4 and M0 binaries */ /* NOTE: These structures must be located in the same location in both M4 and M0 binaries */
struct SharedMemory { struct SharedMemory {
static constexpr size_t baseband_queue_k = 11;
static constexpr size_t application_queue_k = 11; static constexpr size_t application_queue_k = 11;
static constexpr size_t app_local_queue_k = 11; static constexpr size_t app_local_queue_k = 11;
uint8_t baseband_queue_data[1 << baseband_queue_k];
uint8_t application_queue_data[1 << application_queue_k]; uint8_t application_queue_data[1 << application_queue_k];
uint8_t app_local_queue_data[1 << app_local_queue_k]; uint8_t app_local_queue_data[1 << app_local_queue_k];
MessageQueue baseband_queue; const Message* volatile baseband_message;
MessageQueue application_queue; MessageQueue application_queue;
MessageQueue app_local_queue; MessageQueue app_local_queue;