epit.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (c) 2011-2012, Freescale Semiconductor, Inc.
  3. * All rights reserved.
  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 Freescale Semiconductor, Inc. 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. //! @addtogroup diag_epit
  31. //! @{
  32. /*!
  33. * @file epit.h
  34. * @brief EPIT driver public interface.
  35. */
  36. #ifndef __EPIT_H__
  37. #define __EPIT_H__
  38. #include "imx_timer.h"
  39. #include "sdk.h"
  40. ////////////////////////////////////////////////////////////////////////////////
  41. // Definitions
  42. ////////////////////////////////////////////////////////////////////////////////
  43. //! @brief Free running reload mode.
  44. //!
  45. //! When the counter reaches zero it rolls over to 0xFFFF_FFFF.
  46. #define FREE_RUNNING 0
  47. //! @brief Set and forget reload mode.
  48. //!
  49. //! When the counter reaches zero it reloads from the modulus register.
  50. #define SET_AND_FORGET 1
  51. //! @brief Pass to epit_counter_enable() to enable interrupts.
  52. #define IRQ_MODE 1
  53. //! @brief Get the irq id of RPIT by instance number.
  54. //! @param x I2C instance number, from 1 through 2.
  55. #define EPIT_IRQS(x) ( (x) == HW_EPIT1 ? IMX_INT_EPIT1 : (x) == HW_EPIT2 ? IMX_INT_EPIT2 : 0xFFFFFFFF)
  56. ////////////////////////////////////////////////////////////////////////////////
  57. // API
  58. ////////////////////////////////////////////////////////////////////////////////
  59. #if defined(__cplusplus)
  60. extern "C" {
  61. #endif
  62. /*!
  63. * @brief Initialize the EPIT timer.
  64. *
  65. * @param instance the EPIT instance number.
  66. * @param clock_src Source clock of the counter: CLKSRC_OFF, CLKSRC_IPG_CLK,
  67. * CLKSRC_PER_CLK, CLKSRC_CKIL.
  68. * @param prescaler Prescaler of source clock from 1 to 4096.
  69. * @param reload_mode Counter reload mode: FREE_RUNNING or SET_AND_FORGET.
  70. * @param load_val Load value from where the counter start.
  71. * @param low_power_mode Low power during which the timer is enabled:
  72. * WAIT_MODE_EN and/or STOP_MODE_EN.
  73. */
  74. void epit_init(uint32_t instance, uint32_t clock_src, uint32_t prescaler,
  75. uint32_t reload_mode, uint32_t load_val, uint32_t low_power_mode);
  76. /*!
  77. * @brief Setup EPIT interrupt.
  78. *
  79. * It enables or disables the related HW module interrupt, and attached the related sub-routine
  80. * into the vector table.
  81. *
  82. * @param instance the EPIT instance number.
  83. * @param irq_subroutine the EPIT interrupt interrupt routine.
  84. * @param enableIt True to enable the interrupt, false to disable.
  85. */
  86. void epit_setup_interrupt(uint32_t instance, void (*irq_subroutine)(void), bool enableIt);
  87. /*!
  88. * @brief Enable the EPIT module.
  89. *
  90. * Used typically when the epit_init is done, and other interrupt related settings are ready.
  91. *
  92. * In interrupt mode, when the interrupt fires you should call epit_get_compare_event() to
  93. * clear the compare flag.
  94. *
  95. * @param instance the EPIT instance number.
  96. * @param load_val Load value from where the counter starts.
  97. * @param irq_mode Interrupt mode: IRQ_MODE or POLLING_MODE.
  98. */
  99. void epit_counter_enable(uint32_t instance, uint32_t load_val, uint32_t irq_mode);
  100. /*!
  101. * @brief Disable the counter.
  102. *
  103. * It saves energy when not used.
  104. *
  105. * @param instance the EPIT instance number.
  106. */
  107. void epit_counter_disable(uint32_t instance);
  108. /*!
  109. * @brief Get the output compare status flag and clear it if set.
  110. *
  111. * This function can typically be used for polling method, but
  112. * is also used to clear the status compare flag in IRQ mode.
  113. *
  114. * @param instance the EPIT instance number.
  115. * @return Value of the compare event flag.
  116. */
  117. uint32_t epit_get_compare_event(uint32_t instance);
  118. /*!
  119. * @brief Set the output compare register.
  120. *
  121. *
  122. * @param instance the EPIT instance number.
  123. * @param Value of the compare register.
  124. */
  125. void epit_set_compare_event(uint32_t instance, uint32_t compare_val);
  126. /*!
  127. * @brief Get the counter value.
  128. *
  129. *
  130. * @param instance the EPIT instance number.
  131. * @return Value of the counter register.
  132. */
  133. uint32_t epit_get_counter_value(uint32_t instance);
  134. /*!
  135. * @brief Reload the counter with a known value.
  136. *
  137. * @param instance the EPIT instance number.
  138. * @param load_val Value loaded into the timer counter.
  139. */
  140. void epit_reload_counter(uint32_t instance, uint32_t load_val);
  141. #if defined(__cplusplus)
  142. }
  143. #endif
  144. //! @}
  145. #endif //__EPIT_H__
  146. ////////////////////////////////////////////////////////////////////////////////
  147. // EOF
  148. ////////////////////////////////////////////////////////////////////////////////