timer.h 4.0 KB

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