nu_wdt.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**************************************************************************//**
  2. * @file wdt.h
  3. * @brief NUC980 series WDT driver header file
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  7. *****************************************************************************/
  8. #ifndef __NU_WDT_H__
  9. #define __NU_WDT_H__
  10. #include "nuc980.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 << 8) /*!< Setting WDT time-out interval to 2^4 * WDT clocks */
  28. #define WDT_TIMEOUT_2POW6 (1UL << 8) /*!< Setting WDT time-out interval to 2^6 * WDT clocks */
  29. #define WDT_TIMEOUT_2POW8 (2UL << 8) /*!< Setting WDT time-out interval to 2^8 * WDT clocks */
  30. #define WDT_TIMEOUT_2POW10 (3UL << 8) /*!< Setting WDT time-out interval to 2^10 * WDT clocks */
  31. #define WDT_TIMEOUT_2POW12 (4UL << 8) /*!< Setting WDT time-out interval to 2^12 * WDT clocks */
  32. #define WDT_TIMEOUT_2POW14 (5UL << 8) /*!< Setting WDT time-out interval to 2^14 * WDT clocks */
  33. #define WDT_TIMEOUT_2POW16 (6UL << 8) /*!< Setting WDT time-out interval to 2^16 * WDT clocks */
  34. #define WDT_TIMEOUT_2POW18 (7UL << 8) /*!< Setting WDT time-out interval to 2^18 * WDT clocks */
  35. #define WDT_TIMEOUT_2POW20 (8UL << 8) /*!< Setting WDT time-out interval to 2^20 * WDT clocks */
  36. /*---------------------------------------------------------------------------------------------------------*/
  37. /* WDT Reset Delay Period Constant Definitions */
  38. /*---------------------------------------------------------------------------------------------------------*/
  39. #define WDT_RESET_DELAY_1026CLK (0UL) /*!< Setting WDT reset delay period to 1026 * WDT clocks */
  40. #define WDT_RESET_DELAY_130CLK (1UL) /*!< Setting WDT reset delay period to 130 * WDT clocks */
  41. #define WDT_RESET_DELAY_18CLK (2UL) /*!< Setting WDT reset delay period to 18 * WDT clocks */
  42. #define WDT_RESET_DELAY_3CLK (3UL) /*!< Setting WDT reset delay period to 3 * WDT clocks */
  43. /*---------------------------------------------------------------------------------------------------------*/
  44. /* WDT Free Reset Counter Keyword Constant Definitions */
  45. /*---------------------------------------------------------------------------------------------------------*/
  46. #define WDT_FREE_RESET_COUNTER_KEY (0x00005AA5) /*!< Fill this value to WDT_RSTCNT register to free reset WDT counter */
  47. /*@}*/ /* end of group WDT_EXPORTED_CONSTANTS */
  48. /** @addtogroup WDT_EXPORTED_FUNCTIONS WDT Exported Functions
  49. @{
  50. */
  51. /**
  52. * @brief Clear WDT Reset System Flag
  53. *
  54. * @param None
  55. *
  56. * @return None
  57. *
  58. * @details This macro clears WDT time-out reset system flag.
  59. *
  60. * \hideinitializer
  61. */
  62. #define WDT_CLEAR_RESET_FLAG() outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x28) | 0x04)
  63. /**
  64. * @brief Clear WDT Time-out Interrupt Flag
  65. *
  66. * @param None
  67. *
  68. * @return None
  69. *
  70. * @details This macro clears WDT time-out interrupt flag.
  71. *
  72. * \hideinitializer
  73. */
  74. #define WDT_CLEAR_TIMEOUT_INT_FLAG() outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x24) | 0x08)
  75. /**
  76. * @brief Clear WDT Wake-up Flag
  77. *
  78. * @param None
  79. *
  80. * @return None
  81. *
  82. * @details This macro clears WDT time-out wake-up system flag.
  83. *
  84. * \hideinitializer
  85. */
  86. #define WDT_CLEAR_TIMEOUT_WAKEUP_FLAG() outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x0C) | 0x20)
  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. *
  97. * \hideinitializer
  98. */
  99. #define WDT_GET_RESET_FLAG() (inpw(REG_WDT_CTL) & 0x4 ? 1 : 0)
  100. /**
  101. * @brief Get WDT Time-out Interrupt Flag
  102. *
  103. * @param None
  104. *
  105. * @retval 0 WDT time-out interrupt did not occur
  106. * @retval 1 WDT time-out interrupt occurred
  107. *
  108. * @details This macro indicates WDT time-out interrupt occurred or not.
  109. *
  110. * \hideinitializer
  111. */
  112. #define WDT_GET_TIMEOUT_INT_FLAG() (inpw(REG_WDT_CTL) & 0x8 ? 1 : 0)
  113. /**
  114. * @brief Get WDT Time-out Wake-up Flag
  115. *
  116. * @param None
  117. *
  118. * @retval 0 WDT time-out interrupt does not cause CPU wake-up
  119. * @retval 1 WDT time-out interrupt event cause CPU wake-up
  120. *
  121. * @details This macro indicates WDT time-out interrupt event has waked up system or not.
  122. *
  123. * \hideinitializer
  124. */
  125. #define WDT_GET_TIMEOUT_WAKEUP_FLAG() (inpw(REG_WDT_CTL) & 0x20 ? 1 : 0)
  126. /**
  127. * @brief Reset WDT Counter
  128. *
  129. * @param None
  130. *
  131. * @return None
  132. *
  133. * @details This macro is used to reset the internal 18-bit WDT up counter value.
  134. * @note If WDT is activated and time-out reset system function is enabled also, user should \n
  135. * reset the 18-bit WDT up counter value to avoid generate WDT time-out reset signal to \n
  136. * reset system before the WDT time-out reset delay period expires.
  137. *
  138. * \hideinitializer
  139. */
  140. #define WDT_RESET_COUNTER() outpw(REG_WDT_RSTCNT, WDT_FREE_RESET_COUNTER_KEY)
  141. /**
  142. * @brief Stop WDT Counting
  143. *
  144. * @param None
  145. *
  146. * @return None
  147. *
  148. * @details This function will stop WDT counting and disable WDT module.
  149. */
  150. static __inline void WDT_Close(void)
  151. {
  152. outpw(REG_WDT_CTL, 0);
  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. outpw(REG_WDT_CTL, inpw(REG_WDT_CTL) | 0x40);
  167. return;
  168. }
  169. /**
  170. * @brief Disable WDT Time-out Interrupt
  171. *
  172. * @param None
  173. *
  174. * @return None
  175. *
  176. * @details This function will disable the WDT time-out interrupt function.
  177. */
  178. static __inline void WDT_DisableInt(void)
  179. {
  180. /* Do not touch another write 1 clear bits */
  181. outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x6C) | 0x04);
  182. return;
  183. }
  184. void WDT_Open(UINT32 u32TimeoutInterval, UINT32 u32ResetDelay, UINT32 u32EnableReset, UINT32 u32EnableWakeup);
  185. /*@}*/ /* end of group WDT_EXPORTED_FUNCTIONS */
  186. /*@}*/ /* end of group WDT_Driver */
  187. /*@}*/ /* end of group Standard_Driver */
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. #endif /* __NU_WDT_H__ */