summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/kern_ntptime.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/score/src/kern_ntptime.c')
-rw-r--r--cpukit/score/src/kern_ntptime.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/cpukit/score/src/kern_ntptime.c b/cpukit/score/src/kern_ntptime.c
index 8a16702736..c6f70079b3 100644
--- a/cpukit/score/src/kern_ntptime.c
+++ b/cpukit/score/src/kern_ntptime.c
@@ -74,8 +74,24 @@ __FBSDID("$FreeBSD$");
#define ntp_update_second _Timecounter_NTP_update_second
#define time_uptime _Timecounter_Time_uptime
struct thread;
-static __inline long lmax(long a, long b) { return (a > b ? a : b); }
-static __inline quad_t qmin(quad_t a, quad_t b) { return (a < b ? a : b); }
+
+static inline long
+lmax(long a, long b)
+{
+
+ if (a > b)
+ return (a);
+ return (b);
+}
+
+static inline quad_t
+qmin(quad_t a, quad_t b)
+{
+
+ if (a < b)
+ return (a);
+ return (b);
+}
#endif /* __rtems__ */
#ifndef __rtems__
@@ -766,8 +782,7 @@ RTEMS_SYSINIT_ITEM(_NTP_Initialize, RTEMS_SYSINIT_DEVICE_DRIVERS,
* is selected by the STA_MODE status bit.
*/
static void
-hardupdate(offset)
- long offset; /* clock offset (ns) */
+hardupdate(long offset /* clock offset (ns) */)
{
long mtemp;
l_fp ftemp;
@@ -846,11 +861,11 @@ hardupdate(offset)
* variables, except for the actual time and frequency variables, which
* are determined by this routine and updated atomically.
*
- * tsp - time at PPS
- * nsec - hardware counter at PPS
+ * tsp - time at current PPS event
+ * delta_nsec - time elapsed between the previous and current PPS event
*/
void
-hardpps(struct timespec *tsp, long nsec)
+hardpps(struct timespec *tsp, long delta_nsec)
{
long u_sec, u_nsec, v_nsec; /* temps */
l_fp ftemp;
@@ -885,19 +900,10 @@ hardpps(struct timespec *tsp, long nsec)
pps_tf[0].tv_nsec = u_nsec;
/*
- * Compute the difference between the current and previous
- * counter values. If the difference exceeds 0.5 s, assume it
- * has wrapped around, so correct 1.0 s. If the result exceeds
- * the tick interval, the sample point has crossed a tick
- * boundary during the last second, so correct the tick. Very
- * intricate.
+ * Update the frequency accumulator using the difference between the
+ * current and previous PPS event measured directly by the timecounter.
*/
- u_nsec = nsec;
- if (u_nsec > (NANOSECOND >> 1))
- u_nsec -= NANOSECOND;
- else if (u_nsec < -(NANOSECOND >> 1))
- u_nsec += NANOSECOND;
- pps_fcount += u_nsec;
+ pps_fcount += delta_nsec - NANOSECOND;
if (v_nsec > MAXFREQ || v_nsec < -MAXFREQ)
goto out;
time_status &= ~STA_PPSJITTER;