main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include <stdarg.h>
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include <windows.h>
  5. #include "windows_driver_serial.h"
  6. #include "chipset_interface.h"
  7. #include "platform_interface.h"
  8. #include "base/types.h"
  9. #include "utils/spool.h"
  10. #include <logging/bt_log_impl.h>
  11. #include <drivers/hci_driver.h>
  12. #include "host/hci_core.h"
  13. #include <bluetooth/bluetooth.h>
  14. #include <bluetooth/hci.h>
  15. extern void bt_ready(int err);
  16. extern void app_polling_work(void);
  17. int open_hci_driver(int argc, const char *argv[])
  18. {
  19. bt_uart_interface_t *p_interface = NULL;
  20. uint8_t com_num;
  21. // accept config from command line
  22. if (argc > 1)
  23. {
  24. // COM number
  25. com_num = strtol(argv[1], NULL, 0);
  26. bt_uart_interface_t tmp = {0, 0, 0, 0, 0};
  27. if (argc == 2)
  28. {
  29. }
  30. else if (argc == 7)
  31. {
  32. tmp.rate = strtol(argv[2], NULL, 0);
  33. tmp.databits = strtol(argv[3], NULL, 0);
  34. tmp.stopbits = strtol(argv[4], NULL, 0);
  35. tmp.parity = strtol(argv[5], NULL, 0);
  36. tmp.flowcontrol = strtol(argv[6], NULL, 0);
  37. p_interface = &tmp;
  38. }
  39. else
  40. {
  41. printk("Error, input params length error.");
  42. return -1;
  43. }
  44. }
  45. else
  46. {
  47. printk("Error, must input COM number.");
  48. return -1;
  49. }
  50. // Get Input config.
  51. if (p_interface == NULL)
  52. {
  53. p_interface = (bt_uart_interface_t *)bt_chipset_get_uart_interface();
  54. }
  55. if (p_interface == NULL)
  56. {
  57. printk("Error, Interface not set.");
  58. return -1;
  59. }
  60. if (bt_hci_init_serial_device(com_num, p_interface->rate, p_interface->databits, p_interface->stopbits,
  61. p_interface->parity, p_interface->flowcontrol) < 0)
  62. {
  63. printk("Error, uart open failed.");
  64. return -1;
  65. }
  66. return 0;
  67. }
  68. int main(int argc, const char *argv[])
  69. {
  70. int err = 0;
  71. bt_log_impl_register(bt_log_impl_local_instance());
  72. if (open_hci_driver(argc, argv) < 0)
  73. {
  74. return -1;
  75. }
  76. bt_hci_chipset_driver_register(bt_hci_chipset_impl_local_instance());
  77. bt_storage_kv_register(bt_storage_kv_impl_local_instance());
  78. bt_timer_impl_local_init();
  79. /* Initialize the Bluetooth Subsystem */
  80. err = bt_enable(bt_ready);
  81. #if defined(CONFIG_BT_MONITOR_SLEEP)
  82. bt_init_monitor_sleep();
  83. #endif
  84. while (1)
  85. {
  86. #if defined(CONFIG_BT_MONITOR_SLEEP)
  87. if (!bt_check_is_in_sleep())
  88. {
  89. bt_polling_work();
  90. if (bt_is_ready() && bt_check_allow_sleep())
  91. {
  92. bt_sleep_prepare_work();
  93. }
  94. }
  95. #else
  96. bt_polling_work();
  97. #endif
  98. app_polling_work();
  99. extern void bt_hci_h4_polling(void);
  100. bt_hci_h4_polling();
  101. }
  102. return (err);
  103. }