wwdt_5410x.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * @brief LPC5410X WWDT chip driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __WWDT_5410X_H_
  32. #define __WWDT_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup LPC_WWDT CHIP: LPC5410X Windowed Watchdog driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /**
  41. * @brief Windowed Watchdog register block structure
  42. */
  43. typedef struct { /*!< WWDT Structure */
  44. __IO uint32_t MOD; /*!< Watchdog mode register. This register contains the basic mode and status of the Watchdog Timer. */
  45. __IO uint32_t TC; /*!< Watchdog timer constant register. This register determines the time-out value. */
  46. __O uint32_t FEED; /*!< Watchdog feed sequence register. Writing 0xAA followed by 0x55 to this register reloads the Watchdog timer with the value contained in WDTC. */
  47. __I uint32_t TV; /*!< Watchdog timer value register. This register reads out the current value of the Watchdog timer. */
  48. __I uint32_t RESERVED0;
  49. __IO uint32_t WARNINT; /*!< Watchdog warning interrupt register. This register contains the Watchdog warning interrupt compare value. */
  50. __IO uint32_t WINDOW; /*!< Watchdog timer window register. This register contains the Watchdog window value. */
  51. } LPC_WWDT_T;
  52. /**
  53. * @brief Watchdog Mode register definitions
  54. */
  55. /** Watchdog Mode Bitmask */
  56. #define WWDT_WDMOD_BITMASK ((uint32_t) 0x3F)
  57. /** WWDT enable bit */
  58. #define WWDT_WDMOD_WDEN ((uint32_t) (1 << 0))
  59. /** WWDT reset enable bit */
  60. #define WWDT_WDMOD_WDRESET ((uint32_t) (1 << 1))
  61. /** WWDT time-out flag bit */
  62. #define WWDT_WDMOD_WDTOF ((uint32_t) (1 << 2))
  63. /** WWDT warning interrupt flag bit */
  64. #define WWDT_WDMOD_WDINT ((uint32_t) (1 << 3))
  65. /** WWDT Protect flag bit */
  66. #define WWDT_WDMOD_WDPROTECT ((uint32_t) (1 << 4))
  67. /** WWDT lock bit */
  68. #define WWDT_WDMOD_LOCK ((uint32_t) (1 << 5))
  69. /**
  70. * @brief Initialize the Watchdog timer
  71. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  72. * @return None
  73. */
  74. void Chip_WWDT_Init(LPC_WWDT_T *pWWDT);
  75. /**
  76. * @brief Shutdown the Watchdog timer
  77. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  78. * @return None
  79. */
  80. STATIC INLINE void Chip_WWDT_DeInit(LPC_WWDT_T *pWWDT)
  81. {
  82. Chip_Clock_DisablePeriphClock(SYSCON_CLOCK_WWDT);
  83. }
  84. /**
  85. * @brief Set WDT timeout constant value used for feed
  86. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  87. * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX
  88. * @return none
  89. */
  90. STATIC INLINE void Chip_WWDT_SetTimeOut(LPC_WWDT_T *pWWDT, uint32_t timeout)
  91. {
  92. pWWDT->TC = timeout;
  93. }
  94. /**
  95. * @brief Feed watchdog timer
  96. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  97. * @return None
  98. * @note If this function isn't called, a watchdog timer warning will occur.
  99. * After the warning, a timeout will occur if a feed has happened.
  100. * Note that if WWDT registers are modified in an interrupt then it is a good
  101. * idea to prevent those interrupts when writing the feed sequence.
  102. */
  103. STATIC INLINE void Chip_WWDT_Feed(LPC_WWDT_T *pWWDT)
  104. {
  105. pWWDT->FEED = 0xAA;
  106. pWWDT->FEED = 0x55;
  107. }
  108. /**
  109. * @brief Set WWDT warning interrupt
  110. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  111. * @param timeout : WDT warning in ticks, between 0 and 1023
  112. * @return None
  113. * @note This is the number of ticks after the watchdog interrupt that the
  114. * warning interrupt will be generated.
  115. */
  116. STATIC INLINE void Chip_WWDT_SetWarning(LPC_WWDT_T *pWWDT, uint32_t timeout)
  117. {
  118. pWWDT->WARNINT = timeout;
  119. }
  120. /**
  121. * @brief Get WWDT warning interrupt
  122. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  123. * @return WWDT warning interrupt
  124. */
  125. STATIC INLINE uint32_t Chip_WWDT_GetWarning(LPC_WWDT_T *pWWDT)
  126. {
  127. return pWWDT->WARNINT;
  128. }
  129. /**
  130. * @brief Set WWDT window time
  131. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  132. * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX
  133. * @return None
  134. * @note The watchdog timer must be fed between the timeout from the Chip_WWDT_SetTimeOut()
  135. * function and this function, with this function defining the last tick before the
  136. * watchdog window interrupt occurs.
  137. */
  138. STATIC INLINE void Chip_WWDT_SetWindow(LPC_WWDT_T *pWWDT, uint32_t timeout)
  139. {
  140. pWWDT->WINDOW = timeout;
  141. }
  142. /**
  143. * @brief Get WWDT window time
  144. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  145. * @return WWDT window time
  146. */
  147. STATIC INLINE uint32_t Chip_WWDT_GetWindow(LPC_WWDT_T *pWWDT)
  148. {
  149. return pWWDT->WINDOW;
  150. }
  151. /**
  152. * @brief Enable watchdog timer options
  153. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  154. * @param options : An or'ed set of options of values
  155. * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT
  156. * @return None
  157. * @note You can enable more than one option at once (ie, WWDT_WDMOD_WDRESET |
  158. * WWDT_WDMOD_WDPROTECT), but use the WWDT_WDMOD_WDEN after all other options
  159. * are set (or unset) with no other options. If WWDT_WDMOD_LOCK is used, it cannot
  160. * be unset.
  161. */
  162. STATIC INLINE void Chip_WWDT_SetOption(LPC_WWDT_T *pWWDT, uint32_t options)
  163. {
  164. pWWDT->MOD = (pWWDT->MOD & WWDT_WDMOD_BITMASK) | options;
  165. }
  166. /**
  167. * @brief Disable/clear watchdog timer options
  168. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  169. * @param options : An or'ed set of options of values
  170. * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT
  171. * @return None
  172. * @note You can disable more than one option at once (ie, WWDT_WDMOD_WDRESET |
  173. * WWDT_WDMOD_WDTOF).
  174. */
  175. STATIC INLINE void Chip_WWDT_UnsetOption(LPC_WWDT_T *pWWDT, uint32_t options)
  176. {
  177. pWWDT->MOD &= (~options) & WWDT_WDMOD_BITMASK;
  178. }
  179. /**
  180. * @brief Enable WWDT activity
  181. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  182. * @return None
  183. */
  184. STATIC INLINE void Chip_WWDT_Start(LPC_WWDT_T *pWWDT)
  185. {
  186. Chip_WWDT_SetOption(pWWDT, WWDT_WDMOD_WDEN);
  187. Chip_WWDT_Feed(pWWDT);
  188. }
  189. /**
  190. * @brief Read WWDT status flag
  191. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  192. * @return Watchdog status, an Or'ed value of WWDT_WDMOD_*
  193. */
  194. STATIC INLINE uint32_t Chip_WWDT_GetStatus(LPC_WWDT_T *pWWDT)
  195. {
  196. return pWWDT->MOD;
  197. }
  198. /**
  199. * @brief Clear WWDT interrupt status flags
  200. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  201. * @param status : Or'ed value of status flag(s) that you want to clear, should be:
  202. * - WWDT_WDMOD_WDTOF: Clear watchdog timeout flag
  203. * - WWDT_WDMOD_WDINT: Clear watchdog warning flag
  204. * @return None
  205. */
  206. void Chip_WWDT_ClearStatusFlag(LPC_WWDT_T *pWWDT, uint32_t status);
  207. /**
  208. * @brief Get the current value of WDT
  209. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  210. * @return current value of WDT
  211. */
  212. STATIC INLINE uint32_t Chip_WWDT_GetCurrentCount(LPC_WWDT_T *pWWDT)
  213. {
  214. return pWWDT->TV;
  215. }
  216. /**
  217. * @}
  218. */
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222. #endif /* __WWDT_5410X_H_ */