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

VxWorks

开发平台:

C/C++

  1. // VXWWd/vxwWdLib.h - watchdog timer class
  2. // Copyright 1995-1999 Wind River Systems, Inc.
  3. // modification history
  4. // --------------------
  5. // 01c,08mar99,jdi  doc: fixed cross-reference.
  6. // 01b,23feb99,fle  doc : made it refgen compliant
  7. // 01c,21feb99,jdi  added library section, checked in documentation.
  8. // 01b,29sep95,rhp  adjusted comments for new mangen-C++ conventions
  9. // 01a,15jun95,srh  written.
  10. // DESCRIPTION
  11. // This library provides a general watchdog timer facility.  Any task may
  12. // create a watchdog timer and use it to run a specified routine in
  13. // the context of the system-clock ISR, after a specified delay.
  14. //
  15. // Once a timer has been created, it can be started with
  16. // VXWWd::start().  The VXWWd::start() routine specifies what routine to run, a
  17. // parameter for that routine, and the amount of time (in ticks) before
  18. // the routine is to be called.  (The timeout value is in ticks as
  19. // determined by the system clock; see sysClkRateSet() for more
  20. // information.)  After the specified delay ticks have elapsed (unless
  21. // VXWWd::cancel() is called first to cancel the timer) the timeout routine is
  22. // invoked with the parameter specified in the VXWWd::start() call.  The
  23. // timeout routine is invoked whether the task which started the watchdog
  24. // is running, suspended, or deleted.
  25. //
  26. // The timeout routine executes only once per VXWWd::start() invocation; there
  27. // is no need to cancel a timer with VXWWd::cancel() after it has expired, or
  28. // in the expiration callback itself.
  29. //
  30. // Note that the timeout routine is invoked at interrupt level, rather than
  31. // in the context of the task.  Thus, there are restrictions on what the
  32. // routine may do.  Watchdog routines are constrained to the same rules
  33. // as interrupt service routines.  For example, they may not take semaphores,
  34. // issue other calls that may block, or use I/O system routines like printf().
  35. //
  36. // EXAMPLE
  37. // In the fragment below, if maybeSlowRoutine() takes more than 60
  38. // ticks, logMsg() will be called with the string as a parameter,
  39. // causing the message to be printed on the console.  Normally, of
  40. // course, more significant corrective action would be taken.
  41. // .CS
  42. //     VXWWd *pWd = new VXWWd;
  43. //     pWd->start (60, logMsg, "Help, I've timed out!");
  44. //     maybeSlowRoutine ();     /@ user-supplied routine @/
  45. //     delete pWd;
  46. // .CE
  47. //
  48. // INCLUDE FILES: vxwWdLib.h
  49. //
  50. // SEE ALSO: wdLib, logLib,
  51. // .pG "Basic OS",
  52. // .pG "C++ Development"
  53. //
  54. // SECTION: 1C
  55. //
  56. #ifndef vxwWdLib_h
  57. #define vxwWdLib_h
  58. #include "vxWorks.h"
  59. #include "wdLib.h"
  60. #include "vxwObject.h"
  61. #include "vxwErr.h"
  62. class VXWWd : virtual public VXWIdObject
  63.     {
  64.   public:
  65. //_ VXWWd Public Constructors
  66. ////////////////////////////////////////////////////////////////////////////////
  67. //
  68. // VXWWd::VXWWd - construct a watchdog timer
  69. //
  70. // This routine creates a watchdog timer.
  71. //
  72. // RETURNS: N/A
  73. //
  74. // SEE ALSO: VXWWd::~VXWWd()
  75.     VXWWd ()
  76. : wd_ (wdCreate ())
  77. {
  78. if (wd_ == 0)
  79.     vxwThrowErrno ();
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////
  82. //
  83. // VXWWd::VXWWd - construct a watchdog timer
  84. //
  85. // This routine creates a watchdog timer from an existing WDOG_ID.
  86. //
  87. // RETURNS: N/A
  88. //
  89. // SEE ALSO: VXWWd::~VXWWd()
  90.     VXWWd (WDOG_ID aWdId)
  91. : wd_ (aWdId)
  92. {
  93. }
  94. ////////////////////////////////////////////////////////////////////////////////
  95. //
  96. // VXWWd::~VXWWd - destroy a watchdog timer
  97. //
  98. // This routine destroys a watchdog timer.  The watchdog will be removed
  99. // from the timer queue if it has been started.
  100. //
  101. // RETURNS: N/A
  102. //
  103. // SEE ALSO: VXWWd::VXWWd()
  104.     ~VXWWd ()
  105. {
  106. if (wdDelete (wd_) != OK)
  107.     vxwThrowErrno ();
  108. }
  109. //_ VXWWd Public Member Functions
  110. ////////////////////////////////////////////////////////////////////////////////
  111. //
  112. // VXWWd::cancel - cancel a currently counting watchdog
  113. //
  114. // This routine cancels a currently running watchdog timer by
  115. // zeroing its delay count.  Watchdog timers may be canceled from interrupt
  116. // level.
  117. //
  118. // RETURNS: OK, or ERROR if the watchdog timer cannot be canceled.
  119. //
  120. // SEE ALSO: VXWWd::start()
  121. //
  122.     STATUS cancel ()
  123. {
  124. return wdCancel (wd_);
  125. }
  126.     STATUS show () const
  127. {
  128. return wdShow (wd_);
  129. }
  130. ////////////////////////////////////////////////////////////////////////////////
  131. //
  132. // VXWWd::start - start a watchdog timer
  133. // 
  134. // This routine adds a watchdog timer to the system tick queue.  The
  135. // specified watchdog routine will be called from interrupt level after
  136. // the specified number of ticks has elapsed.  Watchdog timers may be
  137. // started from interrupt level.  
  138. // 
  139. // To replace either the timeout <delay> or the routine to be executed,
  140. // call VXWWd::start() again; only the most recent
  141. // VXWWd::start() on a given watchdog ID has any effect.  (If your
  142. // application requires multiple watchdog routines, use VXWWd::VXWWd() to
  143. // generate separate a watchdog for each.)  To cancel a watchdog
  144. // timer before the specified tick count is reached, call VXWWd::cancel().
  145. // 
  146. // Watchdog timers execute only once, but some applications require
  147. // periodically executing timers.  To achieve this effect, the timer
  148. // routine itself must call VXWWd::start() to restart the timer on each
  149. // invocation.
  150. // 
  151. // WARNING: The watchdog routine runs in the context of the
  152. // system-clock ISR; thus, it is subject to all ISR restrictions.
  153. // 
  154. // RETURNS: OK, or ERROR if the watchdog timer cannot be started.
  155. //
  156. // SEE ALSO: VXWWd::cancel()
  157. //
  158.     STATUS start (int delay, FUNCPTR pRoutine, int parameter)
  159. {
  160. return wdStart (wd_, delay, pRoutine, parameter);
  161. }
  162.   protected:
  163. ////////////////////////////////////////////////////////////////////////////////
  164. //
  165. // VXWWd::VXWWd (const VXWWd &) - copy constructor
  166. //
  167. // RETURNS: N/A
  168. //
  169. // NOMANUAL
  170. //
  171.     VXWWd (const VXWWd & aWd)
  172. : wd_ (aWd.wd_)
  173. {
  174. }
  175. ////////////////////////////////////////////////////////////////////////////////
  176. //
  177. // VXWWd::operator=(const VXWWd &) - assignment operator
  178. //
  179. // RETURNS: reference to <this>
  180. //
  181. // NOMANUAL
  182. //
  183.     VXWWd & operator = (const VXWWd & aWd)
  184. {
  185. wd_ = aWd.wd_;
  186. return *this;
  187. }
  188.     virtual void * myValue ();
  189.     WDOG_ID wd_;
  190.     };
  191. #endif /* ifndef vxwWdLib_h */