ppsthread.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * This file is Copyright 2015 by the GPSD project
  3. * SPDX-License-Identifier: BSD-2-clause
  4. *
  5. * Oct 2019: Added qErr* to ppsthread_t
  6. */
  7. #ifndef PPSTHREAD_H
  8. #define PPSTHREAD_H
  9. #include <time.h>
  10. #ifndef TIMEDELTA_DEFINED
  11. #define TIMEDELTA_DEFINED
  12. struct timedelta_t {
  13. struct timespec real;
  14. struct timespec clock;
  15. };
  16. #endif // TIMEDELTA_DEFINED
  17. /*
  18. * Set context, devicefd, and devicename at initialization time, before
  19. * you call pps_thread_activate(). The context pointer can be used to
  20. * pass data to the hook routines.
  21. *
  22. * Do not set the fix_in member or read the pps_out member directly,
  23. * these accesses need to be mutex-locked and that is what the last
  24. * two functions are for.
  25. *
  26. * The report hook is called when each PPS event is recognized. The log
  27. * hook is called to log error and status indications from the thread.
  28. */
  29. struct pps_thread_t {
  30. void *context; // PPS thread code leaves this alone
  31. socket_t devicefd; // device file descriptor
  32. const char *devicename; // device path
  33. char *(*report_hook)(volatile struct pps_thread_t *,
  34. struct timedelta_t *);
  35. PRINTF_FUNC(3, 4) void (*log_hook)(volatile struct pps_thread_t *,
  36. int errlevel, const char *fmt, ...);
  37. struct timedelta_t fix_in; // real & clock time when in-band fix received
  38. struct timedelta_t pps_out; // real & clock time of last PPS event
  39. int ppsout_count;
  40. // quantization error adjustment to PPS. aka "sawtooth" correction
  41. long qErr; /* offset in picoseconds (ps) */
  42. /* time of PPS pulse that qErr applies to */
  43. struct timespec qErr_time;
  44. };
  45. #define THREAD_ERROR 0
  46. #define THREAD_WARN 1
  47. #define THREAD_INF 2
  48. #define THREAD_PROG 3
  49. #define THREAD_RAW 4
  50. extern void pps_thread_activate(volatile struct pps_thread_t *);
  51. extern void pps_thread_deactivate(volatile struct pps_thread_t *);
  52. extern void pps_thread_fixin(volatile struct pps_thread_t *,
  53. volatile struct timedelta_t *);
  54. extern void pps_thread_qErrin(volatile struct pps_thread_t *pps_thread,
  55. long qErr, struct timespec qErr_time);
  56. extern int pps_thread_ppsout(volatile struct pps_thread_t *,
  57. volatile struct timedelta_t *);
  58. int pps_check_fake(const char *);
  59. const char *pps_get_first(void);
  60. #endif // PPSTHREAD_H
  61. // vim: set expandtab shiftwidth=4