wdt.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**************************************************************************//**
  2. * @file wdt.h
  3. * @version V3.00
  4. * $Revision: 7 $
  5. * $Date: 15/08/11 10:26a $
  6. * @brief M451 series WDT driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __WDT_H__
  12. #define __WDT_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup Standard_Driver Standard Driver
  18. @{
  19. */
  20. /** @addtogroup WDT_Driver WDT Driver
  21. @{
  22. */
  23. /** @addtogroup WDT_EXPORTED_CONSTANTS WDT Exported Constants
  24. @{
  25. */
  26. /*---------------------------------------------------------------------------------------------------------*/
  27. /* WDT Time-out Interval Period Constant Definitions */
  28. /*---------------------------------------------------------------------------------------------------------*/
  29. #define WDT_TIMEOUT_2POW4 (0UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^4 * WDT clocks */
  30. #define WDT_TIMEOUT_2POW6 (1UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^6 * WDT clocks */
  31. #define WDT_TIMEOUT_2POW8 (2UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^8 * WDT clocks */
  32. #define WDT_TIMEOUT_2POW10 (3UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^10 * WDT clocks */
  33. #define WDT_TIMEOUT_2POW12 (4UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^12 * WDT clocks */
  34. #define WDT_TIMEOUT_2POW14 (5UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^14 * WDT clocks */
  35. #define WDT_TIMEOUT_2POW16 (6UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^16 * WDT clocks */
  36. #define WDT_TIMEOUT_2POW18 (7UL << WDT_CTL_TOUTSEL_Pos) /*!< Setting WDT time-out interval to 2^18 * WDT clocks */
  37. /*---------------------------------------------------------------------------------------------------------*/
  38. /* WDT Reset Delay Period Constant Definitions */
  39. /*---------------------------------------------------------------------------------------------------------*/
  40. #define WDT_RESET_DELAY_1026CLK (0UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< Setting WDT reset delay period to 1026 * WDT clocks */
  41. #define WDT_RESET_DELAY_130CLK (1UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< Setting WDT reset delay period to 130 * WDT clocks */
  42. #define WDT_RESET_DELAY_18CLK (2UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< Setting WDT reset delay period to 18 * WDT clocks */
  43. #define WDT_RESET_DELAY_3CLK (3UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< Setting WDT reset delay period to 3 * WDT clocks */
  44. /*@}*/ /* end of group WDT_EXPORTED_CONSTANTS */
  45. /** @addtogroup WDT_EXPORTED_FUNCTIONS WDT Exported Functions
  46. @{
  47. */
  48. /**
  49. * @brief Clear WDT Reset System Flag
  50. *
  51. * @param None
  52. *
  53. * @return None
  54. *
  55. * @details This macro clears WDT time-out reset system flag.
  56. */
  57. #define WDT_CLEAR_RESET_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_IF_Msk | WDT_CTL_WKF_Msk)) | WDT_CTL_RSTF_Msk)
  58. /**
  59. * @brief Clear WDT Time-out Interrupt Flag
  60. *
  61. * @param None
  62. *
  63. * @return None
  64. *
  65. * @details This macro clears WDT time-out interrupt flag.
  66. */
  67. #define WDT_CLEAR_TIMEOUT_INT_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_RSTF_Msk | WDT_CTL_WKF_Msk)) | WDT_CTL_IF_Msk)
  68. /**
  69. * @brief Clear WDT Wake-up Flag
  70. *
  71. * @param None
  72. *
  73. * @return None
  74. *
  75. * @details This macro clears WDT time-out wake-up system flag.
  76. */
  77. #define WDT_CLEAR_TIMEOUT_WAKEUP_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_RSTF_Msk | WDT_CTL_IF_Msk)) | WDT_CTL_WKF_Msk)
  78. /**
  79. * @brief Get WDT Time-out Reset Flag
  80. *
  81. * @param None
  82. *
  83. * @retval 0 WDT time-out reset system did not occur
  84. * @retval 1 WDT time-out reset system occurred
  85. *
  86. * @details This macro indicates system has been reset by WDT time-out reset or not.
  87. */
  88. #define WDT_GET_RESET_FLAG() ((WDT->CTL & WDT_CTL_RSTF_Msk)? 1 : 0)
  89. /**
  90. * @brief Get WDT Time-out Interrupt Flag
  91. *
  92. * @param None
  93. *
  94. * @retval 0 WDT time-out interrupt did not occur
  95. * @retval 1 WDT time-out interrupt occurred
  96. *
  97. * @details This macro indicates WDT time-out interrupt occurred or not.
  98. */
  99. #define WDT_GET_TIMEOUT_INT_FLAG() ((WDT->CTL & WDT_CTL_IF_Msk)? 1 : 0)
  100. /**
  101. * @brief Get WDT Time-out Wake-up Flag
  102. *
  103. * @param None
  104. *
  105. * @retval 0 WDT time-out interrupt does not cause CPU wake-up
  106. * @retval 1 WDT time-out interrupt event cause CPU wake-up
  107. *
  108. * @details This macro indicates WDT time-out interrupt event has waked up system or not.
  109. */
  110. #define WDT_GET_TIMEOUT_WAKEUP_FLAG() ((WDT->CTL & WDT_CTL_WKF_Msk)? 1 : 0)
  111. /**
  112. * @brief Reset WDT Counter
  113. *
  114. * @param None
  115. *
  116. * @return None
  117. *
  118. * @details This macro is used to reset the internal 18-bit WDT up counter value.
  119. * @note If WDT is activated and time-out reset system function is enabled also, user should \n
  120. * reset the 18-bit WDT up counter value to avoid generate WDT time-out reset signal to \n
  121. * reset system before the WDT time-out reset delay period expires.
  122. */
  123. #define WDT_RESET_COUNTER() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_IF_Msk | WDT_CTL_WKF_Msk | WDT_CTL_RSTF_Msk)) | WDT_CTL_RSTCNT_Msk)
  124. /**
  125. * @brief Stop WDT Counting
  126. *
  127. * @param None
  128. *
  129. * @return None
  130. *
  131. * @details This function will stop WDT counting and disable WDT module.
  132. */
  133. static __INLINE void WDT_Close(void)
  134. {
  135. WDT->CTL = 0;
  136. return;
  137. }
  138. /**
  139. * @brief Enable WDT Time-out Interrupt
  140. *
  141. * @param None
  142. *
  143. * @return None
  144. *
  145. * @details This function will enable the WDT time-out interrupt function.
  146. */
  147. static __INLINE void WDT_EnableInt(void)
  148. {
  149. WDT->CTL |= WDT_CTL_INTEN_Msk;
  150. return;
  151. }
  152. /**
  153. * @brief Disable WDT Time-out Interrupt
  154. *
  155. * @param None
  156. *
  157. * @return None
  158. *
  159. * @details This function will disable the WDT time-out interrupt function.
  160. */
  161. static __INLINE void WDT_DisableInt(void)
  162. {
  163. // Do not touch another write 1 clear bits
  164. WDT->CTL &= ~(WDT_CTL_INTEN_Msk | WDT_CTL_RSTF_Msk | WDT_CTL_IF_Msk | WDT_CTL_WKF_Msk);
  165. return;
  166. }
  167. void WDT_Open(uint32_t u32TimeoutInterval, uint32_t u32ResetDelay, uint32_t u32EnableReset, uint32_t u32EnableWakeup);
  168. /*@}*/ /* end of group WDT_EXPORTED_FUNCTIONS */
  169. /*@}*/ /* end of group WDT_Driver */
  170. /*@}*/ /* end of group Standard_Driver */
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif //__WDT_H__
  175. /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/