diff options
Diffstat (limited to 'cpukit/score/src/kern_ntptime.c')
-rw-r--r-- | cpukit/score/src/kern_ntptime.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/cpukit/score/src/kern_ntptime.c b/cpukit/score/src/kern_ntptime.c index cb39133408..c6f70079b3 100644 --- a/cpukit/score/src/kern_ntptime.c +++ b/cpukit/score/src/kern_ntptime.c @@ -58,6 +58,9 @@ __FBSDID("$FreeBSD$"); #include <sys/time.h> #include <sys/timex.h> #include <sys/timetc.h> +#ifdef __rtems__ +#define _KERNEL +#endif /* __rtems__ */ #include <sys/timepps.h> #ifndef __rtems__ #include <sys/syscallsubr.h> @@ -71,11 +74,31 @@ __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) +{ + + 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__ #ifdef PPS_SYNC FEATURE(pps_sync, "Support usage of external PPS signal by kernel PLL"); #endif +#endif /* __rtems__ */ /* * Single-precision macros for 64-bit machines @@ -374,7 +397,6 @@ SYSCTL_NODE(_kern, OID_AUTO, ntp_pll, CTLFLAG_RW | CTLFLAG_MPSAFE, 0, SYSCTL_PROC(_kern_ntp_pll, OID_AUTO, gettime, CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, 0, sizeof(struct ntptimeval) , ntp_sysctl, "S,ntptimeval", ""); -#endif /* __rtems__ */ #ifdef PPS_SYNC SYSCTL_INT(_kern_ntp_pll, OID_AUTO, pps_shiftmax, CTLFLAG_RW, @@ -391,6 +413,7 @@ SYSCTL_S64(_kern_ntp_pll, OID_AUTO, time_freq, CTLFLAG_RD | CTLFLAG_MPSAFE, &time_freq, 0, "Frequency offset (ns/sec)"); #endif +#endif /* __rtems__ */ /* * ntp_adjtime() - NTP daemon application interface @@ -531,16 +554,6 @@ kern_ntp_adjtime(struct thread *td, struct timex *ntv, int *retvalp) ntv->jitcnt = pps_jitcnt; ntv->stbcnt = pps_stbcnt; #endif /* PPS_SYNC */ -#ifdef __rtems__ - ntv->ppsfreq = 0; - ntv->jitter = 0; - ntv->shift = 0; - ntv->stabil = 0; - ntv->jitcnt = 0; - ntv->calcnt = 0; - ntv->errcnt = 0; - ntv->stbcnt = 0; -#endif /* __rtems__ */ retval = ntp_is_time_error(time_status) ? TIME_ERROR : time_state; NTP_UNLOCK(); @@ -769,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; @@ -849,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; @@ -888,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; |