nu_wdt.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 "N9H30.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. /*---------------------------------------------------------------------------------------------------------*/
  36. /* WDT Reset Delay Period Constant Definitions */
  37. /*---------------------------------------------------------------------------------------------------------*/
  38. #define WDT_RESET_DELAY_1026CLK (0UL) /*!< Setting WDT reset delay period to 1026 * WDT clocks */
  39. #define WDT_RESET_DELAY_130CLK (1UL) /*!< Setting WDT reset delay period to 130 * WDT clocks */
  40. #define WDT_RESET_DELAY_18CLK (2UL) /*!< Setting WDT reset delay period to 18 * WDT clocks */
  41. #define WDT_RESET_DELAY_3CLK (3UL) /*!< Setting WDT reset delay period to 3 * WDT clocks */
  42. /*@}*/ /* end of group WDT_EXPORTED_CONSTANTS */
  43. /** @addtogroup WDT_EXPORTED_FUNCTIONS WDT Exported Functions
  44. @{
  45. */
  46. /**
  47. * @brief Clear WDT Reset System Flag
  48. *
  49. * @param None
  50. *
  51. * @return None
  52. *
  53. * @details This macro clears WDT time-out reset system flag.
  54. *
  55. * \hideinitializer
  56. */
  57. #define WDT_CLEAR_RESET_FLAG() outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x8) | 0x04)
  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. * \hideinitializer
  68. */
  69. #define WDT_CLEAR_TIMEOUT_INT_FLAG() outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x4) | 0x08)
  70. /**
  71. * @brief Get WDT Time-out Reset Flag
  72. *
  73. * @param None
  74. *
  75. * @retval 0 WDT time-out reset system did not occur
  76. * @retval 1 WDT time-out reset system occurred
  77. *
  78. * @details This macro indicates system has been reset by WDT time-out reset or not.
  79. *
  80. * \hideinitializer
  81. */
  82. #define WDT_GET_RESET_FLAG() (inpw(REG_WDT_CTL) & 0x4 ? 1 : 0)
  83. /**
  84. * @brief Get WDT Time-out Interrupt Flag
  85. *
  86. * @param None
  87. *
  88. * @retval 0 WDT time-out interrupt did not occur
  89. * @retval 1 WDT time-out interrupt occurred
  90. *
  91. * @details This macro indicates WDT time-out interrupt occurred or not.
  92. *
  93. * \hideinitializer
  94. */
  95. #define WDT_GET_TIMEOUT_INT_FLAG() (inpw(REG_WDT_CTL) & 0x8 ? 1 : 0)
  96. /**
  97. * @brief Reset WDT Counter
  98. *
  99. * @param None
  100. *
  101. * @return None
  102. *
  103. * @details This macro is used to reset the internal 18-bit WDT up counter value.
  104. * @note If WDT is activated and time-out reset system function is enabled also, user should \n
  105. * reset the 18-bit WDT up counter value to avoid generate WDT time-out reset signal to \n
  106. * reset system before the WDT time-out reset delay period expires.
  107. *
  108. * \hideinitializer
  109. */
  110. #define WDT_RESET_COUNTER() outpw(REG_WDT_CTL, inpw(REG_WDT_CTL) | (0x1))
  111. /**
  112. * @brief Stop WDT Counting
  113. *
  114. * @param None
  115. *
  116. * @return None
  117. *
  118. * @details This function will stop WDT counting and disable WDT module.
  119. */
  120. static __inline void WDT_Close(void)
  121. {
  122. outpw(REG_WDT_CTL, 0);
  123. return;
  124. }
  125. /**
  126. * @brief Enable WDT Time-out Interrupt
  127. *
  128. * @param None
  129. *
  130. * @return None
  131. *
  132. * @details This function will enable the WDT time-out interrupt function.
  133. */
  134. static __inline void WDT_EnableInt(void)
  135. {
  136. outpw(REG_WDT_CTL, inpw(REG_WDT_CTL) | 0x40);
  137. return;
  138. }
  139. /**
  140. * @brief Disable WDT Time-out Interrupt
  141. *
  142. * @param None
  143. *
  144. * @return None
  145. *
  146. * @details This function will disable the WDT time-out interrupt function.
  147. */
  148. static __inline void WDT_DisableInt(void)
  149. {
  150. /* Do not touch another write 1 clear bits */
  151. outpw(REG_WDT_CTL, (inpw(REG_WDT_CTL) & ~0x6C) | 0x04);
  152. return;
  153. }
  154. void WDT_Open(UINT32 u32TimeoutInterval, UINT32 u32ResetDelay, UINT32 u32EnableReset, UINT32 u32EnableWakeup);
  155. /*@}*/ /* end of group WDT_EXPORTED_FUNCTIONS */
  156. /*@}*/ /* end of group WDT_Driver */
  157. /*@}*/ /* end of group Standard_Driver */
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* __NU_WDT_H__ */