RTEMS 5.2
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
timetc.h
1/*-
2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.ORG> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
8 *
9 * $FreeBSD: head/sys/sys/timetc.h 304285 2016-08-17 09:52:09Z kib $
10 */
11
12#ifndef _SYS_TIMETC_H_
13#define _SYS_TIMETC_H_
14
15#ifndef __rtems__
16#ifndef _KERNEL
17#error "no user-serviceable parts inside"
18#endif
19#endif /* __rtems__ */
20
21/*-
22 * `struct timecounter' is the interface between the hardware which implements
23 * a timecounter and the MI code which uses this to keep track of time.
24 *
25 * A timecounter is a binary counter which has two properties:
26 * * it runs at a fixed, known frequency.
27 * * it has sufficient bits to not roll over in less than approximately
28 * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta,
29 * for some indeterminate value of delta.)
30 */
31
32struct timecounter;
33struct vdso_timehands;
34struct vdso_timehands32;
35#ifndef __rtems__
36typedef u_int timecounter_get_t(struct timecounter *);
37#else /* __rtems__ */
38typedef uint32_t timecounter_get_t(struct timecounter *);
39#endif /* __rtems__ */
40typedef void timecounter_pps_t(struct timecounter *);
41typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
42 struct timecounter *);
43typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
44 struct timecounter *);
45
47 timecounter_get_t *tc_get_timecount;
48#ifndef __rtems__
49 /*
50 * This function reads the counter. It is not required to
51 * mask any unimplemented bits out, as long as they are
52 * constant.
53 */
54 timecounter_pps_t *tc_poll_pps;
55#endif /* __rtems__ */
56 /*
57 * This function is optional. It will be called whenever the
58 * timecounter is rewound, and is intended to check for PPS
59 * events. Normal hardware does not need it but timecounters
60 * which latch PPS in hardware (like sys/pci/xrpu.c) do.
61 */
62 uint32_t tc_counter_mask;
63 /* This mask should mask off any unimplemented bits. */
64 uint64_t tc_frequency;
65 /* Frequency of the counter in Hz. */
66 const char *tc_name;
67 /* Name of the timecounter. */
68 int tc_quality;
69#ifndef __rtems__
70 /*
71 * Used to determine if this timecounter is better than
72 * another timecounter higher means better. Negative
73 * means "only use at explicit request".
74 */
75 u_int tc_flags;
76#define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */
77#define TC_FLAGS_SUSPEND_SAFE 2 /*
78 * Timer functional across
79 * suspend/resume.
80 */
81
82 void *tc_priv;
83 /* Pointer to the timecounter's private parts. */
84 struct timecounter *tc_next;
85 /* Pointer to the next timecounter. */
86 timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
87 timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
88#endif /* __rtems__ */
89};
90
91extern struct timecounter *timecounter;
92extern int tc_min_ticktock_freq; /*
93 * Minimal tc_ticktock() call frequency,
94 * required to handle counter wraps.
95 */
96
97u_int64_t tc_getfrequency(void);
98void tc_init(struct timecounter *tc);
99void tc_setclock(struct timespec *ts);
100void tc_ticktock(int cnt);
101void cpu_tick_calibration(void);
102
103#ifdef SYSCTL_DECL
104SYSCTL_DECL(_kern_timecounter);
105#endif
106
107#endif /* !_SYS_TIMETC_H_ */
Definition: timetc.h:46