Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:14

0001 /**
0002  * @file
0003  *
0004  * @ingroup RTEMSScoreTimecounter
0005  *
0006  * @brief This header file provides interfaces of the timecounter
0007  *   implementation.
0008  */
0009 
0010 /*-
0011  * ----------------------------------------------------------------------------
0012  * "THE BEER-WARE LICENSE" (Revision 42):
0013  * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
0014  * can do whatever you want with this stuff. If we meet some day, and you think
0015  * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
0016  * ----------------------------------------------------------------------------
0017  */
0018 
0019 #ifndef _SYS_TIMETC_H_
0020 #define _SYS_TIMETC_H_
0021 
0022 #ifndef __rtems__
0023 #ifndef _KERNEL
0024 #error "no user-serviceable parts inside"
0025 #endif
0026 #else /* __rtems__ */
0027 #ifdef __cplusplus
0028 extern "C" {
0029 #endif /* __cplusplus */
0030 #endif /* __rtems__ */
0031 
0032 /*-
0033  * `struct timecounter' is the interface between the hardware which implements
0034  * a timecounter and the MI code which uses this to keep track of time.
0035  *
0036  * A timecounter is a binary counter which has two properties:
0037  *    * it runs at a fixed, known frequency.
0038  *    * it has sufficient bits to not roll over in less than approximately
0039  *      max(2 msec, 2/HZ seconds).  (The value 2 here is really 1 + delta,
0040  *      for some indeterminate value of delta.)
0041  */
0042 
0043 struct timecounter;
0044 struct vdso_timehands;
0045 struct vdso_timehands32;
0046 #ifndef __rtems__
0047 typedef u_int timecounter_get_t(struct timecounter *);
0048 #else /* __rtems__ */
0049 typedef uint32_t timecounter_get_t(struct timecounter *);
0050 #define tc_getfrequency _Timecounter_Get_frequency
0051 #endif /* __rtems__ */
0052 typedef void timecounter_pps_t(struct timecounter *);
0053 typedef uint32_t timecounter_fill_vdso_timehands_t(struct vdso_timehands *,
0054     struct timecounter *);
0055 typedef uint32_t timecounter_fill_vdso_timehands32_t(struct vdso_timehands32 *,
0056     struct timecounter *);
0057 
0058 struct timecounter {
0059     timecounter_get_t   *tc_get_timecount;
0060 #ifndef __rtems__
0061         /*
0062          * This function reads the counter.  It is not required to
0063          * mask any unimplemented bits out, as long as they are
0064          * constant.
0065          */
0066     timecounter_pps_t   *tc_poll_pps;
0067 #endif /* __rtems__ */
0068         /*
0069          * This function is optional.  It will be called whenever the
0070          * timecounter is rewound, and is intended to check for PPS
0071          * events.  Normal hardware does not need it but timecounters
0072          * which latch PPS in hardware do.
0073          */
0074     uint32_t        tc_counter_mask;
0075         /* This mask should mask off any unimplemented bits. */
0076     uint64_t        tc_frequency;
0077         /* Frequency of the counter in Hz. */
0078     const char      *tc_name;
0079         /* Name of the timecounter. */
0080     int         tc_quality;
0081 #ifndef __rtems__
0082         /*
0083          * Used to determine if this timecounter is better than
0084          * another timecounter higher means better.  Negative
0085          * means "only use at explicit request".
0086          */
0087     u_int           tc_flags;
0088 #define TC_FLAGS_C2STOP     1   /* Timer dies in C2+. */
0089 #define TC_FLAGS_SUSPEND_SAFE   2   /*
0090                      * Timer functional across
0091                      * suspend/resume.
0092                      */
0093 
0094     void            *tc_priv;
0095         /* Pointer to the timecounter's private parts. */
0096     struct timecounter  *tc_next;
0097         /* Pointer to the next timecounter. */
0098     timecounter_fill_vdso_timehands_t *tc_fill_vdso_timehands;
0099     timecounter_fill_vdso_timehands32_t *tc_fill_vdso_timehands32;
0100 #endif /* __rtems__ */
0101 };
0102 
0103 extern struct timecounter *timecounter;
0104 extern int tc_min_ticktock_freq; /*
0105                   * Minimal tc_ticktock() call frequency,
0106                   * required to handle counter wraps.
0107                   */
0108 
0109 u_int64_t tc_getfrequency(void);
0110 void    tc_init(struct timecounter *tc);
0111 void    tc_setclock(struct timespec *ts);
0112 void    tc_ticktock(int cnt);
0113 void    cpu_tick_calibration(void);
0114 
0115 #ifdef SYSCTL_DECL
0116 SYSCTL_DECL(_kern_timecounter);
0117 #endif
0118 
0119 #ifdef __rtems__
0120 #ifdef __cplusplus
0121 }
0122 #endif /* __cplusplus */
0123 #endif /* __rtems__ */
0124 #endif /* !_SYS_TIMETC_H_ */