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
20 #include <stdbool.h>
21 #include <stdint.h>
22
23 #include <pthread.h>
24 #include "nimble/nimble_npl.h"
25 #include "nimble/nimble_port.h"
26
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
34 static struct ble_npl_task s_task_host;
35 static struct ble_npl_task s_task_hci;
36
37 void nimble_host_task(void *param);
38 void ble_hci_sock_ack_handler(void *param);
39 void ble_hci_sock_init(void);
40
41 #define TASK_DEFAULT_PRIORITY 1
42 #define TASK_DEFAULT_STACK NULL
43 #define TASK_DEFAULT_STACK_SIZE 400
44
ble_hci_sock_task(void * param)45 void *ble_hci_sock_task(void *param)
46 {
47 ble_hci_sock_ack_handler(param);
48 return NULL;
49 }
50
ble_host_task(void * param)51 void *ble_host_task(void *param)
52 {
53 nimble_host_task(param);
54 return NULL;
55 }
56
main(void)57 int main(void)
58 {
59 ble_hci_sock_init();
60 nimble_port_init();
61
62 /* This example provides GATT Alert service */
63 ble_svc_gap_init();
64 ble_svc_gatt_init();
65 ble_svc_ans_init();
66 ble_svc_ias_init();
67 ble_svc_lls_init();
68 ble_svc_tps_init();
69
70 /* XXX Need to have template for store */
71 ble_store_ram_init();
72
73 ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task,
74 NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER,
75 TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
76
77 /* Create task which handles default event queue for host stack. */
78 ble_npl_task_init(&s_task_host, "ble_host", ble_host_task,
79 NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_WAIT_FOREVER,
80 TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE);
81
82 int ret = 0;
83 pthread_exit(&ret);
84
85 while (true)
86 {
87 pthread_yield();
88 }
89 }
90