From bf7f5d256784adb1dd502222f18977d02f639a3e Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Tue, 31 Jan 2017 12:02:51 -0800 Subject: [PATCH] IRQ: Make handlers more independent of EventDispatcher. EventDispatcher is such a hairball... --- firmware/application/event_m0.hpp | 17 ++++------------- firmware/application/irq_controls.cpp | 6 +++++- firmware/application/irq_lcd_frame.cpp | 5 ++++- firmware/application/irq_rtc.cpp | 7 +++++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/firmware/application/event_m0.hpp b/firmware/application/event_m0.hpp index 56f0a5c0..0df46ba0 100644 --- a/firmware/application/event_m0.hpp +++ b/firmware/application/event_m0.hpp @@ -38,9 +38,13 @@ #include +constexpr auto EVT_MASK_RTC_TICK = EVENT_MASK(0); +constexpr auto EVT_MASK_LCD_FRAME_SYNC = EVENT_MASK(1); constexpr auto EVT_MASK_SWITCHES = EVENT_MASK(3); constexpr auto EVT_MASK_ENCODER = EVENT_MASK(4); constexpr auto EVT_MASK_TOUCH = EVENT_MASK(5); +constexpr auto EVT_MASK_APPLICATION = EVENT_MASK(6); +constexpr auto EVT_MASK_LOCAL = EVENT_MASK(7); class EventDispatcher { public: @@ -65,14 +69,6 @@ public: } } - static inline void event_isr_rtc_tick() { - events_flag_isr(EVT_MASK_RTC_TICK); - } - - static inline void event_isr_lcd_frame_sync() { - events_flag_isr(EVT_MASK_LCD_FRAME_SYNC); - } - static inline void events_flag(const eventmask_t events) { if( thread_event_loop ) { chEvtSignal(thread_event_loop, events); @@ -92,11 +88,6 @@ public: } private: - static constexpr auto EVT_MASK_RTC_TICK = EVENT_MASK(0); - static constexpr auto EVT_MASK_LCD_FRAME_SYNC = EVENT_MASK(1); - static constexpr auto EVT_MASK_APPLICATION = EVENT_MASK(6); - static constexpr auto EVT_MASK_LOCAL = EVENT_MASK(7); - static Thread* thread_event_loop; touch::Manager touch_manager { }; diff --git a/firmware/application/irq_controls.cpp b/firmware/application/irq_controls.cpp index d57e9a9a..7cc6c528 100644 --- a/firmware/application/irq_controls.cpp +++ b/firmware/application/irq_controls.cpp @@ -40,6 +40,8 @@ #include "hackrf_hal.hpp" using namespace hackrf::one; +static Thread* thread_controls_event = NULL; + static std::array switch_debounce; static Encoder encoder; @@ -156,7 +158,7 @@ void timer0_callback(GPTDriver* const) { /* Signal event loop */ if( event_mask ) { chSysLockFromIsr(); - EventDispatcher::events_flag_isr(event_mask); + chEvtSignalI(thread_controls_event, event_mask); chSysUnlockFromIsr(); } } @@ -176,6 +178,8 @@ static GPTConfig timer0_config { }; void controls_init() { + thread_controls_event = chThdSelf(); + touch::adc::start(); /* GPT timer 0 is used to scan user interface controls -- touch screen, diff --git a/firmware/application/irq_lcd_frame.cpp b/firmware/application/irq_lcd_frame.cpp index d6a1c1bd..59bce755 100644 --- a/firmware/application/irq_lcd_frame.cpp +++ b/firmware/application/irq_lcd_frame.cpp @@ -28,7 +28,10 @@ #include "portapack_hal.hpp" +static Thread* thread_lcd_frame_event = NULL; + static void pin_int4_interrupt_enable() { + thread_lcd_frame_event = chThdSelf(); nvicEnableVector(PIN_INT4_IRQn, CORTEX_PRIORITY_MASK(LPC43XX_PIN_INT4_IRQ_PRIORITY)); } @@ -54,7 +57,7 @@ CH_IRQ_HANDLER(PIN_INT4_IRQHandler) { CH_IRQ_PROLOGUE(); chSysLockFromIsr(); - EventDispatcher::event_isr_lcd_frame_sync(); + chEvtSignalI(thread_lcd_frame_event, EVT_MASK_LCD_FRAME_SYNC); chSysUnlockFromIsr(); LPC_GPIO_INT->IST = (1U << 4); diff --git a/firmware/application/irq_rtc.cpp b/firmware/application/irq_rtc.cpp index f9c047bf..5bc6c735 100644 --- a/firmware/application/irq_rtc.cpp +++ b/firmware/application/irq_rtc.cpp @@ -27,8 +27,11 @@ using namespace lpc43xx; #include "event_m0.hpp" - + +static Thread* thread_rtc_event = NULL; + void rtc_interrupt_enable() { + thread_rtc_event = chThdSelf(); rtc::interrupt::enable_second_inc(); nvicEnableVector(RTC_IRQn, CORTEX_PRIORITY_MASK(LPC_RTC_IRQ_PRIORITY)); } @@ -39,7 +42,7 @@ CH_IRQ_HANDLER(RTC_IRQHandler) { CH_IRQ_PROLOGUE(); chSysLockFromIsr(); - EventDispatcher::event_isr_rtc_tick(); + chEvtSignalI(thread_rtc_event, EVT_MASK_RTC_TICK); chSysUnlockFromIsr(); rtc::interrupt::clear_all();