ESP32-PaxCounter/src/irqhandler.cpp

88 lines
2.2 KiB
C++
Raw Normal View History

#include "irqhandler.h"
// Local logging tag
2019-02-27 00:52:27 +01:00
static const char TAG[] = __FILE__;
// irq handler task, handles all our application level interrupts
void irqHandler(void *pvParameters) {
configASSERT(((uint32_t)pvParameters) == 1); // FreeRTOS check
uint32_t InterruptStatus;
2019-03-24 16:15:29 +01:00
static bool mask_irq = false;
// task remains in blocked state until it is notified by an irq
for (;;) {
2019-02-27 00:52:27 +01:00
xTaskNotifyWait(0x00, // Don't clear any bits on entry
ULONG_MAX, // Clear all bits on exit
&InterruptStatus, // Receives the notification value
portMAX_DELAY); // wait forever
2019-03-24 16:15:29 +01:00
// interrupt handler to be enabled?
if (InterruptStatus & UNMASK_IRQ)
mask_irq = false;
else if (mask_irq)
continue; // suppress processing if interrupt handler is disabled
// interrupt handler to be disabled?
if (InterruptStatus & MASK_IRQ)
mask_irq = true;
// button pressed?
#ifdef HAS_BUTTON
if (InterruptStatus & BUTTON_IRQ)
readButton();
#endif
// display needs refresh?
2019-03-13 22:08:05 +01:00
#ifdef HAS_DISPLAY
if (InterruptStatus & DISPLAY_IRQ)
refreshtheDisplay();
#endif
// are cyclic tasks due?
2019-03-03 12:57:00 +01:00
if (InterruptStatus & CYCLIC_IRQ)
doHousekeeping();
2019-03-09 00:53:11 +01:00
#if (TIME_SYNC_INTERVAL)
2019-03-03 12:57:00 +01:00
// is time to be synced?
2019-03-09 15:25:44 +01:00
if (InterruptStatus & TIMESYNC_IRQ) {
time_t t = timeProvider();
if (timeIsValid(t))
setTime(t);
}
2019-03-03 12:57:00 +01:00
#endif
// is time to send the payload?
2019-03-03 12:57:00 +01:00
if (InterruptStatus & SENDCYCLE_IRQ)
sendCounter();
}
vTaskDelete(NULL); // shoud never be reached
}
// esp32 hardware timer triggered interrupt service routines
// they notify the irq handler task
2019-03-13 22:08:05 +01:00
#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() {
2019-03-24 00:15:04 +01:00
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
2019-03-03 12:57:00 +01:00
xTaskNotifyFromISR(irqHandlerTask, DISPLAY_IRQ, eSetBits,
&xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
#endif
#ifdef HAS_BUTTON
void IRAM_ATTR ButtonIRQ() {
2019-03-24 00:15:04 +01:00
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
2019-03-03 12:57:00 +01:00
xTaskNotifyFromISR(irqHandlerTask, BUTTON_IRQ, eSetBits,
&xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
#endif