fsl_wdog.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_WDOG_H_
  31. #define _FSL_WDOG_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup wdog
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. *******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. /*! @brief Defines WDOG driver version */
  43. #define FSL_WDOG_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  44. /*@}*/
  45. /*! @name Refresh sequence */
  46. /*@{*/
  47. #define WDOG_REFRESH_KEY (0xAAAA5555U)
  48. /*@}*/
  49. /*! @brief Defines WDOG work mode. */
  50. typedef struct _wdog_work_mode
  51. {
  52. bool enableWait; /*!< continue or suspend WDOG in wait mode */
  53. bool enableStop; /*!< continue or suspend WDOG in stop mode */
  54. bool enableDebug; /*!< continue or suspend WDOG in debug mode */
  55. } wdog_work_mode_t;
  56. /*! @brief Describes WDOG configuration structure. */
  57. typedef struct _wdog_config
  58. {
  59. bool enableWdog; /*!< Enables or disables WDOG */
  60. wdog_work_mode_t workMode; /*!< Configures WDOG work mode in debug stop and wait mode */
  61. bool enableInterrupt; /*!< Enables or disables WDOG interrupt */
  62. uint16_t timeoutValue; /*!< Timeout value */
  63. uint16_t interruptTimeValue; /*!< Interrupt count timeout value */
  64. bool softwareResetExtension; /*!< software reset extension */
  65. bool enablePowerDown; /*!< power down enable bit */
  66. bool softwareAssertion; /*!< software assertion bit*/
  67. bool softwareResetSignal; /*!< software reset signalbit*/
  68. } wdog_config_t;
  69. /*!
  70. * @brief WDOG interrupt configuration structure, default settings all disabled.
  71. *
  72. * This structure contains the settings for all of the WDOG interrupt configurations.
  73. */
  74. enum _wdog_interrupt_enable
  75. {
  76. kWDOG_InterruptEnable = WDOG_WICR_WIE_MASK /*!< WDOG timeout generates an interrupt before reset*/
  77. };
  78. /*!
  79. * @brief WDOG status flags.
  80. *
  81. * This structure contains the WDOG status flags for use in the WDOG functions.
  82. */
  83. enum _wdog_status_flags
  84. {
  85. kWDOG_RunningFlag = WDOG_WCR_WDE_MASK, /*!< Running flag, set when WDOG is enabled*/
  86. kWDOG_PowerOnResetFlag = WDOG_WRSR_POR_MASK, /*!< Power On flag, set when reset is the result of a powerOnReset*/
  87. kWDOG_TimeoutResetFlag = WDOG_WRSR_TOUT_MASK, /*!< Timeout flag, set when reset is the result of a timeout*/
  88. kWDOG_SoftwareResetFlag = WDOG_WRSR_SFTW_MASK, /*!< Software flag, set when reset is the result of a software*/
  89. kWDOG_InterruptFlag = WDOG_WICR_WTIS_MASK /*!< interrupt flag,whether interrupt has occurred or not*/
  90. };
  91. /*******************************************************************************
  92. * API
  93. *******************************************************************************/
  94. #if defined(__cplusplus)
  95. extern "C" {
  96. #endif /* __cplusplus */
  97. /*!
  98. * @name WDOG Initialization and De-initialization.
  99. * @{
  100. */
  101. /*!
  102. * @brief Initializes the WDOG configuration sturcture.
  103. *
  104. * This function initializes the WDOG configuration structure to default values. The default
  105. * values are as follows.
  106. * @code
  107. * wdogConfig->enableWdog = true;
  108. * wdogConfig->workMode.enableWait = true;
  109. * wdogConfig->workMode.enableStop = false;
  110. * wdogConfig->workMode.enableDebug = false;
  111. * wdogConfig->enableInterrupt = false;
  112. * wdogConfig->enablePowerdown = false;
  113. * wdogConfig->resetExtension = flase;
  114. * wdogConfig->timeoutValue = 0xFFU;
  115. * wdogConfig->interruptTimeValue = 0x04u;
  116. * @endcode
  117. *
  118. * @param config Pointer to the WDOG configuration structure.
  119. * @see wdog_config_t
  120. */
  121. void WDOG_GetDefaultConfig(wdog_config_t *config);
  122. /*!
  123. * @brief Initializes the WDOG.
  124. *
  125. * This function initializes the WDOG. When called, the WDOG runs according to the configuration.
  126. *
  127. * This is an example.
  128. * @code
  129. * wdog_config_t config;
  130. * WDOG_GetDefaultConfig(&config);
  131. * config.timeoutValue = 0xffU;
  132. * config->interruptTimeValue = 0x04u;
  133. * WDOG_Init(wdog_base,&config);
  134. * @endcode
  135. *
  136. * @param base WDOG peripheral base address
  137. * @param config The configuration of WDOG
  138. */
  139. void WDOG_Init(WDOG_Type *base, const wdog_config_t *config);
  140. /*!
  141. * @brief Shuts down the WDOG.
  142. *
  143. * This function shuts down the WDOG.
  144. * Watchdog Enable bit is a write one once only bit. It is not
  145. * possible to clear this bit by a software write, once the bit is set.
  146. * This bit(WDE) can be set/reset only in debug mode(exception).
  147. */
  148. void WDOG_Deinit(WDOG_Type *base);
  149. /*!
  150. * @brief Enables the WDOG module.
  151. *
  152. * This function writes a value into the WDOG_WCR register to enable the WDOG.
  153. * This is a write one once only bit. It is not possible to clear this bit by a software write,
  154. * once the bit is set. only debug mode exception.
  155. * @param base WDOG peripheral base address
  156. */
  157. static inline void WDOG_Enable(WDOG_Type *base)
  158. {
  159. base->WCR |= WDOG_WCR_WDE_MASK;
  160. }
  161. /*!
  162. * @brief Disables the WDOG module.
  163. *
  164. * This function writes a value into the WDOG_WCR register to disable the WDOG.
  165. * This is a write one once only bit. It is not possible to clear this bit by a software write,once the bit is set.
  166. * only debug mode exception
  167. * @param base WDOG peripheral base address
  168. */
  169. static inline void WDOG_Disable(WDOG_Type *base)
  170. {
  171. base->WCR &= ~WDOG_WCR_WDE_MASK;
  172. }
  173. /*!
  174. * @brief Enables the WDOG interrupt.
  175. *
  176. *This bit is a write once only bit. Once the software does a write access to this bit, it will get
  177. *locked and cannot be reprogrammed until the next system reset assertion
  178. *
  179. * @param base WDOG peripheral base address
  180. * @param mask The interrupts to enable
  181. * The parameter can be combination of the following source if defined.
  182. * @arg kWDOG_InterruptEnable
  183. */
  184. static inline void WDOG_EnableInterrupts(WDOG_Type *base, uint16_t mask)
  185. {
  186. base->WICR |= mask;
  187. }
  188. /*!
  189. * @brief Gets the WDOG all reset status flags.
  190. *
  191. * This function gets all reset status flags.
  192. *
  193. * @code
  194. * uint16_t status;
  195. * status = WDOG_GetStatusFlags (wdog_base);
  196. * @endcode
  197. * @param base WDOG peripheral base address
  198. * @return State of the status flag: asserted (true) or not-asserted (false).@see _wdog_status_flags
  199. * - true: a related status flag has been set.
  200. * - false: a related status flag is not set.
  201. */
  202. uint16_t WDOG_GetStatusFlags(WDOG_Type *base);
  203. /*!
  204. * @brief Clears the WDOG flag.
  205. *
  206. * This function clears the WDOG status flag.
  207. *
  208. * This is an example for clearing the interrupt flag.
  209. * @code
  210. * WDOG_ClearStatusFlags(wdog_base,KWDOG_InterruptFlag);
  211. * @endcode
  212. * @param base WDOG peripheral base address
  213. * @param mask The status flags to clear.
  214. * The parameter could be any combination of the following values.
  215. * kWDOG_TimeoutFlag
  216. */
  217. void WDOG_ClearInterruptStatus(WDOG_Type *base, uint16_t mask);
  218. /*!
  219. * @brief Sets the WDOG timeout value.
  220. *
  221. * This function sets the timeout value.
  222. * This function writes a value into WCR registers.
  223. * The time-out value can be written at any point of time but it is loaded to the counter at the time
  224. * when WDOG is enabled or after the service routine has been performed.
  225. *
  226. * @param base WDOG peripheral base address
  227. * @param timeoutCount WDOG timeout value; count of WDOG clock tick.
  228. */
  229. static inline void WDOG_SetTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
  230. {
  231. base->WCR = (base->WCR & ~WDOG_WCR_WT_MASK) | WDOG_WCR_WT(timeoutCount);
  232. }
  233. /*!
  234. * @brief Sets the WDOG interrupt count timeout value.
  235. *
  236. * This function sets the interrupt count timeout value.
  237. * This function writes a value into WIC registers which are wirte-once.
  238. * This field is write once only. Once the software does a write access to this field, it will get locked
  239. * and cannot be reprogrammed until the next system reset assertion.
  240. * @param base WDOG peripheral base address
  241. * @param timeoutCount WDOG timeout value; count of WDOG clock tick.
  242. */
  243. static inline void WDOG_SetInterrputTimeoutValue(WDOG_Type *base, uint16_t timeoutCount)
  244. {
  245. base->WICR = (base->WICR & ~WDOG_WICR_WICT_MASK) | WDOG_WICR_WICT(timeoutCount);
  246. }
  247. /*!
  248. * @brief Disable the WDOG power down enable bit.
  249. *
  250. * This function disable the WDOG power down enable(PDE).
  251. * This function writes a value into WMCR registers which are wirte-once.
  252. * This field is write once only. Once software sets this bit it cannot be reset until the next system reset.
  253. * @param base WDOG peripheral base address
  254. */
  255. static inline void WDOG_DisablePowerDownEnable(WDOG_Type *base)
  256. {
  257. base->WMCR &= ~WDOG_WMCR_PDE_MASK;
  258. }
  259. /*!
  260. * @brief Refreshes the WDOG timer.
  261. *
  262. * This function feeds the WDOG.
  263. * This function should be called before the WDOG timer is in timeout. Otherwise, a reset is asserted.
  264. *
  265. * @param base WDOG peripheral base address
  266. */
  267. void WDOG_Refresh(WDOG_Type *base);
  268. /*@}*/
  269. #if defined(__cplusplus)
  270. }
  271. #endif /* __cplusplus */
  272. /*! @}*/
  273. #endif /* _FSL_WDOG_H_ */