wdt.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**************************************************************************//**
  2. * @file wdt.h
  3. * @version V1.00
  4. * $Revision: 8 $
  5. * $Date: 14/05/29 1:13p $
  6. * @brief NUC472/NUC442 WDT driver header file
  7. *
  8. * @note
  9. * Copyright (C) 2013 Nuvoton Technology Corp. All rights reserved.
  10. *****************************************************************************/
  11. #ifndef __WDT_H__
  12. #define __WDT_H__
  13. #ifdef __cplusplus
  14. extern "C"
  15. {
  16. #endif
  17. /** @addtogroup NUC472_442_Device_Driver NUC472/NUC442 Device Driver
  18. @{
  19. */
  20. /** @addtogroup NUC472_442_WDT_Driver WDT Driver
  21. @{
  22. */
  23. /** @addtogroup NUC472_442_WDT_EXPORTED_CONSTANTS WDT Exported Constants
  24. @{
  25. */
  26. #define WDT_TIMEOUT_2POW4 (0UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^4 * WDT clocks \hideinitializer */
  27. #define WDT_TIMEOUT_2POW6 (1UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^6 * WDT clocks \hideinitializer */
  28. #define WDT_TIMEOUT_2POW8 (2UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^8 * WDT clocks \hideinitializer */
  29. #define WDT_TIMEOUT_2POW10 (3UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^10 * WDT clocks \hideinitializer */
  30. #define WDT_TIMEOUT_2POW12 (4UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^12 * WDT clocks \hideinitializer */
  31. #define WDT_TIMEOUT_2POW14 (5UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^14 * WDT clocks \hideinitializer */
  32. #define WDT_TIMEOUT_2POW16 (6UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^16 * WDT clocks \hideinitializer */
  33. #define WDT_TIMEOUT_2POW18 (7UL << WDT_CTL_TOUTSEL_Pos) /*!< WDT setting for timeout interval = 2^18 * WDT clocks \hideinitializer */
  34. #define WDT_RESET_DELAY_3CLK (3UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< WDT setting reset delay to 3 WDT clocks \hideinitializer */
  35. #define WDT_RESET_DELAY_18CLK (2UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< WDT setting reset delay to 18 WDT clocks \hideinitializer */
  36. #define WDT_RESET_DELAY_130CLK (1UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< WDT setting reset delay to 130 WDT clocks \hideinitializer */
  37. #define WDT_RESET_DELAY_1026CLK (0UL << WDT_ALTCTL_RSTDSEL_Pos) /*!< WDT setting reset delay to 1026 WDT clocks \hideinitializer */
  38. /*@}*/ /* end of group NUC472_442_WDT_EXPORTED_CONSTANTS */
  39. /** @addtogroup NUC472_442_WDT_EXPORTED_FUNCTIONS WDT Exported Functions
  40. @{
  41. */
  42. /**
  43. * @brief This macro clear WDT time-out reset system flag.
  44. * @param None
  45. * @return None
  46. * \hideinitializer
  47. */
  48. #define WDT_CLEAR_RESET_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_IF_Msk | WDT_CTL_WKF_Msk)) | WDT_CTL_RSTF_Msk)
  49. /**
  50. * @brief This macro clear WDT time-out interrupt flag.
  51. * @param None
  52. * @return None
  53. * \hideinitializer
  54. */
  55. #define WDT_CLEAR_TIMEOUT_INT_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_RSTF_Msk | WDT_CTL_WKF_Msk)) | WDT_CTL_IF_Msk)
  56. /**
  57. * @brief This macro clear WDT time-out wake-up system flag.
  58. * @param None
  59. * @return None
  60. * \hideinitializer
  61. */
  62. #define WDT_CLEAR_TIMEOUT_WAKEUP_FLAG() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_RSTF_Msk | WDT_CTL_IF_Msk)) | WDT_CTL_WKF_Msk)
  63. /**
  64. * @brief This macro indicate WDT time-out to reset system or not.
  65. * @return WDT reset system or not
  66. * @retval 0 WDT did not cause system reset
  67. * @retval 1 WDT caused system reset
  68. * \hideinitializer
  69. */
  70. #define WDT_GET_RESET_FLAG() (WDT->CTL & WDT_CTL_RSTF_Msk ? 1 : 0)
  71. /**
  72. * @brief This macro indicate WDT time-out interrupt occurred or not.
  73. * @return WDT time-out interrupt occurred or not
  74. * @retval 0 WDT time-out interrupt did not occur
  75. * @retval 1 WDT time-out interrupt occurred
  76. * \hideinitializer
  77. */
  78. #define WDT_GET_TIMEOUT_INT_FLAG() (WDT->CTL & WDT_CTL_IF_Msk ? 1 : 0)
  79. /**
  80. * @brief This macro indicate WDT time-out waked system up or not
  81. * @return WDT time-out waked system up or not
  82. * @retval 0 WDT did not wake up system
  83. * @retval 1 WDT waked up system
  84. * \hideinitializer
  85. */
  86. #define WDT_GET_TIMEOUT_WAKEUP_FLAG() (WDT->CTL & WDT_CTL_WKF_Msk ? 1 : 0)
  87. /**
  88. * @brief This macro is used to reset 18-bit WDT counter.
  89. * @details If WDT is activated and enabled to reset system, software must reset WDT counter
  90. * before WDT time-out plus reset delay reached. Or WDT generate a reset signal.
  91. * \hideinitializer
  92. */
  93. #define WDT_RESET_COUNTER() (WDT->CTL = (WDT->CTL & ~(WDT_CTL_IF_Msk | WDT_CTL_WKF_Msk | WDT_CTL_RSTF_Msk)) | WDT_CTL_RSTCNT_Msk)
  94. /**
  95. * @brief This function stops WDT counting and disable WDT module
  96. * @param None
  97. * @return None
  98. */
  99. __STATIC_INLINE void WDT_Close(void)
  100. {
  101. WDT->CTL = 0;
  102. return;
  103. }
  104. /**
  105. * @brief This function enables the WDT time-out interrupt
  106. * @param None
  107. * @return None
  108. */
  109. __STATIC_INLINE void WDT_EnableInt(void)
  110. {
  111. WDT->CTL |= WDT_CTL_INTEN_Msk;
  112. return;
  113. }
  114. /**
  115. * @brief This function disables the WDT time-out interrupt
  116. * @param None
  117. * @return None
  118. */
  119. __STATIC_INLINE void WDT_DisableInt(void)
  120. {
  121. // Do not touch write 1 clear bits
  122. WDT->CTL &= ~(WDT_CTL_INTEN_Msk | WDT_CTL_RSTF_Msk | WDT_CTL_IF_Msk) ;
  123. return;
  124. }
  125. void WDT_Open(uint32_t u32TimeoutInterval,
  126. uint32_t u32ResetDelay,
  127. uint32_t u32EnableReset,
  128. uint32_t u32EnableWakeup);
  129. /*@}*/ /* end of group NUC472_442_WDT_EXPORTED_FUNCTIONS */
  130. /*@}*/ /* end of group NUC472_442_WDT_Driver */
  131. /*@}*/ /* end of group NUC472_442_Device_Driver */
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif //__WDT_H__
  136. /*** (C) COPYRIGHT 2013 Nuvoton Technology Corp. ***/