diff --git a/include/display.h b/include/display.h index 62cdf363..70187893 100644 --- a/include/display.h +++ b/include/display.h @@ -5,6 +5,7 @@ #include "cyclic.h" #include "qrcode.h" #include "power.h" +#include "timekeeper.h" #if (HAS_DISPLAY) == 1 #include diff --git a/include/irqhandler.h b/include/irqhandler.h index 8b14b293..eacbd35f 100644 --- a/include/irqhandler.h +++ b/include/irqhandler.h @@ -24,7 +24,7 @@ void irqHandler(void *pvParameters); void mask_user_IRQ(); void unmask_user_IRQ(); -void doIRQ(int irq); +void IRAM_ATTR doIRQ(int irq); extern TaskHandle_t irqHandlerTask; diff --git a/include/timekeeper.h b/include/timekeeper.h index 956595df..88084916 100644 --- a/include/timekeeper.h +++ b/include/timekeeper.h @@ -20,8 +20,9 @@ extern const char timeSetSymbols[]; extern Ticker timesyncer; extern timesource_t timeSource; extern TaskHandle_t ClockTask; -extern bool volatile TimePulseTick; // 1sec pps flag set by GPS or RTC +extern DRAM_ATTR bool TimePulseTick; // 1sec pps flag set by GPS or RTC extern hw_timer_t *ppsIRQ; +extern portMUX_TYPE mux; void IRAM_ATTR CLOCKIRQ(void); void clock_init(void); diff --git a/src/display.cpp b/src/display.cpp index 10722fa3..e41dea81 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -317,7 +317,9 @@ void dp_drawPage(bool nextpage) { #if (TIME_SYNC_INTERVAL) timeState = TimePulseTick ? ' ' : timeSetSymbols[timeSource]; - TimePulseTick = false; + portENTER_CRITICAL(&mux); + TimePulseTick = false; // flip global variable pulse ticker + portEXIT_CRITICAL(&mux); time(&now); localtime_r(&now, &timeinfo); strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo); diff --git a/src/main.cpp b/src/main.cpp index 4bc007ab..9cd922fc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -48,37 +48,31 @@ Low priority numbers denote low priority tasks. ------------------------------------------------------------------------------- 0 displayIRQ -> display refresh -> 40ms (DISPLAYREFRESH_MS) 1 ppsIRQ -> pps clock irq -> 1sec +2 (unused) 3 MatrixDisplayIRQ -> matrix mux cycle -> 0,5ms (MATRIX_DISPLAY_SCAN_US) -// Interrupt routines -------------------------------------------------------------------------------- - -irqHandlerTask (Core 1), see irqhandler.cpp - -fired by hardware -DisplayIRQ -> esp32 timer 0 -CLOCKIRQ -> esp32 timer 1 or external GPIO (RTC_INT or GPS_INT) -MatrixDisplayIRQ-> esp32 timer 3 -ButtonIRQ -> external GPIO -PMUIRQ -> PMU chip GPIO - -fired by software -TIMESYNC_IRQ -> setTimeSyncIRQ() -> Ticker.h -CYCLIC_IRQ -> setCyclicIRQ() -> Ticker.h -SENDCYCLE_IRQ -> setSendIRQ() -> xTimer -BME_IRQ -> setBMEIRQ() -> Ticker.h - -ClockTask (Core 1), see timekeeper.cpp - -fired by hardware -CLOCKIRQ -> esp32 timer 1 - - // External RTC timer (if present) ------------------------------------------------------------------------------- triggers pps 1 sec impulse + +// Interrupt routines +------------------------------------------------------------------------------- + +ISRs fired by CPU or GPIO: +DisplayIRQ <- esp32 timer 0 +CLOCKIRQ <- esp32 timer 1 or GPIO (RTC_INT or GPS_INT) +MatrixDisplayIRQ<- esp32 timer 3 +ButtonIRQ <- GPIO <- Button +PMUIRQ <- GPIO <- PMU chip + +Application IRQs fired by software: +TIMESYNC_IRQ <- setTimeSyncIRQ() <- Ticker.h +CYCLIC_IRQ <- setCyclicIRQ() <- Ticker.h +SENDCYCLE_IRQ <- setSendIRQ() <- xTimer +BME_IRQ <- setBMEIRQ() <- Ticker.h + */ // Basic Config diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index fec827a4..84445e77 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -19,7 +19,9 @@ static const char TAG[] = __FILE__; // G = GPS / R = RTC / L = LORA / * = no sync / ? = never synced const char timeSetSymbols[] = {'G', 'R', 'L', '*', '?'}; -DRAM_ATTR bool volatile TimePulseTick = false; +portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; + +DRAM_ATTR bool TimePulseTick = false; timesource_t timeSource = _unsynced; TaskHandle_t ClockTask = NULL; hw_timer_t *ppsIRQ = NULL; @@ -211,7 +213,9 @@ void IRAM_ATTR CLOCKIRQ(void) { // flip time pulse ticker, if needed #ifdef HAS_DISPLAY #if (defined GPS_INT || defined RTC_INT) - TimePulseTick = !TimePulseTick; // flip pulse ticker + portENTER_CRITICAL(&mux); + TimePulseTick = !TimePulseTick; // flip global variable pulse ticker + portEXIT_CRITICAL(&mux); #endif #endif