main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include <stdlib.h>
  22. #include <pthread.h>
  23. #include "nimble/nimble_npl.h"
  24. #include "nimble/nimble_port.h"
  25. #include "mesh/glue.h"
  26. #include "mesh/porting.h"
  27. #include "services/gap/ble_svc_gap.h"
  28. #include "services/gatt/ble_svc_gatt.h"
  29. static struct ble_npl_task s_task_host;
  30. static struct ble_npl_task s_task_hci;
  31. static struct ble_npl_task s_task_mesh_adv;
  32. void nimble_host_task(void *param);
  33. void ble_hci_sock_ack_handler(void *param);
  34. void ble_hci_sock_init(void);
  35. #define TASK_DEFAULT_PRIORITY 1
  36. #define TASK_DEFAULT_STACK NULL
  37. #define TASK_DEFAULT_STACK_SIZE 400
  38. void *ble_hci_sock_task(void *param)
  39. {
  40. ble_hci_sock_ack_handler(param);
  41. return NULL;
  42. }
  43. void *ble_host_task(void *param)
  44. {
  45. nimble_host_task(param);
  46. return NULL;
  47. }
  48. void *ble_mesh_adv_task(void *param)
  49. {
  50. mesh_adv_thread(param);
  51. return NULL;
  52. }
  53. void mesh_initialized(void)
  54. {
  55. ble_npl_task_init(&s_task_mesh_adv, "ble_mesh_adv", ble_mesh_adv_task,
  56. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  57. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  58. }
  59. int main(int argc, char *argv[])
  60. {
  61. int ret = 0;
  62. /* allow to specify custom hci */
  63. if (argc > 1) {
  64. ble_hci_sock_set_device(atoi(argv[1]));
  65. }
  66. nimble_port_init();
  67. ble_hci_sock_init();
  68. ble_svc_gap_init();
  69. ble_svc_gatt_init();
  70. bt_mesh_register_gatt();
  71. /* XXX Need to have template for store */
  72. ble_store_ram_init();
  73. ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
  74. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  75. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  76. /* Create task which handles default event queue for host stack. */
  77. ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
  78. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  79. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  80. pthread_exit(&ret);
  81. }