wdog.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /******************************************************************************
  2. * @brief provide commond watch dog utilities.
  3. *
  4. *******************************************************************************
  5. *
  6. * provide APIs for accessing watch dog
  7. ******************************************************************************/
  8. #ifndef __WDOG_H__
  9. #define __WDOG_H__
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. /******************************************************************************
  14. * Includes
  15. ******************************************************************************/
  16. #include "sim.h"
  17. /******************************************************************************
  18. * Constants
  19. ******************************************************************************/
  20. /******************************************************************************
  21. * Macros
  22. ******************************************************************************/
  23. /* wdog_unlock sequence must be performed within 16 bus clock cycles without
  24. * any interrupt
  25. */
  26. /* WDOG clock sources option */
  27. /******************************************************************************
  28. * define watchdog clock source selection
  29. *
  30. *//*! @addtogroup wdog_clock_sources
  31. * @{
  32. *******************************************************************************/
  33. #define WDOG_CLK_BUS 0 /*!< clock source is bus clock */
  34. #define WDOG_CLK_INTERNAL_32KHZ 2 /*!< clock source is internal oscillator 32 kHz (ICSIRCLK) */
  35. #define WDOG_CLK_INTERNAL_1KHZ 1 /*!< clock source is internal LPO 1 KHz */
  36. #define WDOG_CLK_EXTERNAL 3 /*!< clock source is external clock */
  37. /*! @} End of wdog_clock_sources */
  38. /* WDOG clock source selection */
  39. #define WDOG_CLK (WDOG_CLK_INTERNAL_1KHZ)
  40. /* WDOG default values */
  41. #define WDOG_CS1_DEFAULT_VALUE 0x80
  42. #define WDOG_CS2_DEFAULT_VALUE 0x01
  43. #define WDOG_TOVAL_DEFAULT_VALUE 0x0400
  44. #define WDOG_WIN_DEFAULT_VALUE 0x0000
  45. /* WDOG utilities */
  46. /******************************************************************************
  47. * define watchdog API list
  48. *
  49. *//*! @addtogroup wdog_api_list
  50. * @{
  51. *******************************************************************************/
  52. /*!
  53. * @brief watchdog unlock routine.
  54. */
  55. #define WDOG_Unlock() WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9
  56. //#define WDOG_Unlock() DisableInterrupts; WDOG->CNT = 0x20C5; WDOG->CNT = 0x28D9; EnableInterrupts
  57. /*! @} End of wdog_api_list */
  58. /******************************************************************************
  59. * Types
  60. ******************************************************************************/
  61. /******************************************************************************
  62. * define watchdog configuration structure
  63. *
  64. *//*! @addtogroup wdog_config_type
  65. * @{
  66. *******************************************************************************/
  67. /*!
  68. * @brief watchdog configuration structure.
  69. *
  70. */
  71. typedef struct {
  72. struct {
  73. uint16_t bIntEnable : 1; /*!< watchdog interrupt enable */
  74. uint16_t bDisable : 1; /*!< disable watchdog */
  75. uint16_t bWaitEnable : 1; /*!< enable watchdog in wait mode */
  76. uint16_t bStopEnable : 1; /*!< enable watchdog in stop mode */
  77. uint16_t bDbgEnable : 1; /*!< enable watchdog in debug mode */
  78. uint16_t bWinEnable : 1; /*!< enable watchdog window mode */
  79. uint16_t bUpdateEnable : 1; /*!< enable update of watchdog control */
  80. uint16_t bClkSrc : 2; /*!< watchdog clock source selection */
  81. uint16_t bPrescaler : 1; /*!< prescaler */
  82. }sBits; /*!< bitfield structure */
  83. uint16_t u16ETMeOut; /*!< watchdog ETMeout value */
  84. uint16_t u16WinETMe; /*!< watchdog window value */
  85. } WDOG_ConfigType, *WDOG_ConfigPtr; /*!< watchdog configuration structure type */
  86. /*! @} End of wdog_config_type */
  87. /******************************************************************************
  88. * Global variables
  89. ******************************************************************************/
  90. /******************************************************************************
  91. * Global functions
  92. ******************************************************************************/
  93. /******************************************************************************
  94. * define watchdog API list
  95. *
  96. *//*! @addtogroup wdog_api_list
  97. * @{
  98. *******************************************************************************/
  99. /*****************************************************************************//*!
  100. *
  101. * @brief set ETMe out value for WDOG.
  102. *
  103. * @param[in] u16ETMeOut ETMeout value to TOVAL register.
  104. *
  105. * @return none
  106. *
  107. * @ Pass/ Fail criteria: none
  108. *
  109. *****************************************************************************/
  110. __STATIC_INLINE void WDOG_SetETMeOut(uint16_t u16ETMeOut)
  111. {
  112. WDOG->CNT = 0x20C5;
  113. WDOG->CNT = 0x28D9;
  114. WDOG->TOVAL8B.TOVALL = u16ETMeOut;
  115. WDOG->TOVAL8B.TOVALH = u16ETMeOut >> 8;
  116. }
  117. /*****************************************************************************//*!
  118. *
  119. * @brief set window value for WDOG.
  120. *
  121. * @param[in] u16WinETMe window value to WIN register.
  122. *
  123. * @return none
  124. *
  125. * @ Pass/ Fail criteria: none
  126. *
  127. *****************************************************************************/
  128. __STATIC_INLINE void WDOG_SetWindow(uint16_t u16WinETMe)
  129. {
  130. WDOG->CNT = 0x20C5;
  131. WDOG->CNT = 0x28D9;
  132. WDOG->WIN8B.WINL = u16WinETMe;
  133. WDOG->WIN8B.WINH = u16WinETMe >> 8;
  134. }
  135. /*****************************************************************************//*!
  136. *
  137. * @brief check if watchdog reset occurs.
  138. *
  139. * @param none.
  140. *
  141. * @return TRUE if watchdog reset occurs, FALSE otherwise.
  142. *
  143. * @ Pass/ Fail criteria: none
  144. *****************************************************************************/
  145. __STATIC_INLINE uint8_t WDOG_IsReset(void)
  146. {
  147. if(SIM_GetStatus(SIM_SRSID_WDOG_MASK))
  148. {
  149. return (TRUE);
  150. }
  151. return (FALSE);
  152. }
  153. /*! @} End of wdog_api_list */
  154. void WDOG_Init(WDOG_ConfigPtr pConfig);
  155. void WDOG_DeInit(void);
  156. void WDOG_Disable(void);
  157. void WDOG_DisableWDOGEnableUpdate(void);
  158. void WDOG_Enable(void);
  159. void WDOG_Feed(void);
  160. void WDOG_SetETMeOut(uint16_t u16ETMeOut);
  161. void WDOG_SetWindow(uint16_t u16WinETMe);
  162. void WDOG_EnableUpdate(void);
  163. void WDOG_DisableUpdate(void);
  164. uint8_t WDOG_IsReset(void);
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. /********************************************************************/
  169. #endif /* __WDOG_H__ */