You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3KB

  1. /*
  2. * This file is Copyright (c) 2015 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. */
  5. #ifndef GPSD_NTPSHM_H
  6. #define GPSD_NTPSHM_H
  7. #include <stdbool.h>
  8. #include <time.h>
  9. #include <sys/time.h>
  10. #include <sys/ipc.h>
  11. #include <sys/shm.h>
  12. #define NTPD_BASE 0x4e545030 /* "NTP0" */
  13. /*
  14. * How to read and write fields in an NTP shared segment.
  15. * This definition of shmTime is from ntpd source ntpd/refclock_shm.c
  16. *
  17. * The fields aren't documented there. It appears the only use of
  18. * nsamples is internal to the (obsolete and deprecated) EES M201
  19. * receiver refclock. The precision field is nominally log(2) of the
  20. * source's jitter in seconds:
  21. * -1 is about 100mSec jitter
  22. * -10 is about 1 mSec jitter (GR-601W or other USB with 1ms poll interval)
  23. * -13 is about 100 uSec
  24. * -20 is about 1 uSec (typical for serial PPS)
  25. */
  26. struct shmTime
  27. {
  28. int mode; /* 0 - if valid set
  29. * use values,
  30. * clear valid
  31. * 1 - if valid set
  32. * if count before and after read of values is equal,
  33. * use values
  34. * clear valid
  35. */
  36. volatile int count;
  37. time_t clockTimeStampSec;
  38. int clockTimeStampUSec;
  39. time_t receiveTimeStampSec;
  40. int receiveTimeStampUSec;
  41. int leap; /* not leapsecond offset, a notification code */
  42. int precision; /* log(2) of source jitter */
  43. int nsamples; /* not used */
  44. volatile int valid;
  45. unsigned clockTimeStampNSec; /* Unsigned ns timestamps */
  46. unsigned receiveTimeStampNSec; /* Unsigned ns timestamps */
  47. int dummy[8];
  48. };
  49. /*
  50. * These types are internal to GPSD
  51. */
  52. enum segstat_t {OK, NO_SEGMENT, NOT_READY, BAD_MODE, CLASH};
  53. struct shm_stat_t {
  54. enum segstat_t status;
  55. struct timespec tvc; /* System time when SHM read, for debug only */
  56. struct timespec tvr; /* System time at GPS time */
  57. struct timespec tvt; /* GPS time */
  58. int precision;
  59. int leap;
  60. };
  61. #ifndef TIMEDELTA_DEFINED
  62. struct timedelta_t {
  63. struct timespec real;
  64. struct timespec clock;
  65. };
  66. #define TIMEDELTA_DEFINED
  67. #endif /* TIMEDELTA_DEFINED */
  68. struct shmTime *shm_get(int, bool, bool);
  69. extern char *ntp_name(const int);
  70. enum segstat_t ntp_read(struct shmTime *, struct shm_stat_t *, const bool);
  71. void ntp_write(volatile struct shmTime *, struct timedelta_t *, int, int);
  72. #endif /* GPSD_NTPSHM_H */
  73. /* end */