2018-10-04 22:08:54 +02:00
|
|
|
#include "irqhandler.h"
|
|
|
|
|
|
|
|
// Local logging tag
|
2019-02-27 00:52:27 +01:00
|
|
|
static const char TAG[] = __FILE__;
|
2018-10-04 22:08:54 +02:00
|
|
|
|
|
|
|
// 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
|
2018-10-04 22:08:54 +02:00
|
|
|
|
2019-12-26 16:55:19 +01:00
|
|
|
uint32_t InterruptStatus;
|
2018-10-04 22:08:54 +02:00
|
|
|
|
|
|
|
// 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
|
2018-10-04 22:08:54 +02:00
|
|
|
|
2019-03-31 19:13:06 +02:00
|
|
|
if (InterruptStatus & UNMASK_IRQ) // interrupt handler to be enabled?
|
2019-12-26 16:55:19 +01:00
|
|
|
InterruptStatus &= ~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
|
2019-12-26 16:55:19 +01:00
|
|
|
else if ((InterruptStatus & 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
|
|
|
|
2018-10-04 22:08:54 +02:00
|
|
|
// button pressed?
|
|
|
|
#ifdef HAS_BUTTON
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & BUTTON_IRQ) {
|
2018-10-04 22:08:54 +02:00
|
|
|
readButton();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~BUTTON_IRQ;
|
|
|
|
}
|
2018-10-04 22:08:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// display needs refresh?
|
2019-03-13 22:08:05 +01:00
|
|
|
#ifdef HAS_DISPLAY
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & DISPLAY_IRQ) {
|
2020-03-29 12:10:42 +02:00
|
|
|
dp_refresh();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~DISPLAY_IRQ;
|
|
|
|
}
|
2018-10-04 22:08:54 +02:00
|
|
|
#endif
|
|
|
|
|
2019-05-05 23:43:18 +02:00
|
|
|
// LED Matrix display needs refresh?
|
|
|
|
#ifdef HAS_MATRIX_DISPLAY
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & MATRIX_DISPLAY_IRQ) {
|
2019-05-05 23:43:18 +02:00
|
|
|
refreshTheMatrixDisplay();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~MATRIX_DISPLAY_IRQ;
|
|
|
|
}
|
2019-05-05 23:43:18 +02:00
|
|
|
#endif
|
|
|
|
|
2019-12-26 16:55:19 +01:00
|
|
|
#if (TIME_SYNC_INTERVAL)
|
|
|
|
// is time to be synced?
|
|
|
|
if (InterruptStatus & TIMESYNC_IRQ) {
|
|
|
|
now(); // ensure sysTime is recent
|
|
|
|
calibrateTime();
|
|
|
|
InterruptStatus &= ~TIMESYNC_IRQ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-29 20:23:27 +02:00
|
|
|
// BME sensor data to be read?
|
|
|
|
#if (HAS_BME)
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & BME_IRQ) {
|
2019-07-29 20:23:27 +02:00
|
|
|
bme_storedata(&bme_status);
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~BME_IRQ;
|
|
|
|
}
|
2019-07-29 20:23:27 +02:00
|
|
|
#endif
|
|
|
|
|
2020-06-16 20:29:49 +02:00
|
|
|
// MQTT loop due?
|
|
|
|
#if (HAS_MQTT)
|
|
|
|
if (InterruptStatus & MQTT_IRQ) {
|
|
|
|
mqtt_loop();
|
|
|
|
InterruptStatus &= ~MQTT_IRQ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-10-04 22:08:54 +02:00
|
|
|
// are cyclic tasks due?
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & CYCLIC_IRQ) {
|
2018-10-04 22:08:54 +02:00
|
|
|
doHousekeeping();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~CYCLIC_IRQ;
|
|
|
|
}
|
2018-10-04 22:08:54 +02:00
|
|
|
|
2019-09-09 21:45:19 +02:00
|
|
|
// do we have a power event?
|
2020-10-09 22:47:04 +02:00
|
|
|
#ifdef HAS_PMU
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & PMU_IRQ) {
|
2019-10-16 21:14:34 +02:00
|
|
|
AXP192_powerevent_IRQ();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~PMU_IRQ;
|
|
|
|
}
|
2019-09-09 21:45:19 +02:00
|
|
|
#endif
|
|
|
|
|
2018-10-04 22:08:54 +02:00
|
|
|
// is time to send the payload?
|
2019-12-26 13:25:59 +01:00
|
|
|
if (InterruptStatus & SENDCYCLE_IRQ) {
|
2019-08-30 18:54:53 +02:00
|
|
|
sendData();
|
2019-12-26 13:25:59 +01:00
|
|
|
InterruptStatus &= ~SENDCYCLE_IRQ;
|
|
|
|
}
|
2019-12-26 16:55:19 +01:00
|
|
|
} // for
|
|
|
|
} // irqHandler()
|
2018-10-04 22:08:54 +02:00
|
|
|
|
2020-06-16 20:29:49 +02:00
|
|
|
// timer triggered interrupt service routines
|
2018-10-04 22:08:54 +02:00
|
|
|
// 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);
|
2019-05-05 23:43:18 +02:00
|
|
|
if (xHigherPriorityTaskWoken)
|
|
|
|
portYIELD_FROM_ISR();
|
|
|
|
}
|
2020-06-16 20:29:49 +02:00
|
|
|
|
|
|
|
#ifdef HAS_DISPLAY
|
|
|
|
void IRAM_ATTR DisplayIRQ() { doIRQ(DISPLAY_IRQ); }
|
2019-05-05 23:43:18 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAS_MATRIX_DISPLAY
|
2020-06-16 20:29:49 +02:00
|
|
|
void IRAM_ATTR MatrixDisplayIRQ() { doIRQ(MATRIX_DISPLAY_IRQ); }
|
2018-10-04 22:08:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAS_BUTTON
|
2020-06-16 20:29:49 +02:00
|
|
|
void IRAM_ATTR ButtonIRQ() { doIRQ(BUTTON_IRQ); }
|
2018-10-04 22:08:54 +02:00
|
|
|
#endif
|
2019-03-31 19:13:06 +02:00
|
|
|
|
2019-09-09 21:45:19 +02:00
|
|
|
#ifdef HAS_PMU
|
2020-06-16 20:29:49 +02:00
|
|
|
void IRAM_ATTR PMUIRQ() { doIRQ(PMU_IRQ); }
|
2019-09-09 21:45:19 +02:00
|
|
|
#endif
|
|
|
|
|
2019-07-23 20:07:24 +02:00
|
|
|
void mask_user_IRQ() { xTaskNotify(irqHandlerTask, MASK_IRQ, eSetBits); }
|
2019-03-31 19:13:06 +02:00
|
|
|
|
2019-07-23 20:07:24 +02:00
|
|
|
void unmask_user_IRQ() { xTaskNotify(irqHandlerTask, UNMASK_IRQ, eSetBits); }
|