main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 <pthread.h>
  22. #include "nimble/nimble_npl.h"
  23. #include "nimble/nimble_port.h"
  24. #include "services/gap/ble_svc_gap.h"
  25. #include "services/gatt/ble_svc_gatt.h"
  26. #include "services/ans/ble_svc_ans.h"
  27. #include "services/ias/ble_svc_ias.h"
  28. #include "services/lls/ble_svc_lls.h"
  29. #include "services/tps/ble_svc_tps.h"
  30. static struct ble_npl_task s_task_host;
  31. static struct ble_npl_task s_task_hci;
  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. int main(void)
  49. {
  50. ble_hci_sock_init();
  51. nimble_port_init();
  52. /* This example provides GATT Alert service */
  53. ble_svc_gap_init();
  54. ble_svc_gatt_init();
  55. ble_svc_ans_init();
  56. ble_svc_ias_init();
  57. ble_svc_lls_init();
  58. ble_svc_tps_init();
  59. /* XXX Need to have template for store */
  60. ble_store_ram_init();
  61. ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
  62. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER,
  63. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  64. /* Create task which handles default event queue for host stack. */
  65. ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
  66. NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER,
  67. TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
  68. int ret = 0;
  69. pthread_exit(&ret);
  70. while (true)
  71. {
  72. pthread_yield();
  73. }
  74. }