ritimer_5410x.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * @brief LPC5410x RITimer 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 __RITIMER_5410X_H_
  32. #define __RITIMER_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup RITIMER_5410X CHIP: LPC5410x Repetitive Interrupt Timer driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /**
  41. * @brief Repetitive Interrupt Timer register block structure
  42. */
  43. typedef struct { /*!< RITIMER Structure */
  44. __IO uint32_t COMPVAL; /*!< Compare register */
  45. __IO uint32_t MASK; /*!< Mask register */
  46. __IO uint32_t CTRL; /*!< Control register */
  47. __IO uint32_t COUNTER; /*!< 32-bit counter */
  48. __IO uint32_t COMPVAL_H; /*!< Compare register, upper 16-bits */
  49. __IO uint32_t MASK_H; /*!< Compare register, upper 16-bits */
  50. __I uint32_t reserved;
  51. __IO uint32_t COUNTER_H; /*!< Counter register, upper 16-bits */
  52. } LPC_RITIMER_T;
  53. /*
  54. * @brief RITIMER register support bitfields and mask
  55. */
  56. /*
  57. * RIT control register
  58. */
  59. /** Set by H/W when the counter value equals the masked compare value */
  60. #define RIT_CTRL_INT ((uint32_t) (1))
  61. /** Set timer enable clear to 0 when the counter value equals the masked compare value */
  62. #define RIT_CTRL_ENCLR ((uint32_t) _BIT(1))
  63. /** Set timer enable on debug */
  64. #define RIT_CTRL_ENBR ((uint32_t) _BIT(2))
  65. /** Set timer enable */
  66. #define RIT_CTRL_TEN ((uint32_t) _BIT(3))
  67. /**
  68. * @brief Initialize the RIT
  69. * @param pRITimer : RITimer peripheral selected
  70. * @return None
  71. */
  72. void Chip_RIT_Init(LPC_RITIMER_T *pRITimer);
  73. /**
  74. * @brief Shutdown the RIT
  75. * @param pRITimer : RITimer peripheral selected
  76. * @return None
  77. */
  78. void Chip_RIT_DeInit(LPC_RITIMER_T *pRITimer);
  79. /**
  80. * @brief Enable Timer
  81. * @param pRITimer : RITimer peripheral selected
  82. * @return None
  83. */
  84. STATIC INLINE void Chip_RIT_Enable(LPC_RITIMER_T *pRITimer)
  85. {
  86. pRITimer->CTRL |= RIT_CTRL_TEN;
  87. }
  88. /**
  89. * @brief Disable Timer
  90. * @param pRITimer : RITimer peripheral selected
  91. * @return None
  92. */
  93. STATIC INLINE void Chip_RIT_Disable(LPC_RITIMER_T *pRITimer)
  94. {
  95. pRITimer->CTRL &= ~RIT_CTRL_TEN;
  96. }
  97. /**
  98. * @brief Enable timer debug
  99. * @param pRITimer : RITimer peripheral selected
  100. * @return None
  101. */
  102. STATIC INLINE void Chip_RIT_DebugEnable(LPC_RITIMER_T *pRITimer)
  103. {
  104. pRITimer->CTRL |= RIT_CTRL_ENBR;
  105. }
  106. /**
  107. * @brief Disable timer debug
  108. * @param pRITimer : RITimer peripheral selected
  109. * @return None
  110. */
  111. STATIC INLINE void Chip_RIT_DebugDisable(LPC_RITIMER_T *pRITimer)
  112. {
  113. pRITimer->CTRL &= ~RIT_CTRL_ENBR;
  114. }
  115. /**
  116. * @brief Enable clear on compare match
  117. * @param pRITimer : RITimer peripheral selected
  118. * @return None
  119. */
  120. STATIC INLINE void Chip_RIT_CompClearEnable(LPC_RITIMER_T *pRITimer)
  121. {
  122. pRITimer->CTRL |= RIT_CTRL_ENCLR;
  123. }
  124. /**
  125. * @brief Disable clear on compare match
  126. * @param pRITimer : RITimer peripheral selected
  127. * @return None
  128. */
  129. STATIC INLINE void Chip_RIT_CompClearDisable(LPC_RITIMER_T *pRITimer)
  130. {
  131. pRITimer->CTRL &= ~RIT_CTRL_ENCLR;
  132. }
  133. /**
  134. * @brief Check whether interrupt flag is set or not
  135. * @param pRITimer : RITimer peripheral selected
  136. * @return Current interrupt status, either ET or UNSET
  137. */
  138. IntStatus Chip_RIT_GetIntStatus(LPC_RITIMER_T *pRITimer);
  139. /**
  140. * @brief Set a tick value for the interrupt to time out
  141. * @param pRITimer : RITimer peripheral selected
  142. * @param val : value (in ticks) of the interrupt to be set
  143. * @return None
  144. */
  145. STATIC INLINE void Chip_RIT_SetCOMPVAL(LPC_RITIMER_T *pRITimer, uint32_t val)
  146. {
  147. pRITimer->COMPVAL = val;
  148. pRITimer->COMPVAL_H = 0;
  149. }
  150. /**
  151. * @brief Set a tick value for the interrupt to time out (48-bits)
  152. * @param pRITimer : RITimer peripheral selected
  153. * @param val : value (in ticks) of the interrupt to be set, 48-bits max
  154. * @return None
  155. */
  156. STATIC INLINE void Chip_RIT_SetCOMPVAL64(LPC_RITIMER_T *pRITimer, uint64_t val)
  157. {
  158. pRITimer->COMPVAL = (uint32_t) (val & 0xFFFFFFFF);
  159. pRITimer->COMPVAL_H = (uint32_t) ((val >> 32) & 0xFFFF);
  160. }
  161. /**
  162. * @brief Enables or clears the RIT or interrupt
  163. * @param pRITimer : RITimer peripheral selected
  164. * @param val : RIT to be set, one or more RIT_CTRL_* values
  165. * @return None
  166. */
  167. STATIC INLINE void Chip_RIT_EnableCTRL(LPC_RITIMER_T *pRITimer, uint32_t val)
  168. {
  169. pRITimer->CTRL |= val;
  170. }
  171. /**
  172. * @brief Clears the RIT interrupt
  173. * @param pRITimer : RITimer peripheral selected
  174. * @return None
  175. */
  176. STATIC INLINE void Chip_RIT_ClearInt(LPC_RITIMER_T *pRITimer)
  177. {
  178. pRITimer->CTRL |= RIT_CTRL_INT;
  179. }
  180. /**
  181. * @brief Returns the current RIT Counter value
  182. * @param pRITimer : RITimer peripheral selected
  183. * @return the current timer counter value
  184. */
  185. STATIC INLINE uint32_t Chip_RIT_GetCounter(LPC_RITIMER_T *pRITimer)
  186. {
  187. return pRITimer->COUNTER;
  188. }
  189. /**
  190. * @brief Returns the current RIT Counter value (48-bit)
  191. * @param pRITimer : RITimer peripheral selected
  192. * @return the current timer counter value
  193. */
  194. STATIC INLINE uint64_t Chip_RIT_GetCounter64(LPC_RITIMER_T *pRITimer)
  195. {
  196. uint64_t retVal;
  197. retVal = (uint64_t) pRITimer->COUNTER;
  198. retVal = retVal | (((uint64_t) pRITimer->COUNTER_H) << 32);
  199. return retVal;
  200. }
  201. /**
  202. * @brief Set timer interval value
  203. * @param pRITimer : RITimer peripheral selected
  204. * @param time_interval : timer interval value (ms)
  205. * @return None
  206. */
  207. void Chip_RIT_SetTimerInterval(LPC_RITIMER_T *pRITimer, uint32_t time_interval);
  208. /**
  209. * @brief Set timer interval value (48-bit)
  210. * @param pRITimer : RITimer peripheral selected
  211. * @param time_interval : timer interval value (ms)
  212. * @return None
  213. */
  214. void Chip_RIT_SetTimerInterval64(LPC_RITIMER_T *pRITimer, uint64_t time_interval);
  215. /**
  216. * @}
  217. */
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. #endif /* __RITIMER_5410X_H_ */