timer.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /******************************************************************************
  2. * @attention
  3. *
  4. * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
  5. *
  6. * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  7. * You may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * http://www.st.com/myliberty
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  15. * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. /*
  22. * PROJECT: ST25R391x firmware
  23. * $Revision: $
  24. * LANGUAGE: ANSI C
  25. */
  26. /*! \file timer.h
  27. *
  28. * \brief SW Timer implementation header file
  29. *
  30. * This module makes use of a System Tick in millisconds and provides
  31. * an abstraction for SW timers
  32. *
  33. */
  34. /*
  35. ******************************************************************************
  36. * INCLUDES
  37. ******************************************************************************
  38. */
  39. #include "platform.h"
  40. /*
  41. ******************************************************************************
  42. * GLOBAL MACROS
  43. ******************************************************************************
  44. */
  45. #define timerIsRunning(t) (!timerIsExpired(t))
  46. /*
  47. ******************************************************************************
  48. * GLOBAL DEFINES
  49. ******************************************************************************
  50. */
  51. /*!
  52. *****************************************************************************
  53. * \brief Calculate Timer
  54. *
  55. * This method calculates when the timer will be expired given the amount
  56. * time in milliseconds /a tOut.
  57. * Once the timer has been calculated it will then be used to check when
  58. * it expires.
  59. *
  60. * \see timersIsExpired
  61. *
  62. * \param[in] time : time/duration in Milliseconds for the timer
  63. *
  64. * \return u32 : The new timer calculated based on the given time
  65. *****************************************************************************
  66. */
  67. uint32_t timerCalculateTimer( uint16_t time );
  68. /*!
  69. *****************************************************************************
  70. * \brief Checks if a Timer is Expired
  71. *
  72. * This method checks if a timer has already expired.
  73. * Based on the given timer previously calculated it checks if this timer
  74. * has already elapsed
  75. *
  76. * \see timersCalculateTimer
  77. *
  78. * \param[in] timer : the timer to check
  79. *
  80. * \return true : timer has already expired
  81. * \return false : timer is still running
  82. *****************************************************************************
  83. */
  84. bool timerIsExpired( uint32_t timer );
  85. /*!
  86. *****************************************************************************
  87. * \brief Performs a Delay
  88. *
  89. * This method performs a delay for the given amount of time in Milliseconds
  90. *
  91. * \param[in] time : time/duration in Milliseconds of the delay
  92. *
  93. *****************************************************************************
  94. */
  95. void timerDelay( uint16_t time );
  96. /*!
  97. *****************************************************************************
  98. * \brief Stopwatch start
  99. *
  100. * This method initiates the stopwatch to later measure the time in ms
  101. *
  102. *****************************************************************************
  103. */
  104. void timerStopwatchStart( void );
  105. /*!
  106. *****************************************************************************
  107. * \brief Stopwatch Measure
  108. *
  109. * This method returns the elapsed time in ms since the stopwatch was initiated
  110. *
  111. * \return The time in ms since the stopwatch was started
  112. *****************************************************************************
  113. */
  114. uint32_t timerStopwatchMeasure( void );