wwdt_8xx.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * @brief LPC8xx WWDT chip driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  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_8XX_H_
  32. #define __WWDT_8XX_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup LPC_WWDT CHIP: LPC8xx Windowed Watchdog driver
  37. * @ingroup CHIP_8XX_Drivers
  38. * @{
  39. */
  40. /*!< WDT oscillator frequency value */
  41. #define WDT_OSC (LPC8XX_IRC_FREQ)
  42. /**
  43. * @brief Windowed Watchdog register block structure
  44. */
  45. typedef struct { /*!< WWDT Structure */
  46. __IO uint32_t MOD; /*!< Watchdog mode register. This register contains the basic mode and status of the Watchdog Timer. */
  47. __IO uint32_t TC; /*!< Watchdog timer constant register. This register determines the time-out value. */
  48. __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. */
  49. __I uint32_t TV; /*!< Watchdog timer value register. This register reads out the current value of the Watchdog timer. */
  50. __I uint32_t RESERVED0;
  51. __IO uint32_t WARNINT; /*!< Watchdog warning interrupt register. This register contains the Watchdog warning interrupt compare value. */
  52. __IO uint32_t WINDOW; /*!< Watchdog timer window register. This register contains the Watchdog window value. */
  53. } LPC_WWDT_T;
  54. /* Reserved bits masks for registers */
  55. #define WWDT_MOD_RESERVED (~0x3f)
  56. #define WWDT_TC_RESERVED 0xff000000
  57. #define WWDT_FEED_RESERVED (~0xff)
  58. #define WWDT_TV_RESERVED 0xff000000
  59. #define WWDT_WARNINT_RESERVED (~0x3ff)
  60. #define WWDT_WINDOW_RESERVED 0xff000000
  61. /**
  62. * @brief Watchdog Mode register definitions
  63. */
  64. /** Watchdog Mode Bitmask */
  65. #define WWDT_WDMOD_BITMASK ((uint32_t) 0x1F)
  66. /** WWDT interrupt enable bit */
  67. #define WWDT_WDMOD_WDEN ((uint32_t) (1 << 0))
  68. /** WWDT interrupt enable bit */
  69. #define WWDT_WDMOD_WDRESET ((uint32_t) (1 << 1))
  70. /** WWDT time out flag bit */
  71. #define WWDT_WDMOD_WDTOF ((uint32_t) (1 << 2))
  72. /** WDT Time Out flag bit */
  73. #define WWDT_WDMOD_WDINT ((uint32_t) (1 << 3))
  74. /**
  75. * @brief Initialize the Watchdog timer
  76. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  77. * @return None
  78. */
  79. void Chip_WWDT_Init(LPC_WWDT_T *pWWDT);
  80. /**
  81. * @brief Shutdown the Watchdog timer
  82. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  83. * @return None
  84. */
  85. void Chip_WWDT_DeInit(LPC_WWDT_T *pWWDT);
  86. /**
  87. * @brief Set WDT timeout constant value used for feed
  88. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  89. * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX
  90. * @return none
  91. */
  92. STATIC INLINE void Chip_WWDT_SetTimeOut(LPC_WWDT_T *pWWDT, uint32_t timeout)
  93. {
  94. pWWDT->TC = timeout;
  95. }
  96. /**
  97. * @brief Feed watchdog timer
  98. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  99. * @return None
  100. * @note If this function isn't called, a watchdog timer warning will occur.
  101. * After the warning, a timeout will occur if a feed has happened.
  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 Set WWDT window time
  122. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  123. * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX
  124. * @return None
  125. * @note The watchdog timer must be fed between the timeout from the Chip_WWDT_SetTimeOut()
  126. * function and this function, with this function defining the last tick before the
  127. * watchdog window interrupt occurs.
  128. */
  129. STATIC INLINE void Chip_WWDT_SetWindow(LPC_WWDT_T *pWWDT, uint32_t timeout)
  130. {
  131. pWWDT->WINDOW = timeout;
  132. }
  133. /**
  134. * @brief Enable watchdog timer options
  135. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  136. * @param options : An or'ed set of options of values
  137. * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT
  138. * @return None
  139. * @note You can enable more than one option at once (ie, WWDT_WDMOD_WDRESET |
  140. * WWDT_WDMOD_WDPROTECT), but use the WWDT_WDMOD_WDEN after all other options
  141. * are set (or unset) with no other options. If WWDT_WDMOD_LOCK is used, it cannot
  142. * be unset.
  143. */
  144. STATIC INLINE void Chip_WWDT_SetOption(LPC_WWDT_T *pWWDT, uint32_t options)
  145. {
  146. pWWDT->MOD = options | (pWWDT->MOD & ~WWDT_MOD_RESERVED);
  147. }
  148. /**
  149. * @brief Disable/clear watchdog timer options
  150. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  151. * @param options : An or'ed set of options of values
  152. * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT
  153. * @return None
  154. * @note You can disable more than one option at once (ie, WWDT_WDMOD_WDRESET |
  155. * WWDT_WDMOD_WDTOF).
  156. */
  157. STATIC INLINE void Chip_WWDT_UnsetOption(LPC_WWDT_T *pWWDT, uint32_t options)
  158. {
  159. pWWDT->MOD &= (~options) & WWDT_WDMOD_BITMASK;
  160. }
  161. /**
  162. * @brief Enable WWDT activity
  163. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  164. * @return None
  165. */
  166. STATIC INLINE void Chip_WWDT_Start(LPC_WWDT_T *pWWDT)
  167. {
  168. Chip_WWDT_SetOption(pWWDT, WWDT_WDMOD_WDEN);
  169. Chip_WWDT_Feed(pWWDT);
  170. }
  171. /**
  172. * @brief Read WWDT status flag
  173. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  174. * @return Watchdog status, an Or'ed value of WWDT_WDMOD_*
  175. */
  176. STATIC INLINE uint32_t Chip_WWDT_GetStatus(LPC_WWDT_T *pWWDT)
  177. {
  178. return pWWDT->MOD;
  179. }
  180. /**
  181. * @brief Clear WWDT interrupt status flags
  182. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  183. * @param status : Or'ed value of status flag(s) that you want to clear, should be:
  184. * - WWDT_WDMOD_WDTOF: Clear watchdog timeout flag
  185. * - WWDT_WDMOD_WDINT: Clear watchdog warning flag
  186. * @return None
  187. */
  188. void Chip_WWDT_ClearStatusFlag(LPC_WWDT_T *pWWDT, uint32_t status);
  189. /**
  190. * @brief Get the current value of WDT
  191. * @param pWWDT : The base of WatchDog Timer peripheral on the chip
  192. * @return current value of WDT
  193. */
  194. STATIC INLINE uint32_t Chip_WWDT_GetCurrentCount(LPC_WWDT_T *pWWDT)
  195. {
  196. return pWWDT->TV;
  197. }
  198. /**
  199. * @}
  200. */
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif /* __WWDT_8XX_H_ */