windows_bt_timer_impl.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "base\byteorder.h"
  2. #include "common\timer.h"
  3. #include "host\hci_core.h"
  4. #include <stdio.h>
  5. #include <pthread.h>
  6. #include <windows.h>
  7. // start time.
  8. static ULARGE_INTEGER last_time;
  9. uint32_t timer_get_delay_time_ms(void)
  10. {
  11. FILETIME file_time;
  12. SYSTEMTIME system_time;
  13. ULARGE_INTEGER now_time;
  14. GetSystemTime(&system_time);
  15. SystemTimeToFileTime(&system_time, &file_time);
  16. now_time.LowPart = file_time.dwLowDateTime;
  17. now_time.HighPart = file_time.dwHighDateTime;
  18. uint32_t time_ms = (uint32_t)((now_time.QuadPart - last_time.QuadPart) / 10000);
  19. last_time.LowPart = now_time.LowPart;
  20. last_time.HighPart = now_time.HighPart;
  21. // printf("timer_get_delay_time_ms: %u\n", time_ms);
  22. return time_ms;
  23. }
  24. pthread_t timer_thread;
  25. static int timer_process_loop(void *args)
  26. {
  27. // printk("timer_process_loop\n");
  28. while (1)
  29. {
  30. sys_clock_announce(timer_get_delay_time_ms());
  31. #if defined(CONFIG_BT_MONITOR_SLEEP)
  32. bt_sleep_wakeup_with_timeout();
  33. #endif
  34. Sleep(1);
  35. // if(!is_enable)
  36. // {
  37. // break;
  38. // }
  39. }
  40. return 0;
  41. }
  42. void bt_timer_impl_local_init(void)
  43. {
  44. FILETIME file_time;
  45. SYSTEMTIME system_time;
  46. GetSystemTime(&system_time);
  47. SystemTimeToFileTime(&system_time, &file_time);
  48. last_time.LowPart = file_time.dwLowDateTime;
  49. last_time.HighPart = file_time.dwHighDateTime;
  50. pthread_create(&timer_thread, NULL, (void *)timer_process_loop, NULL);
  51. sys_clock_announce(0);
  52. }