bh_time.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. 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. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "bh_time.h"
  17. /*
  18. * This function returns milliseconds per tick.
  19. * @return milliseconds per tick.
  20. */
  21. uint64 _bh_time_get_tick_millisecond()
  22. {
  23. return k_uptime_get_32();
  24. }
  25. /*
  26. * This function returns milliseconds after boot.
  27. * @return milliseconds after boot.
  28. */
  29. uint64 _bh_time_get_boot_millisecond()
  30. {
  31. return k_uptime_get_32();
  32. }
  33. uint64 _bh_time_get_millisecond_from_1970()
  34. {
  35. return k_uptime_get();
  36. }
  37. size_t _bh_time_strftime(char *str, size_t max, const char *format, int64 time)
  38. {
  39. (void) format;
  40. (void) time;
  41. uint32 t = k_uptime_get_32();
  42. int h, m, s;
  43. t = t % (24 * 60 * 60);
  44. h = t / (60 * 60);
  45. t = t % (60 * 60);
  46. m = t / 60;
  47. s = t % 60;
  48. return snprintf(str, max, "%02d:%02d:%02d", h, m, s);
  49. }