src/rtctime.cpp
// helper function to setup a pulse for time synchronisation
helper function to setup a pulse for time synchronisation
helper function to setup a pulse for time synchronisation
int timepulse_init(uint32_t pulse_period_ms) {
#if defined GPS_INT && defined GPS_CLK
  pinMode(GPS_INT, INPUT_PULLDOWN);
  ESP_LOGI(TAG, "Time base: GPS timepulse");
  switch (GPS_CLK) {
  case 1000:
    break; 
  default:
    goto pulse_period_error;
  }
  return 1; 
#elif defined RTC_INT && defined RTC_CLK
  pinMode(RTC_INT, INPUT_PULLUP);
  ESP_LOGI(TAG, "Time base: external RTC timepulse");
  if (I2C_MUTEX_LOCK()) {
    switch (RTC_CLK) {
    case 1000: 
      Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1Hz);
      break;
    case 1: 
      Rtc.SetSquareWavePinClockFrequency(DS3231SquareWaveClock_1kHz);
      break;
    default:
      goto pulse_period_error;
    }
    Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeClock);
    I2C_MUTEX_UNLOCK();
  } else {
    ESP_LOGE(TAG, "I2c bus busy - RTC initialization error");
    return 0; 
  }
  return 1; 
#else
  if (pulse_period_ms) {
    ESP_LOGI(TAG, "Time base: ESP32 hardware timer");
    clockCycle =
        timerBegin(1, 8000, true); 
    timerAttachInterrupt(clockCycle, &CLOCKIRQ, true);
    timerAlarmWrite(clockCycle, 10 * pulse_period_ms, true); 
  } else
    goto pulse_period_error;
  return 1; 
#endif
pulse_period_error:
  ESP_LOGE(TAG, "Unknown timepulse period value");
  return 0; 
}
int timepulse_init ( uint32_t pulse_period_ms ) { #if defined GPS_INT && defined GPS_CLK pinMode ( GPS_INT , INPUT_PULLDOWN ) ; ESP_LOGI ( TAG , " " ) ; switch ( GPS_CLK ) { case 1000 : break ; default : goto pulse_period_error ; } return 1 ; #elif defined RTC_INT && defined RTC_CLK pinMode ( RTC_INT , INPUT_PULLUP ) ; ESP_LOGI ( TAG , " " ) ; if ( I2C_MUTEX_LOCK ( ) ) { switch ( RTC_CLK ) { case 1000 : Rtc . SetSquareWavePinClockFrequency ( DS3231SquareWaveClock_1Hz ) ; break ; case 1 : Rtc . SetSquareWavePinClockFrequency ( DS3231SquareWaveClock_1kHz ) ; break ; default : goto pulse_period_error ; } Rtc . SetSquareWavePin ( DS3231SquareWavePin_ModeClock ) ; I2C_MUTEX_UNLOCK ( ) ; } else { ESP_LOGE ( TAG , " " ) ; return 0 ; } return 1 ; #else if ( pulse_period_ms ) { ESP_LOGI ( TAG , " " ) ; clockCycle = timerBegin ( 1 , 8000 , true ) ; timerAttachInterrupt ( clockCycle , & CLOCKIRQ , true ) ; timerAlarmWrite ( clockCycle , 10 * pulse_period_ms , true ) ; } else goto pulse_period_error ; return 1 ; #endif pulse_period_error : ESP_LOGE ( TAG , " " ) ; return 0 ; }
helper function to setup a pulse for time synchronisation
helper function to setup a pulse for time synchronisation
// use time pulse from GPS as time base with fixed 1Hz frequency // setup external interupt for active low RTC INT pin // setup external rtc 1Hz clock as pulse per second clock // default GPS timepulse 1000ms // success // use pulse from on board RTC chip as time base with fixed frequency // setup external interupt for active low RTC INT pin // setup external rtc 1Hz clock as pulse per second clock // 1000ms // 1ms // failure // success // use ESP32 hardware timer as time base with adjustable frequency // set 80 MHz prescaler to 1/10000 sec // ms // success // failure