rtctime.cpp: timepulse fixes

This commit is contained in:
Klaus K Wilting 2019-02-09 14:46:41 +01:00
parent 46f41d0ee8
commit e7a5ab3ca6

View File

@ -110,9 +110,14 @@ int timepulse_init(uint32_t pulse_period_ms) {
// setup external interupt for active low RTC INT pin // setup external interupt for active low RTC INT pin
pinMode(GPS_INT, INPUT_PULLDOWN); pinMode(GPS_INT, INPUT_PULLDOWN);
// setup external rtc 1Hz clock as pulse per second clock // setup external rtc 1Hz clock as pulse per second clock
ESP_LOGI(TAG, "Time base GPS timepulse"); ESP_LOGI(TAG, "Time base: GPS timepulse");
switch (GPS_CLK) {
case 1000:
break; // default GPS timepulse 1000ms
default:
goto pulse_period_error;
}
return 1; // success return 1; // success
// use pulse from on board RTC chip as time base with fixed frequency // use pulse from on board RTC chip as time base with fixed frequency
@ -120,11 +125,19 @@ int timepulse_init(uint32_t pulse_period_ms) {
// setup external interupt for active low RTC INT pin // setup external interupt for active low RTC INT pin
pinMode(RTC_INT, INPUT_PULLUP); pinMode(RTC_INT, INPUT_PULLUP);
// setup external rtc 1Hz clock as pulse per second clock // setup external rtc 1Hz clock as pulse per second clock
ESP_LOGI(TAG, "Time base external clock"); ESP_LOGI(TAG, "Time base: external RTC timepulse");
if (I2C_MUTEX_LOCK()) { if (I2C_MUTEX_LOCK()) {
switch (RTC_CLK) {
case 1000: // 1000ms
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz); Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
break;
case 1: // 1ms
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1kHz);
break;
default:
goto pulse_period_error;
}
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock); Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
I2C_MUTEX_UNLOCK(); I2C_MUTEX_UNLOCK();
} else { } else {
@ -136,18 +149,20 @@ int timepulse_init(uint32_t pulse_period_ms) {
#else #else
// use ESP32 hardware timer as time base with adjustable frequency // use ESP32 hardware timer as time base with adjustable frequency
if (pulse_period_ms) { if (pulse_period_ms) {
ESP_LOGI(TAG, "Time base ESP32 clock"); ESP_LOGI(TAG, "Time base: ESP32 hardware timer");
clockCycle = clockCycle =
timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true); timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
timerAlarmWrite(clockCycle, 10 * pulse_period_ms, true); // ms timerAlarmWrite(clockCycle, 10 * pulse_period_ms, true); // ms
} else { } else
ESP_LOGE(TAG, "Invalid pulse clock frequency"); goto pulse_period_error;
return 0; // failure
}
return 1; // success return 1; // success
#endif #endif
pulse_period_error:
ESP_LOGE(TAG, "Unknown timepulse period value");
return 0; // failure
} }
void timepulse_start() { void timepulse_start() {