Move event.* code into event_m[04].*.

Slightly more duplication of code now. Need a base class...
This commit is contained in:
Jared Boone 2016-01-12 22:00:42 -08:00
parent e73a9f98a1
commit 731cea1b96
11 changed files with 42 additions and 30 deletions

View File

@ -32,7 +32,7 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
CH_IRQ_PROLOGUE(); CH_IRQ_PROLOGUE();
chSysLockFromIsr(); chSysLockFromIsr();
events_flag_isr(EVT_MASK_APPLICATION); EventDispatcher::events_flag_isr(EVT_MASK_APPLICATION);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
creg::m4txevent::clear(); creg::m4txevent::clear();
@ -41,3 +41,5 @@ CH_IRQ_HANDLER(M4Core_IRQHandler) {
} }
} }
Thread* EventDispatcher::thread_event_loop = nullptr;

View File

@ -66,6 +66,7 @@ public:
painter(painter), painter(painter),
context(context) context(context)
{ {
thread_event_loop = chThdSelf();
touch_manager.on_event = [this](const ui::TouchEvent event) { touch_manager.on_event = [this](const ui::TouchEvent event) {
this->on_touch_event(event); this->on_touch_event(event);
}; };
@ -86,7 +87,21 @@ public:
is_running = false; is_running = false;
} }
static inline void events_flag(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignal(thread_event_loop, events);
}
}
static inline void events_flag_isr(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignalI(thread_event_loop, events);
}
}
private: private:
static Thread* thread_event_loop;
touch::Manager touch_manager; touch::Manager touch_manager;
ui::Widget* const top_widget; ui::Widget* const top_widget;
ui::Painter& painter; ui::Painter& painter;

View File

@ -165,7 +165,7 @@ void timer0_callback(GPTDriver* const) {
/* Signal event loop */ /* Signal event loop */
if( event_mask ) { if( event_mask ) {
chSysLockFromIsr(); chSysLockFromIsr();
events_flag_isr(event_mask); EventDispatcher::events_flag_isr(event_mask);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
} }

View File

@ -54,7 +54,7 @@ CH_IRQ_HANDLER(PIN_INT4_IRQHandler) {
CH_IRQ_PROLOGUE(); CH_IRQ_PROLOGUE();
chSysLockFromIsr(); chSysLockFromIsr();
events_flag_isr(EVT_MASK_LCD_FRAME_SYNC); EventDispatcher::events_flag_isr(EVT_MASK_LCD_FRAME_SYNC);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
LPC_GPIO_INT->IST = (1U << 4); LPC_GPIO_INT->IST = (1U << 4);

View File

@ -39,7 +39,7 @@ CH_IRQ_HANDLER(RTC_IRQHandler) {
CH_IRQ_PROLOGUE(); CH_IRQ_PROLOGUE();
chSysLockFromIsr(); chSysLockFromIsr();
events_flag_isr(EVT_MASK_RTC_TICK); EventDispatcher::events_flag_isr(EVT_MASK_RTC_TICK);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
rtc::interrupt::clear_all(); rtc::interrupt::clear_all();

View File

@ -66,7 +66,6 @@ int main(void) {
sdcStart(&SDCD1, nullptr); sdcStart(&SDCD1, nullptr);
events_initialize(chThdSelf());
init_message_queues(); init_message_queues();
ui::Context context; ui::Context context;

View File

@ -32,7 +32,7 @@ CH_IRQ_HANDLER(MAPP_IRQHandler) {
CH_IRQ_PROLOGUE(); CH_IRQ_PROLOGUE();
chSysLockFromIsr(); chSysLockFromIsr();
events_flag_isr(EVT_MASK_BASEBAND); EventDispatcher::events_flag_isr(EVT_MASK_BASEBAND);
chSysUnlockFromIsr(); chSysUnlockFromIsr();
creg::m0apptxevent::clear(); creg::m0apptxevent::clear();
@ -41,3 +41,5 @@ CH_IRQ_HANDLER(MAPP_IRQHandler) {
} }
} }
Thread* EventDispatcher::thread_event_loop = nullptr;

View File

@ -44,7 +44,7 @@ constexpr auto EVT_MASK_SPECTRUM = EVENT_MASK(1);
class EventDispatcher { class EventDispatcher {
public: public:
void run() { void run() {
events_initialize(chThdSelf()); thread_event_loop = chThdSelf();
lpc43xx::creg::m0apptxevent::enable(); lpc43xx::creg::m0apptxevent::enable();
baseband_thread.thread_main = chThdSelf(); baseband_thread.thread_main = chThdSelf();
@ -63,7 +63,21 @@ public:
is_running = false; is_running = false;
} }
static inline void events_flag(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignal(thread_event_loop, events);
}
}
static inline void events_flag_isr(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignalI(thread_event_loop, events);
}
}
private: private:
static Thread* thread_event_loop;
BasebandThread baseband_thread; BasebandThread baseband_thread;
RSSIThread rssi_thread; RSSIThread rssi_thread;

View File

@ -27,6 +27,8 @@
#include "event_m4.hpp" #include "event_m4.hpp"
#include "portapack_shared_memory.hpp" #include "portapack_shared_memory.hpp"
#include "event_m4.hpp"
#include <algorithm> #include <algorithm>
void SpectrumCollector::on_message(const Message* const message) { void SpectrumCollector::on_message(const Message* const message) {
@ -97,7 +99,7 @@ void SpectrumCollector::post_message(const buffer_c16_t& data) {
fft_swap(data, channel_spectrum); fft_swap(data, channel_spectrum);
channel_spectrum_sampling_rate = data.sampling_rate; channel_spectrum_sampling_rate = data.sampling_rate;
channel_spectrum_request_update = true; channel_spectrum_request_update = true;
events_flag(EVT_MASK_SPECTRUM); EventDispatcher::events_flag(EVT_MASK_SPECTRUM);
} }
} }

View File

@ -22,9 +22,3 @@
#include "event.hpp" #include "event.hpp"
#include "ch.h" #include "ch.h"
Thread* thread_event_loop = nullptr;
void events_initialize(Thread* const event_loop_thread) {
thread_event_loop = event_loop_thread;
}

View File

@ -24,20 +24,4 @@
#include "ch.h" #include "ch.h"
void events_initialize(Thread* const event_loop_thread);
extern Thread* thread_event_loop;
inline void events_flag(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignal(thread_event_loop, events);
}
}
inline void events_flag_isr(const eventmask_t events) {
if( thread_event_loop ) {
chEvtSignalI(thread_event_loop, events);
}
}
#endif/*__EVENT_H__*/ #endif/*__EVENT_H__*/