Merge pull request #864 from cyberman54/development

Development
This commit is contained in:
Verkehrsrot 2022-03-05 19:09:11 +01:00 committed by GitHub
commit 2dd01b6bbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 11 deletions

View File

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

View File

@ -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,18 @@ 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 uint16_t ppsDiff = millis() - lastRTCpulse;
bool lastTick = TimePulseTick; if (ppsDiff < 1000)
while (TimePulseTick == lastTick) { *msec = ppsDiff;
}; else {
t++; ESP_LOGD(TAG, "no pulse from RTC");
return 0;
}
#endif #endif
*/
return t; return t;
} // get_rtctime() } // get_rtctime()

View File

@ -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();
@ -190,8 +203,10 @@ void timepulse_init(void) {
#endif #endif
// get time if we don't have one // get time if we don't have one
if (timeSource != _set) if (timeSource != _set) {
delay(1000); // wait for first PPS time stamp to arrive
setTimeSyncIRQ(); // init systime by RTC or GPS or LORA setTimeSyncIRQ(); // init systime by RTC or GPS or LORA
}
// start cyclic time sync // start cyclic time sync
timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ); timesyncer.attach(TIME_SYNC_INTERVAL * 60, setTimeSyncIRQ);