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