[rtems commit] score: Add _Timecounter_Set_NTP_update_second()

Jan Sommer jan at rtems.org
Tue Nov 30 14:41:07 UTC 2021


Module:    rtems
Branch:    5
Commit:    5382f617ff3141c429b52b66e0a9ae5663b21750
Changeset: http://git.rtems.org/rtems/commit/?id=5382f617ff3141c429b52b66e0a9ae5663b21750

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Oct 28 11:14:57 2021 +0200

score: Add _Timecounter_Set_NTP_update_second()

Allow the installation of an NTP update second handler which may be used by an
NTP service.

Update #4549.

---

 cpukit/include/rtems/score/timecounter.h | 24 +++++++++++++++++++++++-
 cpukit/score/src/kern_tc.c               | 23 +++++++++++++++++++++--
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/cpukit/include/rtems/score/timecounter.h b/cpukit/include/rtems/score/timecounter.h
index b71ccd3..64429ea 100644
--- a/cpukit/include/rtems/score/timecounter.h
+++ b/cpukit/include/rtems/score/timecounter.h
@@ -7,7 +7,7 @@
  */
 
 /*
- * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
+ * Copyright (c) 2015, 2021 embedded brains GmbH.  All rights reserved.
  *
  *  embedded brains GmbH
  *  Dornierstr. 4
@@ -247,6 +247,28 @@ extern volatile int32_t _Timecounter_Time_uptime;
  */
 extern struct timecounter *_Timecounter;
 
+/**
+ * @brief Handler doing the NTP update second processing shall have this type.
+ *
+ * @param[in, out] adjustment is the NTP time adjustment.
+ *
+ * @param[in, out] newsec is the number of seconds since Unix epoch.
+ */
+typedef	void ( *Timecounter_NTP_update_second )(
+  int64_t *adjustment,
+  time_t  *newsec
+);
+
+/**
+ * @brief Sets the NTP update second handler.
+ *
+ * @param handler is the new NTP update second handler used to carry out the
+ *   NTP update second processing.
+ */
+void _Timecounter_Set_NTP_update_second(
+  Timecounter_NTP_update_second handler
+);
+
 /** @} */
 
 #ifdef __cplusplus
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 1161463..56ec475 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -80,8 +80,6 @@ ISR_LOCK_DEFINE(, _Timecounter_Lock, "Timecounter")
 #define hz rtems_clock_get_ticks_per_second()
 #define printf(...)
 #define log(...)
-/* FIXME: https://devel.rtems.org/ticket/2348 */
-#define ntp_update_second(a, b) do { (void) a; (void) b; } while (0)
 
 static inline void
 atomic_thread_fence_acq(void)
@@ -117,6 +115,17 @@ atomic_load_ptr(void *ptr)
 
 	return ((void *)_Atomic_Load_uintptr(ptr, ATOMIC_ORDER_RELAXED));
 }
+
+static Timecounter_NTP_update_second _Timecounter_NTP_update_second;
+
+void
+_Timecounter_Set_NTP_update_second(Timecounter_NTP_update_second handler)
+{
+
+	_Timecounter_NTP_update_second = handler;
+}
+
+#define	ntp_update_second(a, b) (*ntp_update_second_handler)(a, b)
 #endif /* __rtems__ */
 
 /*
@@ -1605,6 +1614,9 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 #endif
 	int i;
 	time_t t;
+#ifdef __rtems__
+	Timecounter_NTP_update_second ntp_update_second_handler;
+#endif
 
 	/*
 	 * Make the next timehands a copy of the current one, but do
@@ -1680,6 +1692,10 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 	 */
 	bt = th->th_offset;
 	bintime_add(&bt, &th->th_boottime);
+#ifdef __rtems__
+	ntp_update_second_handler = _Timecounter_NTP_update_second;
+	if (ntp_update_second_handler != NULL) {
+#endif /* __rtems__ */
 	i = bt.sec - tho->th_microtime.tv_sec;
 	if (i > 0) {
 		if (i > LARGE_STEP)
@@ -1695,6 +1711,9 @@ _Timecounter_Windup(struct bintime *new_boottimebin,
 
 		recalculate_scaling_factor_and_large_delta(th);
 	}
+#ifdef __rtems__
+	}
+#endif /* __rtems__ */
 
 	/* Update the UTC timestamps used by the get*() functions. */
 	th->th_bintime = bt;



More information about the vc mailing list