VOID EXhalbtc8723a1ant_ConnectNotify( IN PBTC_COEXIST pBtCoexist, IN u1Byte type ) { BOOLEAN bWifiConnected=FALSE; if(pBtCoexist->btInfo.bBtDisabled) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); } else { if(BTC_ASSOCIATE_START == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n")); //set 0x550[3]=1 before PsTdma halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8); // extend wifi slot } else if(BTC_ASSOCIATE_FINISH == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n")); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); if(!bWifiConnected) { // non-connected scan halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); } else { halbtc8723a1ant_CoexForWifiConnect(pBtCoexist); } } } }
VOID EXhalbtc8723a1ant_ScanNotify( IN PBTC_COEXIST pBtCoexist, IN u1Byte type ) { BOOLEAN bWifiConnected=FALSE; halbtc8723a1ant_NotifyFwScan(pBtCoexist, type); if(pBtCoexist->btInfo.bBtDisabled) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); } else { pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); if(BTC_SCAN_START == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n")); if(!bWifiConnected) { // non-connected scan //set 0x550[3]=1 before PsTdma halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE); } halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4); } else if(BTC_SCAN_FINISH == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n")); if(!bWifiConnected) { // non-connected scan halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); } else { halbtc8723a1ant_CoexForWifiConnect(pBtCoexist); } } } }
VOID EXhalbtc8723a1ant_Periodical( IN PBTC_COEXIST pBtCoexist ) { BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE, bWifiConnected=FALSE; BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], 1Ant Periodical!!\n")); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); // work around for c2h hang wa_halbtc8723a1ant_MonitorC2h(pBtCoexist); halbtc8723a1ant_QueryBtInfo(pBtCoexist); halbtc8723a1ant_MonitorBtCtr(pBtCoexist); halbtc8723a1ant_MonitorBtEnableDisable(pBtCoexist); if(bScan) return; if(bLink) return; if(bWifiConnected) { if(pBtCoexist->btInfo.bBtDisabled) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE); halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE); } else { halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE); halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE); halbtc8723a1ant_CoexForWifiConnect(pBtCoexist); } } else { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE); halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE); } }
VOID EXhalbtc8723a1ant_SpecialPacketNotify( IN PBTC_COEXIST pBtCoexist, IN u1Byte type ) { if(type == BTC_PACKET_DHCP) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n")); if(pBtCoexist->btInfo.bBtDisabled) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); } else { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 18); } } }
VOID EXhalbtc8723a1ant_HaltNotify( IN PBTC_COEXIST pBtCoexist ) { halbtc8723a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0); halbtc8723a1ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE); halbtc8723a1ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE); halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE); EXhalbtc8723a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT); }
VOID EXhalbtc8723a1ant_LpsNotify( IN PBTC_COEXIST pBtCoexist, IN u1Byte type ) { if(BTC_LPS_ENABLE == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n")); } else if(BTC_LPS_DISABLE == type) { BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n")); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8); } }
VOID halbtc8723a1ant_CoexAllOff( IN PBTC_COEXIST pBtCoexist ) { // fw all off halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); // sw all off halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE); halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE); // hw all off halbtc8723a1ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3); }
VOID halbtc8723a1ant_CoexForWifiConnect( IN PBTC_COEXIST pBtCoexist ) { BOOLEAN bWifiConnected=FALSE, bWifiBusy=FALSE; u1Byte btState, btInfoOriginal=0; pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected); btState = pCoexDm->btStatus; btInfoOriginal = pCoexSta->btInfoC2h[BT_INFO_SRC_8723A_1ANT_BT_RSP][0]; if(bWifiConnected) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi connected!!\n")); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy); if( !bWifiBusy && ((BT_STATE_8723A_1ANT_NO_CONNECTION == btState) || (BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)) ) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], [Wifi is idle] or [Bt is non connected idle or Bt is connected idle]!!\n")); if(BT_STATE_8723A_1ANT_NO_CONNECTION == btState) halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); else if(BT_STATE_8723A_1ANT_CONNECT_IDLE == btState) halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0); } else { if( (BT_STATE_8723A_1ANT_SCO_ONLY_BUSY == btState) || (BT_STATE_8723A_1ANT_ACL_SCO_BUSY == btState) || (BT_STATE_8723A_1ANT_HID_BUSY == btState) || (BT_STATE_8723A_1ANT_HID_SCO_BUSY == btState) ) { pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0x60); } else { pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0); } switch(btState) { case BT_STATE_8723A_1ANT_NO_CONNECTION: halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5); break; case BT_STATE_8723A_1ANT_CONNECT_IDLE: halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12); break; case BT_STATE_8723A_1ANT_INQ_OR_PAG: halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10); break; case BT_STATE_8723A_1ANT_SCO_ONLY_BUSY: case BT_STATE_8723A_1ANT_ACL_SCO_BUSY: case BT_STATE_8723A_1ANT_HID_BUSY: case BT_STATE_8723A_1ANT_HID_SCO_BUSY: halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist); break; case BT_STATE_8723A_1ANT_ACL_ONLY_BUSY: if (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP) { halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist); } else if(btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1); } else if( (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP) && (btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP) ) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6); } else { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1); } break; default: BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], error!!!, undefined case in halbtc8723a1ant_CoexForWifiConnect()!!\n")); break; } } } else { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is disconnected!!\n")); } pCoexDm->psTdmaGlobalCnt++; }
VOID halbtc8723a1ant_TdmaDurationAdjust( IN PBTC_COEXIST pBtCoexist ) { static s4Byte up,dn,m,n,WaitCount; s4Byte result; //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration u1Byte retryCount=0; u1Byte btState; BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE; u4Byte wifiBw; pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw); btState = pCoexDm->btStatus; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], TdmaDurationAdjust()\n")); if(pCoexDm->psTdmaGlobalCnt != pCoexDm->psTdmaMonitorCnt) { pCoexDm->psTdmaMonitorCnt = 0; pCoexDm->psTdmaGlobalCnt = 0; } if(pCoexDm->psTdmaMonitorCnt == 0) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], first run BT A2DP + WiFi busy state!!\n")); if(btState == BT_STATE_8723A_1ANT_ACL_ONLY_BUSY) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1); pCoexDm->psTdmaDuAdjType = 1; } else { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22); pCoexDm->psTdmaDuAdjType = 22; } //============ up = 0; dn = 0; m = 1; n= 3; result = 0; WaitCount = 0; } else { //accquire the BT TRx retry count from BT_Info byte2 retryCount = pCoexSta->btRetryCnt; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], retryCount = %d\n", retryCount)); result = 0; WaitCount++; if(retryCount == 0) { // no retry in the last 2-second duration up++; dn--; if (dn <= 0) dn = 0; if(up >= n) { // if 連續 n 個2秒 retry count為0, 則調寬WiFi duration WaitCount = 0; n = 3; up = 0; dn = 0; result = 1; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Increase wifi duration!!\n")); } } else if (retryCount <= 3) { // <=3 retry in the last 2-second duration up--; dn++; if (up <= 0) up = 0; if (dn == 2) { // if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration if (WaitCount <= 2) m++; // 避免一直在兩個level中來回 else m = 1; if ( m >= 20) //m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. m = 20; n = 3*m; up = 0; dn = 0; WaitCount = 0; result = -1; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n")); } } else { //retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration if (WaitCount == 1) m++; // 避免一直在兩個level中來回 else m = 1; if ( m >= 20) //m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. m = 20; n = 3*m; up = 0; dn = 0; WaitCount = 0; result = -1; BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n")); } { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT TxRx counter H+L <= 1200\n")); if(btState != BT_STATE_8723A_1ANT_ACL_ONLY_BUSY) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], NOT ACL only busy!\n")); if(BTC_WIFI_BW_HT40 != wifiBw) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], 20MHz\n")); if(result == -1) { if(pCoexDm->curPsTdma == 22) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23); pCoexDm->psTdmaDuAdjType = 23; } else if(pCoexDm->curPsTdma == 23) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24); pCoexDm->psTdmaDuAdjType = 24; } else if(pCoexDm->curPsTdma == 24) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25); pCoexDm->psTdmaDuAdjType = 25; } } else if (result == 1) { if(pCoexDm->curPsTdma == 25) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24); pCoexDm->psTdmaDuAdjType = 24; } else if(pCoexDm->curPsTdma == 24) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23); pCoexDm->psTdmaDuAdjType = 23; } else if(pCoexDm->curPsTdma == 23) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22); pCoexDm->psTdmaDuAdjType = 22; } } // error handle, if not in the following state, // set psTdma again. if( (pCoexDm->psTdmaDuAdjType != 22) && (pCoexDm->psTdmaDuAdjType != 23) && (pCoexDm->psTdmaDuAdjType != 24) && (pCoexDm->psTdmaDuAdjType != 25) ) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n")); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23); pCoexDm->psTdmaDuAdjType = 23; } } else { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], 40MHz\n")); if(result == -1) { if(pCoexDm->curPsTdma == 23) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24); pCoexDm->psTdmaDuAdjType = 24; } else if(pCoexDm->curPsTdma == 24) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25); pCoexDm->psTdmaDuAdjType = 25; } else if(pCoexDm->curPsTdma == 25) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 27); pCoexDm->psTdmaDuAdjType = 27; } } else if (result == 1) { if(pCoexDm->curPsTdma == 27) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25); pCoexDm->psTdmaDuAdjType = 25; } else if(pCoexDm->curPsTdma == 25) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24); pCoexDm->psTdmaDuAdjType = 24; } else if(pCoexDm->curPsTdma == 24) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23); pCoexDm->psTdmaDuAdjType = 23; } } // error handle, if not in the following state, // set psTdma again. if( (pCoexDm->psTdmaDuAdjType != 23) && (pCoexDm->psTdmaDuAdjType != 24) && (pCoexDm->psTdmaDuAdjType != 25) && (pCoexDm->psTdmaDuAdjType != 27) ) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n")); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24); pCoexDm->psTdmaDuAdjType = 24; } } } else { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ACL only busy\n")); if (result == -1) { if(pCoexDm->curPsTdma == 1) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2); pCoexDm->psTdmaDuAdjType = 2; } else if(pCoexDm->curPsTdma == 2) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9); pCoexDm->psTdmaDuAdjType = 9; } else if(pCoexDm->curPsTdma == 9) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11); pCoexDm->psTdmaDuAdjType = 11; } } else if (result == 1) { if(pCoexDm->curPsTdma == 11) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9); pCoexDm->psTdmaDuAdjType = 9; } else if(pCoexDm->curPsTdma == 9) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2); pCoexDm->psTdmaDuAdjType = 2; } else if(pCoexDm->curPsTdma == 2) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1); pCoexDm->psTdmaDuAdjType = 1; } } // error handle, if not in the following state, // set psTdma again. if( (pCoexDm->psTdmaDuAdjType != 1) && (pCoexDm->psTdmaDuAdjType != 2) && (pCoexDm->psTdmaDuAdjType != 9) && (pCoexDm->psTdmaDuAdjType != 11) ) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n")); halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2); pCoexDm->psTdmaDuAdjType = 2; } } } } // if current PsTdma not match with the recorded one (when scan, dhcp...), // then we have to adjust it back to the previous record one. if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType) { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType)); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink); pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam); if( !bScan && !bLink && !bRoam) { halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType); } else { BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n")); } } pCoexDm->psTdmaMonitorCnt++; }