btu_init.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #define LOG_TAG "bt_task"
  19. #include <base/logging.h>
  20. #include <pthread.h>
  21. #include <string.h>
  22. #include "bt_target.h"
  23. #include "btm_int.h"
  24. #include "btu.h"
  25. #include "common/message_loop_thread.h"
  26. #include "device/include/controller.h"
  27. #include "gatt_api.h"
  28. #include "gatt_int.h"
  29. #include "l2c_int.h"
  30. #include "osi/include/alarm.h"
  31. #include "osi/include/fixed_queue.h"
  32. #include "osi/include/log.h"
  33. #include "sdpint.h"
  34. #include "smp_int.h"
  35. using bluetooth::common::MessageLoopThread;
  36. MessageLoopThread bt_startup_thread("bt_startup_thread");
  37. void btu_task_start_up(void* context);
  38. void btu_task_shut_down(void* context);
  39. /*****************************************************************************
  40. *
  41. * Function btu_init_core
  42. *
  43. * Description Initialize control block memory for each core component.
  44. *
  45. *
  46. * Returns void
  47. *
  48. *****************************************************************************/
  49. void btu_init_core() {
  50. /* Initialize the mandatory core stack components */
  51. btm_init();
  52. l2c_init();
  53. sdp_init();
  54. gatt_init();
  55. SMP_Init();
  56. btm_ble_init();
  57. }
  58. /*****************************************************************************
  59. *
  60. * Function btu_free_core
  61. *
  62. * Description Releases control block memory for each core component.
  63. *
  64. *
  65. * Returns void
  66. *
  67. *****************************************************************************/
  68. void btu_free_core() {
  69. /* Free the mandatory core stack components */
  70. gatt_free();
  71. l2c_free();
  72. sdp_free();
  73. btm_free();
  74. }
  75. /*****************************************************************************
  76. *
  77. * Function BTU_StartUp
  78. *
  79. * Description Initializes the BTU control block.
  80. *
  81. * NOTE: Must be called before creating any tasks
  82. * (RPC, BTU, HCIT, APPL, etc.)
  83. *
  84. * Returns void
  85. *
  86. *****************************************************************************/
  87. void BTU_StartUp() {
  88. btu_trace_level = HCI_INITIAL_TRACE_LEVEL;
  89. bt_startup_thread.StartUp();
  90. if (!bt_startup_thread.EnableRealTimeScheduling()) {
  91. LOG(ERROR) << __func__ << ": Unable to set real time scheduling policy for "
  92. << bt_startup_thread;
  93. BTU_ShutDown();
  94. return;
  95. }
  96. if (!bt_startup_thread.DoInThread(FROM_HERE,
  97. base::Bind(btu_task_start_up, nullptr))) {
  98. LOG(ERROR) << __func__ << ": Unable to continue start-up on "
  99. << bt_startup_thread;
  100. BTU_ShutDown();
  101. return;
  102. }
  103. }
  104. void BTU_ShutDown() {
  105. btu_task_shut_down(nullptr);
  106. bt_startup_thread.ShutDown();
  107. }