rtctime.cpp: timepulse fixes
This commit is contained in:
parent
46f41d0ee8
commit
e7a5ab3ca6
@ -110,9 +110,14 @@ int timepulse_init(uint32_t pulse_period_ms) {
|
||||
|
||||
// setup external interupt for active low RTC INT pin
|
||||
pinMode(GPS_INT, INPUT_PULLDOWN);
|
||||
|
||||
// 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
|
||||
|
||||
// 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
|
||||
pinMode(RTC_INT, INPUT_PULLUP);
|
||||
|
||||
// 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()) {
|
||||
switch (RTC_CLK) {
|
||||
case 1000: // 1000ms
|
||||
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
|
||||
break;
|
||||
case 1: // 1ms
|
||||
Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1kHz);
|
||||
break;
|
||||
default:
|
||||
goto pulse_period_error;
|
||||
}
|
||||
Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
|
||||
I2C_MUTEX_UNLOCK();
|
||||
} else {
|
||||
@ -136,18 +149,20 @@ int timepulse_init(uint32_t pulse_period_ms) {
|
||||
#else
|
||||
// use ESP32 hardware timer as time base with adjustable frequency
|
||||
if (pulse_period_ms) {
|
||||
ESP_LOGI(TAG, "Time base ESP32 clock");
|
||||
ESP_LOGI(TAG, "Time base: ESP32 hardware timer");
|
||||
clockCycle =
|
||||
timerBegin(1, 8000, true); // set 80 MHz prescaler to 1/10000 sec
|
||||
timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
|
||||
timerAlarmWrite(clockCycle, 10 * pulse_period_ms, true); // ms
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Invalid pulse clock frequency");
|
||||
return 0; // failure
|
||||
}
|
||||
} else
|
||||
goto pulse_period_error;
|
||||
return 1; // success
|
||||
|
||||
#endif
|
||||
|
||||
pulse_period_error:
|
||||
ESP_LOGE(TAG, "Unknown timepulse period value");
|
||||
return 0; // failure
|
||||
}
|
||||
|
||||
void timepulse_start() {
|
||||
|
Loading…
Reference in New Issue
Block a user