• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2000-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 #define LOG_TAG "bt_task"
20 
21 #include <base/logging.h>
22 #include <pthread.h>
23 #include <string.h>
24 
25 #include "bt_target.h"
26 #include "btm_int.h"
27 #include "btu.h"
28 #include "common/message_loop_thread.h"
29 #include "device/include/controller.h"
30 #include "gatt_api.h"
31 #include "gatt_int.h"
32 #include "l2c_int.h"
33 #include "osi/include/alarm.h"
34 #include "osi/include/fixed_queue.h"
35 #include "osi/include/log.h"
36 #include "sdpint.h"
37 #include "smp_int.h"
38 
39 using bluetooth::common::MessageLoopThread;
40 
41 MessageLoopThread bt_startup_thread("bt_startup_thread");
42 
43 void btu_task_start_up(void* context);
44 void btu_task_shut_down(void* context);
45 
46 /*****************************************************************************
47  *
48  * Function         btu_init_core
49  *
50  * Description      Initialize control block memory for each core component.
51  *
52  *
53  * Returns          void
54  *
55  *****************************************************************************/
btu_init_core()56 void btu_init_core() {
57   /* Initialize the mandatory core stack components */
58   btm_init();
59 
60   l2c_init();
61 
62   sdp_init();
63 
64   gatt_init();
65 
66   SMP_Init();
67 
68   btm_ble_init();
69 }
70 
71 /*****************************************************************************
72  *
73  * Function         btu_free_core
74  *
75  * Description      Releases control block memory for each core component.
76  *
77  *
78  * Returns          void
79  *
80  *****************************************************************************/
btu_free_core()81 void btu_free_core() {
82   /* Free the mandatory core stack components */
83   gatt_free();
84 
85   l2c_free();
86 
87   sdp_free();
88 
89   btm_free();
90 }
91 
92 /*****************************************************************************
93  *
94  * Function         BTU_StartUp
95  *
96  * Description      Initializes the BTU control block.
97  *
98  *                  NOTE: Must be called before creating any tasks
99  *                      (RPC, BTU, HCIT, APPL, etc.)
100  *
101  * Returns          void
102  *
103  *****************************************************************************/
BTU_StartUp()104 void BTU_StartUp() {
105   btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
106   bt_startup_thread.StartUp();
107   if (!bt_startup_thread.EnableRealTimeScheduling()) {
108     LOG(ERROR) << __func__ << ": Unable to set real time scheduling policy for "
109                << bt_startup_thread;
110     BTU_ShutDown();
111     return;
112   }
113   if (!bt_startup_thread.DoInThread(FROM_HERE,
114                                     base::Bind(btu_task_start_up, nullptr))) {
115     LOG(ERROR) << __func__ << ": Unable to continue start-up on "
116                << bt_startup_thread;
117     BTU_ShutDown();
118     return;
119   }
120 }
121 
BTU_ShutDown()122 void BTU_ShutDown() {
123   btu_task_shut_down(nullptr);
124   bt_startup_thread.ShutDown();
125 }
126