main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <nuttx/config.h>
  20. #include <stdbool.h>
  21. #include <stdint.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <pthread.h>
  25. #include "nimble/nimble_npl.h"
  26. #include "nimble/nimble_port.h"
  27. #include "services/gap/ble_svc_gap.h"
  28. #include "services/gatt/ble_svc_gatt.h"
  29. #include "services/ans/ble_svc_ans.h"
  30. #include "services/ias/ble_svc_ias.h"
  31. #include "services/lls/ble_svc_lls.h"
  32. #include "services/tps/ble_svc_tps.h"
  33. static struct ble_npl_task s_task_host;
  34. static struct ble_npl_task s_task_hci;
  35. void nimble_host_task(void *param);
  36. void ble_hci_sock_ack_handler(void *param);
  37. void ble_hci_sock_init(void);
  38. void ble_hci_sock_set_device(int dev);
  39. void ble_store_ram_init(void);
  40. #define TASK_DEFAULT_PRIORITY 1
  41. #define TASK_DEFAULT_STACK NULL
  42. #define TASK_DEFAULT_STACK_SIZE 400
  43. void *ble_hci_sock_task(void *param)
  44. {
  45. printf("hci sock task\n");
  46. ble_hci_sock_ack_handler(param);
  47. return NULL;
  48. }
  49. void *ble_host_task(void *param)
  50. {
  51. printf("host task\n");
  52. nimble_host_task(param);
  53. return NULL;
  54. }
  55. int main(int argc, char *argv[])
  56. {
  57. int ret = 0;
  58. /* allow to specify custom hci */
  59. if (argc > 1) {
  60. ble_hci_sock_set_device(atoi(argv[1]));
  61. }
  62. printf("port init\n");
  63. nimble_port_init();
  64. printf("hci init\n");
  65. ble_hci_sock_init();
  66. /* This example provides GATT Alert service */
  67. printf("gap init\n");
  68. ble_svc_gap_init();
  69. printf("gatt init\n");
  70. ble_svc_gatt_init();
  71. printf("ans init\n");
  72. ble_svc_ans_init();
  73. printf("ias init\n");
  74. ble_svc_ias_init();
  75. printf("lls init\n");
  76. ble_svc_lls_init();
  77. printf("tps init\n");
  78. ble_svc_tps_init();
  79. /* XXX Need to have template for store */
  80. ble_store_ram_init();
  81. printf("hci_sock task init\n");
  82. ret = ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
  83. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  84. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  85. if (ret != 0)
  86. {
  87. fprintf(stderr, "error starting hci task: %i\n", ret);
  88. }
  89. /* Create task which handles default event queue for host stack. */
  90. printf("ble_host task init\n");
  91. ret = ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
  92. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  93. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  94. if (ret != 0)
  95. {
  96. fprintf(stderr, "error starting ble task: %i\n", ret);
  97. }
  98. while (true)
  99. {
  100. usleep(100);
  101. //pause();
  102. }
  103. return 0;
  104. }