fix for RTC syncing (experimental)
This commit is contained in:
parent
01989320e0
commit
f74f103e80
@ -24,7 +24,12 @@ extern Ticker timesyncer;
|
|||||||
extern timesource_t timeSource;
|
extern timesource_t timeSource;
|
||||||
extern TaskHandle_t ClockTask;
|
extern TaskHandle_t ClockTask;
|
||||||
extern DRAM_ATTR bool TimePulseTick; // 1sec pps flag set by GPS or RTC
|
extern DRAM_ATTR bool TimePulseTick; // 1sec pps flag set by GPS or RTC
|
||||||
|
#ifdef GPS_INT
|
||||||
extern DRAM_ATTR unsigned long lastPPS;
|
extern DRAM_ATTR unsigned long lastPPS;
|
||||||
|
#endif
|
||||||
|
#ifdef RTC_INT
|
||||||
|
extern DRAM_ATTR unsigned long lastRTCpulse;
|
||||||
|
#endif
|
||||||
extern hw_timer_t *ppsIRQ;
|
extern hw_timer_t *ppsIRQ;
|
||||||
|
|
||||||
void setTimeSyncIRQ(void);
|
void setTimeSyncIRQ(void);
|
||||||
|
@ -52,9 +52,6 @@ uint8_t set_rtctime(time_t t) { // t is sec epoch time
|
|||||||
ESP_LOGI(TAG, "RTC time synced");
|
ESP_LOGI(TAG, "RTC time synced");
|
||||||
return 1; // success
|
return 1; // success
|
||||||
|
|
||||||
// failure
|
|
||||||
// return 0
|
|
||||||
|
|
||||||
} // set_rtctime()
|
} // set_rtctime()
|
||||||
|
|
||||||
time_t get_rtctime(uint16_t *msec) {
|
time_t get_rtctime(uint16_t *msec) {
|
||||||
@ -65,15 +62,12 @@ time_t get_rtctime(uint16_t *msec) {
|
|||||||
RtcDateTime tt = Rtc.GetDateTime();
|
RtcDateTime tt = Rtc.GetDateTime();
|
||||||
t = tt.Epoch32Time(); // sec2000 -> epoch
|
t = tt.Epoch32Time(); // sec2000 -> epoch
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
// if we have a RTC pulse, we calculate msec
|
||||||
#ifdef RTC_INT
|
#ifdef RTC_INT
|
||||||
// adjust time to top of next second by waiting TimePulseTick to flip
|
*msec = lastRTCpulse % 1000;
|
||||||
bool lastTick = TimePulseTick;
|
|
||||||
while (TimePulseTick == lastTick) {
|
|
||||||
};
|
|
||||||
t++;
|
|
||||||
#endif
|
#endif
|
||||||
*/
|
|
||||||
return t;
|
return t;
|
||||||
|
|
||||||
} // get_rtctime()
|
} // get_rtctime()
|
||||||
|
@ -12,7 +12,13 @@ static const char TAG[] = __FILE__;
|
|||||||
const char timeSetSymbols[] = {'G', 'R', 'L', '*', '?'};
|
const char timeSetSymbols[] = {'G', 'R', 'L', '*', '?'};
|
||||||
|
|
||||||
DRAM_ATTR bool TimePulseTick = false;
|
DRAM_ATTR bool TimePulseTick = false;
|
||||||
|
#ifdef GPS_INT
|
||||||
DRAM_ATTR unsigned long lastPPS = millis();
|
DRAM_ATTR unsigned long lastPPS = millis();
|
||||||
|
#endif
|
||||||
|
#ifdef RTC_INT
|
||||||
|
DRAM_ATTR unsigned long lastRTCpulse = millis();
|
||||||
|
#endif
|
||||||
|
|
||||||
timesource_t timeSource = _unsynced;
|
timesource_t timeSource = _unsynced;
|
||||||
TaskHandle_t ClockTask = NULL;
|
TaskHandle_t ClockTask = NULL;
|
||||||
hw_timer_t *ppsIRQ = NULL;
|
hw_timer_t *ppsIRQ = NULL;
|
||||||
@ -31,6 +37,7 @@ Ticker timesyncer;
|
|||||||
|
|
||||||
void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
void setTimeSyncIRQ() { xTaskNotify(irqHandlerTask, TIMESYNC_IRQ, eSetBits); }
|
||||||
|
|
||||||
|
#ifdef GPS_INT
|
||||||
// interrupt service routine triggered by GPS PPS
|
// interrupt service routine triggered by GPS PPS
|
||||||
void IRAM_ATTR GPSIRQ(void) {
|
void IRAM_ATTR GPSIRQ(void) {
|
||||||
|
|
||||||
@ -43,6 +50,7 @@ void IRAM_ATTR GPSIRQ(void) {
|
|||||||
if (xHigherPriorityTaskWoken)
|
if (xHigherPriorityTaskWoken)
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// interrupt service routine triggered by esp32 hardware timer
|
// interrupt service routine triggered by esp32 hardware timer
|
||||||
void IRAM_ATTR CLOCKIRQ(void) {
|
void IRAM_ATTR CLOCKIRQ(void) {
|
||||||
@ -60,6 +68,11 @@ void IRAM_ATTR CLOCKIRQ(void) {
|
|||||||
TimePulseTick = !TimePulseTick; // flip global variable pulse ticker
|
TimePulseTick = !TimePulseTick; // flip global variable pulse ticker
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// take timestamp if we have RTC pulse
|
||||||
|
#ifdef RTC_INT
|
||||||
|
lastRTCpulse = millis(); // last time of RTC pulse
|
||||||
|
#endif
|
||||||
|
|
||||||
// yield only if we should
|
// yield only if we should
|
||||||
if (xHigherPriorityTaskWoken)
|
if (xHigherPriorityTaskWoken)
|
||||||
portYIELD_FROM_ISR();
|
portYIELD_FROM_ISR();
|
||||||
|
Loading…
Reference in New Issue
Block a user