fsl_rit.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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_RIT_H_
  31. #define _FSL_RIT_H_
  32. #include "fsl_common.h"
  33. /*!
  34. * @addtogroup rit
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @name Driver version */
  41. /*@{*/
  42. #define FSL_RIT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
  43. /*@}*/
  44. /*! @brief List of RIT status flags */
  45. typedef enum _rit_status_flags
  46. {
  47. kRIT_TimerFlag = RIT_CTRL_RITINT_MASK, /*!< Timer flag */
  48. } rit_status_flags_t;
  49. /*!
  50. * @brief RIT config structure
  51. *
  52. * This structure holds the configuration settings for the RIT peripheral. To initialize this
  53. * structure to reasonable defaults, call the RIT_GetDefaultConfig() function and pass a
  54. * pointer to your config structure instance.
  55. *
  56. * The config struct can be made const so it resides in flash
  57. */
  58. typedef struct _rit_config
  59. {
  60. bool enableRunInDebug; /*!< true: The timer is halted when the processor is halted for debugging.; false: Debug has
  61. no effect on the timer operation. */
  62. } rit_config_t;
  63. /*******************************************************************************
  64. * API
  65. ******************************************************************************/
  66. #if defined(__cplusplus)
  67. extern "C" {
  68. #endif
  69. /*!
  70. * @name Initialization and deinitialization
  71. * @{
  72. */
  73. /*!
  74. * @brief Ungates the RIT clock, enables the RIT module, and configures the peripheral for basic operations.
  75. *
  76. * @note This API should be called at the beginning of the application using the RIT driver.
  77. *
  78. * @param base RIT peripheral base address
  79. * @param config Pointer to the user's RIT config structure
  80. */
  81. void RIT_Init(RIT_Type *base, const rit_config_t *config);
  82. /*!
  83. * @brief Gates the RIT clock and disables the RIT module.
  84. *
  85. * @param base RIT peripheral base address
  86. */
  87. void RIT_Deinit(RIT_Type *base);
  88. /*!
  89. * @brief Fills in the RIT configuration structure with the default settings.
  90. *
  91. * The default values are as follows.
  92. * @code
  93. * config->enableRunInDebug = false;
  94. * @endcode
  95. * @param config Pointer to the onfiguration structure.
  96. */
  97. void RIT_GetDefaultConfig(rit_config_t *config);
  98. /*! @}*/
  99. /*!
  100. * @name Status Interface
  101. * @{
  102. */
  103. /*!
  104. * @brief Gets the RIT status flags.
  105. *
  106. * @param base RIT peripheral base address
  107. *
  108. * @return The status flags. This is the logical OR of members of the
  109. * enumeration ::rit_status_flags_t
  110. */
  111. static inline uint32_t RIT_GetStatusFlags(RIT_Type *base)
  112. {
  113. return (base->CTRL);
  114. }
  115. /*!
  116. * @brief Clears the RIT status flags.
  117. *
  118. * @param base RIT peripheral base address
  119. * @param mask The status flags to clear. This is a logical OR of members of the
  120. * enumeration ::rit_status_flags_t
  121. */
  122. static inline void RIT_ClearStatusFlags(RIT_Type *base, uint32_t mask)
  123. {
  124. base->CTRL |= mask;
  125. }
  126. /*! @}*/
  127. /*!
  128. * @name Read and Write the timer period
  129. * @{
  130. */
  131. /*!
  132. * @brief Sets the timer period in units of count.
  133. *
  134. * Timers begin counting from the value set by this function until it XXXXXXX,
  135. * then it counting the value again.
  136. * Software must stop the counter before reloading it with a new value..
  137. *
  138. * @note Users can call the utility macros provided in fsl_common.h to convert to ticks
  139. *
  140. * @param base RIT peripheral base address
  141. * @param count Timer period in units of ticks
  142. */
  143. void RIT_SetTimerCompare(RIT_Type *base, uint64_t count);
  144. /*!
  145. * @brief Sets the mask bit of count compare.
  146. *
  147. * Timers begin counting from the value set by this function until it XXXXXXX,
  148. * then it counting the value again.
  149. * Software must stop the counter before reloading it with a new value..
  150. *
  151. * @note Users can call the utility macros provided in fsl_common.h to convert to ticks
  152. *
  153. * @param base RIT peripheral base address
  154. * @param count Timer period in units of ticks
  155. */
  156. void RIT_SetMaskBit(RIT_Type *base, uint64_t count);
  157. /*!
  158. * @brief Reads the current timer counting value of compare register.
  159. *
  160. * This function returns the real-time timer counting value, in a range from 0 to a
  161. * timer period.
  162. *
  163. * @note Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
  164. *
  165. * @param base RIT peripheral base address
  166. *
  167. * @return Current timer counting value in ticks
  168. */
  169. uint64_t RIT_GetCompareTimerCount(RIT_Type *base);
  170. /*!
  171. * @brief Reads the current timer counting value of counter register.
  172. *
  173. * This function returns the real-time timer counting value, in a range from 0 to a
  174. * timer period.
  175. *
  176. * @note Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
  177. *
  178. * @param base RIT peripheral base address
  179. *
  180. * @return Current timer counting value in ticks
  181. */
  182. uint64_t RIT_GetCounterTimerCount(RIT_Type *base);
  183. /*!
  184. * @brief Reads the current timer counting value of mask register.
  185. *
  186. * This function returns the real-time timer counting value, in a range from 0 to a
  187. * timer period.
  188. *
  189. * @note Users can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
  190. *
  191. * @param base RIT peripheral base address
  192. *
  193. * @return Current timer counting value in ticks
  194. */
  195. uint64_t RIT_GetMaskTimerCount(RIT_Type *base);
  196. /*! @}*/
  197. /*!
  198. * @name Timer Start and Stop
  199. * @{
  200. */
  201. /*!
  202. * @brief Starts the timer counting.
  203. *
  204. * After calling this function, timers load initial value(0U), count up to desired value or over-flow
  205. * then the counter will count up again. Each time a timer reaches desired value,
  206. * it generates a XXXXXXX and sets XXXXXXX.
  207. *
  208. * @param base RIT peripheral base address
  209. */
  210. static inline void RIT_StartTimer(RIT_Type *base)
  211. {
  212. base->CTRL |= RIT_CTRL_RITEN_MASK;
  213. }
  214. /*!
  215. * @brief Stops the timer counting.
  216. *
  217. * This function stop timer counting. Timer reload their new value
  218. * after the next time they call the RIT_StartTimer.
  219. *
  220. * @param base RIT peripheral base address
  221. * @param channel Timer channel number.
  222. */
  223. static inline void RIT_StopTimer(RIT_Type *base)
  224. {
  225. /* Disable RIT timers */
  226. base->CTRL &= ~RIT_CTRL_RITEN_MASK;
  227. }
  228. /*! @}*/
  229. static inline void RIT_ClearCounter(RIT_Type *base, bool enable)
  230. {
  231. if (enable)
  232. {
  233. base->CTRL |= RIT_CTRL_RITENCLR_MASK;
  234. }
  235. else
  236. {
  237. base->CTRL &= ~RIT_CTRL_RITENCLR_MASK;
  238. }
  239. }
  240. #if defined(__cplusplus)
  241. }
  242. #endif
  243. /*! @}*/
  244. #endif /* _FSL_RIT_H_ */