sanitize ISR IRAM_ATTR and global vars

This commit is contained in:
cyberman54 2022-02-07 15:38:15 +01:00
parent c41d44bd7d
commit 69da95cd66
6 changed files with 31 additions and 29 deletions

View File

@ -5,6 +5,7 @@
#include "cyclic.h"
#include "qrcode.h"
#include "power.h"
#include "timekeeper.h"
#if (HAS_DISPLAY) == 1
#include <OneBitDisplay.h>

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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