Ejemplo n.º 1
0
void
clock_set_time(timestamp_t new_sync_timestamp)
{
  /* The clock was synced */
  if (sync_timestamp)
  {
    delta = new_sync_timestamp - sync_timestamp;
#if defined(CLOCK_NTP_ADJUST_SUPPORT) && !defined(CLOCK_CPU_SUPPORT)
    NTPADJDEBUG("sync timestamp delta is %d\n", delta);
    if (delta < -300 || delta > 300)
      NTPADJDEBUG("eeek, delta too large. " "not adjusting.\n");

    else if (sync_timestamp != clock_timestamp)
      NTPADJDEBUG("our clock is not up with ntp clock.\n");

    else if (NTP_RESYNC_PERIOD == -delta)
      NTPADJDEBUG("-delta equals resync period, eeek!? "
                  "clock isn't running at all.\n");
    else
    {
      uint32_t new_value = TC1_COUNTER_COMPARE;
      new_value *= NTP_RESYNC_PERIOD;
      new_value /= NTP_RESYNC_PERIOD + delta;

      NTPADJDEBUG("new OCR1A value %d\n", new_value);
      TC1_COUNTER_COMPARE = new_value;
    }
#endif /* CLOCK_NTP_ADJUST_SUPPORT */
  }

  sync_timestamp = new_sync_timestamp;
  n_sync_timestamp = new_sync_timestamp;
  n_sync_tick = TIMER_8_AS_1_COUNTER_CURRENT;

#if defined(CLOCK_DATETIME_SUPPORT) || defined(DCF77_SUPPORT) || defined(CLOCK_DATE_SUPPORT) || defined(CLOCK_TIME_SUPPORT)
  clock_reset_dst_change();
#endif

  /* Allow the clock to jump forward, but not to go backward
   * except the time difference is greater than 5 minutes */
  if (sync_timestamp > clock_timestamp ||
      (clock_timestamp - sync_timestamp) > 300)
    clock_timestamp = sync_timestamp;

#ifdef I2C_DS13X7_SUPPORT
  i2c_ds13x7_sync(sync_timestamp);
#endif
#ifdef I2C_PCF8583_SUPPORT
  i2c_pcf8583_set(sync_timestamp);
#endif

#ifdef NTP_SUPPORT
  ntp_timer = NTP_RESYNC_PERIOD;
#endif
}
Ejemplo n.º 2
0
void
clock_set_time(uint32_t new_sync_timestamp)
{
	/* The clock was synced */
	if (sync_timestamp) {
		delta = new_sync_timestamp - sync_timestamp;
#if defined(CLOCK_NTP_ADJUST_SUPPORT) && !defined(CLOCK_CPU_SUPPORT)
		NTPADJDEBUG ("sync timestamp delta is %d\n", delta);
		if (delta < -300 || delta > 300)
			NTPADJDEBUG ("eeek, delta too large. "
				     "not adjusting.\n");

		else if (sync_timestamp != timestamp)
			NTPADJDEBUG ("our clock is not up with ntp clock.\n");

		else if (NTP_RESYNC_PERIOD == -delta)
			NTPADJDEBUG ("-delta equals resync period, eeek!? "
				     "clock isn't running at all.\n");
		else {
			uint32_t new_value = OCR1A;
			new_value *= NTP_RESYNC_PERIOD;
			new_value /= NTP_RESYNC_PERIOD + delta;

			NTPADJDEBUG ("new OCR1A value %d\n", new_value);
			OCR1A = new_value;
		}
#endif  /* CLOCK_NTP_ADJUST_SUPPORT */
	}

	sync_timestamp = new_sync_timestamp;
	n_sync_timestamp = new_sync_timestamp;
	n_sync_tick = TCNT2;

	/* Allow the clock to jump forward, but not to go backward
	 * except the time difference is greater than 5 minutes */
	if (sync_timestamp > timestamp || (timestamp - sync_timestamp) > 300)
		timestamp = sync_timestamp;

#ifdef WHM_SUPPORT
	if (startup_timestamp == 0)
		startup_timestamp = sync_timestamp;
#endif

#ifdef I2C_DS13X7_SUPPORT
        i2c_ds13x7_sync(sync_timestamp);
#endif

#ifdef NTP_SUPPORT
	ntp_timer = NTP_RESYNC_PERIOD;
#endif
}