nu_wdt.h 7.6 KB

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