summaryrefslogtreecommitdiff
path: root/ntpshm.h
blob: b30d624d180112c45cacbc97c14c66ec71ce03b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * This file is Copyright (c) 2015 by the GPSD project
 * BSD terms apply: see the file COPYING in the distribution root for details.
 */

#ifndef GPSD_NTPSHM_H
#define GPSD_NTPSHM_H

#include <stdbool.h>
#include <time.h>
#include <sys/time.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define NTPD_BASE	0x4e545030	/* "NTP0" */

/* 
 * How to read and write fields in an NTP shared segment.
 * This definition of shmTime is from ntpd source ntpd/refclock_shm.c
 *
 * The fields aren't documented there.  It appears the only use of nsamples
 * is internal to the EES M201 receiver refclock. The precision field
 * is nominally log(2) of the jitter in seconds:
 * 	-1 is about 100mSec jitter
 *	-10 is about 1 mSec jitter (GR-601W or other USB with 1ms poll interval)
 *	-13 is about 100 uSec
 *	-20 is about 1 nSec (typical for serial PPS)
 */

struct shmTime
{
    int mode;	/* 0 - if valid set
		 *       use values,
		 *       clear valid
		 * 1 - if valid set
		 *       if count before and after read of values is equal,
		 *         use values
		 *       clear valid
		 */
    volatile int count;
    time_t clockTimeStampSec;
    int clockTimeStampUSec;
    time_t receiveTimeStampSec;
    int receiveTimeStampUSec;
    int leap;			/* not leapsecond offset, a notification code */
    int precision;		/* log(2) of source jitter */
    int nsamples;		/* not used */
    volatile int valid;
    unsigned        clockTimeStampNSec;     /* Unsigned ns timestamps */
    unsigned        receiveTimeStampNSec;   /* Unsigned ns timestamps */
    int             dummy[8];
};

#endif

/*
 * These types are internal to GPSD
 */
enum segstat_t {
    OK, NO_SEGMENT, NOT_READY, BAD_MODE, CLASH};

struct shm_stat_t {
    int mode;
    struct timespec tvc, tvr, tvt;
    int precision;
    int leap;
};

struct shmTime *shm_get(int, bool, bool);
extern char *shm_name(const int);
enum segstat_t shm_query(struct shmTime *, struct shm_stat_t *);

/* end */