From 8e14d2f4e8224c21fde4c9f1c2a20297cdead87c Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 27 Mar 2016 22:49:30 -0700 Subject: [PATCH] Signal SD card write thread from M4 event. --- firmware/application/audio_thread.hpp | 16 +++++++++++++--- firmware/application/event_m0.cpp | 4 ++++ firmware/application/event_m0.hpp | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/firmware/application/audio_thread.hpp b/firmware/application/audio_thread.hpp index 5155fc4f..9752d018 100644 --- a/firmware/application/audio_thread.hpp +++ b/firmware/application/audio_thread.hpp @@ -67,11 +67,23 @@ public: ~AudioThread() { chThdTerminate(thread); + chEvtSignal(thread, EVT_FIFO_HIGHWATER); chThdWait(thread); } + static void check_fifo_isr() { + if( (shared_memory.FIFO_HACK != nullptr) && (thread != nullptr) ) { + auto fifo = reinterpret_cast*>(shared_memory.FIFO_HACK); + if( fifo->len() >= write_size ) { + chEvtSignalI(thread, EVT_FIFO_HIGHWATER); + } + } + } + private: static constexpr size_t write_size = 4096; + static constexpr eventmask_t EVT_FIFO_HIGHWATER = 1; + const std::string file_path; File file; @@ -95,7 +107,7 @@ private: } while( !chThdShouldTerminate() ) { - // SUCH A HACK!!! + chEvtWaitAny(EVT_FIFO_HIGHWATER); auto fifo = reinterpret_cast*>(shared_memory.FIFO_HACK); if( !fifo ) { @@ -117,8 +129,6 @@ private: } led_usb.off(); } - - chThdSleepMilliseconds(25); } file.close(); diff --git a/firmware/application/event_m0.cpp b/firmware/application/event_m0.cpp index 06890318..af12bee1 100644 --- a/firmware/application/event_m0.cpp +++ b/firmware/application/event_m0.cpp @@ -31,6 +31,8 @@ #include "irq_controls.hpp" +#include "audio_thread.hpp" + #include "ch.h" #include "lpc43xx_cpp.hpp" @@ -44,6 +46,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) { CH_IRQ_PROLOGUE(); chSysLockFromIsr(); + AudioThread::check_fifo_isr(); EventDispatcher::events_flag_isr(EVT_MASK_APPLICATION); chSysUnlockFromIsr(); @@ -56,6 +59,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) { MessageHandlerMap EventDispatcher::message_map_; Thread* EventDispatcher::thread_event_loop = nullptr; +Thread* EventDispatcher::thread_record = nullptr; EventDispatcher::EventDispatcher( ui::Widget* const top_widget, diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index 414a3a62..69dcede2 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -73,6 +73,8 @@ public: return message_map_; } + static Thread* thread_record; + private: static MessageHandlerMap message_map_; static Thread* thread_event_loop;