utils_timer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef QCLOUD_IOT_UTILS_TIMER_H_
  19. #define QCLOUD_IOT_UTILS_TIMER_H_
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. // Add the platform specific timer includes to define the Timer struct
  24. #include "qcloud_iot_import.h"
  25. /**
  26. * @brief Check if a timer is expired
  27. *
  28. * Call this function passing in a timer to check if that timer has expired.
  29. *
  30. * @param timer - pointer to the timer to be checked for expiration
  31. * @return bool - true = timer expired, false = timer not expired
  32. */
  33. bool expired(Timer *timer);
  34. /**
  35. * @brief Create a timer (milliseconds)
  36. *
  37. * Sets the timer to expire in a specified number of milliseconds.
  38. *
  39. * @param timer - pointer to the timer to be set to expire in milliseconds
  40. * @param timeout_ms - set the timer to expire in this number of milliseconds
  41. */
  42. void countdown_ms(Timer *timer, unsigned int timeout_ms);
  43. /**
  44. * @brief Create a timer (seconds)
  45. *
  46. * Sets the timer to expire in a specified number of seconds.
  47. *
  48. * @param timer - pointer to the timer to be set to expire in seconds
  49. * @param timeout - set the timer to expire in this number of seconds
  50. */
  51. void countdown(Timer *timer, unsigned int timeout);
  52. /**
  53. * @brief Check the time remaining on a give timer
  54. *
  55. * Checks the input timer and returns the number of milliseconds remaining on
  56. * the timer.
  57. *
  58. * @param timer - pointer to the timer to be set to checked
  59. * @return int - milliseconds left on the countdown timer
  60. */
  61. int left_ms(Timer *timer);
  62. /**
  63. * @brief Initialize a timer
  64. *
  65. * Performs any initialization required to the timer passed in.
  66. *
  67. * @param timer - pointer to the timer to be initialized
  68. */
  69. void InitTimer(Timer *timer);
  70. #ifdef __cplusplus
  71. }
  72. #endif
  73. #endif // QCLOUD_IOT_UTILS_TIMER_H_