RTEMS CPU Kit with SuperCore  4.11.3
timetc.h
Go to the documentation of this file.
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 r277406 2015-01-20T03:54:30Z$
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 
32 struct timecounter;
33 typedef uint32_t timecounter_get_t(struct timecounter *);
34 typedef void timecounter_pps_t(struct timecounter *);
35 
36 struct timecounter {
37  timecounter_get_t *tc_get_timecount;
38  /*
39  * This function reads the counter. It is not required to
40  * mask any unimplemented bits out, as long as they are
41  * constant.
42  */
43  timecounter_pps_t *tc_poll_pps;
44  /*
45  * This function is optional. It will be called whenever the
46  * timecounter is rewound, and is intended to check for PPS
47  * events. Normal hardware does not need it but timecounters
48  * which latch PPS in hardware (like sys/pci/xrpu.c) do.
49  */
50  uint32_t tc_counter_mask;
51  /* This mask should mask off any unimplemented bits. */
52  uint64_t tc_frequency;
53  /* Frequency of the counter in Hz. */
54  char *tc_name;
55  /* Name of the timecounter. */
56  int tc_quality;
57  /*
58  * Used to determine if this timecounter is better than
59  * another timecounter higher means better. Negative
60  * means "only use at explicit request".
61  */
62  u_int tc_flags;
63 #define TC_FLAGS_C2STOP 1 /* Timer dies in C2+. */
64 #define TC_FLAGS_SUSPEND_SAFE 2 /*
65  * Timer functional across
66  * suspend/resume.
67  */
68 
69  void *tc_priv;
70  /* Pointer to the timecounter's private parts. */
71  struct timecounter *tc_next;
72  /* Pointer to the next timecounter. */
73 };
74 
75 extern struct timecounter *timecounter;
76 extern int tc_min_ticktock_freq; /*
77  * Minimal tc_ticktock() call frequency,
78  * required to handle counter wraps.
79  */
80 
81 u_int64_t tc_getfrequency(void);
82 void tc_init(struct timecounter *tc);
83 void tc_setclock(struct timespec *ts);
84 void tc_ticktock(int cnt);
85 void cpu_tick_calibration(void);
86 
87 #ifdef SYSCTL_DECL
88 SYSCTL_DECL(_kern_timecounter);
89 #endif
90 
91 #endif /* !_SYS_TIMETC_H_ */