1 /*
2 * SPDX-License-Identifier: Apache-2.0
3 *
4 * Date Author Notes
5 * 2018-12-18 ChenYong first implementation
6 */
7
8
9 #include <stddef.h>
10 #include <rtthread.h>
11 #include <rthw.h>
12 #include "syscfg/syscfg.h"
13 #include "nimble/nimble_port.h"
14
15 #if NIMBLE_CFG_CONTROLLER
16 static rt_thread_t ll_task_h;
17 #endif
18
19 extern void ble_ll_task(void *arg);
20
__aeabi_assert(const char * expr,const char * file,int line)21 RT_WEAK void __aeabi_assert(const char *expr, const char *file, int line)
22 {
23 rt_assert_handler(expr, file, line);
24 }
25
nimble_port_rtthread_init(void)26 int nimble_port_rtthread_init(void)
27 {
28 nimble_port_init();
29
30 #if NIMBLE_CFG_CONTROLLER
31 /*
32 * Create task where NimBLE LL will run. This one is required as LL has its
33 * own event queue and should have highest priority. The task function is
34 * provided by NimBLE and in case of FreeRTOS it does not need to be wrapped
35 * since it has compatible prototype.
36 */
37 ll_task_h = rt_thread_create("ll", ble_ll_task, NULL,
38 MYNEWT_VAL(BLE_CTLR_THREAD_STACK_SIZE),
39 MYNEWT_VAL(BLE_CTLR_THREAD_PRIORITY), 10);
40 if (ll_task_h != RT_NULL)
41 rt_thread_startup(ll_task_h);
42
43 #endif
44
45 return 0;
46 }
47
ble_hs_thread_entry(void * parameter)48 void ble_hs_thread_entry(void *parameter)
49 {
50 nimble_port_run();
51 }
52
ble_hs_thread_startup(void)53 void ble_hs_thread_startup(void)
54 {
55 rt_thread_t tid;
56
57 tid = rt_thread_create("host", ble_hs_thread_entry, NULL,
58 MYNEWT_VAL(BLE_HOST_THREAD_STACK_SIZE),
59 MYNEWT_VAL(BLE_HOST_THREAD_PRIORITY), 10);
60 if (tid != RT_NULL)
61 rt_thread_startup(tid);
62 }
63
64 INIT_COMPONENT_EXPORT(nimble_port_rtthread_init);
65