15738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 25738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 35738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Copyright (C) 2003-2012 Broadcom Corporation 45738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 55738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 65738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * you may not use this file except in compliance with the License. 75738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * You may obtain a copy of the License at: 85738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 95738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * See the License for the specific language governing permissions and 155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * limitations under the License. 165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/****************************************************************************** 205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * This is the main implementation file for the BTA system manager. 225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project * 235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project ******************************************************************************/ 24f8027005333c88a2f097cfd70d15c3d54c7764aeChris Manton#define LOG_TAG "bt_bta_sys_main" 2544802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati 2644802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include <assert.h> 27307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton#include <string.h> 285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 290f9b91e150e153229235c163861198e23600e636Sharvil Nanavati#include "osi/include/alarm.h" 305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "btm_api.h" 315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_api.h" 325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_sys.h" 335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_sys_int.h" 345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 350f9b91e150e153229235c163861198e23600e636Sharvil Nanavati#include "osi/include/fixed_queue.h" 365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "gki.h" 370f9b91e150e153229235c163861198e23600e636Sharvil Nanavati#include "osi/include/hash_map.h" 380f9b91e150e153229235c163861198e23600e636Sharvil Nanavati#include "osi/include/osi.h" 3905d0366413bedc16b4189b9e74395fe4b11ba41aZach Johnson#include "osi/include/hash_functions.h" 4044802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati#include "osi/include/log.h" 410f9b91e150e153229235c163861198e23600e636Sharvil Nanavati#include "osi/include/thread.h" 425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) 435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#include "bta_ar_api.h" 445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif 455cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen#include "utl.h" 465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* system manager control block definition */ 485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if BTA_DYNAMIC_MEMORY == FALSE 495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjecttBTA_SYS_CB bta_sys_cb; 505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif 515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5218023290406f076c5c76cdffdbf8ee081450a42fChris Mantonfixed_queue_t *btu_bta_alarm_queue; 5318023290406f076c5c76cdffdbf8ee081450a42fChris Mantonstatic hash_map_t *bta_alarm_hash_map; 5418023290406f076c5c76cdffdbf8ee081450a42fChris Mantonstatic const size_t BTA_ALARM_HASH_MAP_SIZE = 17; 5518023290406f076c5c76cdffdbf8ee081450a42fChris Mantonstatic pthread_mutex_t bta_alarm_lock; 56307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Mantonextern thread_t *bt_workqueue_thread; 5718023290406f076c5c76cdffdbf8ee081450a42fChris Manton 585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* trace level */ 595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* TODO Bluedroid - Hard-coded trace levels - Needs to be configurable */ 60689d66b6559dcb3a0ad7f6cc33b6129e50910253The Android Open Source ProjectUINT8 appl_trace_level = BT_TRACE_LEVEL_WARNING; //APPL_INITIAL_TRACE_LEVEL; 61689d66b6559dcb3a0ad7f6cc33b6129e50910253The Android Open Source ProjectUINT8 btif_trace_level = BT_TRACE_LEVEL_WARNING; 625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 63860a9af89f8dbf8ef65785d5db960c1fa488d2baChris Manton// Communication queue between btu_task and bta. 64860a9af89f8dbf8ef65785d5db960c1fa488d2baChris Mantonextern fixed_queue_t *btu_bta_msg_queue; 65307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Mantonvoid btu_bta_alarm_ready(fixed_queue_t *queue, UNUSED_ATTR void *context); 66860a9af89f8dbf8ef65785d5db960c1fa488d2baChris Manton 675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectstatic const tBTA_SYS_REG bta_sys_hw_reg = 685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_sm_execute, 705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project NULL 715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* type for action functions */ 755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projecttypedef void (*tBTA_SYS_ACTION)(tBTA_SYS_HW_MSG *p_data); 765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* action function list */ 785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst tBTA_SYS_ACTION bta_sys_action[] = 795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* device manager local device API events - cf bta_sys.h for events */ 815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_api_enable, /* 0 BTA_SYS_HW_API_ENABLE_EVT */ 825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_evt_enabled, /* 1 BTA_SYS_HW_EVT_ENABLED_EVT */ 835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_evt_stack_enabled, /* 2 BTA_SYS_HW_EVT_STACK_ENABLED_EVT */ 845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_api_disable, /* 3 BTA_SYS_HW_API_DISABLE_EVT */ 855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_evt_disabled, /* 4 BTA_SYS_HW_EVT_DISABLED_EVT */ 865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_error /* 5 BTA_SYS_HW_ERROR_EVT */ 875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* state machine action enumeration list */ 905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectenum 915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* device manager local device API events */ 935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_API_ENABLE, 945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_EVT_ENABLED, 955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_EVT_STACK_ENABLED, 965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_API_DISABLE, 975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_EVT_DISABLED, 985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTA_SYS_HW_ERROR 995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_SYS_NUM_ACTIONS (BTA_SYS_MAX_EVT & 0x00ff) 1025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_SYS_IGNORE BTA_SYS_NUM_ACTIONS 1035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* state table information */ 1055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_SYS_ACTIONS 2 /* number of actions */ 1065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_SYS_NEXT_STATE 2 /* position of next state */ 1075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#define BTA_SYS_NUM_COLS 3 /* number of columns in state tables */ 1085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* state table for OFF state */ 1115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst UINT8 bta_sys_hw_off[][BTA_SYS_NUM_COLS] = 1125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* Event Action 1 Action 2 Next State */ 1145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, 1155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, 1165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_DISABLE */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}, 1185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_DISABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}, 1195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ERROR */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF} 1205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst UINT8 bta_sys_hw_starting[][BTA_SYS_NUM_COLS] = 1235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* Event Action 1 Action 2 Next State */ 1255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* wait for completion event */ 1265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, 1275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive disable/enable: change state wait for completion to disable */ 1295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_HW_API_ENABLE, BTA_SYS_HW_STARTING}, /* successive enable/disable: notify, then restart HW */ 1305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON} 1315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst UINT8 bta_sys_hw_on[][BTA_SYS_NUM_COLS] = 1345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* Event Action 1 Action 2 Next State */ 1365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_DISABLE */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, /* don't change the state here, as some other modules might be active */ 1405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_DISABLED */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, 1415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON} 1425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst UINT8 bta_sys_hw_stopping[][BTA_SYS_NUM_COLS] = 1455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* Event Action 1 Action 2 Next State */ 1475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* change state, and wait for completion event to enable */ 1485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: finish the enable before disabling */ 1495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_HW_API_DISABLE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: notify, then stop */ 1505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* wait for completion event */ 1515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}, 1525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* EVT_ERROR */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING} 1535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projecttypedef const UINT8 (*tBTA_SYS_ST_TBL)[BTA_SYS_NUM_COLS]; 1565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/* state table */ 1585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectconst tBTA_SYS_ST_TBL bta_sys_st_tbl[] = { 1595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_off, 1605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_starting, 1615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_on, 1625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_hw_stopping 1635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project}; 1645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 1665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_init 1685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description BTA initialization; called from task initialization. 1705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 1735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 1745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 17524933b5b1a06274c47133debac5251a97128a267June R. Tate-Gansvoid bta_sys_init(void) 1765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 1775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project memset(&bta_sys_cb, 0, sizeof(tBTA_SYS_CB)); 178860a9af89f8dbf8ef65785d5db960c1fa488d2baChris Manton 17918023290406f076c5c76cdffdbf8ee081450a42fChris Manton pthread_mutex_init(&bta_alarm_lock, NULL); 18018023290406f076c5c76cdffdbf8ee081450a42fChris Manton 18118023290406f076c5c76cdffdbf8ee081450a42fChris Manton bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE, 182aa3a0114b6f018d0dd296d5bdb113d2f881cbc51Zach Johnson hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL); 18318023290406f076c5c76cdffdbf8ee081450a42fChris Manton btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX); 18418023290406f076c5c76cdffdbf8ee081450a42fChris Manton 185307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton fixed_queue_register_dequeue(btu_bta_alarm_queue, 186307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton thread_get_reactor(bt_workqueue_thread), 187307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton btu_bta_alarm_ready, 188307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton NULL); 189307381ef1ed1b434c956a9a98ca25ba6b415d7c7Chris Manton 190245876929944e9958d80db9f087008ce35f5f133Chris Manton appl_trace_level = APPL_INITIAL_TRACE_LEVEL; 1915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* register BTA SYS message handler */ 1935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_register( BTA_ID_SYS, &bta_sys_hw_reg); 1945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* register for BTM notifications */ 1965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTM_RegisterForDeviceStatusNotif ((tBTM_DEV_STATUS_CB*)&bta_sys_hw_btm_cback ); 1975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 1985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE) 1995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_ar_init(); 2005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project#endif 2015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 20424933b5b1a06274c47133debac5251a97128a267June R. Tate-Gansvoid bta_sys_free(void) { 20518023290406f076c5c76cdffdbf8ee081450a42fChris Manton fixed_queue_free(btu_bta_alarm_queue, NULL); 20618023290406f076c5c76cdffdbf8ee081450a42fChris Manton hash_map_free(bta_alarm_hash_map); 20718023290406f076c5c76cdffdbf8ee081450a42fChris Manton pthread_mutex_destroy(&bta_alarm_lock); 20818023290406f076c5c76cdffdbf8ee081450a42fChris Manton} 20918023290406f076c5c76cdffdbf8ee081450a42fChris Manton 2105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_dm_sm_execute 2135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description State machine event handling function for DM 2155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 2185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN bta_sys_sm_execute(BT_HDR *p_msg) 2215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BOOLEAN freebuf = TRUE; 2235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_SYS_ST_TBL state_table; 2245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 action; 2255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int i; 2265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 227e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_EVENT("bta_sys_sm_execute state:%d, event:0x%x", bta_sys_cb.state, p_msg->event); 2285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* look up the state table for the current state */ 2305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project state_table = bta_sys_st_tbl[bta_sys_cb.state]; 2315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* update state */ 2325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.state = state_table[p_msg->event & 0x00ff][BTA_SYS_NEXT_STATE]; 2335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* execute action functions */ 2355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (i = 0; i < BTA_SYS_ACTIONS; i++) 2365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_SYS_IGNORE) 2385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*bta_sys_action[action])( (tBTA_SYS_HW_MSG*) p_msg); 2405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 2445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return freebuf; 2475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback) 2525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[module]=cback; 2545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module ) 2585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[module]=NULL; 2605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 2615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 2635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_btm_cback 2655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description This function is registered by BTA SYS to BTM in order to get status notifications 2675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns 2705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 2715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 2725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_btm_cback( tBTM_DEV_STATUS status ) 2735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 2745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project tBTA_SYS_HW_MSG *sys_event; 2765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 277e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG(" bta_sys_hw_btm_cback was called with parameter: %i" , status ); 2785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* send a message to BTA SYS */ 2805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((sys_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) 2815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (status == BTM_DEV_STATUS_UP) 2835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project sys_event->hdr.event = BTA_SYS_EVT_STACK_ENABLED_EVT; 2845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else if (status == BTM_DEV_STATUS_DOWN) 2855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project sys_event->hdr.event = BTA_SYS_ERROR_EVT; 2865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* BTM_DEV_STATUS_CMD_TOUT is ignored for now. */ 2895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GKI_freebuf (sys_event); 2905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project sys_event = NULL; 2915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 2935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (sys_event) 2945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 2955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_sendmsg(sys_event); 2965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 2985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 2995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 300e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("ERROR bta_sys_hw_btm_cback couldn't send msg" ); 3015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_error 3095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description In case the HW device stops answering... Try to turn it off, then re-enable all 3115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** previously active SW modules. 3125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 3145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg) 3175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 module_index; 3195cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_sys_hw_msg); 3205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 321e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("%s", __FUNCTION__); 3225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES; module_index++) 3245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if( bta_sys_cb.sys_hw_module_active & ((UINT32)1 << module_index )) { 3265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project switch( module_index) 3275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case BTA_SYS_HW_BLUETOOTH: 3295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* Send BTA_SYS_HW_ERROR_EVT to DM */ 3305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.sys_hw_cback[module_index] != NULL) 3315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[module_index] (BTA_SYS_HW_ERROR_EVT); 3325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 3335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project default: 3345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* not yet supported */ 3355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 3365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_enable 3465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description this function is called after API enable and HW has been turned on 3485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 3515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg ) 3555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 3565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((!bta_sys_cb.sys_hw_module_active) && (bta_sys_cb.state != BTA_SYS_HW_ON)) 3575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* register which HW module was turned on */ 3595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_module_active |= ((UINT32)1 << p_sys_hw_msg->hw_module ); 3605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 361186d09582c58cbcf078934135c95229880c2fd10Zach Johnson tBTA_SYS_HW_MSG *p_msg; 362186d09582c58cbcf078934135c95229880c2fd10Zach Johnson if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) 363186d09582c58cbcf078934135c95229880c2fd10Zach Johnson { 364186d09582c58cbcf078934135c95229880c2fd10Zach Johnson p_msg->hdr.event = BTA_SYS_EVT_ENABLED_EVT; 365186d09582c58cbcf078934135c95229880c2fd10Zach Johnson p_msg->hw_module = p_sys_hw_msg->hw_module; 366186d09582c58cbcf078934135c95229880c2fd10Zach Johnson 367186d09582c58cbcf078934135c95229880c2fd10Zach Johnson bta_sys_sendmsg(p_msg); 368186d09582c58cbcf078934135c95229880c2fd10Zach Johnson } 3695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 3715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 3725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* register which HW module was turned on */ 3735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_module_active |= ((UINT32)1 << p_sys_hw_msg->hw_module ); 3745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* HW already in use, so directly notify the caller */ 3765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL ) 3775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]( BTA_SYS_HW_ON_EVT ); 3785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 3795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 380e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_EVENT ("bta_sys_hw_api_enable for %d, active modules 0x%04X", 3815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active); 3825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 3845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 3855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 3865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_disable 3885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description if no other module is using the HW, this function will call ( if defined ) a user-macro to turn off the HW 3905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 3935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 3945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 3955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg) 3965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 397e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_sys_hw_api_disable for %d, active modules: 0x%04X", 3985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active ); 3995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* make sure the related SW blocks were stopped */ 4015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_disable( p_sys_hw_msg->hw_module ); 4025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* register which module we turn off */ 4055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_module_active &= ~((UINT32)1 << p_sys_hw_msg->hw_module ); 4065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if there are still some SW modules using the HW, just provide an answer to the calling */ 4095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if( bta_sys_cb.sys_hw_module_active != 0 ) 4105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* if there are still some SW modules using the HW, directly notify the caller */ 4125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if( bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL ) 4135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]( BTA_SYS_HW_OFF_EVT ); 4145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 4165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* manually update the state of our system */ 4185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.state = BTA_SYS_HW_STOPPING; 419186d09582c58cbcf078934135c95229880c2fd10Zach Johnson 420186d09582c58cbcf078934135c95229880c2fd10Zach Johnson tBTA_SYS_HW_MSG *p_msg; 421186d09582c58cbcf078934135c95229880c2fd10Zach Johnson if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) 422186d09582c58cbcf078934135c95229880c2fd10Zach Johnson { 423186d09582c58cbcf078934135c95229880c2fd10Zach Johnson p_msg->hdr.event = BTA_SYS_EVT_DISABLED_EVT; 424186d09582c58cbcf078934135c95229880c2fd10Zach Johnson p_msg->hw_module = p_sys_hw_msg->hw_module; 425186d09582c58cbcf078934135c95229880c2fd10Zach Johnson 426186d09582c58cbcf078934135c95229880c2fd10Zach Johnson bta_sys_sendmsg(p_msg); 427186d09582c58cbcf078934135c95229880c2fd10Zach Johnson } 4285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_event_enabled 4365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description 4385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 4415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_evt_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) 4445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 445e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_EVENT("bta_sys_hw_evt_enabled for %i", p_sys_hw_msg->hw_module); 4465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BTM_DeviceReset( NULL ); 4475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_event_disabled 4535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description 4555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 4585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) 4615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 hw_module_index; 4635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 464e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X", p_sys_hw_msg->hw_module); 4655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++) 4675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL) 4695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_OFF_EVT); 4705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 4745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_hw_event_stack_enabled 4765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4775cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen** Description we receive this event once the SW side is ready ( stack, FW download,... ), 4785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** i.e. we can really start using the device. So notify the app. 4795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns success or failure 4815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 4825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 4835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg) 4845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 4855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 hw_module_index; 4865cd8bff2dd0337cb52bf48f312e3d2d55a8882fbMike J. Chen UNUSED(p_sys_hw_msg); 4875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 488e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers"); 4895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++ ) 4915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 4925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL) 4935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_ON_EVT); 4945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 4955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 4965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 4995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_event 5035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description BTA event handler; called from task event handler. 5055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 5085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 51024933b5b1a06274c47133debac5251a97128a267June R. Tate-Gansvoid bta_sys_event(BT_HDR *p_msg) 5115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project UINT8 id; 5135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project BOOLEAN freebuf = TRUE; 5145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 515e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_EVENT("BTA got event 0x%x", p_msg->event); 5165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* get subsystem id from event */ 5185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project id = (UINT8) (p_msg->event >> 8); 5195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project /* verify id and call subsystem event handler */ 5215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if ((id < BTA_ID_MAX) && (bta_sys_cb.reg[id] != NULL)) 5225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project freebuf = (*bta_sys_cb.reg[id]->evt_hdlr)(p_msg); 5245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project else 5265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 527e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_WARNING("BTA got unregistered event id %d", id); 5285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (freebuf) 5315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 5325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project GKI_freebuf(p_msg); 5335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 5345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_register 5405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Called by other BTA subsystems to register their event 5425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** handler. 5435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 5465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg) 5495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.reg[id] = (tBTA_SYS_REG *) p_reg; 5515738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.is_reg[id] = TRUE; 5525738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5535738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5545738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5555738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5565738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_deregister 5575738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5585738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Called by other BTA subsystems to de-register 5595738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** handler. 5605738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5615738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5625738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 5635738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5645738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_deregister(UINT8 id) 5665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_sys_cb.is_reg[id] = FALSE; 5685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_is_register 5735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5745738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Called by other BTA subsystems to get registeration 5755738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** status. 5765738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5775738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5785738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 5795738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5805738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5815738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectBOOLEAN bta_sys_is_register(UINT8 id) 5825738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 5835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return bta_sys_cb.is_reg[id]; 5845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 5855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 5865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 5875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_sendmsg 5895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Send a GKI message to BTA. This function is designed to 5915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** optimize sending of messages to BTA. It is called by BTA 5925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** API functions and call-in functions. 5935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 5965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 5975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 5985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_sendmsg(void *p_msg) 5995738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 60050333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray // There is a race condition that occurs if the stack is shut down while 60150333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray // there is a procedure in progress that can schedule a task via this 60250333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray // message queue. This causes |btu_bta_msg_queue| to get cleaned up before 60350333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray // it gets used here; hence we check for NULL before using it. 60450333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray if (btu_bta_msg_queue) 60550333a25ba3dac54033738d1e2a2688e2977ff2eArman Uguray fixed_queue_enqueue(btu_bta_msg_queue, p_msg); 6065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6085738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_start_timer 6115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Start a protocol timer for the specified amount 6135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** of time in milliseconds. 6145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 6165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 61818023290406f076c5c76cdffdbf8ee081450a42fChris Mantonvoid bta_alarm_cb(void *data) { 61918023290406f076c5c76cdffdbf8ee081450a42fChris Manton assert(data != NULL); 62018023290406f076c5c76cdffdbf8ee081450a42fChris Manton TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data; 62118023290406f076c5c76cdffdbf8ee081450a42fChris Manton 62218023290406f076c5c76cdffdbf8ee081450a42fChris Manton fixed_queue_enqueue(btu_bta_alarm_queue, p_tle); 62318023290406f076c5c76cdffdbf8ee081450a42fChris Manton} 62418023290406f076c5c76cdffdbf8ee081450a42fChris Manton 6253ca27de478059136506cce747a17856f6470425aSharvil Nanavativoid bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) { 62618023290406f076c5c76cdffdbf8ee081450a42fChris Manton assert(p_tle != NULL); 62718023290406f076c5c76cdffdbf8ee081450a42fChris Manton 62818023290406f076c5c76cdffdbf8ee081450a42fChris Manton // Get the alarm for this p_tle. 62918023290406f076c5c76cdffdbf8ee081450a42fChris Manton pthread_mutex_lock(&bta_alarm_lock); 63018023290406f076c5c76cdffdbf8ee081450a42fChris Manton if (!hash_map_has_key(bta_alarm_hash_map, p_tle)) { 63118023290406f076c5c76cdffdbf8ee081450a42fChris Manton hash_map_set(bta_alarm_hash_map, p_tle, alarm_new()); 63218023290406f076c5c76cdffdbf8ee081450a42fChris Manton } 63318023290406f076c5c76cdffdbf8ee081450a42fChris Manton pthread_mutex_unlock(&bta_alarm_lock); 63418023290406f076c5c76cdffdbf8ee081450a42fChris Manton 63518023290406f076c5c76cdffdbf8ee081450a42fChris Manton alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle); 63618023290406f076c5c76cdffdbf8ee081450a42fChris Manton if (alarm == NULL) { 63744802768c447ab480d4227b3a852a97d923b816dSharvil Nanavati LOG_ERROR("%s unable to create alarm.", __func__); 63818023290406f076c5c76cdffdbf8ee081450a42fChris Manton return; 63918023290406f076c5c76cdffdbf8ee081450a42fChris Manton } 64018023290406f076c5c76cdffdbf8ee081450a42fChris Manton 64118023290406f076c5c76cdffdbf8ee081450a42fChris Manton p_tle->event = type; 6423ca27de478059136506cce747a17856f6470425aSharvil Nanavati p_tle->ticks = timeout_ms; 6433ca27de478059136506cce747a17856f6470425aSharvil Nanavati alarm_set(alarm, (period_ms_t)timeout_ms, bta_alarm_cb, p_tle); 6445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 64676356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavanbool hash_iter_ro_cb(hash_map_entry_t *hash_map_entry, void *context) 64776356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan{ 64876356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan alarm_t *alarm = (alarm_t *)hash_map_entry->data; 64976356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan period_ms_t *p_remaining_ms = (period_ms_t*)context; 65076356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan *p_remaining_ms += alarm_get_remaining_ms(alarm); 65176356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan return true; 65276356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan} 65376356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan 65476356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavanUINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle) 65576356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan{ 65676356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan period_ms_t remaining_ms = 0; 65776356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan pthread_mutex_lock(&bta_alarm_lock); 65876356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan // Get the alarm for this p_tle 65976356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan hash_map_foreach(bta_alarm_hash_map, hash_iter_ro_cb, &remaining_ms); 66076356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan pthread_mutex_unlock(&bta_alarm_lock); 66176356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan return remaining_ms; 66276356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan} 66376356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan 66476356aee883af67898ddc1aa3b628195f396d42aVenkatRaghavan VijayaRaghavan 6655738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6665738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6675738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_stop_timer 6685738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6695738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Stop a BTA timer. 6705738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6715738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 6725738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6735738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 67418023290406f076c5c76cdffdbf8ee081450a42fChris Mantonvoid bta_sys_stop_timer(TIMER_LIST_ENT *p_tle) { 67518023290406f076c5c76cdffdbf8ee081450a42fChris Manton assert(p_tle != NULL); 67618023290406f076c5c76cdffdbf8ee081450a42fChris Manton 67718023290406f076c5c76cdffdbf8ee081450a42fChris Manton alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle); 67818023290406f076c5c76cdffdbf8ee081450a42fChris Manton if (alarm == NULL) { 679f8027005333c88a2f097cfd70d15c3d54c7764aeChris Manton LOG_DEBUG("%s expected alarm was not in bta alarm hash map.", __func__); 68018023290406f076c5c76cdffdbf8ee081450a42fChris Manton return; 68118023290406f076c5c76cdffdbf8ee081450a42fChris Manton } 68218023290406f076c5c76cdffdbf8ee081450a42fChris Manton alarm_cancel(alarm); 6835738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 6845738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 6855738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 6865738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6875738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_disable 6885738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6895738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description For each registered subsystem execute its disable function. 6905738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6915738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 6925738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 6935738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 6945738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_disable(tBTA_SYS_HW_MODULE module) 6955738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 6965738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int bta_id = 0; 6975738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project int bta_id_max = 0; 6985738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 699e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_DEBUG("bta_sys_disable: module %i", module); 7005738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7015738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project switch( module ) 7025738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7035738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project case BTA_SYS_HW_BLUETOOTH: 7045738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_id = BTA_ID_DM; 7055738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project bta_id_max = BTA_ID_BLUETOOTH_MAX; 7065738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project break; 7075738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project default: 708e8c3d75b75493911ebf0f99c83676359657178f7Sharvil Nanavati APPL_TRACE_WARNING("bta_sys_disable: unkown module"); 7095738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return; 7105738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7115738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7125738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project for ( ; bta_id <= bta_id_max; bta_id++) 7135738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7145738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.reg[bta_id] != NULL) 7155738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7165738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project if (bta_sys_cb.is_reg[bta_id] == TRUE && bta_sys_cb.reg[bta_id]->disable != NULL) 7175738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project { 7185738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project (*bta_sys_cb.reg[bta_id]->disable)(); 7195738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7205738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7215738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project } 7225738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 7235738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7245738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 7255738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7265738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_set_trace_level 7275738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7285738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Set trace level for BTA 7295738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7305738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns void 7315738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7325738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 7335738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Projectvoid bta_sys_set_trace_level(UINT8 level) 7345738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 7355738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project appl_trace_level = level; 7365738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 7375738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project 7385738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project/******************************************************************************* 7395738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7405738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Function bta_sys_get_sys_features 7415738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7425738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Description Returns sys_features to other BTA modules. 7435738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7445738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** Returns sys_features 7455738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project** 7465738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project*******************************************************************************/ 7475738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source ProjectUINT16 bta_sys_get_sys_features (void) 7485738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project{ 7495738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project return bta_sys_cb.sys_features; 7505738f83aeb59361a0a2eda2460113f6dc919427The Android Open Source Project} 751