timerLibP.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:4k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* timerLibP.h - private POSIX 1003.4 Clocks & Timers header */
  2. /* Copyright 1991-2002 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 03g,12nov01,gls  Account for system clock rate (SPR #70255)
  7. 03f,27jun96,dbt  modified TV_CONVERT_TO_TICK to round up the value to
  8.  return (SPR #5647).
  9.  Updated copyright.
  10. 03e,29nov93,dvs  updated for POSIX draft 14
  11. 03d,23sep92,kdl  changed name to timerLibP.h
  12. 03c,22sep92,rrr  added support for c++
  13. 03b,31jul92,gae  added sigevent.h, time.h and timers.h includes.
  14. 03a,22jul92,gae  Draft 12 revision; removed object stuff; moved
  15.  some prototype definitions to timers.h.
  16. 02a,04jul92,jcf  cleaned up.
  17. 01d,26may92,rrr  the tree shuffle
  18. 01c,30apr92,rrr  some preparation for posix signals.
  19. 01a,16oct91,gae  written.
  20. */
  21. /*
  22. DESCRIPTION
  23. This file provides header information for the
  24. POSIX 1003.4 Clocks & Timers interface per Draft 12.
  25. */
  26. #ifndef __INCtimerLibPh
  27. #define __INCtimerLibPh
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. #include "sys/types.h"
  32. #include "time.h"
  33. #include "signal.h"
  34. #include "sigevent.h"
  35. #include "timers.h"
  36. #include "private/sigLibP.h"
  37. #include "wdLib.h"
  38. typedef struct __timer
  39.     {
  40.     WDOG_ID wdog; /* expiry mechanism */
  41.     int active; /* wdog is set */
  42.     int taskId; /* "owner" of timer */
  43.     clock_t clock_id; /* always CLOCK_REALTIME */
  44.     struct sigpend sigpend;
  45.     struct sigevent sevent; /* user's signal event */
  46.     struct itimerspec exp; /* time to go off plus interval */
  47.     VOIDFUNCPTR routine; /* user's routine */
  48.     int arg; /* argument to user's routine */
  49.     struct timespec     timeStamp; /* timestamp when timer is armed */
  50.     } TIMER;
  51. typedef struct clock
  52.     {
  53.     UINT64 tickBase; /* vxTicks when time set */
  54.     struct timespec timeBase; /* time set */
  55.     } CLOCK;
  56. extern struct clock _clockRealtime;
  57. /* macros for "time value" manipulation */
  58. #define BILLION         1000000000 /* 1000 million nanoseconds / second */
  59. #define TV_EQ(a,b)
  60.         ((a).tv_sec == (b).tv_sec && (a).tv_nsec == (b).tv_nsec)
  61. #define TV_GT(a,b)
  62.         ((a).tv_sec  > (b).tv_sec ||
  63.         ((a).tv_sec == (b).tv_sec && (a).tv_nsec > (b).tv_nsec))
  64. #define TV_LT(a,b)
  65.         ((a).tv_sec  < (b).tv_sec ||
  66.         ((a).tv_sec == (b).tv_sec && (a).tv_nsec < (b).tv_nsec))
  67. #define TV_ISZERO(a)
  68.         ((a).tv_sec == 0 && (a).tv_nsec == 0)
  69. #define TV_SET(a,b)
  70.         (a).tv_sec = (b).tv_sec; (a).tv_nsec = (b).tv_nsec
  71. #define TV_ADD(a,b)
  72.         (a).tv_sec += (b).tv_sec; (a).tv_nsec += (b).tv_nsec; TV_NORMALIZE(a)
  73. #define TV_SUB(a,b)
  74.         (a).tv_sec -= (b).tv_sec; (a).tv_nsec -= (b).tv_nsec; TV_NORMALIZE(a)
  75. #define TV_NORMALIZE(a)
  76. if ((a).tv_nsec >= BILLION)
  77.     { (a).tv_sec++; (a).tv_nsec -= BILLION; }
  78. else if ((a).tv_nsec < 0)
  79.     { (a).tv_sec--; (a).tv_nsec += BILLION; }
  80. #define TV_VALID(a)
  81.         ((a).tv_nsec >= 0 && (a).tv_nsec < BILLION)
  82. #define TV_ZERO(a)
  83.         (a).tv_sec = 0; (a).tv_nsec = 0
  84. #define TV_CONVERT_TO_SEC(a,b)  
  85.         do { 
  86.         register UINT32 hz = sysClkRateGet(); 
  87. (a).tv_sec  = (time_t)((b) / hz);   
  88. (a).tv_nsec = (long)(((b) % hz) * (BILLION / hz)); 
  89.         } while (0)
  90. #define TV_CONVERT_TO_TICK(a,b) 
  91.         do { 
  92.         register UINT32 hz = sysClkRateGet(); 
  93.         register UINT32 res = (BILLION / hz); 
  94.         (a) = (UINT64) ((b).tv_sec) * hz + 
  95.         (UINT64) ((b).tv_nsec) / res + 
  96.               (((UINT64)((b).tv_nsec) % res) ? 1 : 0); 
  97.         } while (0)
  98. /* non-standard function declarations */
  99. #if defined(__STDC__) || defined(__cplusplus)
  100. extern int  clock_setres (clockid_t clock_id, struct timespec *res);
  101. extern int  timer_cancel (timer_t timerid);
  102. extern int  timer_connect (timer_t timerid, VOIDFUNCPTR routine, int arg);
  103. extern int  timer_show (timer_t timerid);
  104. #else
  105. extern int  clock_setres ();
  106. extern int  timer_cancel ();
  107. extern int  timer_connect ();
  108. extern int  timer_show ();
  109. #endif /* __STDC__ */
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif /* __INCtimerLibPh */