watchdog.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 THE COPYRIGHT HOLDERS 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 THE
  23. * COPYRIGHT OWNER 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$
  36. * Revision 1.4 2008/09/02 14:32:25 haraldkipp
  37. * Includes stdint header.
  38. *
  39. * Revision 1.3 2008/08/11 06:59:59 haraldkipp
  40. * BSD types replaced by stdint types (feature request #1282721).
  41. *
  42. * Revision 1.2 2006/05/25 09:13:23 haraldkipp
  43. * Platform independent watchdog API added.
  44. *
  45. * Revision 1.1 2006/02/23 15:36:35 haraldkipp
  46. * Added support for AT91 watchdog timer.
  47. *
  48. */
  49. #include <cfg/arch.h>
  50. #include <sys/types.h>
  51. #include <stdint.h>
  52. /*!
  53. * \addtogroup xgWatchDog
  54. */
  55. /*@{*/
  56. /*!
  57. * \brief Start the watch dog timer.
  58. *
  59. * This function can be used by applications to prevent hang-ups.
  60. *
  61. * \param ms Watch dog time out in milliseconds.
  62. * \param xmode Hardware specific mode. If 0, the default mode is used.
  63. * In this mode, the watch dog will reset the CPU if not
  64. * restarted within the specified time out period.
  65. *
  66. * \return The actual time out value, which may differ from the
  67. * specified value due to hardware limitations. The watch
  68. * dog timer will be automatically enabled on return.
  69. *
  70. * The following code fragment starts the watch timer with a time out
  71. * of 550 milliseconds and restarts it every 500 milliseconds.
  72. *
  73. * \code
  74. * #include <dev/watchdog.h>
  75. * #include <sys/timer.h>
  76. *
  77. * NutWatchDogStart(550, 0);
  78. * for(;;) {
  79. * NutWatchDogRestart();
  80. * NutSleep(500);
  81. * }
  82. *
  83. * \endcode
  84. *
  85. * \todo AVR implementation.
  86. *
  87. * \note The AT91 implementation does not calculate the actual time out
  88. * value, but simply returns the specified number of milliseconds.
  89. */
  90. extern uint32_t NutWatchDogStart(uint32_t ms, uint32_t xmode);
  91. /*!
  92. * \brief Restart the watch dog timer.
  93. */
  94. extern void NutWatchDogRestart(void);
  95. /*!
  96. * \brief Disables the watch dog timer.
  97. *
  98. * Applications should call this function to temporarily disable the
  99. * watch dog timer. To re-enable it, call NutWatchDogEnable().
  100. *
  101. * \code
  102. * #include <dev/watchdog.h>
  103. *
  104. * NutWatchDogStart(100, 0);
  105. *
  106. * //Some code here.
  107. *
  108. * NutWatchDogRestart();
  109. *
  110. * //Some code here.
  111. *
  112. * NutWatchDogDisable();
  113. *
  114. * //Some lengthy code here, like writing to flash memory.
  115. *
  116. * NutWatchDogEnable();
  117. *
  118. * \endcode
  119. */
  120. extern void NutWatchDogDisable(void);
  121. /*!
  122. * \brief Enables the watch dog timer.
  123. *
  124. * The function can be safely used within nested subroutines.
  125. * The watch dog will be enabled only, if this function is called
  126. * the same number of times as NutWatchDogDisable(). If enabled,
  127. * the watch dog timer will also have been re-started and the
  128. * full time out value is available before another NutWatchDogRestart()
  129. * is required.
  130. *
  131. * If the watch has not been started by NutWatchDogStart(), then this
  132. * function does nothing.
  133. */
  134. extern void NutWatchDogEnable(void);
  135. #if defined(__AVR__)
  136. extern uint32_t AvrWatchDogStart(uint32_t ms);
  137. extern void AvrWatchDogRestart(void);
  138. extern void AvrWatchDogDisable(void);
  139. extern void AvrWatchDogEnable(void);
  140. #elif defined(MCU_AT91R40008) || defined(MCU_AT91SAM7X) || defined(MCU_AT91SAM7S) || defined(MCU_AT91SAM7SE)
  141. extern uint32_t At91WatchDogStart(uint32_t ms, uint32_t xmode);
  142. extern void At91WatchDogRestart(void);
  143. extern void At91WatchDogDisable(void);
  144. extern void At91WatchDogEnable(void);
  145. #elif defined(__AVR32__)
  146. extern uint32_t Avr32WatchDogStart(uint32_t ms);
  147. extern void Avr32WatchDogRestart(void);
  148. extern void Avr32WatchDogDisable(void);
  149. extern void Avr32WatchDogEnable(void);
  150. #elif defined(MCU_LPC17xx)
  151. extern uint32_t Lpc17xxWatchDogStart(uint32_t ms, uint32_t xmode);
  152. extern void Lpc17xxWatchDogRestart(void);
  153. extern void Lpc17xxWatchDogDisable(void);
  154. extern void Lpc17xxWatchDogEnable(void);
  155. #elif defined(MCU_MCF5225X)
  156. extern uint32_t Mcf5225xWatchDogStart(uint32_t ms);
  157. extern void Mcf5225xWatchDogRestart(void);
  158. extern void Mcf5225xWatchDogDisable(void);
  159. extern void Mcf5225xWatchDogEnable(void);
  160. #endif
  161. /*@}*/
  162. #endif