tmr_utils.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * @file tmr_utils.h
  3. * @brief Timer utility function declarations
  4. */
  5. /* *****************************************************************************
  6. * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  21. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
  22. * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  24. * OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. * Except as contained in this notice, the name of Maxim Integrated
  27. * Products, Inc. shall not be used except as stated in the Maxim Integrated
  28. * Products, Inc. Branding Policy.
  29. *
  30. * The mere transfer of this software does not imply any licenses
  31. * of trade secrets, proprietary technology, copyrights, patents,
  32. * trademarks, maskwork rights, or any other form of intellectual
  33. * property whatsoever. Maxim Integrated Products, Inc. retains all
  34. * ownership rights.
  35. *
  36. * $Date: 2018-10-17 14:16:30 -0500 (Wed, 17 Oct 2018) $
  37. * $Revision: 38560 $
  38. *
  39. **************************************************************************** */
  40. /* Define to prevent redundant inclusion */
  41. #ifndef _TMR_UTILS_H
  42. #define _TMR_UTILS_H
  43. /***** Includes *****/
  44. #include "mxc_config.h"
  45. #include "tmr_regs.h"
  46. #include "mxc_sys.h"
  47. #ifdef __cplusplus
  48. extern "C" {
  49. #endif
  50. /**
  51. * @ingroup tmr
  52. * @defgroup tmr_utils Timer Utility Functions
  53. * @{
  54. */
  55. /* **** Definitions **** */
  56. /** @def Macro to convert the parameter \p s from seconds to micro-seconds. */
  57. #define SEC(s) (((unsigned long)s) * 1000000UL)
  58. /** @def Macro to convert the parameter \p ms from milli-seconds to micro-seconds. */
  59. #define MSEC(ms) (ms * 1000UL)
  60. /** @def Macro to convert the parameter \p us to micro-seconds. */
  61. #define USEC(us) (us)
  62. /* **** Globals **** */
  63. /* **** Function Prototypes **** */
  64. /**
  65. * @brief Delays for the specified number of microseconds.
  66. * @param tmr Which Timer instance to use
  67. * @param us Number of microseconds to delay.
  68. * @param sys_cfg System configuration object, identical to TMR_Init()
  69. */
  70. void TMR_Delay(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
  71. /**
  72. * @brief Start the timeout time for the specified number of microseconds.
  73. * @param tmr Which Timer instance to use
  74. * @param us Number of microseconds in the timeout.
  75. * @param sys_cfg System configuration object, identical to TMR_Init()
  76. */
  77. void TMR_TO_Start(mxc_tmr_regs_t *tmr, unsigned long us, const sys_cfg_tmr_t *sys_cfg);
  78. /**
  79. * @brief Check if the timeout has occurred.
  80. * @param tmr Which Timer instance to use
  81. * @return #E_NO_ERROR if the timeout has not occurred, #E_TIME_OUT if it has.
  82. */
  83. int TMR_TO_Check(mxc_tmr_regs_t *tmr);
  84. /**
  85. * @brief Stops the timer for the timeout.
  86. * @param tmr Which Timer instance to use
  87. */
  88. void TMR_TO_Stop(mxc_tmr_regs_t *tmr);
  89. /**
  90. * @brief Clears the timeout flag.
  91. * @param tmr Which Timer instance to use
  92. */
  93. void TMR_TO_Clear(mxc_tmr_regs_t *tmr);
  94. /**
  95. * @brief Get the number of microseconds elapsed since TMR_TO_Start().
  96. * @param tmr Which Timer instance to use
  97. * @return Number of microseconds since TMR_TO_Start().
  98. */
  99. unsigned int TMR_TO_Elapsed(mxc_tmr_regs_t *tmr);
  100. /**
  101. * @brief Get the number of microseconds remaining in the timeout.
  102. * @param tmr Which Timer instance to use
  103. * @return Number of microseconds until timeout.
  104. */
  105. unsigned int TMR_TO_Remaining(mxc_tmr_regs_t *tmr);
  106. /**
  107. * @brief Start the stopwatch.
  108. * @note This function does not handle overflows
  109. * @param tmr Which Timer to use
  110. * @param sys_cfg System configuration object, identical to TMR_Init()
  111. */
  112. void TMR_SW_Start(mxc_tmr_regs_t *tmr, const sys_cfg_tmr_t *sys_cfg);
  113. /**
  114. * @brief Stop the stopwatch and return the number of microseconds that
  115. * have elapsed.
  116. * @note This function does not handle overflows
  117. * @param tmr Which Timer instance to use
  118. * @return Number of microseconds since TMR_SW_Start().
  119. */
  120. unsigned int TMR_SW_Stop(mxc_tmr_regs_t *tmr);
  121. /**@} end of defgroup tmr_utils*/
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif /* _TMR_UTILS_H */