From 215a4054880af2993f81c1e26245084e2075a6da Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 11 Mar 2015 08:32:15 -0400 Subject: Simplify the thread-monitor interface. PPS observed live on GR601W. --- gpsd.c | 2 +- gpsmon.c | 4 ++-- libgpsd_core.c | 2 +- ppsthread.c | 27 ++++++++++++--------------- ppsthread.h | 11 +++++------ 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/gpsd.c b/gpsd.c index b689d81f..3ffdc4c0 100644 --- a/gpsd.c +++ b/gpsd.c @@ -1531,7 +1531,7 @@ static void all_reports(struct gps_device_t *device, gps_mask_t changed) } else if (isnan(device->newdata.time)) { //gpsd_log(&context.errout, LOG_PROG, "NTP: bad new time\n"); #if defined(PPS_ENABLE) && !defined(S_SPLINT_S) - } else if (device->newdata.time <= device->pps_thread.fixin_real.tv_sec) { + } else if (device->newdata.time <= device->pps_thread.fixin.real.tv_sec) { //gpsd_log(&context.errout, LOG_PROG, "NTP: Not a new time\n"); #endif /* PPS_ENABLE */ } else if (!device->ship_to_ntpd) { diff --git a/gpsmon.c b/gpsmon.c index 2d40ccd1..bee05b83 100644 --- a/gpsmon.c +++ b/gpsmon.c @@ -252,7 +252,7 @@ void pps_update(WINDOW *win, int y, int x) /*@-type -noeffect@*/ /* splint is confused about struct timespec */ struct timedelta_t ppstimes; - if (pps_thread_lastpps(&session.pps_thread, &ppstimes) > 0) { + if (pps_thread_ppsout(&session.pps_thread, &ppstimes) > 0) { /* NOTE: can not use double here due to precision requirements */ struct timespec timedelta; int i; @@ -853,7 +853,7 @@ static void gpsmon_hook(struct gps_device_t *device, gps_mask_t changed UNUSED) if ( 0 != isnan(device->newdata.time)) { // "NTP: bad new time #if defined(PPS_ENABLE) && !defined(S_SPLINT_S) - } else if (device->newdata.time <= device->pps_thread.fixin_real.tv_sec) { + } else if (device->newdata.time <= device->pps_thread.fixin.real.tv_sec) { // "NTP: Not a new time #endif /* PPS_ENABLE */ } else diff --git a/libgpsd_core.c b/libgpsd_core.c index 4464d0c2..5923e240 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -1690,7 +1690,7 @@ void ntp_latch(struct gps_device_t *device, struct timedelta_t /*@out@*/*td) #ifdef PPS_ENABLE /* thread-safe update */ /*@-compdef@*/ - pps_thread_stash_fixtime(&device->pps_thread, td->real, td->clock); + pps_thread_fixin(&device->pps_thread, td); /*@+compdef@*/ #endif /* PPS_ENABLE */ } diff --git a/ppsthread.c b/ppsthread.c index 2cabaf7f..1f47807e 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -316,8 +316,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) volatile struct pps_thread_t *thread_context = (struct pps_thread_t *)arg; /* the system clock time, to the nSec, when the last fix received */ /* using a double would cause loss of precision */ - struct timespec last_fixtime_clock = {0, 0}; - struct timespec last_fixtime_real = {0, 0}; + volatile struct timedelta_t last_fixtime = {{0, 0}, {0, 0}}; struct timespec clock_ts = {0, 0}; time_t last_second_used = 0; #if defined(TIOCMIWAIT) @@ -395,8 +394,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - last_fixtime_real = thread_context->fixin_real; - last_fixtime_clock = thread_context->fixin_clock; + last_fixtime = thread_context->fixin; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -440,7 +438,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) * PPS when time is valid. It is common to get PPS, and no * fixtime, while autobauding. */ - if (last_fixtime_real.tv_sec == 0) + if (last_fixtime.real.tv_sec == 0) continue; /* mask for monitored lines */ @@ -657,7 +655,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) log = "Too long for 0.5Hz\n"; } #endif /* TIOCMIWAIT */ - if ( ok && last_second_used >= last_fixtime_real.tv_sec ) { + if ( ok && last_second_used >= last_fixtime.real.tv_sec ) { /* uh, oh, this second already handled */ ok = 0; log = "this second already handled\n"; @@ -706,7 +704,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) */ /*@+relaxtypes@*/ - ppstimes.real.tv_sec = (time_t)last_fixtime_real.tv_sec + 1; + ppstimes.real.tv_sec = (time_t)last_fixtime.real.tv_sec + 1; ppstimes.real.tv_nsec = 0; /* need to be fixed for 5Hz */ ppstimes.clock = clock_ts; /*@-relaxtypes@*/ @@ -715,7 +713,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) * GPS serial input then use that */ /*@-compdef@*/ TS_SUB( &offset, &ppstimes.real, &ppstimes.clock); - TS_SUB( &delay, &ppstimes.clock, &last_fixtime_clock); + TS_SUB( &delay, &ppstimes.clock, &last_fixtime.clock); timespec_str( &delay, delay_str, sizeof(delay_str) ); /*@+compdef@*/ @@ -733,7 +731,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) log1 = "timestamp out of range"; } else { /*@-compdef@*/ - last_second_used = last_fixtime_real.tv_sec; + last_second_used = last_fixtime.real.tv_sec; if (thread_context->report_hook != NULL) log1 = thread_context->report_hook(thread_context, &ppstimes); else @@ -833,8 +831,8 @@ void pps_thread_deactivate(volatile struct pps_thread_t *pps_thread) /*@+nullstate +mustfreeonly@*/ } -void pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, - struct timespec realtime, struct timespec clocktime) +void pps_thread_fixin(volatile struct pps_thread_t *pps_thread, + volatile struct timedelta_t *fixin) /* thread-safe update of last fix time - only way we pass data in */ { /*@ -unrecog (splint has no pthread declarations as yet) @*/ @@ -846,8 +844,7 @@ void pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - pps_thread->fixin_real = realtime; - pps_thread->fixin_clock = clocktime; + pps_thread->fixin = *fixin; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -859,8 +856,8 @@ void pps_thread_stash_fixtime(volatile struct pps_thread_t *pps_thread, /*@ +unrecog @*/ } -int pps_thread_lastpps(volatile struct pps_thread_t *pps_thread, - struct timedelta_t *td) +int pps_thread_ppsout(volatile struct pps_thread_t *pps_thread, + volatile struct timedelta_t *td) /* return the delta at the time of the last PPS - only way we pass data out */ { volatile int ret; diff --git a/ppsthread.h b/ppsthread.h index c048afaf..167a183c 100644 --- a/ppsthread.h +++ b/ppsthread.h @@ -37,8 +37,7 @@ struct timedelta_t { #define timespec_diff_ns(x, y) (long)(((x).tv_sec-(y).tv_sec)*1000000000+(x).tv_nsec-(y).tv_nsec) struct pps_thread_t { - struct timespec fixin_real; /* in-band time of the fix */ - struct timespec fixin_clock; /* system clock time when fix received */ + struct timedelta_t fixin; /* real & clock time when in-band fix received */ #if defined(HAVE_SYS_TIMEPPS_H) pps_handle_t kernelpps_handle; #endif /* defined(HAVE_SYS_TIMEPPS_H) */ @@ -62,9 +61,9 @@ struct pps_thread_t { extern void pps_thread_activate(volatile struct pps_thread_t *); extern void pps_thread_deactivate(volatile struct pps_thread_t *); -extern void pps_thread_stash_fixtime(volatile struct pps_thread_t *, - struct timespec, struct timespec); -extern int pps_thread_lastpps(volatile struct pps_thread_t *, - struct timedelta_t *); +extern void pps_thread_fixin(volatile struct pps_thread_t *, + volatile struct timedelta_t *); +extern int pps_thread_ppsout(volatile struct pps_thread_t *, + volatile struct timedelta_t *); #endif /* PPSTHREAD_H */ -- cgit v1.2.1