• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

include/nucleus/timebase.h

Go to the documentation of this file.
00001 
00023 #ifndef _XENO_NUCLEUS_TIMEBASE_H
00024 #define _XENO_NUCLEUS_TIMEBASE_H
00025 
00029 #include <nucleus/queue.h>
00030 
00031 #if defined(__KERNEL__) || defined(__XENO_SIM__)
00032 
00033 #include <nucleus/vfile.h>
00034 
00035 struct xntimer;
00036 
00037 typedef struct xntbops {
00038 
00039         int (*start_timer)(struct xntimer *timer,
00040                            xnticks_t value,
00041                            xnticks_t interval,
00042                            xntmode_t mode);
00043         void (*stop_timer)(struct xntimer *timer);
00044         xnticks_t (*get_timer_date)(struct xntimer *timer);
00045         xnticks_t (*get_timer_timeout)(struct xntimer *timer);
00046         xnticks_t (*get_timer_interval)(struct xntimer *timer);
00047         xnticks_t (*get_timer_raw_expiry)(struct xntimer *timer);
00048         void (*move_timer)(struct xntimer *timer);
00049 
00050 } xntbops_t;
00051 
00052 #define XNTBRUN  0x00000001     /* Time base is running. */
00053 #define XNTBSET  0x00000002     /* Time set in time base. */
00054 #define XNTBLCK  0x00000004     /* Time base is locked. */
00055 #define XNTBISO  0x00000008     /* Time base uses private wallclock offset */
00056 
00057 typedef struct xntbase {
00058 
00059         struct xntbops *ops;    
00061         xnticks_t jiffies;      
00063         void (*hook)(void);     
00065         xnticks_t wallclock_offset; 
00067         u_long tickvalue;       
00069         u_long ticks2sec;       
00071         u_long status;          
00073         const char *name;       /* !< Name of time base. */
00074 
00075         xnholder_t link;
00076 
00077 #define link2tbase(ln)          container_of(ln, xntbase_t, link)
00078 
00079 #ifdef CONFIG_XENO_OPT_STATS
00080         struct xnvfile_snapshot vfile;  /* !< Virtual file for access. */
00081         struct xnvfile_rev_tag revtag; /* !< Revision (for non-atomic list walks). */
00082         struct xnqueue timerq;  /* !< Timer holder in timebase. */
00083 #endif /* CONFIG_XENO_OPT_STATS */
00084 
00085 } xntbase_t;
00086 
00087 #ifdef __cplusplus
00088 extern "C" {
00089 #endif
00090 
00091 extern xntbase_t nktbase;
00092 
00093 extern xnqueue_t nktimebaseq;
00094 
00095 static inline u_long xntbase_get_ticks2sec(xntbase_t *base)
00096 {
00097         return base->ticks2sec;
00098 }
00099 
00100 static inline u_long xntbase_get_tickval(xntbase_t *base)
00101 {
00102         /* Returns the duration of a tick in nanoseconds */
00103         return base->tickvalue;
00104 }
00105 
00106 static inline xnticks_t xntbase_get_wallclock_offset(xntbase_t *base)
00107 {
00108         return base->wallclock_offset;
00109 }
00110 
00111 static inline void xntbase_set_hook(xntbase_t *base, void (*hook)(void))
00112 {
00113         base->hook = hook;
00114 }
00115 
00116 static inline int xntbase_timeset_p(xntbase_t *base)
00117 {
00118         return !!testbits(base->status, XNTBSET);
00119 }
00120 
00121 static inline int xntbase_enabled_p(xntbase_t *base)
00122 {
00123         return !!testbits(base->status, XNTBRUN);
00124 }
00125 
00126 static inline int xntbase_isolated_p(xntbase_t *base)
00127 {
00128         return !!testbits(base->status, XNTBISO);
00129 }
00130 
00131 static inline const char *xntbase_name(xntbase_t *base)
00132 {
00133         return base->name;
00134 }
00135 
00136 #ifdef CONFIG_XENO_OPT_TIMING_PERIODIC
00137 
00138 static inline xntime_t xntbase_ticks2ns(xntbase_t *base, xnticks_t ticks)
00139 {
00140         /* Convert a count of ticks in nanoseconds */
00141         return ticks * xntbase_get_tickval(base);
00142 }
00143 
00144 static inline xnticks_t xntbase_ns2ticks(xntbase_t *base, xntime_t t)
00145 {
00146         return xnarch_ulldiv(t, xntbase_get_tickval(base), NULL);
00147 }
00148 
00149 static inline int xntbase_master_p(xntbase_t *base)
00150 {
00151         return base == &nktbase;
00152 }
00153 
00154 static inline int xntbase_periodic_p(xntbase_t *base)
00155 {
00156         return !xntbase_master_p(base);
00157 }
00158 
00159 static inline xnticks_t xntbase_get_jiffies(xntbase_t *base)
00160 {
00161         return xntbase_periodic_p(base) ? base->jiffies : xnarch_get_cpu_time();
00162 }
00163 
00164 static inline xnticks_t xntbase_get_rawclock(xntbase_t *base)
00165 {
00166         return xntbase_periodic_p(base) ? base->jiffies : xnarch_get_cpu_tsc();
00167 }
00168 
00169 int xntbase_alloc(const char *name,
00170                   u_long period,
00171                   u_long flags,
00172                   xntbase_t **basep);
00173 
00174 void xntbase_free(xntbase_t *base);
00175 
00176 int xntbase_update(xntbase_t *base,
00177                    u_long period);
00178 
00179 int xntbase_switch(const char *name,
00180                    u_long period,
00181                    xntbase_t **basep);
00182 
00183 void xntbase_start(xntbase_t *base);
00184 
00185 void xntbase_stop(xntbase_t *base);
00186 
00187 void xntbase_tick(xntbase_t *base);
00188 
00189 xnticks_t xntbase_ns2ticks_ceil(xntbase_t *base, xntime_t t);
00190 
00191 xnticks_t xntbase_convert(xntbase_t *srcbase,
00192                           xnticks_t ticks,
00193                           xntbase_t *dstbase);
00194 
00195 #else /* !CONFIG_XENO_OPT_TIMING_PERIODIC */
00196 
00197 void xntimer_tick_aperiodic(void);
00198 
00199 static inline xntime_t xntbase_ticks2ns(xntbase_t *base, xnticks_t ticks)
00200 {
00201         return ticks;
00202 }
00203 
00204 static inline xnticks_t xntbase_ns2ticks(xntbase_t *base, xntime_t t)
00205 {
00206         return t;
00207 }
00208 
00209 static inline xnticks_t xntbase_ns2ticks_ceil(xntbase_t *base, xntime_t t)
00210 {
00211         return t;
00212 }
00213 
00214 static inline int xntbase_master_p(xntbase_t *base)
00215 {
00216         return 1;
00217 }
00218 
00219 static inline xnticks_t xntbase_convert(xntbase_t *srcbase, xnticks_t ticks, xntbase_t *dstbase)
00220 {
00221         return ticks;
00222 }
00223 
00224 static inline int xntbase_periodic_p(xntbase_t *base)
00225 {
00226         return 0;
00227 }
00228 
00229 static inline xnticks_t xntbase_get_jiffies(xntbase_t *base)
00230 {
00231         return xnarch_get_cpu_time();
00232 }
00233 
00234 static inline xnticks_t xntbase_get_rawclock(xntbase_t *base)
00235 {
00236         return xnarch_get_cpu_tsc();
00237 }
00238 
00239 static inline int xntbase_alloc(const char *name, u_long period, u_long flags, xntbase_t **basep)
00240 {
00241         *basep = &nktbase;
00242         return 0;
00243 }
00244 
00245 static inline void xntbase_free(xntbase_t *base)
00246 {
00247 }
00248 
00249 static inline int xntbase_update(xntbase_t *base, u_long period)
00250 {
00251         return 0;
00252 }
00253 
00254 static inline int xntbase_switch(const char *name, u_long period, xntbase_t **basep)
00255 {
00256         return period == XN_APERIODIC_TICK ? 0 : -ENODEV;
00257 }
00258 
00259 static inline void xntbase_start(xntbase_t *base)
00260 {
00261 }
00262 
00263 static inline void xntbase_stop(xntbase_t *base)
00264 {
00265 }
00266 
00267 static inline void xntbase_tick(xntbase_t *base)
00268 {
00269         xntimer_tick_aperiodic();
00270 }
00271 
00272 #endif /* !CONFIG_XENO_OPT_TIMING_PERIODIC */
00273 
00301 static inline xnticks_t xntbase_get_time(xntbase_t *base)
00302 {
00303         /* Return an adjusted value of the monotonic time with the
00304            translated system wallclock offset. */
00305         return xntbase_get_jiffies(base) + base->wallclock_offset;
00306 }
00307 
00308 void xntbase_adjust_time(xntbase_t *base, xnsticks_t delta);
00309 
00310 #ifdef __cplusplus
00311 }
00312 #endif
00313 
00314 #define xntbase_mount() \
00315 do {                                            \
00316         inith(&nktbase.link);                   \
00317         appendq(&nktimebaseq, &nktbase.link);   \
00318         xntbase_declare_proc(&nktbase); \
00319 } while (0)
00320 
00321 #define xntbase_umount()                        \
00322 do {                                            \
00323         xntbase_remove_proc(&nktbase);          \
00324         removeq(&nktimebaseq, &nktbase.link);   \
00325 } while (0)
00326 
00327 void xntbase_init_proc(void);
00328 
00329 void xntbase_cleanup_proc(void);
00330 
00331 #ifdef CONFIG_XENO_OPT_STATS
00332 void xntbase_declare_proc(xntbase_t *base);
00333 void xntbase_remove_proc(xntbase_t *base);
00334 #else /* !CONFIG_XENO_OPT_STATS */
00335 static inline void xntbase_declare_proc(xntbase_t *base) { }
00336 static inline void xntbase_remove_proc(xntbase_t *base) { }
00337 #endif /* !CONFIG_XENO_OPT_STATS */
00338 
00339 extern struct xnvfile_rev_tag tbaselist_tag;
00340 
00341 #endif /* __KERNEL__ || __XENO_SIM__ */
00342 
00345 #endif /* !_XENO_NUCLEUS_TIMEBASE_H */

Generated on Wed Nov 2 2011 18:01:06 for Xenomai API by  doxygen 1.7.1