summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2021-10-28 11:14:57 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2021-11-15 08:56:54 +0100
commitffb8833dd28418cb7e427f0a0469bfc49e18ecf2 (patch)
treed7e17b6638cfb0fb661a93af6616a57dabac96c7 /cpukit/score
parentscore: Optimize timehand updates for non-SMP (diff)
downloadrtems-ffb8833dd28418cb7e427f0a0469bfc49e18ecf2.tar.bz2
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 #2348.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/src/kern_tc.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index 42318d1c80..e999172cad 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -5,9 +5,10 @@
*
* @brief This source file contains the definition of
* ::_Timecounter, ::_Timecounter_Time_second, and ::_Timecounter_Time_uptime
- * and the implementation of _Timecounter_Binuptime(),
- * _Timecounter_Nanouptime(), _Timecounter_Microuptime(),
- * _Timecounter_Bintime(), _Timecounter_Nanotime(), _Timecounter_Microtime(),
+ * and the implementation of _Timecounter_Set_NTP_update_second(),
+ * _Timecounter_Binuptime(), _Timecounter_Nanouptime(),
+ * _Timecounter_Microuptime(), _Timecounter_Bintime(),
+ * _Timecounter_Nanotime(), _Timecounter_Microtime(),
* _Timecounter_Getbinuptime(), _Timecounter_Getnanouptime(),
* _Timecounter_Getmicrouptime(), _Timecounter_Getbintime(),
* _Timecounter_Getnanotime(), _Timecounter_Getmicrotime(),
@@ -97,8 +98,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)
@@ -134,6 +133,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__ */
/*
@@ -1622,6 +1632,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
@@ -1697,6 +1710,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)
@@ -1712,6 +1729,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;