timer.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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_timer
  31. //! @{
  32. /*!
  33. * @file timer.h
  34. * @brief various defines used by the timer driver.
  35. */
  36. #ifndef __TIMER_H__
  37. #define __TIMER_H__
  38. #include "sdk.h"
  39. ////////////////////////////////////////////////////////////////////////////////
  40. // Constants
  41. ////////////////////////////////////////////////////////////////////////////////
  42. //! @brief Options for low power mode support for the timers.
  43. //!
  44. //! These constants are bit masks that are or'd together to select in which low
  45. //! power modes the timer will continue counting.
  46. enum _timer_low_power_modes
  47. {
  48. WAIT_MODE_EN = 1, //!< Timer is enabled in wait mode.
  49. STOP_MODE_EN = 2 //!< Timer is enabled in stop mode.
  50. };
  51. //! @brief Available clock sources for the timers.
  52. enum _timer_clock_sources
  53. {
  54. CLKSRC_OFF = 0, //!< clock source is OFF
  55. CLKSRC_IPG_CLK = 1, //!< clock source is peripheral clock
  56. CLKSRC_PER_CLK = 2, //!< clock source is high-freq reference clock
  57. CLKSRC_CLKIN = 3, //!< clock source is external from a CLKIN input
  58. CLKSRC_CKIL = 3 //!< clock source is low-freq reference clock
  59. };
  60. //! @brief Do not enable interrupts.
  61. #define POLLING_MODE 0
  62. ////////////////////////////////////////////////////////////////////////////////
  63. // Externs
  64. ////////////////////////////////////////////////////////////////////////////////
  65. extern uint32_t g_system_timer_port;
  66. ////////////////////////////////////////////////////////////////////////////////
  67. // API
  68. ////////////////////////////////////////////////////////////////////////////////
  69. #if defined(__cplusplus)
  70. extern "C" {
  71. #endif
  72. //! @brief Delay for a given number of microseconds.
  73. //!
  74. //! system_time_init() must have been called before using this function.
  75. //!
  76. //! @param usecs Delay in microseconds.
  77. void hal_delay_us(uint32_t usecs);
  78. //! @brief Init system timer facilities.
  79. //!
  80. //! Inits the EPIT timer used for delay, and inits the microsecond counter.
  81. void system_time_init(void);
  82. //! @brief Return the current microsecond counter value.
  83. //!
  84. //! @return The number of microseconds elapsed since system_time_init()
  85. //! was called. This value may roll over before reaching all ones.
  86. uint64_t time_get_microseconds();
  87. #if defined(__cplusplus)
  88. }
  89. #endif
  90. //! @}
  91. #endif // __TIMER_H__
  92. ////////////////////////////////////////////////////////////////////////////////
  93. // EOF
  94. ////////////////////////////////////////////////////////////////////////////////