watchdog.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _DEV_WATCHDOG_H_
  2. #define _DEV_WATCHDOG_H_
  3. /*
  4. * Copyright (C) 2006 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log: watchdog.h,v $
  36. * Revision 1.2 2006/05/25 09:13:23 haraldkipp
  37. * Platform independent watchdog API added.
  38. *
  39. * Revision 1.1 2006/02/23 15:36:35 haraldkipp
  40. * Added support for AT91 watchdog timer.
  41. *
  42. */
  43. #include <sys/types.h>
  44. /*!
  45. * \addtogroup xgWatchDog
  46. */
  47. /*@{*/
  48. __BEGIN_DECLS
  49. /* Prototypes */
  50. /*!
  51. * \brief Start the watch dog timer.
  52. *
  53. * This function can be used by applications to prevent hang-ups.
  54. *
  55. * \param ms Watch dog time out in milliseconds.
  56. * \param xmode Hardware specific mode. If 0, the default mode is used.
  57. * In this mode, the watch dog will reset the CPU if not
  58. * restarted within the specified time out period.
  59. *
  60. * \return The actual time out value, which may differ from the
  61. * specified value due to hardware limitations. The watch
  62. * dog timer will be automatically enabled on return.
  63. *
  64. * The following code fragment starts the watch timer with a time out
  65. * of 550 milliseconds and restarts it every 500 milliseconds.
  66. *
  67. * \code
  68. * #include <dev/watchdog.h>
  69. * #include <sys/timer.h>
  70. *
  71. * NutWatchDogStart(550, 0);
  72. * for(;;) {
  73. * NutWatchDogRestart();
  74. * NutSleep(500);
  75. * }
  76. *
  77. * \endcode
  78. *
  79. * \todo AVR implementation.
  80. *
  81. * \note The AT91 implementation does not calculate the actual time out
  82. * value, but simply returns the specified number of milliseconds.
  83. */
  84. extern u_long NutWatchDogStart(u_long ms, u_long xmode);
  85. /*!
  86. * \brief Restart the watch dog timer.
  87. */
  88. extern void NutWatchDogRestart(void);
  89. /*!
  90. * \brief Disables the watch dog timer.
  91. *
  92. * Applications should call this function to temporarily disable the
  93. * watch dog timer. To re-enable it, call NutWatchDogEnable().
  94. *
  95. * \code
  96. * #include <dev/watchdog.h>
  97. *
  98. * NutWatchDogStart(100, 0);
  99. *
  100. * //Some code here.
  101. *
  102. * NutWatchDogRestart();
  103. *
  104. * //Some code here.
  105. *
  106. * NutWatchDogDisable();
  107. *
  108. * //Some lengthy code here, like writing to flash memory.
  109. *
  110. * NutWatchDogEnable();
  111. *
  112. * \endcode
  113. */
  114. extern void NutWatchDogDisable(void);
  115. /*!
  116. * \brief Enables the watch dog timer.
  117. *
  118. * The function can be safely used within nested subroutines.
  119. * The watch dog will be enabled only, if this function is called
  120. * the same number of times as NutWatchDogDisable(). If enabled,
  121. * the watch dog timer will also have been re-started and the
  122. * full time out value is available before another NutWatchDogRestart()
  123. * is required.
  124. *
  125. * If the watch has not been started by NutWatchDogStart(), then this
  126. * function does nothing.
  127. */
  128. extern void NutWatchDogEnable(void);
  129. #if defined(__AVR__)
  130. extern u_long AvrWatchDogStart(u_long ms);
  131. extern void AvrWatchDogRestart(void);
  132. extern void AvrWatchDogDisable(void);
  133. extern void AvrWatchDogEnable(void);
  134. #elif defined(MCU_AT91R40008)
  135. extern u_long At91WatchDogStart(u_long ms, u_long xmode);
  136. extern void At91WatchDogRestart(void);
  137. extern void At91WatchDogDisable(void);
  138. extern void At91WatchDogEnable(void);
  139. #endif
  140. __END_DECLS
  141. /* End of prototypes */
  142. /*@}*/
  143. #endif