ESP32-PaxCounter/src/irqhandler.cpp

105 lines
2.7 KiB
C++
Raw Normal View History

#include "irqhandler.h"
TaskHandle_t irqHandlerTask = NULL;
// irq handler task, handles all our application level interrupts
void irqHandler(void *pvParameters) {
2020-10-30 12:24:16 +01:00
_ASSERT((uint32_t)pvParameters == 1); // FreeRTOS check
2022-01-08 18:01:28 +01:00
uint32_t irqSource;
// task remains in blocked state until it is notified by an irq
for (;;) {
2022-11-06 15:00:54 +01:00
xTaskNotifyWait(0x00, // Don't clear any bits on entry
ULONG_MAX, // Clear all bits on exit
&irqSource, // Receives the notification value
portMAX_DELAY); // wait forever
2022-01-08 18:01:28 +01:00
if (irqSource & UNMASK_IRQ) // interrupt handler to be enabled?
irqSource &= ~MASK_IRQ; // then clear irq mask flag
2019-12-26 16:58:42 +01:00
// else suppress processing if interrupt handler is disabled
// or time critical lmic jobs are pending in next 100ms
2022-01-08 18:01:28 +01:00
else if ((irqSource & MASK_IRQ)
2019-12-26 16:58:42 +01:00
#if (HAS_LORA)
|| os_queryTimeCriticalJobs(ms2osticks(100))
2019-10-20 21:11:59 +02:00
#endif
2019-12-26 16:58:42 +01:00
)
2019-03-31 19:13:06 +02:00
continue;
2019-10-24 19:15:23 +02:00
// button pressed?
#ifdef HAS_BUTTON
2022-01-08 18:01:28 +01:00
if (irqSource & BUTTON_IRQ)
readButton();
#endif
// display needs refresh?
2019-03-13 22:08:05 +01:00
#ifdef HAS_DISPLAY
2022-01-08 18:01:28 +01:00
if (irqSource & DISPLAY_IRQ)
dp_refresh();
#endif
// LED Matrix display needs refresh?
#ifdef HAS_MATRIX_DISPLAY
2022-01-08 18:01:28 +01:00
if (irqSource & MATRIX_DISPLAY_IRQ)
refreshTheMatrixDisplay();
#endif
2019-12-26 16:55:19 +01:00
#if (TIME_SYNC_INTERVAL)
// is time to be synced?
2022-01-08 18:01:28 +01:00
if (irqSource & TIMESYNC_IRQ) {
2019-12-26 16:55:19 +01:00
calibrateTime();
}
#endif
// BME sensor data to be read?
#if (HAS_BME)
2022-01-08 18:01:28 +01:00
if (irqSource & BME_IRQ)
bme_storedata(&bme_status);
#endif
// are cyclic tasks due?
2022-01-08 18:01:28 +01:00
if (irqSource & CYCLIC_IRQ)
doHousekeeping();
// do we have a power event?
2020-10-09 22:47:04 +02:00
#ifdef HAS_PMU
2022-01-08 18:01:28 +01:00
if (irqSource & PMU_IRQ)
2019-10-16 21:14:34 +02:00
AXP192_powerevent_IRQ();
#endif
// is time to send the payload?
2022-01-08 18:01:28 +01:00
if (irqSource & SENDCYCLE_IRQ) {
2019-08-30 18:54:53 +02:00
sendData();
2020-12-09 10:15:12 +01:00
// goto sleep if we have a sleep cycle
if (cfg.sleepcycle)
#ifdef HAS_BUTTON
2022-11-13 22:27:06 +01:00
enter_deepsleep(cfg.sleepcycle * 10UL, (gpio_num_t)HAS_BUTTON);
2020-12-09 10:15:12 +01:00
#else
2022-11-13 22:27:06 +01:00
enter_deepsleep(cfg.sleepcycle * 10UL, GPIO_NUM_MAX);
2020-12-09 10:15:12 +01:00
#endif
}
2019-12-26 16:55:19 +01:00
} // for
} // irqHandler()
2020-06-16 20:29:49 +02:00
// timer triggered interrupt service routines
// they notify the irq handler task
2020-06-16 20:29:49 +02:00
void IRAM_ATTR doIRQ(int irq) {
2019-03-24 00:15:04 +01:00
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
2020-06-16 20:29:49 +02:00
xTaskNotifyFromISR(irqHandlerTask, irq, eSetBits, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken)
portYIELD_FROM_ISR();
}
2020-06-16 20:29:49 +02:00
#ifdef HAS_DISPLAY
void IRAM_ATTR DisplayIRQ() { doIRQ(DISPLAY_IRQ); }
#endif
#ifdef HAS_MATRIX_DISPLAY
2020-06-16 20:29:49 +02:00
void IRAM_ATTR MatrixDisplayIRQ() { doIRQ(MATRIX_DISPLAY_IRQ); }
#endif
void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
2019-03-31 19:13:06 +02:00
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }