HAL_Timer_rtthread.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "uiot_import.h"
  19. #include <rtthread.h>
  20. bool HAL_Timer_Expired(Timer *timer) {
  21. rt_tick_t now;
  22. now = rt_tick_get();
  23. return timer->end_time < now;
  24. }
  25. void HAL_Timer_Countdown_ms(_IN_ Timer *timer, unsigned int timeout_ms) {
  26. rt_tick_t now;
  27. now = rt_tick_get();
  28. timer->end_time = now + rt_tick_from_millisecond(timeout_ms);
  29. }
  30. void HAL_Timer_Countdown(_IN_ Timer *timer, unsigned int timeout) {
  31. rt_tick_t now;
  32. now = rt_tick_get();
  33. timer->end_time = now + rt_tick_from_millisecond(timeout * 1000);
  34. }
  35. uint32_t HAL_Timer_Remain_ms(Timer *timer) {
  36. rt_tick_t now;
  37. now = rt_tick_get();
  38. rt_tick_t result = timer->end_time - now;
  39. return result;
  40. }
  41. void HAL_Timer_Init(Timer *timer) {
  42. timer->end_time = (rt_tick_t)0;
  43. }
  44. #ifdef __cplusplus
  45. }
  46. #endif