main.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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 "services/gap/ble_svc_gap.h"
  26. #include "services/gatt/ble_svc_gatt.h"
  27. #include "services/ans/ble_svc_ans.h"
  28. #include "services/ias/ble_svc_ias.h"
  29. #include "services/lls/ble_svc_lls.h"
  30. #include "services/tps/ble_svc_tps.h"
  31. static struct ble_npl_task s_task_host;
  32. static struct ble_npl_task s_task_hci;
  33. void nimble_host_task(void *param);
  34. void ble_hci_sock_ack_handler(void *param);
  35. void ble_hci_sock_init(void);
  36. void ble_hci_sock_set_device(int dev);
  37. #define TASK_DEFAULT_PRIORITY 1
  38. #define TASK_DEFAULT_STACK NULL
  39. #define TASK_DEFAULT_STACK_SIZE 400
  40. void *ble_hci_sock_task(void *param)
  41. {
  42. ble_hci_sock_ack_handler(param);
  43. return NULL;
  44. }
  45. void *ble_host_task(void *param)
  46. {
  47. nimble_host_task(param);
  48. return NULL;
  49. }
  50. int main(int argc, char *argv[])
  51. {
  52. int ret = 0;
  53. /* allow to specify custom hci */
  54. if (argc > 1) {
  55. ble_hci_sock_set_device(atoi(argv[1]));
  56. }
  57. nimble_port_init();
  58. ble_hci_sock_init();
  59. /* This example provides GATT Alert service */
  60. ble_svc_gap_init();
  61. ble_svc_gatt_init();
  62. ble_svc_ans_init();
  63. ble_svc_ias_init();
  64. ble_svc_lls_init();
  65. ble_svc_tps_init();
  66. /* XXX Need to have template for store */
  67. ble_store_ram_init();
  68. ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
  69. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  70. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  71. /* Create task which handles default event queue for host stack. */
  72. ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
  73. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER,
  74. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  75. pthread_exit(&ret);
  76. }