1 //============================================================
4 // This file is for RTL8703B Co-exist mechanism
7 // 2012/11/15 Cosa first check in.
9 //============================================================
11 //============================================================
13 //============================================================
14 #include "Mp_Precomp.h"
16 #if WPP_SOFTWARE_TRACE
17 #include "HalBtc8703b1Ant.tmh"
20 #if (RTL8703B_SUPPORT == 1)
22 #if(BT_30_SUPPORT == 1)
23 //============================================================
24 // Global variables, these are static variables
25 //============================================================
26 static COEX_DM_8703B_1ANT GLCoexDm8703b1Ant;
27 static PCOEX_DM_8703B_1ANT pCoexDm=&GLCoexDm8703b1Ant;
28 static COEX_STA_8703B_1ANT GLCoexSta8703b1Ant;
29 static PCOEX_STA_8703B_1ANT pCoexSta=&GLCoexSta8703b1Ant;
30 static PSDSCAN_STA_8703B_1ANT GLPsdScan8703b1Ant;
31 static PPSDSCAN_STA_8703B_1ANT pPsdScan = &GLPsdScan8703b1Ant;
34 const char *const GLBtInfoSrc8703b1Ant[]={
37 "BT Info[bt auto report]",
40 u4Byte GLCoexVerDate8703b1Ant=20150904;
41 u4Byte GLCoexVer8703b1Ant=0x04;
43 //============================================================
44 // local function proto type if needed
45 //============================================================
46 //============================================================
47 // local function start with halbtc8703b1ant_
48 //============================================================
50 halbtc8703b1ant_BtRssiState(
57 u1Byte btRssiState=pCoexSta->preBtRssiState;
59 btRssi = pCoexSta->btRssi;
63 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
64 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
66 if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
68 btRssiState = BTC_RSSI_STATE_HIGH;
72 btRssiState = BTC_RSSI_STATE_STAY_LOW;
77 if(btRssi < rssiThresh)
79 btRssiState = BTC_RSSI_STATE_LOW;
83 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
87 else if(levelNum == 3)
89 if(rssiThresh > rssiThresh1)
91 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));
92 return pCoexSta->preBtRssiState;
95 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
96 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
98 if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
100 btRssiState = BTC_RSSI_STATE_MEDIUM;
104 btRssiState = BTC_RSSI_STATE_STAY_LOW;
107 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
108 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
110 if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
112 btRssiState = BTC_RSSI_STATE_HIGH;
114 else if(btRssi < rssiThresh)
116 btRssiState = BTC_RSSI_STATE_LOW;
120 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
125 if(btRssi < rssiThresh1)
127 btRssiState = BTC_RSSI_STATE_MEDIUM;
131 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
136 pCoexSta->preBtRssiState = btRssiState;
142 halbtc8703b1ant_WifiRssiState(
143 IN PBTC_COEXIST pBtCoexist,
146 IN u1Byte rssiThresh,
147 IN u1Byte rssiThresh1
151 u1Byte wifiRssiState=pCoexSta->preWifiRssiState[index];
153 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
157 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
158 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
160 if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
162 wifiRssiState = BTC_RSSI_STATE_HIGH;
166 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
171 if(wifiRssi < rssiThresh)
173 wifiRssiState = BTC_RSSI_STATE_LOW;
177 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
181 else if(levelNum == 3)
183 if(rssiThresh > rssiThresh1)
185 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
186 return pCoexSta->preWifiRssiState[index];
189 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
190 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
192 if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
194 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
198 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
201 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
202 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
204 if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
206 wifiRssiState = BTC_RSSI_STATE_HIGH;
208 else if(wifiRssi < rssiThresh)
210 wifiRssiState = BTC_RSSI_STATE_LOW;
214 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
219 if(wifiRssi < rssiThresh1)
221 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
225 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
230 pCoexSta->preWifiRssiState[index] = wifiRssiState;
232 return wifiRssiState;
236 halbtc8703b1ant_UpdateRaMask(
237 IN PBTC_COEXIST pBtCoexist,
238 IN BOOLEAN bForceExec,
239 IN u4Byte disRateMask
242 pCoexDm->curRaMask = disRateMask;
244 if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
246 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);
248 pCoexDm->preRaMask = pCoexDm->curRaMask;
252 halbtc8703b1ant_AutoRateFallbackRetry(
253 IN PBTC_COEXIST pBtCoexist,
254 IN BOOLEAN bForceExec,
258 BOOLEAN bWifiUnderBMode=FALSE;
260 pCoexDm->curArfrType = type;
262 if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))
264 switch(pCoexDm->curArfrType)
266 case 0: // normal mode
267 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);
268 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);
271 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
274 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
275 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
279 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
280 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
288 pCoexDm->preArfrType = pCoexDm->curArfrType;
292 halbtc8703b1ant_RetryLimit(
293 IN PBTC_COEXIST pBtCoexist,
294 IN BOOLEAN bForceExec,
298 pCoexDm->curRetryLimitType = type;
300 if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))
302 switch(pCoexDm->curRetryLimitType)
304 case 0: // normal mode
305 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);
307 case 1: // retry limit=8
308 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
315 pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
319 halbtc8703b1ant_AmpduMaxTime(
320 IN PBTC_COEXIST pBtCoexist,
321 IN BOOLEAN bForceExec,
325 pCoexDm->curAmpduTimeType = type;
327 if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))
329 switch(pCoexDm->curAmpduTimeType)
331 case 0: // normal mode
332 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);
334 case 1: // AMPDU timw = 0x38 * 32us
335 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
342 pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
346 halbtc8703b1ant_LimitedTx(
347 IN PBTC_COEXIST pBtCoexist,
348 IN BOOLEAN bForceExec,
349 IN u1Byte raMaskType,
351 IN u1Byte retryLimitType,
352 IN u1Byte ampduTimeType
357 case 0: // normal mode
358 halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
360 case 1: // disable cck 1/2
361 halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
363 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4
364 halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
370 halbtc8703b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
371 halbtc8703b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
372 halbtc8703b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
376 halbtc8703b1ant_LimitedRx(
377 IN PBTC_COEXIST pBtCoexist,
378 IN BOOLEAN bForceExec,
379 IN BOOLEAN bRejApAggPkt,
380 IN BOOLEAN bBtCtrlAggBufSize,
384 BOOLEAN bRejectRxAgg=bRejApAggPkt;
385 BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;
386 u1Byte rxAggSize=aggBufSize;
388 //============================================
389 // Rx Aggregation related setting
390 //============================================
391 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
392 // decide BT control aggregation buf size or not
393 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
394 // aggregation buf size, only work when BT control Rx aggregation size.
395 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
396 // real update aggregation setting
397 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
403 halbtc8703b1ant_QueryBtInfo(
404 IN PBTC_COEXIST pBtCoexist
407 u1Byte H2C_Parameter[1] ={0};
409 pCoexSta->bC2hBtInfoReqSent = TRUE;
411 H2C_Parameter[0] |= BIT0; // trigger
413 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n",
416 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
420 halbtc8703b1ant_MonitorBtCtr(
421 IN PBTC_COEXIST pBtCoexist
424 u4Byte regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;
425 u4Byte regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
426 u1Byte u1Tmp, u1Tmp1;
428 static u1Byte NumOfBtCounterChk = 0;
430 //to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS
431 //if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) )
433 if (pCoexSta->bUnderIps)
435 //pCoexSta->highPriorityTx = 65535;
436 //pCoexSta->highPriorityRx = 65535;
437 //pCoexSta->lowPriorityTx = 65535;
438 //pCoexSta->lowPriorityRx = 65535;
445 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
446 regHPTx = u4Tmp & bMaskLWord;
447 regHPRx = (u4Tmp & bMaskHWord)>>16;
449 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
450 regLPTx = u4Tmp & bMaskLWord;
451 regLPRx = (u4Tmp & bMaskHWord)>>16;
453 pCoexSta->highPriorityTx = regHPTx;
454 pCoexSta->highPriorityRx = regHPRx;
455 pCoexSta->lowPriorityTx = regLPTx;
456 pCoexSta->lowPriorityRx = regLPRx;
458 if( (pCoexSta->lowPriorityTx > 1150) && (!pCoexSta->bC2hBtInquiryPage))
459 pCoexSta->popEventCnt++;
461 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
462 regHPRx, regHPTx, regLPRx, regLPTx));
465 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
467 if ((regHPTx == 0) && (regHPRx ==0) && (regLPTx == 0) && (regLPRx == 0))
470 if (NumOfBtCounterChk >= 3)
472 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
473 NumOfBtCounterChk = 0;
480 halbtc8703b1ant_MonitorWiFiCtr(
481 IN PBTC_COEXIST pBtCoexist
487 BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;
488 static u1Byte nCCKLockCounter = 0;
491 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
492 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
493 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
495 if (pCoexSta->bUnderIps)
497 pCoexSta->nCRCOK_CCK = 0;
498 pCoexSta->nCRCOK_11g = 0;
499 pCoexSta->nCRCOK_11n = 0;
500 pCoexSta->nCRCOK_11nAgg = 0;
502 pCoexSta->nCRCErr_CCK = 0;
503 pCoexSta->nCRCErr_11g = 0;
504 pCoexSta->nCRCErr_11n = 0;
505 pCoexSta->nCRCErr_11nAgg = 0;
509 pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
510 pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
511 pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
512 pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
514 pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
515 pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
516 pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
517 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
522 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
523 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
525 if ( (bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))
527 TotalCnt = pCoexSta->nCRCOK_CCK + pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n +
528 pCoexSta->nCRCOK_11nAgg;
530 if ( (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_BUSY) ||
531 (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
532 (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_SCO_BUSY) )
534 if (pCoexSta->nCRCOK_CCK >(TotalCnt -pCoexSta->nCRCOK_CCK))
536 if (nCCKLockCounter < 3)
541 if (nCCKLockCounter > 0)
548 if (nCCKLockCounter > 0)
554 if (nCCKLockCounter > 0)
558 if (!pCoexSta->bPreCCKLock)
561 if (nCCKLockCounter >= 3)
562 pCoexSta->bCCKLock = TRUE;
564 pCoexSta->bCCKLock = FALSE;
568 if (nCCKLockCounter == 0)
569 pCoexSta->bCCKLock = FALSE;
571 pCoexSta->bCCKLock = TRUE;
574 if (pCoexSta->bCCKLock)
575 pCoexSta->bCCKEverLock = TRUE;
577 pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
583 halbtc8703b1ant_IsWifiStatusChanged(
584 IN PBTC_COEXIST pBtCoexist
587 static BOOLEAN bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
588 BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
589 BOOLEAN bWifiConnected=FALSE;
591 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
592 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
593 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
594 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
598 if(bWifiBusy != bPreWifiBusy)
600 bPreWifiBusy = bWifiBusy;
603 if(bUnder4way != bPreUnder4way)
605 bPreUnder4way = bUnder4way;
608 if(bBtHsOn != bPreBtHsOn)
610 bPreBtHsOn = bBtHsOn;
619 halbtc8703b1ant_UpdateBtLinkInfo(
620 IN PBTC_COEXIST pBtCoexist
623 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
624 BOOLEAN bBtHsOn=FALSE;
626 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
628 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
629 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
630 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
631 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
632 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
633 pBtLinkInfo->bBtHiPriLinkExist = pCoexSta->bBtHiPriLinkExist;
635 // work around for HS mode.
638 pBtLinkInfo->bPanExist = TRUE;
639 pBtLinkInfo->bBtLinkExist = TRUE;
643 if( pBtLinkInfo->bScoExist &&
644 !pBtLinkInfo->bA2dpExist &&
645 !pBtLinkInfo->bPanExist &&
646 !pBtLinkInfo->bHidExist )
647 pBtLinkInfo->bScoOnly = TRUE;
649 pBtLinkInfo->bScoOnly = FALSE;
651 // check if A2dp only
652 if( !pBtLinkInfo->bScoExist &&
653 pBtLinkInfo->bA2dpExist &&
654 !pBtLinkInfo->bPanExist &&
655 !pBtLinkInfo->bHidExist )
656 pBtLinkInfo->bA2dpOnly = TRUE;
658 pBtLinkInfo->bA2dpOnly = FALSE;
661 if( !pBtLinkInfo->bScoExist &&
662 !pBtLinkInfo->bA2dpExist &&
663 pBtLinkInfo->bPanExist &&
664 !pBtLinkInfo->bHidExist )
665 pBtLinkInfo->bPanOnly = TRUE;
667 pBtLinkInfo->bPanOnly = FALSE;
670 if( !pBtLinkInfo->bScoExist &&
671 !pBtLinkInfo->bA2dpExist &&
672 !pBtLinkInfo->bPanExist &&
673 pBtLinkInfo->bHidExist )
674 pBtLinkInfo->bHidOnly = TRUE;
676 pBtLinkInfo->bHidOnly = FALSE;
680 halbtc8703b1ant_UpdateWifiChannelInfo(
681 IN PBTC_COEXIST pBtCoexist,
685 u1Byte H2C_Parameter[3] ={0};
687 u1Byte wifiCentralChnl;
688 BOOLEAN bWifiUnderBMode = FALSE;
690 // only 2.4G we need to inform bt the chnl mask
691 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
692 if( (BTC_MEDIA_CONNECT == type) &&
693 (wifiCentralChnl <= 14) )
695 H2C_Parameter[0] = 0x1; //enable BT AFH skip WL channel for 8703b because BT Rx LO interference
696 //H2C_Parameter[0] = 0x0;
697 H2C_Parameter[1] = wifiCentralChnl;
698 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
699 if(BTC_WIFI_BW_HT40 == wifiBw)
700 H2C_Parameter[2] = 0x30;
702 H2C_Parameter[2] = 0x20;
705 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
706 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
707 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
709 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n",
710 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
712 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
717 halbtc8703b1ant_ActionAlgorithm(
718 IN PBTC_COEXIST pBtCoexist
721 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
722 BOOLEAN bBtHsOn=FALSE;
723 u1Byte algorithm=BT_8703B_1ANT_COEX_ALGO_UNDEFINED;
724 u1Byte numOfDiffProfile=0;
726 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
728 if(!pBtLinkInfo->bBtLinkExist)
730 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
734 if(pBtLinkInfo->bScoExist)
736 if(pBtLinkInfo->bHidExist)
738 if(pBtLinkInfo->bPanExist)
740 if(pBtLinkInfo->bA2dpExist)
743 if(numOfDiffProfile == 1)
745 if(pBtLinkInfo->bScoExist)
747 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO only\n"));
748 algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
752 if(pBtLinkInfo->bHidExist)
754 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID only\n"));
755 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
757 else if(pBtLinkInfo->bA2dpExist)
759 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP only\n"));
760 algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP;
762 else if(pBtLinkInfo->bPanExist)
766 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(HS) only\n"));
767 algorithm = BT_8703B_1ANT_COEX_ALGO_PANHS;
771 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(EDR) only\n"));
772 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR;
777 else if(numOfDiffProfile == 2)
779 if(pBtLinkInfo->bScoExist)
781 if(pBtLinkInfo->bHidExist)
783 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID\n"));
784 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
786 else if(pBtLinkInfo->bA2dpExist)
788 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));
789 algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
791 else if(pBtLinkInfo->bPanExist)
795 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));
796 algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
800 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));
801 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
807 if( pBtLinkInfo->bHidExist &&
808 pBtLinkInfo->bA2dpExist )
810 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP\n"));
811 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
813 else if( pBtLinkInfo->bHidExist &&
814 pBtLinkInfo->bPanExist )
818 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));
819 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
823 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));
824 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
827 else if( pBtLinkInfo->bPanExist &&
828 pBtLinkInfo->bA2dpExist )
832 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));
833 algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS;
837 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));
838 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP;
843 else if(numOfDiffProfile == 3)
845 if(pBtLinkInfo->bScoExist)
847 if( pBtLinkInfo->bHidExist &&
848 pBtLinkInfo->bA2dpExist )
850 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));
851 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
853 else if( pBtLinkInfo->bHidExist &&
854 pBtLinkInfo->bPanExist )
858 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));
859 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
863 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));
864 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
867 else if( pBtLinkInfo->bPanExist &&
868 pBtLinkInfo->bA2dpExist )
872 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));
873 algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
877 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));
878 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
884 if( pBtLinkInfo->bHidExist &&
885 pBtLinkInfo->bPanExist &&
886 pBtLinkInfo->bA2dpExist )
890 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));
891 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
895 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));
896 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
901 else if(numOfDiffProfile >= 3)
903 if(pBtLinkInfo->bScoExist)
905 if( pBtLinkInfo->bHidExist &&
906 pBtLinkInfo->bPanExist &&
907 pBtLinkInfo->bA2dpExist )
911 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));
916 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
917 algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
927 halbtc8703b1ant_SetBtAutoReport(
928 IN PBTC_COEXIST pBtCoexist,
929 IN BOOLEAN bEnableAutoReport
932 u1Byte H2C_Parameter[1] ={0};
934 H2C_Parameter[0] = 0;
936 if(bEnableAutoReport)
938 H2C_Parameter[0] |= BIT0;
941 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n",
942 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));
944 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);
948 halbtc8703b1ant_BtAutoReport(
949 IN PBTC_COEXIST pBtCoexist,
950 IN BOOLEAN bForceExec,
951 IN BOOLEAN bEnableAutoReport
954 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",
955 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));
956 pCoexDm->bCurBtAutoReport = bEnableAutoReport;
960 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport)
963 halbtc8703b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);
965 pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;
968 VOID halbtc8703b1ant_WriteScoreBoard(
969 IN PBTC_COEXIST pBtCoexist,
970 IN u2Byte scoreboardval
975 val = (scoreboardval & 0x7fff) | 0x8000;
977 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0xaa, val);
980 u1Byte H2C_Parameter[3] ={0,0,0};
983 // write "Set Status"
984 H2C_Parameter[0] = 0x2;
986 // write score board 15-bit value to H2C parameter
987 H2C_Parameter[1] = scoreboardval & 0xff;
988 H2C_Parameter[2] = (scoreboardval & 0x7f00) >> 8;
990 // Set Interrupt to BT
991 H2C_Parameter[2] = H2C_Parameter[2] | 0x80;
993 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Write BT Scoreboard: H2C 0x71[1:0]= %02x%02x\n",
994 H2C_Parameter[2], H2C_Parameter[1]));
996 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x71, 3, H2C_Parameter);
1001 VOID halbtc8703b1ant_ReadScoreBoard(
1002 IN PBTC_COEXIST pBtCoexist,
1003 IN u2Byte* uScoreBoardVal
1007 *uScoreBoardVal = (pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xaa)) & 0x7fff;
1012 u1Byte H2C_Parameter[3] ={0,0,0};
1014 // write "Get Status"
1015 H2C_Parameter[0] = 0x1;
1017 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Read BT Scoreboard!!\n"));
1019 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x71, 3, H2C_Parameter);
1021 //the BT Scoreboard will be returned by C2H from EXhalbtc8703b1ant_ScoreBoardStatusNotify()
1025 VOID halbtc8703b1ant_PostActiveStateToBT(
1026 IN PBTC_COEXIST pBtCoexist,
1027 IN BOOLEAN bWifiActive
1033 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Post WL = Active in Scoreboard!!\n"));
1034 halbtc8703b1ant_WriteScoreBoard(pBtCoexist, 0x0001);
1038 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Post WL = Non-Active in Scoreboard!!\n"));
1039 halbtc8703b1ant_WriteScoreBoard(pBtCoexist, 0x0000);
1042 // The BT should set "No Shunt-down" mode if WL = Active for BT Synthesizer on/off interference WL Lo issue at 8703b b-cut.
1047 halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(
1048 IN PBTC_COEXIST pBtCoexist,
1049 IN BOOLEAN bLowPenaltyRa
1052 u1Byte H2C_Parameter[6] ={0};
1054 H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty
1058 H2C_Parameter[1] |= BIT0;
1059 H2C_Parameter[2] = 0x00; //normal rate except MCS7/6/5, OFDM54/48/36
1060 H2C_Parameter[3] = 0xf7; //MCS7 or OFDM54
1061 H2C_Parameter[4] = 0xf8; //MCS6 or OFDM48
1062 H2C_Parameter[5] = 0xf9; //MCS5 or OFDM36
1065 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s",
1066 (bLowPenaltyRa? "ON!!":"OFF!!") ));
1068 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
1072 halbtc8703b1ant_LowPenaltyRa(
1073 IN PBTC_COEXIST pBtCoexist,
1074 IN BOOLEAN bForceExec,
1075 IN BOOLEAN bLowPenaltyRa
1078 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
1082 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
1085 halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
1087 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
1091 halbtc8703b1ant_LTECoex_InDirectReadReg(
1092 IN PBTC_COEXIST pBtCoexist,
1099 //wait for ready bit before access 0x7c0
1100 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0x800F0000|RegAddr);
1105 }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1108 return(pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x7c8)); //get read data
1113 halbtc8703b1ant_LTECoex_InDirectWriteReg(
1114 IN PBTC_COEXIST pBtCoexist,
1120 u4Byte val, i=0, j=0, bitpos = 0;
1125 if (BitMask == 0xffffffff)
1127 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, RegValue); //put write data
1129 //wait for ready bit before access 0x7c0
1133 }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1136 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
1140 for(i=0; i<=31; i++)
1142 if ( ((BitMask >> i) & 0x1) == 0x1)
1149 //read back register value before write
1150 val = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, RegAddr);
1151 val = (val & (~BitMask)) | (RegValue << bitpos);
1153 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, val); //put write data
1155 //wait for ready bit before access 0x7c0
1159 }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1162 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
1169 halbtc8703b1ant_LTECoex_Enable(
1170 IN PBTC_COEXIST pBtCoexist,
1176 val = (bEnable)? 1 : 0;
1177 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, 0x80, val); //0x38[7]
1182 halbtc8703b1ant_LTECoex_PathControlOwner(
1183 IN PBTC_COEXIST pBtCoexist,
1184 IN BOOLEAN bWiFiControl
1189 val = (bWiFiControl)? 1 : 0;
1190 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x4, val); //0x70[26]
1195 halbtc8703b1ant_LTECoex_Set_GNT_BT(
1196 IN PBTC_COEXIST pBtCoexist,
1197 IN u1Byte nControlBlock,
1198 IN BOOLEAN bSWControl,
1202 u4Byte val=0, BitMask;
1204 nState = nState & 0x1;
1205 val = (bSWControl)? ((nState<<1) | 0x1) : 0;
1207 switch(nControlBlock)
1209 case BT_8703B_1ANT_GNT_BLOCK_RFC_BB:
1212 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
1214 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]
1216 case BT_8703B_1ANT_GNT_BLOCK_RFC:
1218 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
1220 case BT_8703B_1ANT_GNT_BLOCK_BB:
1222 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]
1230 halbtc8703b1ant_LTECoex_Set_GNT_WL(
1231 IN PBTC_COEXIST pBtCoexist,
1232 IN u1Byte nControlBlock,
1233 IN BOOLEAN bSWControl,
1237 u4Byte val=0, BitMask;
1239 nState = nState & 0x1;
1240 val = (bSWControl)? ((nState<<1) | 0x1) : 0;
1242 switch(nControlBlock)
1244 case BT_8703B_1ANT_GNT_BLOCK_RFC_BB:
1247 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
1249 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]
1251 case BT_8703B_1ANT_GNT_BLOCK_RFC:
1253 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
1255 case BT_8703B_1ANT_GNT_BLOCK_BB:
1257 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]
1265 halbtc8703b1ant_LTECoex_Set_CoexTable(
1266 IN PBTC_COEXIST pBtCoexist,
1267 IN u1Byte nTableType,
1268 IN u2Byte nTableContent
1271 u2Byte RegAddr = 0x0000;
1275 case BT_8703B_1ANT_CTT_WL_VS_LTE:
1278 case BT_8703B_1ANT_CTT_BT_VS_LTE:
1283 if (RegAddr != 0x0000)
1284 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xffff, nTableContent); // 0xa0[15:0] or 0xa4[15:0]
1291 halbtc8703b1ant_LTECoex_Set_BreakTable(
1292 IN PBTC_COEXIST pBtCoexist,
1293 IN u1Byte nTableType,
1294 IN u1Byte nTableContent
1297 u2Byte RegAddr = 0x0000;
1301 case BT_8703B_1ANT_LBTT_WL_BREAK_LTE:
1304 case BT_8703B_1ANT_LBTT_BT_BREAK_LTE:
1307 case BT_8703B_1ANT_LBTT_LTE_BREAK_WL:
1310 case BT_8703B_1ANT_LBTT_LTE_BREAK_BT:
1315 if (RegAddr != 0x0000)
1316 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xff, nTableContent); // 0xa8[15:0] or 0xb4[15:0]
1322 halbtc8703b1ant_SetCoexTable(
1323 IN PBTC_COEXIST pBtCoexist,
1330 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
1331 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
1333 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
1334 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
1336 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
1337 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
1339 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
1340 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
1344 halbtc8703b1ant_CoexTable(
1345 IN PBTC_COEXIST pBtCoexist,
1346 IN BOOLEAN bForceExec,
1353 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n",
1354 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));
1355 pCoexDm->curVal0x6c0 = val0x6c0;
1356 pCoexDm->curVal0x6c4 = val0x6c4;
1357 pCoexDm->curVal0x6c8 = val0x6c8;
1358 pCoexDm->curVal0x6cc = val0x6cc;
1362 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1363 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1364 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1365 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
1368 halbtc8703b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1370 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1371 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1372 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1373 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1377 halbtc8703b1ant_CoexTableWithType(
1378 IN PBTC_COEXIST pBtCoexist,
1379 IN BOOLEAN bForceExec,
1383 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1386 u1Byte nSelectTable;
1389 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));
1391 pCoexSta->nCoexTableType = type;
1393 if (pCoexSta->bConCurrentRxModeOn == TRUE)
1395 nBreakTable = 0xf0ffffff; //set WL hi-pri can break BT
1396 nSelectTable = 0xb; //set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS)
1400 nBreakTable = 0xffffff;
1407 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, nBreakTable, nSelectTable);
1410 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, nBreakTable, nSelectTable);
1413 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa5a5a5a, 0xaa5a5a5a, nBreakTable, nSelectTable);
1416 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
1419 //if ( (pCoexSta->bCCKEverLock) && (pCoexSta->nScanAPNum <= 5) )
1420 // halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
1422 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
1425 //if ( (pCoexSta->bCCKEverLock) && (pCoexSta->nScanAPNum <= 5) )
1426 // halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
1428 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, nBreakTable, nSelectTable);
1431 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, nBreakTable, nSelectTable);
1434 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, nBreakTable, nSelectTable);
1437 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1440 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1443 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1446 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1449 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1452 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, nBreakTable, nSelectTable);
1455 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, nBreakTable, nSelectTable);
1458 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, nBreakTable, nSelectTable);
1466 halbtc8703b1ant_SetFwIgnoreWlanAct(
1467 IN PBTC_COEXIST pBtCoexist,
1471 u1Byte H2C_Parameter[1] ={0};
1475 H2C_Parameter[0] |= BIT0; // function enable
1478 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
1481 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1485 halbtc8703b1ant_IgnoreWlanAct(
1486 IN PBTC_COEXIST pBtCoexist,
1487 IN BOOLEAN bForceExec,
1491 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
1492 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));
1493 pCoexDm->bCurIgnoreWlanAct = bEnable;
1497 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1500 halbtc8703b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1502 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1506 halbtc8703b1ant_SetLpsRpwm(
1507 IN PBTC_COEXIST pBtCoexist,
1513 u1Byte rpwm=rpwmVal;
1515 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
1516 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1520 halbtc8703b1ant_LpsRpwm(
1521 IN PBTC_COEXIST pBtCoexist,
1522 IN BOOLEAN bForceExec,
1527 BOOLEAN bForceExecPwrCmd=FALSE;
1529 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n",
1530 (bForceExec? "force to":""), lpsVal, rpwmVal));
1531 pCoexDm->curLps = lpsVal;
1532 pCoexDm->curRpwm = rpwmVal;
1536 if( (pCoexDm->preLps == pCoexDm->curLps) &&
1537 (pCoexDm->preRpwm == pCoexDm->curRpwm) )
1542 halbtc8703b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1544 pCoexDm->preLps = pCoexDm->curLps;
1545 pCoexDm->preRpwm = pCoexDm->curRpwm;
1549 halbtc8703b1ant_SwMechanism(
1550 IN PBTC_COEXIST pBtCoexist,
1551 IN BOOLEAN bLowPenaltyRA
1554 halbtc8703b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1558 halbtc8703b1ant_SetAntPath(
1559 IN PBTC_COEXIST pBtCoexist,
1560 IN u1Byte antPosType,
1561 IN BOOLEAN bForceExec,
1562 IN BOOLEAN bInitHwCfg,
1566 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1567 u4Byte fwVer=0, u4Tmp=0, cntBtCalChk=0;
1568 BOOLEAN bPgExtSwitch=FALSE;
1569 BOOLEAN bUseExtSwitch=FALSE;
1570 BOOLEAN bIsInMpMode = FALSE;
1571 u1Byte H2C_Parameter[2] ={0}, u1Tmp = 0;
1572 u4Byte u4Tmp1=0, u4Tmp2=0;
1574 pCoexDm->curAntPosType = antPosType;
1577 u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
1578 u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
1579 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
1581 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Setup) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1586 //Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required)
1587 halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
1589 //GNT_WL_LTE always = 1 (this should be config if LTE coex is required)
1590 halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, BT_8703B_1ANT_CTT_WL_VS_LTE, 0xffff);
1592 //GNT_BT_LTE always = 1 (this should be config if LTE coex is required)
1593 halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, BT_8703B_1ANT_CTT_BT_VS_LTE, 0xffff);
1595 // Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware)
1596 while(cntBtCalChk <= 20)
1598 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
1602 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", cntBtCalChk));
1607 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", cntBtCalChk));
1612 //set Path control owner to WL at initial step
1613 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);
1617 //Disable LTE Coex Function in WiFi side
1618 halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
1621 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
1623 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE); //set Path control owner to WiFI
1625 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_BTSIDE);//set Path control owner to BT
1629 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);
1633 if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType) || bInitHwCfg || bWifiOff)
1635 // internal switch setting
1638 case BTC_ANT_PATH_WIFI:
1639 // set GNT_BT to low
1640 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
1641 //Set GNT_WL to high
1642 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
1644 case BTC_ANT_PATH_BT:
1645 // set GNT_BT to high
1646 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
1648 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
1651 case BTC_ANT_PATH_PTA:
1652 // set GNT_BT to PTA
1653 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, BT_8703B_1ANT_SIG_STA_SET_BY_HW);
1655 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, BT_8703B_1ANT_SIG_STA_SET_BY_HW);
1661 u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
1662 u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
1663 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
1667 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Init) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1671 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After WiFi off) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1675 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Run time) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1679 pCoexDm->preAntPosType = pCoexDm->curAntPosType;
1684 halbtc8703b1ant_SetFwPstdma(
1685 IN PBTC_COEXIST pBtCoexist,
1693 u1Byte H2C_Parameter[5] ={0};
1694 u1Byte realByte1=byte1, realByte5=byte5;
1695 BOOLEAN bApEnable=FALSE;
1697 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1701 if(byte1&BIT4 && !(byte1&BIT5))
1703 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
1712 H2C_Parameter[0] = realByte1;
1713 H2C_Parameter[1] = byte2;
1714 H2C_Parameter[2] = byte3;
1715 H2C_Parameter[3] = byte4;
1716 H2C_Parameter[4] = realByte5;
1718 pCoexDm->psTdmaPara[0] = realByte1;
1719 pCoexDm->psTdmaPara[1] = byte2;
1720 pCoexDm->psTdmaPara[2] = byte3;
1721 pCoexDm->psTdmaPara[3] = byte4;
1722 pCoexDm->psTdmaPara[4] = realByte5;
1724 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
1726 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1728 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1733 halbtc8703b1ant_PsTdma(
1734 IN PBTC_COEXIST pBtCoexist,
1735 IN BOOLEAN bForceExec,
1740 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1741 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
1742 BOOLEAN bTurnOnByCnt=FALSE, bWifiBusy=FALSE, bWiFiNoisy=FALSE;
1743 u1Byte psTdmaTypeByCnt=0, rssiAdjustVal=0;
1744 u1Byte psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
1745 s1Byte nWiFiDurationAdjust = 0x0;
1746 static BOOLEAN bPreWifiBusy=FALSE;
1748 pCoexDm->bCurPsTdmaOn = bTurnOn;
1749 pCoexDm->curPsTdma = type;
1751 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1753 if (bWifiBusy != bPreWifiBusy)
1756 bPreWifiBusy = bWifiBusy;
1759 if (pCoexDm->bCurPsTdmaOn)
1761 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n",
1762 pCoexDm->curPsTdma));
1766 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(off, %d) **********\n",
1767 pCoexDm->curPsTdma));
1772 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1773 (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
1777 // Adjust WiFi slot by AP number
1778 if (pCoexSta->nScanAPNum <= 5)
1779 nWiFiDurationAdjust = 5;
1780 else if (pCoexSta->nScanAPNum >= 40)
1781 nWiFiDurationAdjust = -15;
1782 else if (pCoexSta->nScanAPNum >= 20)
1783 nWiFiDurationAdjust = -10;
1785 // for A2DP only case, PS-TDMA/ TDMA
1786 if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || (type == 101)
1787 || (type == 102) || (type == 109) || (type == 101) || (type == 7) )
1789 if (!pCoexSta->bForceLpsOn) //Native power save TDMA, only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30
1791 psTdmaByte0Val = 0x61; //no null-pkt (TDMA)
1792 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1795 psTdmaByte4Val = 0x14; //BT-Auto-Slot
1797 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1801 psTdmaByte0Val = 0x51; //null-pkt (PS-TDMA)
1802 psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1805 psTdmaByte4Val = 0x14; //BT-Auto-Slot
1807 psTdmaByte4Val = 0x50; // 0x778 = d/1 toggle, dynamic slot
1810 else if ((type == 3) ||(type == 4) || (type == 13) || (type == 14) || (type == 103) || (type == 113) || (type == 114))
1812 psTdmaByte0Val = 0x51; //null-pkt (PS-TDMA)
1813 psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1814 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1816 else //native power save case
1818 psTdmaByte0Val = 0x61; //no null-pkt (TDMA)
1819 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1820 psTdmaByte4Val = 0x11; // 0x778 = d/1 toggle, no dynamic slot
1821 //psTdmaByte4Va is not defne for 0x778 = d/1, 1/1 case
1825 if ((pBtLinkInfo->bSlaveRole == TRUE) && (pBtLinkInfo->bA2dpExist))
1826 psTdmaByte4Val = psTdmaByte4Val | 0x1; //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1828 // (for Antenna Detection Mechanism)
1831 psTdmaByte0Val = psTdmaByte0Val | 0x82; //set antenna control by SW
1832 psTdmaByte3Val = psTdmaByte3Val | 0x60; //set antenna no toggle, control by antenna diversity
1841 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);
1844 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1847 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1850 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1853 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1856 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1859 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1862 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x1e, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1865 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1e, 0x3, 0x10, 0x14);
1868 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1871 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1874 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1877 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);
1880 if (pCoexSta->nScanAPNum <= 3) // for Lenovo CPT test A2DP + OPP
1881 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1883 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1886 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1889 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);
1892 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);
1895 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1898 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1901 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);
1904 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1907 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);
1910 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);
1913 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1916 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1919 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);
1922 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);
1925 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);
1928 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);
1931 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);
1934 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1937 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, 0x10);
1940 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);
1943 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);
1946 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);
1948 case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving
1949 /* here softap mode screen off will cost 70-80mA for phone */
1950 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);
1953 // 1-Ant translate to 2-Ant (for Antenna Detection Mechanism)
1955 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1958 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1961 //halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, psTdmaByte4Val);
1962 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1965 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1968 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1971 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1974 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1977 //halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, psTdmaByte4Val);
1978 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1981 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1984 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1987 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1990 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1993 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x11);
2004 case 8: //PTA Control
2005 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
2008 default: //Software control, Antenna at BT side
2009 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
2011 case 1: // 2-Ant, 0x778=3, antenna control by antenna diversity
2012 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
2015 case 9: //Software control, Antenna at WiFi side
2016 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
2017 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);
2023 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);
2026 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2027 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67)));
2030 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
2031 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
2035 halbtc8703b1ant_IsCommonAction(
2036 IN PBTC_COEXIST pBtCoexist
2039 BOOLEAN bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
2041 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2042 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2044 if(!bWifiConnected &&
2045 BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
2047 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));
2049 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2053 else if(bWifiConnected &&
2054 (BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )
2056 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
2058 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2062 else if(!bWifiConnected &&
2063 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
2065 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));
2067 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2071 else if(bWifiConnected &&
2072 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
2074 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
2076 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2080 else if(!bWifiConnected &&
2081 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )
2083 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
2085 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2093 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
2097 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
2108 halbtc8703b1ant_TdmaDurationAdjustForAcl(
2109 IN PBTC_COEXIST pBtCoexist,
2110 IN u1Byte wifiStatus
2113 static s4Byte up,dn,m,n,WaitCount;
2114 s4Byte result; //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
2115 u1Byte retryCount=0, btInfoExt;
2116 static BOOLEAN bPreWifiBusy=FALSE;
2117 BOOLEAN bWifiBusy = FALSE;
2119 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));
2121 if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus)
2126 if( (BT_8703B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
2127 (BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
2128 (BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )
2130 if( pCoexDm->curPsTdma != 1 &&
2131 pCoexDm->curPsTdma != 2 &&
2132 pCoexDm->curPsTdma != 3 &&
2133 pCoexDm->curPsTdma != 9 )
2135 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2136 pCoexDm->psTdmaDuAdjType = 9;
2148 if(!pCoexDm->bAutoTdmaAdjust)
2150 pCoexDm->bAutoTdmaAdjust = TRUE;
2151 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
2153 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2154 pCoexDm->psTdmaDuAdjType = 2;
2165 //accquire the BT TRx retry count from BT_Info byte2
2166 retryCount = pCoexSta->btRetryCnt;
2167 btInfoExt = pCoexSta->btInfoExt;
2169 if ( (pCoexSta->lowPriorityTx) > 1050 || (pCoexSta->lowPriorityRx) > 1250 )
2175 if(retryCount == 0) // no retry in the last 2-second duration
2183 if(up >= n) // if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration
2190 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2193 else if (retryCount <= 3) // <=3 retry in the last 2-second duration
2201 if (dn == 2) // if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration
2204 m++; // ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^
2208 if ( m >= 20) //m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
2216 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
2219 else //retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration
2222 m++; // ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^
2226 if ( m >= 20) //m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
2234 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
2239 /* if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2240 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2242 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2243 pCoexDm->psTdmaDuAdjType = 9;
2245 else */ if(pCoexDm->curPsTdma == 1)
2247 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2248 pCoexDm->psTdmaDuAdjType = 2;
2250 else if(pCoexDm->curPsTdma == 2)
2252 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2253 pCoexDm->psTdmaDuAdjType = 9;
2255 else if(pCoexDm->curPsTdma == 9)
2257 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2258 pCoexDm->psTdmaDuAdjType = 11;
2261 else if(result == 1)
2263 /* if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2264 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2266 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2267 pCoexDm->psTdmaDuAdjType = 9;
2269 else */ if(pCoexDm->curPsTdma == 11)
2271 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2272 pCoexDm->psTdmaDuAdjType = 9;
2274 else if(pCoexDm->curPsTdma == 9)
2276 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2277 pCoexDm->psTdmaDuAdjType = 2;
2279 else if(pCoexDm->curPsTdma == 2)
2281 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2282 pCoexDm->psTdmaDuAdjType = 1;
2288 if(bWifiBusy != bPreWifiBusy) //if busy / idle change
2290 bPreWifiBusy = bWifiBusy;
2291 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);
2295 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n",
2296 pCoexDm->curPsTdma));
2299 if( pCoexDm->curPsTdma != 1 &&
2300 pCoexDm->curPsTdma != 2 &&
2301 pCoexDm->curPsTdma != 9 &&
2302 pCoexDm->curPsTdma != 11 )
2304 // recover to previous adjust type
2305 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
2311 halbtc8703b1ant_PsTdmaCheckForPowerSaveState(
2312 IN PBTC_COEXIST pBtCoexist,
2313 IN BOOLEAN bNewPsState
2318 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
2320 if(lpsMode) // already under LPS state
2324 // keep state under LPS, do nothing.
2328 // will leave LPS state, turn off psTdma first
2329 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2336 // will enter LPS state, turn off psTdma first
2337 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2341 // keep state under NO PS state, do nothing.
2347 halbtc8703b1ant_PowerSaveState(
2348 IN PBTC_COEXIST pBtCoexist,
2354 BOOLEAN bLowPwrDisable=FALSE;
2358 case BTC_PS_WIFI_NATIVE:
2359 // recover to original 32k low power setting
2360 pCoexSta->bForceLpsOn = FALSE;
2361 bLowPwrDisable = FALSE;
2362 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2363 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2367 pCoexSta->bForceLpsOn = TRUE;
2368 halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
2369 halbtc8703b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
2370 // when coex force to enter LPS, do not enter 32k low power.
2371 bLowPwrDisable = TRUE;
2372 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2373 // power save must executed before psTdma.
2374 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
2377 case BTC_PS_LPS_OFF:
2378 pCoexSta->bForceLpsOn = FALSE;
2379 halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
2380 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2389 halbtc8703b1ant_ActionWifiOnly(
2390 IN PBTC_COEXIST pBtCoexist
2393 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2394 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2395 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
2399 halbtc8703b1ant_MonitorBtEnableDisable(
2400 IN PBTC_COEXIST pBtCoexist
2403 static BOOLEAN bPreBtDisabled=FALSE;
2404 static u4Byte btDisableCnt=0;
2405 BOOLEAN bBtActive=TRUE, bBtDisabled=FALSE;
2407 // This function check if bt is disabled
2409 if( pCoexSta->highPriorityTx == 0 &&
2410 pCoexSta->highPriorityRx == 0 &&
2411 pCoexSta->lowPriorityTx == 0 &&
2412 pCoexSta->lowPriorityRx == 0)
2416 if( pCoexSta->highPriorityTx == 0xffff &&
2417 pCoexSta->highPriorityRx == 0xffff &&
2418 pCoexSta->lowPriorityTx == 0xffff &&
2419 pCoexSta->lowPriorityRx == 0xffff)
2426 bBtDisabled = FALSE;
2427 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
2428 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
2433 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n",
2435 if(btDisableCnt >= 2)
2438 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
2439 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
2440 halbtc8703b1ant_ActionWifiOnly(pBtCoexist);
2443 if(bPreBtDisabled != bBtDisabled)
2445 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n",
2446 (bPreBtDisabled ? "disabled":"enabled"),
2447 (bBtDisabled ? "disabled":"enabled")));
2448 bPreBtDisabled = bBtDisabled;
2454 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2455 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2460 //=============================================
2462 // Software Coex Mechanism start
2464 //=============================================
2466 // SCO only or SCO+PAN(HS)
2470 halbtc8703b1ant_ActionSco(
2471 IN PBTC_COEXIST pBtCoexist
2474 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2479 halbtc8703b1ant_ActionHid(
2480 IN PBTC_COEXIST pBtCoexist
2483 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2486 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
2488 halbtc8703b1ant_ActionA2dp(
2489 IN PBTC_COEXIST pBtCoexist
2492 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2496 halbtc8703b1ant_ActionA2dpPanHs(
2497 IN PBTC_COEXIST pBtCoexist
2500 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2504 halbtc8703b1ant_ActionPanEdr(
2505 IN PBTC_COEXIST pBtCoexist
2508 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2513 halbtc8703b1ant_ActionPanHs(
2514 IN PBTC_COEXIST pBtCoexist
2517 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2522 halbtc8703b1ant_ActionPanEdrA2dp(
2523 IN PBTC_COEXIST pBtCoexist
2526 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2530 halbtc8703b1ant_ActionPanEdrHid(
2531 IN PBTC_COEXIST pBtCoexist
2534 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2537 // HID+A2DP+PAN(EDR)
2539 halbtc8703b1ant_ActionHidA2dpPanEdr(
2540 IN PBTC_COEXIST pBtCoexist
2543 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2547 halbtc8703b1ant_ActionHidA2dp(
2548 IN PBTC_COEXIST pBtCoexist
2551 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2556 //=============================================
2558 // Non-Software Coex Mechanism start
2560 //=============================================
2562 halbtc8703b1ant_ActionBtWhckTest(
2563 IN PBTC_COEXIST pBtCoexist
2566 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2568 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2569 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2570 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2574 halbtc8703b1ant_ActionWifiMultiPort(
2575 IN PBTC_COEXIST pBtCoexist
2578 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2580 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2581 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2582 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2586 halbtc8703b1ant_ActionHs(
2587 IN PBTC_COEXIST pBtCoexist
2590 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2591 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2595 halbtc8703b1ant_ActionBtInquiry(
2596 IN PBTC_COEXIST pBtCoexist
2599 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2600 BOOLEAN bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;
2602 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2603 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2604 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2605 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
2607 if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )
2609 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2610 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2611 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2612 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2614 else if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
2616 // SCO/HID/A2DP busy
2617 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2618 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2620 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2622 else if ( (pBtLinkInfo->bPanExist) || (bWifiBusy) )
2624 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2626 //for BT inquiry/page fail after S4 resume
2627 //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2628 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2630 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2634 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2636 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2637 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2638 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2641 //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2642 //halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2647 halbtc8703b1ant_ActionBtScoHidOnlyBusy(
2648 IN PBTC_COEXIST pBtCoexist,
2649 IN u1Byte wifiStatus
2652 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2653 BOOLEAN bWifiConnected=FALSE;
2654 u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
2656 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2658 // tdma and coex table
2660 if(pBtLinkInfo->bScoExist)
2662 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2663 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2667 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2668 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2673 halbtc8703b1ant_ActionWifiConnectedBtAclBusy(
2674 IN PBTC_COEXIST pBtCoexist,
2675 IN u1Byte wifiStatus
2680 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2681 btRssiState = halbtc8703b1ant_BtRssiState(2, 28, 0);
2683 if ( (pCoexSta->lowPriorityRx >= 950) && (!pCoexSta->bUnderIps)
2684 && (pCoexSta->lowPriorityRx >= pCoexSta->lowPriorityTx) && (!pCoexSta->bC2hBtInquiryPage))
2686 pBtLinkInfo->bSlaveRole = TRUE;
2690 pBtLinkInfo->bSlaveRole = FALSE;
2693 if(pBtLinkInfo->bHidOnly) //HID
2695 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
2696 pCoexDm->bAutoTdmaAdjust = FALSE;
2699 else if(pBtLinkInfo->bA2dpOnly) //A2DP
2701 if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
2703 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2704 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2705 pCoexDm->bAutoTdmaAdjust = FALSE;
2709 //halbtc8703b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
2710 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2711 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2712 pCoexDm->bAutoTdmaAdjust = TRUE;
2715 else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||
2716 (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)
2718 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2719 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2720 pCoexDm->bAutoTdmaAdjust = FALSE;
2722 else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) //HID+A2DP
2724 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2725 pCoexDm->bAutoTdmaAdjust = FALSE;
2727 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2729 else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)
2731 if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
2732 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2734 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2736 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2737 pCoexDm->bAutoTdmaAdjust = FALSE;
2741 //BT no-profile busy (0x9)
2742 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);
2743 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2744 pCoexDm->bAutoTdmaAdjust = FALSE;
2749 halbtc8703b1ant_ActionWifiNotConnected(
2750 IN PBTC_COEXIST pBtCoexist
2754 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2756 // tdma and coex table
2757 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2758 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2759 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2763 halbtc8703b1ant_ActionWifiNotConnectedScan(
2764 IN PBTC_COEXIST pBtCoexist
2767 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2769 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2771 // tdma and coex table
2772 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2774 if (pBtLinkInfo->bA2dpExist)
2776 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2777 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2779 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2781 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2782 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2786 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2787 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2790 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2791 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2793 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2794 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2799 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2800 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2801 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2806 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(
2807 IN PBTC_COEXIST pBtCoexist
2810 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2812 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2814 // tdma and coex table
2815 if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
2817 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2818 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
2820 else if (pBtLinkInfo->bPanExist)
2822 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2823 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
2827 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2828 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2829 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 2);
2834 halbtc8703b1ant_ActionWifiConnectedScan(
2835 IN PBTC_COEXIST pBtCoexist
2838 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2840 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2842 // tdma and coex table
2843 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2845 if (pBtLinkInfo->bA2dpExist)
2847 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2848 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2850 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2852 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2853 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2857 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2858 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2861 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2862 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2864 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2865 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2870 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2871 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2872 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2877 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(
2878 IN PBTC_COEXIST pBtCoexist
2881 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2882 BOOLEAN bWifiBusy = FALSE;
2884 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2886 //no special packet process for both WiFi and BT very busy
2887 if ((bWifiBusy) && ((pBtLinkInfo->bPanExist) || (pCoexSta->nNumOfProfile >= 2)))
2890 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2892 // tdma and coex table
2893 if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist))
2895 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2896 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2898 else if (pBtLinkInfo->bA2dpExist)
2900 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2901 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2903 else if(pBtLinkInfo->bPanExist)
2905 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2906 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2910 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2911 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2912 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2917 halbtc8703b1ant_ActionWifiConnected(
2918 IN PBTC_COEXIST pBtCoexist
2921 BOOLEAN bWifiBusy=FALSE;
2922 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
2923 BOOLEAN bUnder4way=FALSE, bApEnable=FALSE;
2926 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect()===>\n"));
2928 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
2931 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2932 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));
2936 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2937 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2938 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2939 if(bScan || bLink || bRoam)
2942 halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
2944 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2945 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));
2949 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2950 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2953 if(!bApEnable && BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)
2955 if(pBtCoexist->btLinkInfo.bA2dpOnly) //A2DP
2958 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2961 if (pCoexSta->nScanAPNum >= BT_8703B_1ANT_WIFI_NOISY_THRESH) //no force LPS, no PS-TDMA, use pure TDMA
2963 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2967 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2971 else if ((pCoexSta->bPanExist == FALSE) && (pCoexSta->bA2dpExist == FALSE) && (pCoexSta->bHidExist == FALSE))
2972 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2974 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2977 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2979 // tdma and coex table
2982 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2984 halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
2985 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2987 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2988 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2990 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2991 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2995 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2996 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2997 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3002 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
3004 halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
3005 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3007 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3008 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
3010 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
3011 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3015 //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
3016 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
3017 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
3018 //halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3019 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
3025 halbtc8703b1ant_RunSwCoexistMechanism(
3026 IN PBTC_COEXIST pBtCoexist
3031 algorithm = halbtc8703b1ant_ActionAlgorithm(pBtCoexist);
3032 pCoexDm->curAlgorithm = algorithm;
3034 if(halbtc8703b1ant_IsCommonAction(pBtCoexist))
3040 switch(pCoexDm->curAlgorithm)
3042 case BT_8703B_1ANT_COEX_ALGO_SCO:
3043 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = SCO.\n"));
3044 //halbtc8703b1ant_ActionSco(pBtCoexist);
3046 case BT_8703B_1ANT_COEX_ALGO_HID:
3047 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID.\n"));
3048 //halbtc8703b1ant_ActionHid(pBtCoexist);
3050 case BT_8703B_1ANT_COEX_ALGO_A2DP:
3051 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP.\n"));
3052 //halbtc8703b1ant_ActionA2dp(pBtCoexist);
3054 case BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS:
3055 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));
3056 //halbtc8703b1ant_ActionA2dpPanHs(pBtCoexist);
3058 case BT_8703B_1ANT_COEX_ALGO_PANEDR:
3059 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR).\n"));
3060 //halbtc8703b1ant_ActionPanEdr(pBtCoexist);
3062 case BT_8703B_1ANT_COEX_ALGO_PANHS:
3063 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HS mode.\n"));
3064 //halbtc8703b1ant_ActionPanHs(pBtCoexist);
3066 case BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP:
3067 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));
3068 //halbtc8703b1ant_ActionPanEdrA2dp(pBtCoexist);
3070 case BT_8703B_1ANT_COEX_ALGO_PANEDR_HID:
3071 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));
3072 //halbtc8703b1ant_ActionPanEdrHid(pBtCoexist);
3074 case BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
3075 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));
3076 //halbtc8703b1ant_ActionHidA2dpPanEdr(pBtCoexist);
3078 case BT_8703B_1ANT_COEX_ALGO_HID_A2DP:
3079 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP.\n"));
3080 //halbtc8703b1ant_ActionHidA2dp(pBtCoexist);
3083 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = coexist All Off!!\n"));
3084 //halbtc8703b1ant_CoexAllOff(pBtCoexist);
3087 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
3092 halbtc8703b1ant_RunCoexistMechanism(
3093 IN PBTC_COEXIST pBtCoexist
3096 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
3097 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
3098 BOOLEAN bIncreaseScanDevNum=FALSE;
3099 BOOLEAN bBtCtrlAggBufSize=FALSE;
3100 BOOLEAN bMiracastPlusBt=FALSE;
3101 u1Byte aggBufSize=5;
3102 u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
3103 u4Byte wifiLinkStatus=0;
3104 u4Byte numOfWifiLink=0, wifiBw;
3105 u1Byte iotPeer=BTC_IOT_PEER_UNKNOWN;
3107 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
3109 if(pBtCoexist->bManualControl)
3111 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
3115 if(pBtCoexist->bStopCoexDm)
3117 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));
3121 if(pCoexSta->bUnderIps)
3123 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
3127 if(pCoexSta->bBtWhckTest)
3129 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));
3130 halbtc8703b1ant_ActionBtWhckTest(pBtCoexist);
3134 if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
3135 (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3136 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
3138 bIncreaseScanDevNum = TRUE;
3141 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);
3142 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3144 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3145 numOfWifiLink = wifiLinkStatus>>16;
3147 if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
3149 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );
3151 if(pBtLinkInfo->bBtLinkExist)
3153 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
3154 bMiracastPlusBt = TRUE;
3158 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3159 bMiracastPlusBt = FALSE;
3161 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3162 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
3164 if ( (pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage) )
3166 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
3167 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
3170 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
3176 bMiracastPlusBt = FALSE;
3177 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3180 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3182 if ( (pBtLinkInfo->bBtLinkExist) && (bWifiConnected) )
3184 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
3186 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_IOT_PEER, &iotPeer);
3188 if(BTC_IOT_PEER_CISCO != iotPeer)
3190 if(pBtLinkInfo->bScoExist)//if (pBtLinkInfo->bBtHiPriLinkExist)
3191 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
3193 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3197 if(pBtLinkInfo->bScoExist)
3198 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
3201 if (BTC_WIFI_BW_HT40==wifiBw)
3202 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x10);
3204 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
3208 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
3209 halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist); //just print debug message
3213 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3215 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3217 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
3218 halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist); ////just print debug message
3221 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3222 if(pCoexSta->bC2hBtInquiryPage)
3224 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
3225 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
3230 halbtc8703b1ant_ActionHs(pBtCoexist);
3237 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
3239 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is non connected-idle !!!\n"));
3241 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
3242 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
3243 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
3245 if(bScan || bLink || bRoam)
3248 halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist);
3250 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
3253 halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
3255 else // wifi LPS/Busy
3257 halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
3262 halbtc8703b1ant_PSD_Log2Base(
3263 IN PBTC_COEXIST pBtCoexist,
3269 u4Byte tmp, tmp2, val_integerdB=0, tindex, shiftcount=0;
3270 u4Byte result,val_fractiondB=0,Table_fraction[21]= {0,432, 332, 274, 232, 200,
3271 174, 151,132,115,100,86,74,62,51,42,
3291 val_integerdB = shiftcount+1;
3294 for (j=1; j<= val_integerdB;j++)
3297 tmp = (val*100) /tmp2;
3303 val_fractiondB = Table_fraction[tindex];
3305 result = val_integerdB*100 - val_fractiondB;
3313 halbtc8703b1ant_InitCoexDm(
3314 IN PBTC_COEXIST pBtCoexist
3317 // force to reset coex mechanism
3320 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
3322 //halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3323 //halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3325 pCoexSta->popEventCnt = 0;
3329 halbtc8703b1ant_InitHwConfig(
3330 IN PBTC_COEXIST pBtCoexist,
3332 IN BOOLEAN bWifiOnly
3335 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
3336 u4Byte u4Tmp=0;//, fwVer;
3338 u1Byte u1Tmp=0, u1Tmpa=0, u1Tmpb=0;
3339 u1Byte H2C_Parameter[2] ={0};
3341 u4Byte u4Tmp1=0, u4Tmp2=0;
3344 u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
3345 u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
3347 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Init HW config) 0x38= 0x%x, 0x54= 0x%x**********\n", u4Tmp1, u4Tmp2));
3349 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));
3352 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); //enable TBTT nterrupt
3354 //BT report packet sample rate
3355 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
3357 // Enable BT counter statistics
3358 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
3360 //Enable PTA (3-wire function form BT side)
3361 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
3362 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x41, 0x02, 0x1);
3364 //Enable PTA (tx/rx signal form WiFi side)
3365 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4c6, 0x10, 0x1);
3367 //enable GNT_WL/GNT_BT debug signal to GPIO14/15
3368 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x8, 0x1);
3371 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4e, 0x40, 0x0);
3372 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x1, 0x0);
3374 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3379 pCoexSta->bConCurrentRxModeOn = FALSE;
3380 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, TRUE, FALSE);
3381 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, FALSE, FALSE);
3385 pCoexSta->bConCurrentRxModeOn = TRUE;
3386 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x953, 0x2, 0x1);
3387 //RF 0x1[0] = 0 -> Set GNT_WL_RF_Rx always = 1 for con-current Rx
3388 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0x1, 0x0);
3389 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, TRUE, FALSE);
3393 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3400 halbtc8703b1ant_PSD_ShowData(
3401 IN PBTC_COEXIST pBtCoexist
3404 pu1Byte cliBuf=pBtCoexist->cliBuf;
3405 u4Byte nDeltaFreqPerPoint;
3406 u4Byte freq,freq1,freq2,n=0,i=0, j=0, m=0, PsdRep1, PsdRep2;
3408 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n\n============[PSD info] (%d)============\n",
3409 pPsdScan->nPSDGenCount);
3412 if (pPsdScan->nPSDGenCount == 0)
3414 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n No Data !!\n");
3419 if (pPsdScan->nPSDPoint == 0)
3420 nDeltaFreqPerPoint = 0;
3422 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
3424 //if (pPsdScan->bIsPSDShowMaxOnly)
3427 PsdRep1 = pPsdScan->nPSDMaxValue/100;
3428 PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;
3430 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);
3431 freq1 = freq/1000000;
3432 freq2 = freq/1000 - freq1 * 1000;
3435 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.0%d MHz",
3438 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.%d MHz",
3442 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.0%d dB, (%d) \n",
3443 PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3445 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.%d dB, (%d)\n",
3446 PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3452 m = pPsdScan->nPSDStartPoint;
3453 n = pPsdScan->nPSDStartPoint;
3461 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + m * nDeltaFreqPerPoint);
3462 freq1 = freq/1000000;
3463 freq2 = freq/1000 - freq1 * 1000;
3468 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.000", freq1);
3469 else if (freq2 < 100)
3470 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.0%2d", freq1,freq2);
3472 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.%3d", freq1,freq2);
3474 else if ( (i%8 == 0) || (m == pPsdScan->nPSDStopPoint) )
3477 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000\n", freq1);
3478 else if (freq2 < 100)
3479 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d\n", freq1,freq2);
3481 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d\n", freq1,freq2);
3486 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000", freq1);
3487 else if (freq2 < 100)
3488 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d", freq1,freq2);
3490 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d", freq1,freq2);
3497 }while( (i <= 8) && (m <= pPsdScan->nPSDStopPoint));
3502 PsdRep1 = pPsdScan->nPSDReport_MaxHold[n]/100;
3503 PsdRep2 = pPsdScan->nPSDReport_MaxHold[n] - PsdRep1 * 100;
3508 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.0%d", PsdRep1,PsdRep2);
3510 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.%d", PsdRep1,PsdRep2);
3512 else if ( (j%8 == 0) || (n == pPsdScan->nPSDStopPoint) )
3515 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d\n", PsdRep1,PsdRep2);
3517 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d\n", PsdRep1,PsdRep2);
3522 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d", PsdRep1,PsdRep2);
3524 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d", PsdRep1,PsdRep2);
3531 } while( (j <= 8) && (n <= pPsdScan->nPSDStopPoint));
3533 if ( (m > pPsdScan->nPSDStopPoint) || (n > pPsdScan->nPSDStopPoint) )
3548 halbtc8703b1ant_PSD_MaxHoldData(
3549 IN PBTC_COEXIST pBtCoexist,
3553 u4Byte i=0, i_max=0, val_max=0, j;
3557 memcpy(pPsdScan->nPSDReport_MaxHold, pPsdScan->nPSDReport, BT_8703B_1ANT_ANTDET_PSD_POINTS*sizeof(u4Byte));
3559 for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3561 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
3564 pPsdScan->nPSDMaxValuePoint = 0;
3565 pPsdScan->nPSDMaxValue = 0;
3570 for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3572 if (pPsdScan->nPSDReport[i] > pPsdScan->nPSDReport_MaxHold[i])
3573 pPsdScan->nPSDReport_MaxHold[i] = pPsdScan->nPSDReport[i];
3576 if (i ==pPsdScan->nPSDStartPoint )
3579 val_max = pPsdScan->nPSDReport_MaxHold[i];
3583 if (pPsdScan->nPSDReport_MaxHold[i] > val_max)
3586 val_max = pPsdScan->nPSDReport_MaxHold[i];
3590 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
3594 pPsdScan->nPSDMaxValuePoint = i_max;
3595 pPsdScan->nPSDMaxValue = val_max;
3597 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i_Max = %d, PSDReport_Max = %d dB\n", pPsdScan->nPSDMaxValuePoint
3598 // ,pPsdScan->nPSDMaxValue));
3605 halbtc8703b1ant_PSD_GetData(
3606 IN PBTC_COEXIST pBtCoexist,
3610 //reg 0x808[9:0]: FFT data x
3611 //reg 0x808[22]: 0-->1 to get 1 FFT data y
3612 //reg 0x8b4[15:0]: FFT data y report
3614 u4Byte val = 0, psd_report =0;
3616 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3621 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3624 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3627 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x8b4);
3629 psd_report = val & 0x0000ffff;
3636 halbtc8703b1ant_PSD_SweepPoint(
3637 IN PBTC_COEXIST pBtCoexist,
3646 u4Byte nPoints=0, psd_report=0;
3647 u4Byte nStartP=0, nStopP=0, nDeltaFreqPerPoint=156250;
3648 u4Byte nPSDCenterFreq=20*10^6, freq,freq1,freq2;
3649 BOOLEAN outloop = FALSE;
3651 u4Byte tmp, PsdRep1, PsdRep2;
3652 u4Byte WiFi_OriginalChannel = 1;
3654 pPsdScan->bIsPSDRunning = TRUE;
3660 case 0: //Get PSD parameters
3662 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), centFreq=0x%x, offset=0x%x, span=0x%x\n",
3663 // centFreq, offset, span));
3665 pPsdScan->nPSDBandWidth = 40*1000000;
3666 pPsdScan->nPSDPoint = points;
3667 pPsdScan->nPSDStartBase = points/2;
3668 pPsdScan->nPSDAvgNum = avgnum;
3669 pPsdScan->nRealCentFreq = centFreq;
3670 pPsdScan->nRealOffset = offset;
3671 pPsdScan->nRealSpan = span;
3674 nPoints = pPsdScan->nPSDPoint;
3675 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
3678 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3681 switch(pPsdScan->nPSDPoint)
3698 switch(pPsdScan->nPSDAvgNum)
3714 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3716 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD BW= %d, DeltaFreq=%d\n"
3717 // , pPsdScan->nPSDBandWidth, nDeltaFreqPerPoint));
3720 case 1: //calculate the PSD point index from freq/offset/span
3721 nPSDCenterFreq = pPsdScan->nPSDBandWidth /2 +offset*(1000000);
3722 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD Center Freq = %d\n", (centFreq + offset)));
3724 nStartP = pPsdScan->nPSDStartBase + (nPSDCenterFreq - span *(1000000)/2) /nDeltaFreqPerPoint;
3725 pPsdScan->nPSDStartPoint = nStartP - pPsdScan->nPSDStartBase;
3726 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Start PSD Poin Matrix Index = %d\n", pPsdScan->nPSDStartPoint));
3728 nStopP = pPsdScan->nPSDStartBase + (nPSDCenterFreq + span *(1000000)/2) /nDeltaFreqPerPoint;
3729 pPsdScan->nPSDStopPoint = nStopP - pPsdScan->nPSDStartBase-1;
3730 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Stop PSD Poin Matrix Index = %d\n",pPsdScan->nPSDStopPoint));
3734 case 2: //set RF channel/BW/Mode
3737 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3739 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3742 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3744 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
3746 //store WiFi original channel
3747 WiFi_OriginalChannel = pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff);
3750 if (centFreq == 2484)
3751 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, 0xe);
3753 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, (centFreq-2412)/5 + 1); //WiFi TRx Mask on
3755 //Set RF mode = Rx, RF Gain = 0x8a0
3756 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x0, 0xfffff, 0x308a0);
3758 //Set RF Rx filter corner
3759 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x3e4);
3762 //un-lock TRx Mask setup
3763 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);
3764 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);
3766 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3771 memset(pPsdScan->nPSDReport,0, pPsdScan->nPSDPoint*sizeof(u4Byte));
3772 nStartP = pPsdScan->nPSDStartPoint + pPsdScan->nPSDStartBase;
3773 nStopP = pPsdScan->nPSDStopPoint + pPsdScan->nPSDStartBase + 1;
3781 psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i-nPoints);
3785 psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i);
3788 if (psd_report == 0)
3791 //tmp = 20*log10((double)psd_report);
3792 //20*log2(x)/log2(10), log2Base return theresult of the psd_report*100
3793 tmp = 6 * halbtc8703b1ant_PSD_Log2Base(pBtCoexist, psd_report);
3795 n = i-pPsdScan->nPSDStartBase;
3796 pPsdScan->nPSDReport[n] = tmp;
3797 PsdRep1 = pPsdScan->nPSDReport[n] /100;
3798 PsdRep2 = pPsdScan->nPSDReport[n] - PsdRep1 * 100;
3800 freq = ((centFreq-20) * 1000000 + n * nDeltaFreqPerPoint);
3801 freq1 = freq/1000000;
3802 freq2 = freq/1000 - freq1 * 1000;
3805 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.0%d MHz)", n, freq1, freq2));
3807 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.%d MHz)", n, freq1, freq2));
3810 RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.0%d dB)\n",psd_report, PsdRep1, PsdRep2));
3812 RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.%d dB)\n",psd_report, PsdRep1,PsdRep2));
3818 //Add Delay between PSD point
3825 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint()==============\n"));
3834 case 100: //recovery
3837 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3839 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3842 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3844 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
3847 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3849 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x808,val);
3852 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3854 //lock TRx Mask setup
3855 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);
3856 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);
3858 //Set RF Rx filter corner
3859 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x0);
3861 //restore WiFi original channel
3862 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, WiFi_OriginalChannel);
3873 pPsdScan->bIsPSDRunning = FALSE;
3878 //============================================================
3879 // work around function start with wa_halbtc8703b1ant_
3880 //============================================================
3881 //============================================================
3882 // extern function start with EXhalbtc8703b1ant_
3883 //============================================================
3885 EXhalbtc8703b1ant_PowerOnSetting(
3886 IN PBTC_COEXIST pBtCoexist
3889 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
3893 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx Execute 8703b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"));
3895 RT_TRACE(COMP_COEX, DBG_LOUD, ("Ant Det Finish = %s, Ant Det Number = %d\n",
3896 (pBoardInfo->btdmAntDetFinish? "Yes":"No"), pBoardInfo->btdmAntNumByAntDet));
3898 pBtCoexist->bStopCoexDm = TRUE;
3900 // enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.
3901 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
3902 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
3904 //set Path control owner to WiFi
3905 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);
3907 // set GNT_BT to high
3908 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
3910 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
3913 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
3916 // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)
3917 // Local setting bit define
3918 // BIT0: "0" for no antenna inverse; "1" for antenna inverse
3919 // BIT1: "0" for internal switch; "1" for external switch
3920 // BIT2: "0" for one antenna; "1" for two antenna
3921 // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0
3924 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
3926 if(pBtCoexist->chipInterface == BTC_INTF_USB)
3928 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
3930 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
3932 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
3935 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38)));
3939 if(pBtCoexist->chipInterface == BTC_INTF_USB)
3941 // fixed at S0 for USB interface
3942 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3944 u1Tmp |= 0x1; // antenna inverse
3945 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
3947 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3952 // for PCIE and SDIO interface, we check efuse 0xc3[6]
3953 if(pBoardInfo->singleAntPath == 0)
3956 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
3957 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
3959 else if(pBoardInfo->singleAntPath == 1)
3962 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3963 u1Tmp |= 0x1; // antenna inverse
3964 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3969 if(pBtCoexist->chipInterface == BTC_INTF_PCI)
3971 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
3973 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
3975 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
3983 EXhalbtc8703b1ant_PreLoadFirmware(
3984 IN PBTC_COEXIST pBtCoexist
3990 EXhalbtc8703b1ant_InitHwConfig(
3991 IN PBTC_COEXIST pBtCoexist,
3992 IN BOOLEAN bWifiOnly
3995 halbtc8703b1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);
3996 pBtCoexist->bStopCoexDm = FALSE;
4000 EXhalbtc8703b1ant_InitCoexDm(
4001 IN PBTC_COEXIST pBtCoexist
4004 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
4006 pBtCoexist->bStopCoexDm = FALSE;
4008 halbtc8703b1ant_InitCoexDm(pBtCoexist);
4010 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4014 EXhalbtc8703b1ant_DisplayCoexInfo(
4015 IN PBTC_COEXIST pBtCoexist
4018 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
4019 PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
4020 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
4021 pu1Byte cliBuf=pBtCoexist->cliBuf;
4022 u1Byte u1Tmp[4], i, btInfoExt, psTdmaCase=0;
4025 u4Byte faOfdm, faCck;
4026 u4Byte fwVer=0, btPatchVer=0;
4027 static u1Byte PopReportIn10s = 0;
4029 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
4032 if(pBtCoexist->bManualControl)
4034 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
4036 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4039 if(pBtCoexist->bStopCoexDm)
4041 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");
4043 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4047 if (pPsdScan->bAntDet_TryCount == 0)
4049 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Mech/ Pos",
4050 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);
4055 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d (%d/%d/%d)", "Ant PG Num/ Mech(Ant_Det)/ Pos",
4056 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNumByAntDet, pBoardInfo->btdmAntPos,
4057 pPsdScan->bAntDet_TryCount, pPsdScan->bAntDet_FailCount, pPsdScan->nAntDet_Result);
4060 if (pBoardInfo->btdmAntDetFinish)
4062 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "Ant Det PSD Value", pPsdScan->nAntDet_PeakVal);
4067 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
4068 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
4071 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4072 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4073 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
4074 GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer);
4077 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
4078 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
4079 pCoexDm->wifiChnlInfo[2]);
4081 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "WifibHiPri/ Ccklock/ CckEverLock", \
4082 (pCoexSta->bWiFiIsHighPriTask? "Yes":"No"),
4083 (pCoexSta->bCCKLock? "Yes":"No"),
4084 (pCoexSta->bCCKEverLock? "Yes":"No"));
4088 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
4090 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
4092 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
4096 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \
4097 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"): ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
4098 ( (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
4099 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);
4102 if (PopReportIn10s >= 5)
4104 pCoexSta->popEventCnt = 0;
4108 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d / %d", "SCO/HID/PAN/A2DP/Hi-Pri", \
4109 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist, pBtLinkInfo->bBtHiPriLinkExist);
4112 if (pStackInfo->bProfileNotified)
4114 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
4118 btInfoExt = pCoexSta->btInfoExt;
4120 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "BT Role/A2DP rate", \
4121 (pBtLinkInfo->bSlaveRole )? "Slave":"Master", (btInfoExt&BIT0)? "BR":"EDR");
4126 for(i=0; i<BT_INFO_SRC_8703B_1ANT_MAX; i++)
4128 if(pCoexSta->btInfoC2hCnt[i])
4130 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8703b1Ant[i], \
4131 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
4132 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
4133 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
4134 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
4140 if(pBtCoexist->bManualControl)
4142 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism] (before Manual)============");
4146 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
4151 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ 0x%x", "SM[LowPenaltyRA]/RA Mask", \
4152 pCoexDm->bCurLowPenaltyRa, pBtCoexist->btInfo.raMask);
4155 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "NoAggr/ CtrlAggr/ AggrSize", \
4156 (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),
4157 pBtCoexist->btInfo.aggBufSize);
4161 if(pBtCoexist->bManualControl)
4163 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism] (before Manual) ============");
4167 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
4172 psTdmaCase = pCoexDm->curPsTdma;
4173 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", "PS TDMA", \
4174 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
4175 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
4176 pCoexDm->psTdmaPara[4], psTdmaCase,
4177 (pCoexDm->bCurPsTdmaOn? "On":"Off"),
4178 (pCoexDm->bAutoTdmaAdjust? "Adj":"Fix") );
4182 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "WL/BT Coex Table Type", \
4183 pCoexSta->nCoexTableType);
4186 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
4187 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
4188 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
4189 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \
4190 u4Tmp[0], u4Tmp[1], u4Tmp[2]);
4193 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4194 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
4195 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/IgnWlanAct", \
4196 u1Tmp[0], u4Tmp[0], pCoexDm->bCurIgnoreWlanAct);
4199 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa0);
4200 u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa4);
4202 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "LTE Coex Table W_L/B_L", \
4203 u4Tmp[0]&0xffff, u4Tmp[1]&0xffff);
4206 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa8);
4207 u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xac);
4208 u4Tmp[2] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb0);
4209 u4Tmp[3] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb4);
4211 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "LTE Break Table W_L/B_L/L_W/L_B", \
4212 u4Tmp[0]&0xffff, u4Tmp[1]&0xffff, u4Tmp[2]&0xffff, u4Tmp[3]&0xffff);
4216 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
4220 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4221 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4222 u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4223 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4224 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
4225 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
4229 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
4230 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
4232 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", "LTE CoexOn/Path Ctrl Owner", \
4233 ((u4Tmp[0]&BIT7)>> 7), ((u1Tmp[0]&BIT2)? "WL":"BT"));
4236 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "LTE 3Wire/OPMode/UART/UARTMode", \
4237 ((u4Tmp[0]&BIT6)>> 6), ((u4Tmp[0]&(BIT5|BIT4))>> 4),((u4Tmp[0]&BIT3)>> 3), (u4Tmp[0]&(BIT2|BIT1|BIT0)));
4240 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg", \
4241 ((u4Tmp[0]&BIT12)>> 12), ((u4Tmp[0]&BIT14)>> 14), ((u1Tmp[0]&BIT3)? "On":"Off"));
4244 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
4246 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", \
4247 ((u4Tmp[0]&BIT2)>> 2), ((u4Tmp[0]&BIT3)>> 3), ((u4Tmp[0]&BIT1)>> 1), (u4Tmp[0]&BIT0));
4251 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4c6);
4252 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
4254 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x4c6[4]/0x40[5] (WL/BT PTA)", \
4255 ((u1Tmp[0] & BIT4)>>4), ((u1Tmp[1] & BIT5)>>5));
4258 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
4259 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
4260 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x953);
4261 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", "0x550(bcn ctrl)/0x522/4-RxAGC", \
4262 u4Tmp[0], u1Tmp[0], (u1Tmp[1]&0x2)? "On": "Off");
4265 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
4266 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
4267 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
4268 u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
4270 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
4271 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
4273 faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) + ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) + \
4274 ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
4275 faCck = (u1Tmp[0] << 8) + u1Tmp[1];
4277 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
4279 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xc50/OFDM-CCA/OFDM-FA/CCK-FA", \
4280 u4Tmp[1]&0xff, u4Tmp[0]&0xffff, faOfdm, faCck);
4284 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
4285 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
4288 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
4289 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
4292 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
4293 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
4295 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
4296 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
4299 halbtc8703b1ant_ReadScoreBoard(pBtCoexist, &u2Tmp[0]);
4301 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x", "ScoreBoard[14:0] (from BT)", u2Tmp[0]);
4304 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 1)
4305 //halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
4307 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
4312 EXhalbtc8703b1ant_IpsNotify(
4313 IN PBTC_COEXIST pBtCoexist,
4319 if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
4322 if(BTC_IPS_ENTER == type)
4324 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
4325 pCoexSta->bUnderIps = TRUE;
4327 //Write WL "Active" in Score-board for LPS off
4328 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4330 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
4331 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
4332 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4334 else if(BTC_IPS_LEAVE == type)
4336 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
4337 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4339 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
4340 halbtc8703b1ant_InitCoexDm(pBtCoexist);
4341 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4343 pCoexSta->bUnderIps = FALSE;
4348 EXhalbtc8703b1ant_LpsNotify(
4349 IN PBTC_COEXIST pBtCoexist,
4353 if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
4356 if(BTC_LPS_ENABLE == type)
4358 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
4359 pCoexSta->bUnderLps = TRUE;
4361 if (pCoexSta->bForceLpsOn == TRUE) // LPS No-32K
4363 //Write WL "Active" in Score-board for PS-TDMA
4364 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4367 else // LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28)
4369 //Write WL "Non-Active" in Score-board for Native-PS
4370 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4374 else if(BTC_LPS_DISABLE == type)
4376 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
4377 pCoexSta->bUnderLps = FALSE;
4380 //Write WL "Active" in Score-board for LPS off
4381 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4387 EXhalbtc8703b1ant_ScanNotify(
4388 IN PBTC_COEXIST pBtCoexist,
4392 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
4393 u4Byte wifiLinkStatus=0;
4394 u4Byte numOfWifiLink=0;
4395 BOOLEAN bBtCtrlAggBufSize=FALSE;
4396 u1Byte aggBufSize=5;
4398 u1Byte u1Tmpa, u1Tmpb;
4401 if(pBtCoexist->bManualControl ||
4402 pBtCoexist->bStopCoexDm )
4405 if(BTC_SCAN_START == type)
4407 pCoexSta->bWiFiIsHighPriTask = TRUE;
4408 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4409 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4410 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4411 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4415 pCoexSta->bWiFiIsHighPriTask = FALSE;
4416 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4418 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);
4421 if(pBtCoexist->btInfo.bBtDisabled)
4424 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4425 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4427 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4429 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4430 numOfWifiLink = wifiLinkStatus>>16;
4431 if(numOfWifiLink >= 2)
4433 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4434 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4435 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4439 if(pCoexSta->bC2hBtInquiryPage)
4441 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4446 halbtc8703b1ant_ActionHs(pBtCoexist);
4450 if(BTC_SCAN_START == type)
4452 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4453 if(!bWifiConnected) // non-connected scan
4455 halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist);
4457 else // wifi is connected
4459 halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
4462 else if(BTC_SCAN_FINISH == type)
4464 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4465 if(!bWifiConnected) // non-connected scan
4467 halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
4471 halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
4477 EXhalbtc8703b1ant_ConnectNotify(
4478 IN PBTC_COEXIST pBtCoexist,
4482 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
4483 u4Byte wifiLinkStatus=0;
4484 u4Byte numOfWifiLink=0;
4485 BOOLEAN bBtCtrlAggBufSize=FALSE;
4486 u1Byte aggBufSize=5;
4488 if(pBtCoexist->bManualControl ||
4489 pBtCoexist->bStopCoexDm ||
4490 pBtCoexist->btInfo.bBtDisabled )
4493 if(BTC_ASSOCIATE_START == type)
4495 pCoexSta->bWiFiIsHighPriTask = TRUE;
4496 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4497 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4498 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4499 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
4500 pCoexDm->nArpCnt = 0;
4504 pCoexSta->bWiFiIsHighPriTask = FALSE;
4505 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4506 //pCoexDm->nArpCnt = 0;
4509 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4510 numOfWifiLink = wifiLinkStatus>>16;
4511 if(numOfWifiLink >= 2)
4513 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4514 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4515 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4519 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4520 if(pCoexSta->bC2hBtInquiryPage)
4522 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4527 halbtc8703b1ant_ActionHs(pBtCoexist);
4531 if(BTC_ASSOCIATE_START == type)
4533 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
4534 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
4536 else if(BTC_ASSOCIATE_FINISH == type)
4538 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4540 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4541 if(!bWifiConnected) // non-connected scan
4543 halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
4547 halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
4553 EXhalbtc8703b1ant_MediaStatusNotify(
4554 IN PBTC_COEXIST pBtCoexist,
4558 u1Byte H2C_Parameter[3] ={0};
4560 u1Byte wifiCentralChnl;
4561 BOOLEAN bWifiUnderBMode = FALSE;
4563 if(pBtCoexist->bManualControl ||
4564 pBtCoexist->bStopCoexDm ||
4565 pBtCoexist->btInfo.bBtDisabled )
4568 if(BTC_MEDIA_CONNECT == type)
4570 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
4571 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4572 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4573 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4574 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
4576 //Set CCK Tx/Rx high Pri except 11b mode
4577 if (bWifiUnderBMode)
4579 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
4580 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); //CCK Rx
4584 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); //CCK Tx
4585 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
4586 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
4587 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
4590 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4591 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4592 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4593 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4597 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
4598 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4599 pCoexDm->nArpCnt = 0;
4601 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); //CCK Tx
4602 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); //CCK Rx
4604 pCoexSta->bCCKEverLock = FALSE;
4607 halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, type);
4612 EXhalbtc8703b1ant_SpecialPacketNotify(
4613 IN PBTC_COEXIST pBtCoexist,
4617 BOOLEAN bBtHsOn=FALSE;
4618 u4Byte wifiLinkStatus=0;
4619 u4Byte numOfWifiLink=0;
4620 BOOLEAN bBtCtrlAggBufSize=FALSE, bUnder4way=FALSE;
4621 u1Byte aggBufSize=5;
4623 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
4625 if(pBtCoexist->bManualControl ||
4626 pBtCoexist->bStopCoexDm ||
4627 pBtCoexist->btInfo.bBtDisabled )
4630 if( BTC_PACKET_DHCP == type ||
4631 BTC_PACKET_EAPOL == type ||
4632 BTC_PACKET_ARP == type )
4634 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4636 if (BTC_PACKET_ARP == type)
4638 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet ARP notify\n"));
4641 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));
4643 if((pCoexDm->nArpCnt >= 10) && (!bUnder4way)) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist)
4645 pCoexSta->bWiFiIsHighPriTask = FALSE;
4649 pCoexSta->bWiFiIsHighPriTask = TRUE;
4654 pCoexSta->bWiFiIsHighPriTask = TRUE;
4655 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));
4660 pCoexSta->bWiFiIsHighPriTask = FALSE;
4661 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet [Type = %d] notify\n", type));
4664 pCoexSta->specialPktPeriodCnt = 0;
4666 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4667 numOfWifiLink = wifiLinkStatus>>16;
4668 if(numOfWifiLink >= 2)
4670 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4671 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4672 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4676 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4677 if(pCoexSta->bC2hBtInquiryPage)
4679 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4684 halbtc8703b1ant_ActionHs(pBtCoexist);
4688 if( BTC_PACKET_DHCP == type ||
4689 BTC_PACKET_EAPOL == type ||
4690 ( (BTC_PACKET_ARP == type ) && (pCoexSta->bWiFiIsHighPriTask) ) )
4692 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
4697 EXhalbtc8703b1ant_BtInfoNotify(
4698 IN PBTC_COEXIST pBtCoexist,
4703 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
4705 u1Byte i, rspSource=0;
4706 BOOLEAN bWifiConnected=FALSE;
4707 BOOLEAN bBtBusy=FALSE;
4708 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
4710 pCoexSta->bC2hBtInfoReqSent = FALSE;
4712 rspSource = tmpBuf[0]&0xf;
4713 if(rspSource >= BT_INFO_SRC_8703B_1ANT_MAX)
4714 rspSource = BT_INFO_SRC_8703B_1ANT_WIFI_FW;
4715 pCoexSta->btInfoC2hCnt[rspSource]++;
4717 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
4718 for(i=0; i<length; i++)
4720 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
4725 RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
4729 RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
4733 // if 0xff, it means BT is under WHCK test
4735 pCoexSta->bBtWhckTest = TRUE;
4737 pCoexSta->bBtWhckTest = FALSE;
4739 if(BT_INFO_SRC_8703B_1ANT_WIFI_FW != rspSource)
4741 pCoexSta->btRetryCnt = // [3:0]
4742 pCoexSta->btInfoC2h[rspSource][2]&0xf;
4744 if (pCoexSta->btRetryCnt >= 1)
4745 pCoexSta->popEventCnt++;
4747 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)
4748 pCoexSta->bC2hBtPage = TRUE;
4750 pCoexSta->bC2hBtPage = FALSE;
4753 pCoexSta->btInfoC2h[rspSource][3]*2-90;
4754 //pCoexSta->btInfoC2h[rspSource][3]*2+10;
4756 pCoexSta->btInfoExt =
4757 pCoexSta->btInfoC2h[rspSource][4];
4759 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
4760 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
4763 // Here we need to resend some wifi info to BT
4764 // because bt is reset and loss of the info.
4765 if(pCoexSta->btInfoExt & BIT1)
4767 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
4768 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4771 halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_CONNECT);
4775 halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_DISCONNECT);
4779 if(pCoexSta->btInfoExt & BIT3)
4781 if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
4783 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
4784 halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
4789 // BT already NOT ignore Wlan active, do nothing here.
4791 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
4792 if( (pCoexSta->btInfoExt & BIT4) )
4794 // BT auto report already enabled, do nothing
4798 halbtc8703b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);
4803 // check BIT2 first ==> check if bt is under inquiry or page scan
4804 if(btInfo & BT_INFO_8703B_1ANT_B_INQ_PAGE)
4805 pCoexSta->bC2hBtInquiryPage = TRUE;
4807 pCoexSta->bC2hBtInquiryPage = FALSE;
4809 pCoexSta->nNumOfProfile = 0;
4811 // set link exist status
4812 if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
4814 pCoexSta->bBtLinkExist = FALSE;
4815 pCoexSta->bPanExist = FALSE;
4816 pCoexSta->bA2dpExist = FALSE;
4817 pCoexSta->bHidExist = FALSE;
4818 pCoexSta->bScoExist = FALSE;
4820 pCoexSta->bBtHiPriLinkExist = FALSE;
4822 else // connection exists
4824 pCoexSta->bBtLinkExist = TRUE;
4825 if(btInfo & BT_INFO_8703B_1ANT_B_FTP)
4827 pCoexSta->bPanExist = TRUE;
4828 pCoexSta->nNumOfProfile++;
4831 pCoexSta->bPanExist = FALSE;
4832 if(btInfo & BT_INFO_8703B_1ANT_B_A2DP)
4834 pCoexSta->bA2dpExist = TRUE;
4835 pCoexSta->nNumOfProfile++;
4838 pCoexSta->bA2dpExist = FALSE;
4839 if(btInfo & BT_INFO_8703B_1ANT_B_HID)
4841 pCoexSta->bHidExist = TRUE;
4842 pCoexSta->nNumOfProfile++;
4845 pCoexSta->bHidExist = FALSE;
4846 if(btInfo & BT_INFO_8703B_1ANT_B_SCO_ESCO)
4848 pCoexSta->bScoExist = TRUE;
4849 pCoexSta->nNumOfProfile++;
4852 pCoexSta->bScoExist = FALSE;
4854 if ((pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) &&( pCoexSta->bScoExist == FALSE))
4856 if (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
4858 pCoexSta->bHidExist = TRUE;
4859 pCoexSta->wrongProfileNotification++;
4860 pCoexSta->nNumOfProfile++;
4861 btInfo = btInfo | 0x28;
4862 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT HID = true (Hi-Pri > 160)!\n"));
4866 //Add Hi-Pri Tx/Rx counter to avoid false detection
4867 if (((pCoexSta->bHidExist) || (pCoexSta->bScoExist)) && (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
4868 && (!pCoexSta->bC2hBtInquiryPage))
4869 pCoexSta->bBtHiPriLinkExist = TRUE;
4871 pCoexSta->bBtHiPriLinkExist = FALSE;
4873 if((btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY) && (pCoexSta->nNumOfProfile == 0))
4875 if (pCoexSta->lowPriorityTx + pCoexSta->lowPriorityRx >= 160)
4877 pCoexSta->bPanExist = TRUE;
4878 pCoexSta->nNumOfProfile++;
4879 pCoexSta->wrongProfileNotification++;
4880 btInfo = btInfo | 0x88;
4885 halbtc8703b1ant_UpdateBtLinkInfo(pBtCoexist);
4887 btInfo = btInfo & 0x1f; //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)
4889 if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
4891 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
4892 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
4894 else if(btInfo == BT_INFO_8703B_1ANT_B_CONNECTION) // connection exists but no busy
4896 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE;
4897 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
4899 else if((btInfo&BT_INFO_8703B_1ANT_B_SCO_ESCO) ||
4900 (btInfo&BT_INFO_8703B_1ANT_B_SCO_BUSY))
4902 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_SCO_BUSY;
4903 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
4905 else if(btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY)
4907 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)
4908 pCoexDm->bAutoTdmaAdjust = FALSE;
4909 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_ACL_BUSY;
4910 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
4914 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_MAX;
4915 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
4918 if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
4919 (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
4920 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
4924 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
4926 halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);
4930 EXhalbtc8703b1ant_RfStatusNotify(
4931 IN PBTC_COEXIST pBtCoexist,
4936 u1Byte u1Tmpa,u1Tmpb, u1Tmpc;
4938 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF Status notify\n"));
4940 if(BTC_RF_ON == type)
4942 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned ON!!\n"));
4943 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4944 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
4945 pBtCoexist->bStopCoexDm = FALSE;
4947 else if(BTC_RF_OFF == type)
4949 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned OFF!!\n"));
4950 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4952 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4953 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4954 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
4955 halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4956 pBtCoexist->bStopCoexDm = TRUE;
4962 EXhalbtc8703b1ant_HaltNotify(
4963 IN PBTC_COEXIST pBtCoexist
4968 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
4970 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4972 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4973 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4974 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
4976 halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4978 EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
4980 pBtCoexist->bStopCoexDm = TRUE;
4984 EXhalbtc8703b1ant_PnpNotify(
4985 IN PBTC_COEXIST pBtCoexist,
4989 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));
4991 if(BTC_WIFI_PNP_SLEEP == pnpState)
4993 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));
4995 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4997 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4998 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
4999 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
5000 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
5002 pBtCoexist->bStopCoexDm = TRUE;
5004 else if(BTC_WIFI_PNP_WAKE_UP == pnpState)
5006 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));
5007 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
5009 pBtCoexist->bStopCoexDm = FALSE;
5010 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5011 halbtc8703b1ant_InitCoexDm(pBtCoexist);
5012 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
5018 EXhalbtc8703b1ant_ScoreBoardStatusNotify(
5019 IN PBTC_COEXIST pBtCoexist,
5030 EXhalbtc8703b1ant_CoexDmReset(
5031 IN PBTC_COEXIST pBtCoexist
5034 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], *****************Coex DM Reset*****************\n"));
5036 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5037 //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
5038 //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
5039 halbtc8703b1ant_InitCoexDm(pBtCoexist);
5043 EXhalbtc8703b1ant_Periodical(
5044 IN PBTC_COEXIST pBtCoexist
5047 static u1Byte disVerInfoCnt=0;
5048 u4Byte fwVer=0, btPatchVer=0;
5049 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
5050 PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
5052 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
5054 if(disVerInfoCnt <= 5)
5057 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5058 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
5059 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
5060 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",
5061 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
5062 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
5063 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
5064 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
5065 GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer));
5066 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5069 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
5070 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
5071 halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
5073 halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
5074 halbtc8703b1ant_MonitorWiFiCtr(pBtCoexist);
5075 #if BT_8703B_1ANT_ANTDET_ENABLE
5076 halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
5079 if( halbtc8703b1ant_IsWifiStatusChanged(pBtCoexist) ||
5080 pCoexDm->bAutoTdmaAdjust )
5083 halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);
5086 pCoexSta->specialPktPeriodCnt++;
5092 EXhalbtc8703b1ant_AntennaDetection(
5093 IN PBTC_COEXIST pBtCoexist,
5100 //No Antenna Detection required because 8730b is only 1-Ant
5104 EXhalbtc8703b1ant_AntennaIsolation(
5105 IN PBTC_COEXIST pBtCoexist,
5117 EXhalbtc8703b1ant_PSDScan(
5118 IN PBTC_COEXIST pBtCoexist,
5130 EXhalbtc8703b1ant_DisplayAntDetection(
5131 IN PBTC_COEXIST pBtCoexist
5139 #else // #if (RTL8723B_SUPPORT == 1)
5141 EXhalbtc8703b1ant_PowerOnSetting(
5142 IN PBTC_COEXIST pBtCoexist
5145 EXhalbtc8703b1ant_PreLoadFirmware(
5146 IN PBTC_COEXIST pBtCoexist
5149 EXhalbtc8703b1ant_InitHwConfig(
5150 IN PBTC_COEXIST pBtCoexist,
5151 IN BOOLEAN bWifiOnly
5154 EXhalbtc8703b1ant_InitCoexDm(
5155 IN PBTC_COEXIST pBtCoexist
5158 EXhalbtc8703b1ant_IpsNotify(
5159 IN PBTC_COEXIST pBtCoexist,
5163 EXhalbtc8703b1ant_LpsNotify(
5164 IN PBTC_COEXIST pBtCoexist,
5168 EXhalbtc8703b1ant_ScanNotify(
5169 IN PBTC_COEXIST pBtCoexist,
5173 EXhalbtc8703b1ant_ConnectNotify(
5174 IN PBTC_COEXIST pBtCoexist,
5178 EXhalbtc8703b1ant_MediaStatusNotify(
5179 IN PBTC_COEXIST pBtCoexist,
5183 EXhalbtc8703b1ant_SpecialPacketNotify(
5184 IN PBTC_COEXIST pBtCoexist,
5188 EXhalbtc8703b1ant_BtInfoNotify(
5189 IN PBTC_COEXIST pBtCoexist,
5194 EXhalbtc8703b1ant_RfStatusNotify(
5195 IN PBTC_COEXIST pBtCoexist,
5199 EXhalbtc8703b1ant_HaltNotify(
5200 IN PBTC_COEXIST pBtCoexist
5203 EXhalbtc8703b1ant_PnpNotify(
5204 IN PBTC_COEXIST pBtCoexist,
5208 EXhalbtc8703b1ant_ScoreBoardStatusNotify(
5209 IN PBTC_COEXIST pBtCoexist,
5214 EXhalbtc8703b1ant_CoexDmReset(
5215 IN PBTC_COEXIST pBtCoexist
5218 EXhalbtc8703b1ant_Periodical(
5219 IN PBTC_COEXIST pBtCoexist
5222 EXhalbtc8703b1ant_DisplayCoexInfo(
5223 IN PBTC_COEXIST pBtCoexist
5226 EXhalbtc8703b1ant_AntennaDetection(
5227 IN PBTC_COEXIST pBtCoexist,
5234 EXhalbtc8703b1ant_DisplayAntDetection(
5235 IN PBTC_COEXIST pBtCoexist