nu_wdt.h 7.9 KB

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