wdt.h 7.5 KB

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