fsl_wdog.h 10 KB

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