• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <assert.h>
17 #include "syscfg/syscfg.h"
18 #include "nimble/nimble_port.h"
19 #include "wm_mem.h"
20 #include "wm_osal.h"
21 #if TLS_OS_FREERTOS
22 static void *tls_host_task_stack_ptr = NULL;
23 #endif
24 static tls_os_task_t host_task_ptr = NULL;
nimble_host_task(void * arg)25 static void nimble_host_task(void *arg)
26 {
27     nimble_port_run();
28 }
29 
tls_nimble_start(void)30 void tls_nimble_start(void)
31 {
32 #if TLS_OS_LITEOS
33     tls_os_task_create(&host_task_ptr, "bth",
34                        nimble_host_task,
35                        (void *)0,
36                        (void *)NULL,
37                        MYNEWT_VAL(OS_HS_STACK_SIZE)*sizeof(uint32_t),
38                        MYNEWT_VAL(OS_HS_TASK_PRIO),
39                        0);
40 #else
41     tls_host_task_stack_ptr = (void *)tls_mem_alloc(MYNEWT_VAL(OS_HS_STACK_SIZE) * sizeof(uint32_t));
42     assert(tls_host_task_stack_ptr != NULL);
43     tls_os_task_create(&host_task_ptr, "bth",
44                        nimble_host_task,
45                        (void *)0,
46                        (void *)tls_host_task_stack_ptr,
47                        MYNEWT_VAL(OS_HS_STACK_SIZE)*sizeof(uint32_t),
48                        MYNEWT_VAL(OS_HS_TASK_PRIO),
49                        0);
50 #endif
51 }
52 
free_host_task_stack(void)53 static void free_host_task_stack(void)
54 {
55 #if TLS_OS_LITEOS
56 #else
57 
58     if (tls_host_task_stack_ptr) {
59         tls_mem_free(tls_host_task_stack_ptr);
60         tls_host_task_stack_ptr = NULL;
61     }
62 
63 #endif
64 }
tls_nimble_stop(void)65 void tls_nimble_stop(void)
66 {
67     if (host_task_ptr) {
68         tls_os_task_del_by_task_handle(host_task_ptr, free_host_task_stack);
69     }
70 }