Repository navigation
Conversation
| ****************************************************************************/ | ||
|
|
||
| #define NSEC_PER_SEC_LL 1000000000LL | ||
| #define HALF_SEC_NS 500000000LL |
Contributor
There was a problem hiding this comment.
use the macro from nuttx/clock.h instead
|
|
||
| #define RT_SYS_SAMPLES 5 | ||
|
|
||
| #ifndef CONFIG_SYSTEM_GNSSPPS_DEVPATH |
|
|
||
| static int64_t ts2ns(FAR const struct timespec *ts) | ||
| { | ||
| return (int64_t)ts->tv_sec * NSEC_PER_SEC_LL + ts->tv_nsec; |
Contributor
There was a problem hiding this comment.
Suggested change
| return (int64_t)ts->tv_sec * NSEC_PER_SEC_LL + ts->tv_nsec; | |
| return ts->tv_sec * NSEC_PER_SEC_LL + ts->tv_nsec; |
| memset(&tx, 0, sizeof(tx)); | ||
| tx.modes = ADJ_SETOFFSET | ADJ_NANO; | ||
| tx.time.tv_sec = (time_t)sec; | ||
| tx.time.tv_usec = (long)nsec; |
| break; | ||
|
|
||
| case 'c': | ||
| g.channel = (unsigned int)strtoul(optarg, NULL, 0); |
|
|
||
| printf("gnsspps: rms %" PRId64 " ns max %" PRId64 | ||
| " ns freq %+" PRId64 " ppb%s\n", | ||
| (int64_t)x, g->stat_max, (int64_t)g->freq, |
| clock_gettime(CLOCK_REALTIME, &now); | ||
| ns = ts2ns(&now) + offset; | ||
| now.tv_sec = (time_t)(ns / NSEC_PER_SEC_LL); | ||
| now.tv_nsec = (long)(ns % NSEC_PER_SEC_LL); |
| struct timeval delta; | ||
|
|
||
| delta.tv_sec = (time_t)(offset / 1000000000); | ||
| delta.tv_usec = (long)((offset % 1000000000) / 1000); |
Contributor
There was a problem hiding this comment.
remove the cast too
| g->outliers = 0; | ||
|
|
||
| printf("gnsspps: locked, offset %+" PRId64 " ns stepped, " | ||
| "freq %+" PRId64 " ppb\n", offset, (int64_t)g->freq); |
| if (g->verbose) | ||
| { | ||
| printf("gnsspps: offset %+6" PRId64 " ns freq %+" PRId64 | ||
| " ppb\n", offset, (int64_t)g->freq); |
gnsspps synchronizes a NuttX board to GNSS time with the PPS output of a GNSS receiver, so that boards with their own receiver share the same time scale without a network. It reads the PPS time stamps as external time stamp (EXTTS) events from a PTP clock (/dev/ptpX, for example CONFIG_PTP_PPS) and steers the clock with clock_adjtime(): * Acquire: the frequency error is measured from two pulses, then the phase is removed with one step. * Locked: a PI servo (Kp 0.7, Ki 0.3 by default, as linuxptp) runs on every pulse, with outlier rejection and re-acquisition. * Holdover: the last frequency is kept when the PPS is lost. * The whole seconds come from the NMEA RMC or ZDA sentences of the receiver, parsed with minmea (CONFIG_GNSSUTILS_MINMEA_LIB) and confirmed by two sentences before a step. * Optionally (-r) CLOCK_REALTIME follows the PTP clock. The RMS and maximum phase error and the frequency are printed every 16 pulses. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Alan Carvalho de Assis <acassis@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gnsspps synchronizes a NuttX board to GNSS time with the PPS output of a GNSS receiver, so that boards with their own receiver share the same time scale without a network.
It reads the PPS time stamps as external time stamp (EXTTS) events from a PTP clock (/dev/ptpX, for example CONFIG_PTP_PPS) and steers the clock with clock_adjtime():
The RMS and maximum phase error and the frequency are printed every 16 pulses.
Impact
Users could use a low cost GNSS with PPS to sync two or more boards.
Testing