From 2ed0653056a2c22680a07d987573142c09c218bb Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Thu, 27 Apr 2023 01:44:17 +0300 Subject: [PATCH] rotary:[#9] process interrupts and send to master --- source/shoh/src/threads/common/Event.h | 5 ++++ source/shoh/src/threads/master/Master.cpp | 17 ++++++++++-- source/shoh/src/threads/rotary/Rotary.cpp | 34 ++++++++++++++++++++--- source/shoh/src/threads/rotary/Rotary.h | 4 +-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/source/shoh/src/threads/common/Event.h b/source/shoh/src/threads/common/Event.h index 30c9dea..5577b00 100644 --- a/source/shoh/src/threads/common/Event.h +++ b/source/shoh/src/threads/common/Event.h @@ -47,6 +47,11 @@ public: return pos->second; } + void inline setDataOf(Event::EventType e, EventRawData data) + { + events[e] = data; + } + private: std::map events; }; diff --git a/source/shoh/src/threads/master/Master.cpp b/source/shoh/src/threads/master/Master.cpp index e761e1e..70c46bf 100644 --- a/source/shoh/src/threads/master/Master.cpp +++ b/source/shoh/src/threads/master/Master.cpp @@ -18,9 +18,22 @@ void Master::taskFunction() { bool LedState = true; for (;;) { _qm->receive(ThreadCommon::QueueManager::master_event_all, &data, portMAX_DELAY); - if(data.getDataOf(Event::Rotary) == ThreadCommon::RotaryAction::Idle){ - Board_LED_Set(led, LedState); + switch(data.getDataOf(Event::Rotary)) + { + case ThreadCommon::RotaryAction::Right: + Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); + break; + case ThreadCommon::RotaryAction::Left: + Board_LED_Set(ThreadCommon::RotaryAction::Left, LedState); + break; + case ThreadCommon::RotaryAction::Press: + Board_LED_Set(ThreadCommon::RotaryAction::Press, LedState); + break; + case ThreadCommon::RotaryAction::Idle: + Board_LED_Set(ThreadCommon::RotaryAction::Right, LedState); + break; } + LedState = !LedState; } } diff --git a/source/shoh/src/threads/rotary/Rotary.cpp b/source/shoh/src/threads/rotary/Rotary.cpp index f35cbd9..be7e78c 100644 --- a/source/shoh/src/threads/rotary/Rotary.cpp +++ b/source/shoh/src/threads/rotary/Rotary.cpp @@ -7,6 +7,9 @@ #include "Rotary.h" #include "board.h" +#include "queue.h" + +static QueueHandle_t * p_rotary_isr_q; extern "C" { @@ -14,18 +17,30 @@ extern "C" PIN_INT0_IRQHandler (void) { Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT0_IRQn)); + portBASE_TYPE xHigherPriorityWoken = pdFALSE; + uint8_t data = ThreadCommon::RotaryAction::Right; + xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken); + portEND_SWITCHING_ISR(xHigherPriorityWoken); } void PIN_INT1_IRQHandler (void) { Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT1_IRQn)); + portBASE_TYPE xHigherPriorityWoken = pdFALSE; + uint8_t data = ThreadCommon::RotaryAction::Left; + xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken); + portEND_SWITCHING_ISR(xHigherPriorityWoken); } void PIN_INT2_IRQHandler (void) { Chip_PININT_ClearIntStatus (LPC_PININT, PININTCH (PIN_INT2_IRQn)); + portBASE_TYPE xHigherPriorityWoken = pdFALSE; + uint8_t data = ThreadCommon::RotaryAction::Press; + xQueueSendFromISR (*p_rotary_isr_q, &data, &xHigherPriorityWoken); + portEND_SWITCHING_ISR(xHigherPriorityWoken); } } @@ -38,17 +53,28 @@ Rotary::~Rotary() {} void Rotary::taskFunction() { -Event data(Event::Null, 0); - Event* e = new Event(Event::Rotary, ThreadCommon::RotaryAction::Idle); - _qm->send(ThreadCommon::QueueManager::master_event_all, e, 10); + auto action_from_rotary_isr = ThreadCommon::RotaryAction::Idle; + Event * p_e= new Event(Event::EventType::Rotary, action_from_rotary_isr); + for (;;) { - vTaskDelay(500); + xQueueReceive(*p_rotary_isr_q, &action_from_rotary_isr, portMAX_DELAY); + p_e->setDataOf(Event::EventType::Rotary, action_from_rotary_isr); + _qm->send(ThreadCommon::QueueManager::master_event_all, p_e, 10); } } void rotary_thread(void* pvParams) { + // Special case for ISR + QueueHandle_t rotary_isr_q = xQueueCreate(15, sizeof(char)); + p_rotary_isr_q = &rotary_isr_q; + Rotary r(static_cast(pvParams)); r.taskFunction(); } + +static inline void sendActionAndAssertQueue (uint8_t *data, BaseType_t *const pxHPW) +{ + +} diff --git a/source/shoh/src/threads/rotary/Rotary.h b/source/shoh/src/threads/rotary/Rotary.h index b47e38c..56fdf17 100644 --- a/source/shoh/src/threads/rotary/Rotary.h +++ b/source/shoh/src/threads/rotary/Rotary.h @@ -20,8 +20,8 @@ public: private: Event* message; ThreadCommon::QueueManager* _qm; - DigitalIoPin signal[3] = { { 0, 1, true, true, false, true, PIN_INT0_IRQn}, - { 0, 5, true, false, false, true, PIN_INT1_IRQn}, + DigitalIoPin signal[3] = { { 0, 1, true, true, false, true, PIN_INT0_IRQn}, //SW1 + { 0, 16, true, true, false, true, PIN_INT1_IRQn}, //SW2 { 1, 8, true, false, false, true, PIN_INT2_IRQn} }; };