utils_timer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2012-2019 UCloud. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License").
  5. * You may not use this file except in compliance with the License.
  6. * A copy of the License is located at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. #ifndef C_SDK_UTILS_TIMER_H_
  16. #define C_SDK_UTILS_TIMER_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. // Add the platform specific timer includes to define the Timer struct
  21. #include "uiot_import.h"
  22. /**
  23. * @brief Check if a timer is expired
  24. *
  25. * Call this function passing in a timer to check if that timer has expired.
  26. *
  27. * @param timer - pointer to the timer to be checked for expiration
  28. * @return bool - true = timer expired, false = timer not expired
  29. */
  30. bool has_expired(Timer *timer);
  31. /**
  32. * @brief Create a timer (milliseconds)
  33. *
  34. * Sets the timer to expire in a specified number of milliseconds.
  35. *
  36. * @param timer - pointer to the timer to be set to expire in milliseconds
  37. * @param timeout_ms - set the timer to expire in this number of milliseconds
  38. */
  39. void countdown_ms(Timer *timer, unsigned int timeout_ms);
  40. /**
  41. * @brief Create a timer (seconds)
  42. *
  43. * Sets the timer to expire in a specified number of seconds.
  44. *
  45. * @param timer - pointer to the timer to be set to expire in seconds
  46. * @param timeout - set the timer to expire in this number of seconds
  47. */
  48. void countdown(Timer *timer, unsigned int timeout);
  49. /**
  50. * @brief Check the time remaining on a give timer
  51. *
  52. * Checks the input timer and returns the number of milliseconds remaining on the timer.
  53. *
  54. * @param timer - pointer to the timer to be set to checked
  55. * @return int - milliseconds left on the countdown timer
  56. */
  57. int left_ms(Timer *timer);
  58. /**
  59. * @brief Initialize a timer
  60. *
  61. * Performs any initialization required to the timer passed in.
  62. *
  63. * @param timer - pointer to the timer to be initialized
  64. */
  65. void init_timer(Timer *timer);
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69. #endif //C_SDK_UTILS_TIMER_H_