RTEMS 6.1-rc2
Loading...
Searching...
No Matches
timepps.h
Go to the documentation of this file.
1
10/*-
11 * ----------------------------------------------------------------------------
12 * "THE BEER-WARE LICENSE" (Revision 42):
13 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
14 * can do whatever you want with this stuff. If we meet some day, and you think
15 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
16 * ----------------------------------------------------------------------------
17 *
18 * Copyright (c) 2011 The FreeBSD Foundation
19 * All rights reserved.
20 *
21 * Portions of this software were developed by Julien Ridoux at the University
22 * of Melbourne under sponsorship from the FreeBSD Foundation.
23 *
24 * $FreeBSD: head/sys/sys/timepps.h 282424 2015-05-04 17:59:39Z ian $
25 *
26 * The is a FreeBSD version of the RFC 2783 API for Pulse Per Second
27 * timing interfaces.
28 */
29
30#ifndef _SYS_TIMEPPS_H_
31#define _SYS_TIMEPPS_H_
32
33#include <sys/_ffcounter.h>
34#include <sys/ioccom.h>
35#include <sys/time.h>
36#ifdef __rtems__
37#include <rtems/score/atomic.h>
38#define PPS_SYNC
39#define hardpps _Timecounter_Discipline
40#ifdef __cplusplus
41extern "C" {
42#endif /* __cplusplus */
43#endif /* __rtems__ */
44
45#define PPS_API_VERS_1 1
46
47typedef int pps_handle_t;
48
49#ifndef __rtems__
50typedef unsigned pps_seq_t;
51#else /* __rtems__ */
52typedef Atomic_Uint pps_seq_t;
53#endif /* __rtems__ */
54
55typedef struct ntp_fp {
56 unsigned int integral;
57 unsigned int fractional;
58} ntp_fp_t;
59
60typedef union pps_timeu {
61 struct timespec tspec;
62 ntp_fp_t ntpfp;
63 unsigned long longpad[3];
65
66typedef struct {
67 pps_seq_t assert_sequence; /* assert event seq # */
68 pps_seq_t clear_sequence; /* clear event seq # */
69 pps_timeu_t assert_tu;
70 pps_timeu_t clear_tu;
71 int current_mode; /* current mode bits */
73
74typedef struct {
75 pps_seq_t assert_sequence; /* assert event seq # */
76 pps_seq_t clear_sequence; /* clear event seq # */
77 pps_timeu_t assert_tu;
78 pps_timeu_t clear_tu;
79 ffcounter assert_ffcount; /* ffcounter on assert event */
80 ffcounter clear_ffcount; /* ffcounter on clear event */
81 int current_mode; /* current mode bits */
83
84#define assert_timestamp assert_tu.tspec
85#define clear_timestamp clear_tu.tspec
86
87#define assert_timestamp_ntpfp assert_tu.ntpfp
88#define clear_timestamp_ntpfp clear_tu.ntpfp
89
90typedef struct {
91 int api_version; /* API version # */
92 int mode; /* mode bits */
93 pps_timeu_t assert_off_tu;
94 pps_timeu_t clear_off_tu;
96
97#define assert_offset assert_off_tu.tspec
98#define clear_offset clear_off_tu.tspec
99
100#define assert_offset_ntpfp assert_off_tu.ntpfp
101#define clear_offset_ntpfp clear_off_tu.ntpfp
102
103
104#define PPS_CAPTUREASSERT 0x01
105#define PPS_CAPTURECLEAR 0x02
106#define PPS_CAPTUREBOTH 0x03
107
108#define PPS_OFFSETASSERT 0x10
109#define PPS_OFFSETCLEAR 0x20
110
111#define PPS_ECHOASSERT 0x40
112#define PPS_ECHOCLEAR 0x80
113
114#define PPS_CANWAIT 0x100
115#define PPS_CANPOLL 0x200
116
117#define PPS_TSFMT_TSPEC 0x1000
118#define PPS_TSFMT_NTPFP 0x2000
119
120#define PPS_TSCLK_FBCK 0x10000
121#define PPS_TSCLK_FFWD 0x20000
122#define PPS_TSCLK_MASK 0x30000
123
124#define PPS_KC_HARDPPS 0
125#define PPS_KC_HARDPPS_PLL 1
126#define PPS_KC_HARDPPS_FLL 2
127
129 int tsformat;
130 pps_info_t pps_info_buf;
131 struct timespec timeout;
132};
133
135 int tsformat;
136 pps_info_ffc_t pps_info_buf_ffc;
137 struct timespec timeout;
138};
139
141 int kernel_consumer;
142 int edge;
143 int tsformat;
144};
145
146#define PPS_IOC_CREATE _IO('1', 1)
147#define PPS_IOC_DESTROY _IO('1', 2)
148#define PPS_IOC_SETPARAMS _IOW('1', 3, pps_params_t)
149#define PPS_IOC_GETPARAMS _IOR('1', 4, pps_params_t)
150#define PPS_IOC_GETCAP _IOR('1', 5, int)
151#define PPS_IOC_FETCH _IOWR('1', 6, struct pps_fetch_args)
152#define PPS_IOC_KCBIND _IOW('1', 7, struct pps_kcbind_args)
153#define PPS_IOC_FETCH_FFCOUNTER _IOWR('1', 8, struct pps_fetch_ffc_args)
154
155#ifdef _KERNEL
156
157struct mtx;
158
159#define KCMODE_EDGEMASK 0x03
160#define KCMODE_ABIFLAG 0x80000000 /* Internal use: abi-aware driver. */
161
162#define PPS_ABI_VERSION 1
163
164#define PPSFLAG_MTX_SPIN 0x01 /* Driver mtx is MTX_SPIN type. */
165
166struct pps_state {
167 /* Capture information. */
168 struct timehands *capth;
169 struct fftimehands *capffth;
170 unsigned capgen;
171 unsigned capcount;
172
173 /* State information. */
174 pps_params_t ppsparam;
175 pps_info_t ppsinfo;
176 pps_info_ffc_t ppsinfo_ffc;
177 int kcmode;
178 int ppscap;
179 struct timecounter *ppstc;
180 unsigned ppscount[3];
181#ifdef __rtems__
196 int (*wait)(struct pps_state *pps, struct timespec timeout);
197
203 void (*wakeup)(struct pps_state *pps);
204#endif /* __rtems__ */
205 /*
206 * The following fields are valid if the driver calls pps_init_abi().
207 */
208 uint16_t driver_abi; /* Driver sets before pps_init_abi(). */
209 uint16_t kernel_abi; /* Kernel sets during pps_init_abi(). */
210 struct mtx *driver_mtx; /* Optional, valid if non-NULL. */
211 uint32_t flags;
212};
213
214void pps_capture(struct pps_state *pps);
215void pps_event(struct pps_state *pps, int event);
216void pps_init(struct pps_state *pps);
217void pps_init_abi(struct pps_state *pps);
218int pps_ioctl(unsigned long cmd, caddr_t data, struct pps_state *pps);
219void hardpps(struct timespec *tsp, long nsec);
220
221#else /* !_KERNEL */
222
223static __inline int
224time_pps_create(int filedes, pps_handle_t *handle)
225{
226 int error;
227
228 *handle = -1;
229 error = ioctl(filedes, PPS_IOC_CREATE, 0);
230 if (error < 0)
231 return (-1);
232 *handle = filedes;
233 return (0);
234}
235
236static __inline int
237time_pps_destroy(pps_handle_t handle)
238{
239 return (ioctl(handle, PPS_IOC_DESTROY, 0));
240}
241
242static __inline int
243time_pps_setparams(pps_handle_t handle, const pps_params_t *ppsparams)
244{
245 return (ioctl(handle, PPS_IOC_SETPARAMS, ppsparams));
246}
247
248static __inline int
249time_pps_getparams(pps_handle_t handle, pps_params_t *ppsparams)
250{
251 return (ioctl(handle, PPS_IOC_GETPARAMS, ppsparams));
252}
253
254static __inline int
255time_pps_getcap(pps_handle_t handle, int *mode)
256{
257 return (ioctl(handle, PPS_IOC_GETCAP, mode));
258}
259
260static __inline int
261time_pps_fetch(pps_handle_t handle, const int tsformat,
262 pps_info_t *ppsinfobuf, const struct timespec *timeout)
263{
264 int error;
265 struct pps_fetch_args arg;
266
267 arg.tsformat = tsformat;
268 if (timeout == NULL) {
269 arg.timeout.tv_sec = -1;
270 arg.timeout.tv_nsec = -1;
271 } else
272 arg.timeout = *timeout;
273 error = ioctl(handle, PPS_IOC_FETCH, &arg);
274 *ppsinfobuf = arg.pps_info_buf;
275 return (error);
276}
277
278static __inline int
279time_pps_fetch_ffc(pps_handle_t handle, const int tsformat,
280 pps_info_ffc_t *ppsinfobuf, const struct timespec *timeout)
281{
282 struct pps_fetch_ffc_args arg;
283 int error;
284
285 arg.tsformat = tsformat;
286 if (timeout == NULL) {
287 arg.timeout.tv_sec = -1;
288 arg.timeout.tv_nsec = -1;
289 } else {
290 arg.timeout = *timeout;
291 }
292 error = ioctl(handle, PPS_IOC_FETCH_FFCOUNTER, &arg);
293 *ppsinfobuf = arg.pps_info_buf_ffc;
294 return (error);
295}
296
297static __inline int
298time_pps_kcbind(pps_handle_t handle, const int kernel_consumer,
299 const int edge, const int tsformat)
300{
301 struct pps_kcbind_args arg;
302
303 arg.kernel_consumer = kernel_consumer;
304 arg.edge = edge;
305 arg.tsformat = tsformat;
306 return (ioctl(handle, PPS_IOC_KCBIND, &arg));
307}
308
309#endif /* KERNEL */
310
311#ifdef __rtems__
312#ifdef __cplusplus
313}
314#endif /* __cplusplus */
315#endif /* __rtems__ */
316#endif /* !_SYS_TIMEPPS_H_ */
This header file provides interfaces of the feed-forward clock counter.
#define NULL
Requests a GPIO pin group configuration.
Definition: xil_types.h:54
This header file provides the interfaces of the Atomic Operations.
Definition: timepps.h:55
Definition: timepps.h:128
Definition: timepps.h:134
Definition: timepps.h:74
Definition: timepps.h:66
Definition: timepps.h:140
Definition: timepps.h:90
Definition: timetc.h:60
Definition: kern_tc.c:197
Definition: timepps.h:60