Merge branch 'develop-3.10-next' of 10.10.10.29:rk/kernel into develop-3.10-next
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs-vq0 / hal / OUTSRC-BTCoexist / HalBtc8723b1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8723B Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/11/15 Cosa first check in.\r
8 //\r
9 //============================================================\r
10 \r
11 //============================================================\r
12 // include files\r
13 //============================================================\r
14 #include "Mp_Precomp.h"\r
15 #if(BT_30_SUPPORT == 1)\r
16 //============================================================\r
17 // Global variables, these are static variables\r
18 //============================================================\r
19 static COEX_DM_8723B_1ANT               GLCoexDm8723b1Ant;\r
20 static PCOEX_DM_8723B_1ANT      pCoexDm=&GLCoexDm8723b1Ant;\r
21 static COEX_STA_8723B_1ANT              GLCoexSta8723b1Ant;\r
22 static PCOEX_STA_8723B_1ANT     pCoexSta=&GLCoexSta8723b1Ant;\r
23 static PSDSCAN_STA_8723B_1ANT   GLPsdScan8723b1Ant;\r
24 static PPSDSCAN_STA_8723B_1ANT pPsdScan = &GLPsdScan8723b1Ant;\r
25 \r
26 \r
27 const char *const GLBtInfoSrc8723b1Ant[]={\r
28         "BT Info[wifi fw]",\r
29         "BT Info[bt rsp]",\r
30         "BT Info[bt auto report]",\r
31 };\r
32 \r
33 u4Byte  GLCoexVerDate8723b1Ant=20140929;\r
34 u4Byte  GLCoexVer8723b1Ant=0x54;\r
35 \r
36 //============================================================\r
37 // local function proto type if needed\r
38 //============================================================\r
39 //============================================================\r
40 // local function start with halbtc8723b1ant_\r
41 //============================================================\r
42 u1Byte\r
43 halbtc8723b1ant_BtRssiState(\r
44         u1Byte                  levelNum,\r
45         u1Byte                  rssiThresh,\r
46         u1Byte                  rssiThresh1\r
47         )\r
48 {\r
49         s4Byte                  btRssi=0;\r
50         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
51 \r
52         btRssi = pCoexSta->btRssi;\r
53 \r
54         if(levelNum == 2)\r
55         {                       \r
56                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
57                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
58                 {\r
59                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
60                         {\r
61                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
62                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
63                         }\r
64                         else\r
65                         {\r
66                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
67                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
68                         }\r
69                 }\r
70                 else\r
71                 {\r
72                         if(btRssi < rssiThresh)\r
73                         {\r
74                                 btRssiState = BTC_RSSI_STATE_LOW;\r
75                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
76                         }\r
77                         else\r
78                         {\r
79                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
80                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
81                         }\r
82                 }\r
83         }\r
84         else if(levelNum == 3)\r
85         {\r
86                 if(rssiThresh > rssiThresh1)\r
87                 {\r
88                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
89                         return pCoexSta->preBtRssiState;\r
90                 }\r
91                 \r
92                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
93                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
94                 {\r
95                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
96                         {\r
97                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
98                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
99                         }\r
100                         else\r
101                         {\r
102                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
103                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
104                         }\r
105                 }\r
106                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
107                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
108                 {\r
109                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
110                         {\r
111                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
112                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
113                         }\r
114                         else if(btRssi < rssiThresh)\r
115                         {\r
116                                 btRssiState = BTC_RSSI_STATE_LOW;\r
117                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
118                         }\r
119                         else\r
120                         {\r
121                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
122                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
123                         }\r
124                 }\r
125                 else\r
126                 {\r
127                         if(btRssi < rssiThresh1)\r
128                         {\r
129                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
130                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
131                         }\r
132                         else\r
133                         {\r
134                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
135                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
136                         }\r
137                 }\r
138         }\r
139                 \r
140         pCoexSta->preBtRssiState = btRssiState;\r
141 \r
142         return btRssiState;\r
143 }\r
144 \r
145 u1Byte\r
146 halbtc8723b1ant_WifiRssiState(\r
147         IN      PBTC_COEXIST            pBtCoexist,\r
148         IN      u1Byte                  index,\r
149         IN      u1Byte                  levelNum,\r
150         IN      u1Byte                  rssiThresh,\r
151         IN      u1Byte                  rssiThresh1\r
152         )\r
153 {\r
154         s4Byte                  wifiRssi=0;\r
155         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
156 \r
157         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
158         \r
159         if(levelNum == 2)\r
160         {\r
161                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
162                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
163                 {\r
164                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
165                         {\r
166                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
167                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
168                         }\r
169                         else\r
170                         {\r
171                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
172                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
173                         }\r
174                 }\r
175                 else\r
176                 {\r
177                         if(wifiRssi < rssiThresh)\r
178                         {\r
179                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
180                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
181                         }\r
182                         else\r
183                         {\r
184                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
185                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
186                         }\r
187                 }\r
188         }\r
189         else if(levelNum == 3)\r
190         {\r
191                 if(rssiThresh > rssiThresh1)\r
192                 {\r
193                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
194                         return pCoexSta->preWifiRssiState[index];\r
195                 }\r
196                 \r
197                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
198                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
199                 {\r
200                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
201                         {\r
202                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
203                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
204                         }\r
205                         else\r
206                         {\r
207                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
208                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
209                         }\r
210                 }\r
211                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
212                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
213                 {\r
214                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
215                         {\r
216                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
217                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
218                         }\r
219                         else if(wifiRssi < rssiThresh)\r
220                         {\r
221                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
222                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
223                         }\r
224                         else\r
225                         {\r
226                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
227                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
228                         }\r
229                 }\r
230                 else\r
231                 {\r
232                         if(wifiRssi < rssiThresh1)\r
233                         {\r
234                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
235                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
236                         }\r
237                         else\r
238                         {\r
239                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
240                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
241                         }\r
242                 }\r
243         }\r
244                 \r
245         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
246 \r
247         return wifiRssiState;\r
248 }\r
249 \r
250 VOID\r
251 halbtc8723b1ant_UpdateRaMask(\r
252         IN      PBTC_COEXIST            pBtCoexist,\r
253         IN      BOOLEAN                         bForceExec,\r
254         IN      u4Byte                          disRateMask\r
255         )\r
256 {\r
257         pCoexDm->curRaMask = disRateMask;\r
258         \r
259         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
260         {\r
261                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
262         }\r
263         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
264 }\r
265 \r
266 VOID\r
267 halbtc8723b1ant_AutoRateFallbackRetry(\r
268         IN      PBTC_COEXIST            pBtCoexist,\r
269         IN      BOOLEAN                         bForceExec,\r
270         IN      u1Byte                          type\r
271         )\r
272 {\r
273         BOOLEAN bWifiUnderBMode=FALSE;\r
274         \r
275         pCoexDm->curArfrType = type;\r
276 \r
277         if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))\r
278         {\r
279                 switch(pCoexDm->curArfrType)\r
280                 {\r
281                         case 0: // normal mode\r
282                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);\r
283                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);\r
284                                 break;\r
285                         case 1: \r
286                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
287                                 if(bWifiUnderBMode)\r
288                                 {\r
289                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
290                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);\r
291                                 }\r
292                                 else\r
293                                 {\r
294                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
295                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);\r
296                                 }\r
297                                 break;\r
298                         default:\r
299                                 break;\r
300                 }\r
301         }\r
302 \r
303         pCoexDm->preArfrType = pCoexDm->curArfrType;\r
304 }\r
305 \r
306 VOID\r
307 halbtc8723b1ant_RetryLimit(\r
308         IN      PBTC_COEXIST            pBtCoexist,\r
309         IN      BOOLEAN                         bForceExec,\r
310         IN      u1Byte                          type\r
311         )\r
312 {\r
313         pCoexDm->curRetryLimitType = type;\r
314 \r
315         if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))\r
316         {\r
317                 switch(pCoexDm->curRetryLimitType)\r
318                 {\r
319                         case 0: // normal mode\r
320                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);\r
321                                 break;\r
322                         case 1: // retry limit=8\r
323                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);\r
324                                 break;\r
325                         default:\r
326                                 break;\r
327                 }\r
328         }\r
329 \r
330         pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;\r
331 }\r
332 \r
333 VOID\r
334 halbtc8723b1ant_AmpduMaxTime(\r
335         IN      PBTC_COEXIST            pBtCoexist,\r
336         IN      BOOLEAN                         bForceExec,\r
337         IN      u1Byte                          type\r
338         )\r
339 {\r
340         pCoexDm->curAmpduTimeType = type;\r
341 \r
342         if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))\r
343         {\r
344                 switch(pCoexDm->curAmpduTimeType)\r
345                 {\r
346                         case 0: // normal mode\r
347                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);\r
348                                 break;\r
349                         case 1: // AMPDU timw = 0x38 * 32us\r
350                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);\r
351                                 break;\r
352                         default:\r
353                                 break;\r
354                 }\r
355         }\r
356 \r
357         pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;\r
358 }\r
359 \r
360 VOID\r
361 halbtc8723b1ant_LimitedTx(\r
362         IN      PBTC_COEXIST            pBtCoexist,\r
363         IN      BOOLEAN                         bForceExec,\r
364         IN      u1Byte                          raMaskType,\r
365         IN      u1Byte                          arfrType,\r
366         IN      u1Byte                          retryLimitType,\r
367         IN      u1Byte                          ampduTimeType\r
368         )\r
369 {\r
370         switch(raMaskType)\r
371         {\r
372                 case 0: // normal mode\r
373                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);\r
374                         break;\r
375                 case 1: // disable cck 1/2\r
376                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);\r
377                         break;\r
378                 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4\r
379                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);\r
380                         break;\r
381                 default:\r
382                         break;\r
383         }\r
384 \r
385         halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
386         halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
387         halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
388 }\r
389 \r
390 VOID\r
391 halbtc8723b1ant_LimitedRx(\r
392         IN      PBTC_COEXIST            pBtCoexist,\r
393         IN      BOOLEAN                         bForceExec,\r
394         IN      BOOLEAN                         bRejApAggPkt,\r
395         IN      BOOLEAN                         bBtCtrlAggBufSize,\r
396         IN      u1Byte                          aggBufSize\r
397         )\r
398 {\r
399         BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
400         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
401         u1Byte  rxAggSize=aggBufSize;\r
402 \r
403         //============================================\r
404         //      Rx Aggregation related setting\r
405         //============================================\r
406         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
407         // decide BT control aggregation buf size or not\r
408         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
409         // aggregation buf size, only work when BT control Rx aggregation size.\r
410         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
411         // real update aggregation setting\r
412         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
413 \r
414 \r
415 }\r
416 \r
417 VOID\r
418 halbtc8723b1ant_QueryBtInfo(\r
419         IN      PBTC_COEXIST            pBtCoexist\r
420         )\r
421 {\r
422         u1Byte                  H2C_Parameter[1] ={0};\r
423 \r
424         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
425 \r
426         H2C_Parameter[0] |= BIT0;       // trigger\r
427 \r
428         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
429                 H2C_Parameter[0]));\r
430 \r
431         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
432 }\r
433 \r
434 VOID\r
435 halbtc8723b1ant_MonitorBtCtr(\r
436         IN      PBTC_COEXIST            pBtCoexist\r
437         )\r
438 {\r
439         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;\r
440         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
441         u1Byte                  u1Tmp, u1Tmp1;\r
442         s4Byte                  wifiRssi;\r
443         static u1Byte           NumOfBtCounterChk = 0;\r
444         \r
445        //to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS\r
446         //if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) ) \r
447 \r
448         if (pCoexSta->bUnderIps)\r
449         {\r
450                 //pCoexSta->highPriorityTx = 65535;\r
451                 //pCoexSta->highPriorityRx = 65535;\r
452                 //pCoexSta->lowPriorityTx = 65535;\r
453                 //pCoexSta->lowPriorityRx = 65535;\r
454                 //return;\r
455         }\r
456                 \r
457         regHPTxRx = 0x770;\r
458         regLPTxRx = 0x774;\r
459 \r
460         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
461         regHPTx = u4Tmp & bMaskLWord;\r
462         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
463 \r
464         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
465         regLPTx = u4Tmp & bMaskLWord;\r
466         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
467                 \r
468         pCoexSta->highPriorityTx = regHPTx;\r
469         pCoexSta->highPriorityRx = regHPRx;\r
470         pCoexSta->lowPriorityTx = regLPTx;\r
471         pCoexSta->lowPriorityRx = regLPRx;\r
472 \r
473         if( (pCoexSta->lowPriorityTx > 1150)  && (!pCoexSta->bC2hBtInquiryPage))\r
474                 pCoexSta->popEventCnt++;\r
475 \r
476         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",\r
477                 regHPRx, regHPTx, regLPRx, regLPTx));\r
478 \r
479         // reset counter\r
480         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
481 \r
482         if ((regHPTx == 0) && (regHPRx ==0) && (regLPTx == 0) && (regLPRx == 0))\r
483         {\r
484                 NumOfBtCounterChk++;\r
485                 if (NumOfBtCounterChk >= 3)\r
486 {\r
487                         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
488                         NumOfBtCounterChk = 0;\r
489                 }\r
490         }\r
491 }\r
492 \r
493 \r
494 VOID\r
495 halbtc8723b1ant_MonitorWiFiCtr(\r
496         IN      PBTC_COEXIST            pBtCoexist\r
497         )\r
498 {\r
499         u4Byte  u4Tmp;\r
500         u2Byte  u2Tmp[3];\r
501         s4Byte  wifiRssi=0;\r
502         BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;\r
503         static u1Byte nCCKLockCounter = 0;\r
504 \r
505         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
506         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
507         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
508 \r
509         if (pCoexSta->bUnderIps)\r
510         {\r
511                 pCoexSta->nCRCOK_CCK = 0;\r
512                 pCoexSta->nCRCOK_11g = 0;\r
513                 pCoexSta->nCRCOK_11n = 0;\r
514                 pCoexSta->nCRCOK_11nAgg = 0;\r
515 \r
516                 pCoexSta->nCRCErr_CCK = 0;\r
517                 pCoexSta->nCRCErr_11g = 0;\r
518                 pCoexSta->nCRCErr_11n = 0;\r
519                 pCoexSta->nCRCErr_11nAgg = 0;   \r
520         }\r
521         else\r
522         {\r
523                 pCoexSta->nCRCOK_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);\r
524                 pCoexSta->nCRCOK_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);\r
525                 pCoexSta->nCRCOK_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);\r
526                 pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);\r
527 \r
528                 pCoexSta->nCRCErr_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);\r
529                 pCoexSta->nCRCErr_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);\r
530                 pCoexSta->nCRCErr_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);\r
531                 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);                \r
532         }\r
533 \r
534 \r
535         //reset counter\r
536         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);\r
537         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);\r
538 \r
539         if ( (bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))\r
540         {\r
541                 if ( (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||\r
542                         (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||\r
543                         (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) )\r
544                 {\r
545                         if (pCoexSta->nCRCOK_CCK >(pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n + \r
546                                 pCoexSta->nCRCOK_11nAgg) )\r
547                         {\r
548                                 if (nCCKLockCounter < 5)\r
549                                  nCCKLockCounter++;\r
550                         }\r
551                         else\r
552                         {\r
553                                 if (nCCKLockCounter > 0)\r
554                                  nCCKLockCounter--;\r
555                         }\r
556 \r
557                 }\r
558                 else\r
559                 {\r
560                         if (nCCKLockCounter > 0)\r
561                           nCCKLockCounter--;\r
562                 }\r
563         }\r
564         else\r
565         {\r
566                 if (nCCKLockCounter > 0)\r
567                         nCCKLockCounter--;\r
568         }\r
569 \r
570         if (!pCoexSta->bPreCCKLock)\r
571         {\r
572 \r
573                 if (nCCKLockCounter >= 5)\r
574                  pCoexSta->bCCKLock = TRUE;\r
575                 else\r
576                  pCoexSta->bCCKLock = FALSE;                    \r
577         }\r
578         else\r
579         {\r
580                 if (nCCKLockCounter == 0)\r
581                  pCoexSta->bCCKLock = FALSE;\r
582                 else\r
583                  pCoexSta->bCCKLock = TRUE;             \r
584         }\r
585 \r
586         if  (pCoexSta->bCCKLock)\r
587                 pCoexSta->bCCKEverLock = TRUE;\r
588         \r
589         pCoexSta->bPreCCKLock =  pCoexSta->bCCKLock;    \r
590                 \r
591 \r
592 }\r
593 \r
594 BOOLEAN\r
595 halbtc8723b1ant_IsWifiStatusChanged(\r
596         IN      PBTC_COEXIST            pBtCoexist\r
597         )\r
598 {\r
599         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
600         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
601         BOOLEAN bWifiConnected=FALSE;\r
602 \r
603         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
604         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
605         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
606         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
607 \r
608         if(bWifiConnected)\r
609         {\r
610                 if(bWifiBusy != bPreWifiBusy)\r
611                 {\r
612                         bPreWifiBusy = bWifiBusy;\r
613                         return TRUE;\r
614                 }\r
615                 if(bUnder4way != bPreUnder4way)\r
616                 {\r
617                         bPreUnder4way = bUnder4way;\r
618                         return TRUE;\r
619                 }\r
620                 if(bBtHsOn != bPreBtHsOn)\r
621                 {\r
622                         bPreBtHsOn = bBtHsOn;\r
623                         return TRUE;\r
624                 }\r
625         }\r
626 \r
627         return FALSE;\r
628 }\r
629 \r
630 VOID\r
631 halbtc8723b1ant_UpdateBtLinkInfo(\r
632         IN      PBTC_COEXIST            pBtCoexist\r
633         )\r
634 {\r
635         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
636         BOOLEAN                         bBtHsOn=FALSE;\r
637 \r
638         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
639 \r
640         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
641         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
642         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
643         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
644         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
645         pBtLinkInfo->bBtHiPriLinkExist = pCoexSta->bBtHiPriLinkExist;\r
646 \r
647         // work around for HS mode.\r
648         if(bBtHsOn)\r
649         {\r
650                 pBtLinkInfo->bPanExist = TRUE;\r
651                 pBtLinkInfo->bBtLinkExist = TRUE;\r
652         }\r
653 \r
654         // check if Sco only\r
655         if( pBtLinkInfo->bScoExist &&\r
656                 !pBtLinkInfo->bA2dpExist &&\r
657                 !pBtLinkInfo->bPanExist &&\r
658                 !pBtLinkInfo->bHidExist )\r
659                 pBtLinkInfo->bScoOnly = TRUE;\r
660         else\r
661                 pBtLinkInfo->bScoOnly = FALSE;\r
662 \r
663         // check if A2dp only\r
664         if( !pBtLinkInfo->bScoExist &&\r
665                 pBtLinkInfo->bA2dpExist &&\r
666                 !pBtLinkInfo->bPanExist &&\r
667                 !pBtLinkInfo->bHidExist )\r
668                 pBtLinkInfo->bA2dpOnly = TRUE;\r
669         else\r
670                 pBtLinkInfo->bA2dpOnly = FALSE;\r
671 \r
672         // check if Pan only\r
673         if( !pBtLinkInfo->bScoExist &&\r
674                 !pBtLinkInfo->bA2dpExist &&\r
675                 pBtLinkInfo->bPanExist &&\r
676                 !pBtLinkInfo->bHidExist )\r
677                 pBtLinkInfo->bPanOnly = TRUE;\r
678         else\r
679                 pBtLinkInfo->bPanOnly = FALSE;\r
680         \r
681         // check if Hid only\r
682         if( !pBtLinkInfo->bScoExist &&\r
683                 !pBtLinkInfo->bA2dpExist &&\r
684                 !pBtLinkInfo->bPanExist &&\r
685                 pBtLinkInfo->bHidExist )\r
686                 pBtLinkInfo->bHidOnly = TRUE;\r
687         else\r
688                 pBtLinkInfo->bHidOnly = FALSE;\r
689 }\r
690 \r
691 u1Byte\r
692 halbtc8723b1ant_ActionAlgorithm(\r
693         IN      PBTC_COEXIST            pBtCoexist\r
694         )\r
695 {\r
696         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
697         BOOLEAN                         bBtHsOn=FALSE;\r
698         u1Byte                          algorithm=BT_8723B_1ANT_COEX_ALGO_UNDEFINED;\r
699         u1Byte                          numOfDiffProfile=0;\r
700 \r
701         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
702 \r
703         if(!pBtLinkInfo->bBtLinkExist)\r
704         {\r
705                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
706                 return algorithm;\r
707         }\r
708 \r
709         if(pBtLinkInfo->bScoExist)\r
710                 numOfDiffProfile++;\r
711         if(pBtLinkInfo->bHidExist)\r
712                 numOfDiffProfile++;\r
713         if(pBtLinkInfo->bPanExist)\r
714                 numOfDiffProfile++;\r
715         if(pBtLinkInfo->bA2dpExist)\r
716                 numOfDiffProfile++;\r
717         \r
718         if(numOfDiffProfile == 1)\r
719         {\r
720                 if(pBtLinkInfo->bScoExist)\r
721                 {\r
722                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO only\n"));\r
723                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
724                 }\r
725                 else\r
726                 {\r
727                         if(pBtLinkInfo->bHidExist)\r
728                         {\r
729                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID only\n"));\r
730                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
731                         }\r
732                         else if(pBtLinkInfo->bA2dpExist)\r
733                         {\r
734                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP only\n"));\r
735                                 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;\r
736                         }\r
737                         else if(pBtLinkInfo->bPanExist)\r
738                         {\r
739                                 if(bBtHsOn)\r
740                                 {\r
741                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(HS) only\n"));\r
742                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;\r
743                                 }\r
744                                 else\r
745                                 {\r
746                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(EDR) only\n"));\r
747                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;\r
748                                 }\r
749                         }\r
750                 }\r
751         }\r
752         else if(numOfDiffProfile == 2)\r
753         {\r
754                 if(pBtLinkInfo->bScoExist)\r
755                 {\r
756                         if(pBtLinkInfo->bHidExist)\r
757                         {\r
758                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID\n"));\r
759                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
760                         }\r
761                         else if(pBtLinkInfo->bA2dpExist)\r
762                         {\r
763                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));\r
764                                 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
765                         }\r
766                         else if(pBtLinkInfo->bPanExist)\r
767                         {\r
768                                 if(bBtHsOn)\r
769                                 {\r
770                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));\r
771                                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
772                                 }\r
773                                 else\r
774                                 {\r
775                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));\r
776                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
777                                 }\r
778                         }\r
779                 }\r
780                 else\r
781                 {\r
782                         if( pBtLinkInfo->bHidExist &&\r
783                                 pBtLinkInfo->bA2dpExist )\r
784                         {\r
785                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP\n"));\r
786                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
787                         }\r
788                         else if( pBtLinkInfo->bHidExist &&\r
789                                 pBtLinkInfo->bPanExist )\r
790                         {\r
791                                 if(bBtHsOn)\r
792                                 {\r
793                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));\r
794                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
795                                 }\r
796                                 else\r
797                                 {\r
798                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));\r
799                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
800                                 }\r
801                         }\r
802                         else if( pBtLinkInfo->bPanExist &&\r
803                                 pBtLinkInfo->bA2dpExist )\r
804                         {\r
805                                 if(bBtHsOn)\r
806                                 {\r
807                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));\r
808                                         algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;\r
809                                 }\r
810                                 else\r
811                                 {\r
812                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));\r
813                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;\r
814                                 }\r
815                         }\r
816                 }\r
817         }\r
818         else if(numOfDiffProfile == 3)\r
819         {\r
820                 if(pBtLinkInfo->bScoExist)\r
821                 {\r
822                         if( pBtLinkInfo->bHidExist &&\r
823                                 pBtLinkInfo->bA2dpExist )\r
824                         {\r
825                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));\r
826                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
827                         }\r
828                         else if( pBtLinkInfo->bHidExist &&\r
829                                 pBtLinkInfo->bPanExist )\r
830                         {\r
831                                 if(bBtHsOn)\r
832                                 {\r
833                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));\r
834                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
835                                 }\r
836                                 else\r
837                                 {\r
838                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));\r
839                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
840                                 }\r
841                         }\r
842                         else if( pBtLinkInfo->bPanExist &&\r
843                                 pBtLinkInfo->bA2dpExist )\r
844                         {\r
845                                 if(bBtHsOn)\r
846                                 {\r
847                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));\r
848                                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
849                                 }\r
850                                 else\r
851                                 {\r
852                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));\r
853                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
854                                 }\r
855                         }\r
856                 }\r
857                 else\r
858                 {\r
859                         if( pBtLinkInfo->bHidExist &&\r
860                                 pBtLinkInfo->bPanExist &&\r
861                                 pBtLinkInfo->bA2dpExist )\r
862                         {\r
863                                 if(bBtHsOn)\r
864                                 {\r
865                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));\r
866                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
867                                 }\r
868                                 else\r
869                                 {\r
870                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));\r
871                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
872                                 }\r
873                         }\r
874                 }\r
875         }\r
876         else if(numOfDiffProfile >= 3)\r
877         {\r
878                 if(pBtLinkInfo->bScoExist)\r
879                 {\r
880                         if( pBtLinkInfo->bHidExist &&\r
881                                 pBtLinkInfo->bPanExist &&\r
882                                 pBtLinkInfo->bA2dpExist )\r
883                         {\r
884                                 if(bBtHsOn)\r
885                                 {\r
886                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));\r
887 \r
888                                 }\r
889                                 else\r
890                                 {\r
891                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
892                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
893                                 }\r
894                         }\r
895                 }\r
896         }\r
897 \r
898         return algorithm;\r
899 }\r
900 \r
901 VOID\r
902 halbtc8723b1ant_SetBtAutoReport(\r
903         IN      PBTC_COEXIST            pBtCoexist,\r
904         IN      BOOLEAN                 bEnableAutoReport\r
905         )\r
906 {\r
907         u1Byte                  H2C_Parameter[1] ={0};\r
908         \r
909         H2C_Parameter[0] = 0;\r
910 \r
911         if(bEnableAutoReport)\r
912         {\r
913                 H2C_Parameter[0] |= BIT0;\r
914         }\r
915 \r
916         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
917                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
918 \r
919         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
920 }\r
921 \r
922 VOID\r
923 halbtc8723b1ant_BtAutoReport(\r
924         IN      PBTC_COEXIST            pBtCoexist,\r
925         IN      BOOLEAN                 bForceExec,\r
926         IN      BOOLEAN                 bEnableAutoReport\r
927         )\r
928 {\r
929         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
930                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
931         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
932 \r
933         if(!bForceExec)\r
934         {\r
935                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
936                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
937 \r
938                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
939                         return;\r
940         }\r
941         halbtc8723b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
942 \r
943         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
944 }\r
945 \r
946 VOID\r
947 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(\r
948         IN      PBTC_COEXIST            pBtCoexist,\r
949         IN      BOOLEAN                 bLowPenaltyRa\r
950         )\r
951 {\r
952         u1Byte                  H2C_Parameter[6] ={0};\r
953         \r
954         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
955 \r
956         if(bLowPenaltyRa)\r
957         {\r
958                 H2C_Parameter[1] |= BIT0;\r
959                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
960                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
961                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
962                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
963         }\r
964 \r
965         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
966                 (bLowPenaltyRa? "ON!!":"OFF!!") ));\r
967 \r
968         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
969 }\r
970 \r
971 VOID\r
972 halbtc8723b1ant_LowPenaltyRa(\r
973         IN      PBTC_COEXIST            pBtCoexist,\r
974         IN      BOOLEAN                 bForceExec,\r
975         IN      BOOLEAN                 bLowPenaltyRa\r
976         )\r
977 {\r
978         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
979 \r
980         if(!bForceExec)\r
981         {\r
982                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
983                         return;\r
984         }\r
985         halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
986 \r
987         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
988 }\r
989 \r
990 VOID\r
991 halbtc8723b1ant_SetCoexTable(\r
992         IN      PBTC_COEXIST    pBtCoexist,\r
993         IN      u4Byte          val0x6c0,\r
994         IN      u4Byte          val0x6c4,\r
995         IN      u4Byte          val0x6c8,\r
996         IN      u1Byte          val0x6cc\r
997         )\r
998 {\r
999         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1000         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1001 \r
1002         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
1003         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
1004 \r
1005         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1006         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1007 \r
1008         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1009         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1010 }\r
1011 \r
1012 VOID\r
1013 halbtc8723b1ant_CoexTable(\r
1014         IN      PBTC_COEXIST            pBtCoexist,\r
1015         IN      BOOLEAN                 bForceExec,\r
1016         IN      u4Byte                  val0x6c0,\r
1017         IN      u4Byte                  val0x6c4,\r
1018         IN      u4Byte                  val0x6c8,\r
1019         IN      u1Byte                  val0x6cc\r
1020         )\r
1021 {\r
1022         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n", \r
1023                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));\r
1024         pCoexDm->curVal0x6c0 = val0x6c0;\r
1025         pCoexDm->curVal0x6c4 = val0x6c4;\r
1026         pCoexDm->curVal0x6c8 = val0x6c8;\r
1027         pCoexDm->curVal0x6cc = val0x6cc;\r
1028 \r
1029         if(!bForceExec)\r
1030         {\r
1031                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
1032                 //      pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
1033                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
1034                 //      pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
1035         \r
1036                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1037                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
1038                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1039                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1040                         return;\r
1041         }\r
1042         halbtc8723b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
1043 \r
1044         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1045         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
1046         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1047         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1048 }\r
1049 \r
1050 VOID\r
1051 halbtc8723b1ant_CoexTableWithType(\r
1052         IN      PBTC_COEXIST            pBtCoexist,\r
1053         IN      BOOLEAN                         bForceExec,\r
1054         IN      u1Byte                          type\r
1055         )\r
1056 {\r
1057         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));\r
1058         \r
1059         pCoexSta->nCoexTableType = type;\r
1060         \r
1061         switch(type)\r
1062         {\r
1063                 case 0:\r
1064                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
1065                         break;\r
1066                 case 1:\r
1067                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
1068                         break;\r
1069                 case 2:\r
1070                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
1071                         break;\r
1072                 case 3:\r
1073                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
1074                         break;\r
1075                 case 4:\r
1076                         if ((pCoexSta->nScanAPNum <= 5) || ( pCoexSta->bCCKEverLock) )\r
1077                                 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);\r
1078                         else\r
1079                                 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);\r
1080                         break;\r
1081                 case 5:\r
1082                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);\r
1083                         break;\r
1084                 case 6:\r
1085                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);\r
1086                         break;\r
1087                 case 7:\r
1088                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
1089                         break;\r
1090                 default:\r
1091                         break;\r
1092         }\r
1093 }\r
1094 \r
1095 VOID\r
1096 halbtc8723b1ant_SetFwIgnoreWlanAct(\r
1097         IN      PBTC_COEXIST            pBtCoexist,\r
1098         IN      BOOLEAN                 bEnable\r
1099         )\r
1100 {\r
1101         u1Byte                  H2C_Parameter[1] ={0};\r
1102                 \r
1103         if(bEnable)\r
1104         {\r
1105                 H2C_Parameter[0] |= BIT0;               // function enable\r
1106         }\r
1107         \r
1108         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
1109                 H2C_Parameter[0]));\r
1110 \r
1111         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
1112 }\r
1113 \r
1114 VOID\r
1115 halbtc8723b1ant_IgnoreWlanAct(\r
1116         IN      PBTC_COEXIST            pBtCoexist,\r
1117         IN      BOOLEAN                 bForceExec,\r
1118         IN      BOOLEAN                 bEnable\r
1119         )\r
1120 {\r
1121         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1122                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1123         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1124 \r
1125         if(!bForceExec)\r
1126         {\r
1127                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
1128                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
1129 \r
1130                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1131                         return;\r
1132         }\r
1133         halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1134 \r
1135         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1136 }\r
1137 \r
1138 VOID\r
1139 halbtc8723b1ant_SetLpsRpwm(\r
1140         IN      PBTC_COEXIST            pBtCoexist,\r
1141         IN      u1Byte                  lpsVal,\r
1142         IN      u1Byte                  rpwmVal\r
1143         )\r
1144 {\r
1145         u1Byte  lps=lpsVal;\r
1146         u1Byte  rpwm=rpwmVal;\r
1147         \r
1148         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1149         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1150 }\r
1151 \r
1152 VOID\r
1153 halbtc8723b1ant_LpsRpwm(\r
1154         IN      PBTC_COEXIST            pBtCoexist,\r
1155         IN      BOOLEAN                 bForceExec,\r
1156         IN      u1Byte                  lpsVal,\r
1157         IN      u1Byte                  rpwmVal\r
1158         )\r
1159 {\r
1160         BOOLEAN bForceExecPwrCmd=FALSE;\r
1161         \r
1162         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1163                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1164         pCoexDm->curLps = lpsVal;\r
1165         pCoexDm->curRpwm = rpwmVal;\r
1166 \r
1167         if(!bForceExec)\r
1168         {\r
1169                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RxBeaconMode=0x%x , LPS-RPWM=0x%x!!\n", \r
1170                          pCoexDm->curLps, pCoexDm->curRpwm));\r
1171 \r
1172                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1173                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1174                 {\r
1175                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RPWM_Last=0x%x , LPS-RPWM_Now=0x%x!!\n", \r
1176                                  pCoexDm->preRpwm, pCoexDm->curRpwm));\r
1177 \r
1178                         return;\r
1179                 }\r
1180         }\r
1181         halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1182 \r
1183         pCoexDm->preLps = pCoexDm->curLps;\r
1184         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1185 }\r
1186 \r
1187 VOID\r
1188 halbtc8723b1ant_SwMechanism(\r
1189         IN      PBTC_COEXIST    pBtCoexist,     \r
1190         IN      BOOLEAN                 bLowPenaltyRA\r
1191         ) \r
1192 {\r
1193         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], SM[LpRA] = %d\n", \r
1194                 bLowPenaltyRA));\r
1195 \r
1196         halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1197 }\r
1198 \r
1199 VOID\r
1200 halbtc8723b1ant_SetAntPath(\r
1201         IN      PBTC_COEXIST            pBtCoexist,\r
1202         IN      u1Byte                          antPosType,\r
1203         IN      BOOLEAN                         bForceExec,\r
1204         IN      BOOLEAN                         bInitHwCfg,\r
1205         IN      BOOLEAN                         bWifiOff\r
1206         )\r
1207 {\r
1208         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1209         u4Byte                  fwVer=0, u4Tmp=0, cntBtCalChk=0;\r
1210         BOOLEAN                 bPgExtSwitch=FALSE;\r
1211         BOOLEAN                 bUseExtSwitch=FALSE;\r
1212         BOOLEAN                 bIsInMpMode = FALSE;\r
1213         u1Byte                  H2C_Parameter[2] ={0}, u1Tmp = 0;\r
1214 \r
1215         pCoexDm->curAntPosType = antPosType;\r
1216         \r
1217         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);\r
1218         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);        // [31:16]=fw ver, [15:0]=fw sub ver\r
1219 \r
1220         if((fwVer>0 && fwVer<0xc0000) || bPgExtSwitch)\r
1221                 bUseExtSwitch = TRUE;\r
1222 \r
1223         if(bInitHwCfg)\r
1224         {\r
1225                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi TRx Mask on\r
1226                 //remove due to interrupt is disabled that polling c2h will fail and delay 100ms.\r
1227                 //pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT TRx Mask on\r
1228 \r
1229                 if(fwVer >= 0x180000)\r
1230                 {\r
1231                 /* Use H2C to set GNT_BT to HIGH */\r
1232                 H2C_Parameter[0] = 1;\r
1233                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
1234                 }\r
1235                 else\r
1236                 {\r
1237                         // set grant_bt to high\r
1238                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); \r
1239                 }\r
1240                 //set wlan_act control by PTA\r
1241                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); \r
1242 \r
1243                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT\r
1244 \r
1245                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);\r
1246                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);\r
1247                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);\r
1248                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);\r
1249         }\r
1250         else if(bWifiOff)\r
1251         {\r
1252                 if(fwVer >= 0x180000)\r
1253                 {\r
1254                 /* Use H2C to set GNT_BT to HIGH */\r
1255                 H2C_Parameter[0] = 1;\r
1256                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
1257                 }\r
1258                 else\r
1259                 {\r
1260                         // set grant_bt to high\r
1261                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18); \r
1262                 }\r
1263                 //set wlan_act to always low\r
1264                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
1265                 \r
1266                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);\r
1267                 if(!bIsInMpMode)        \r
1268                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT\r
1269                 else\r
1270                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
1271         \r
1272                 // 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL   BT Vendor 0xac=0xf002\r
1273                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1274                 u4Tmp &= ~BIT23;\r
1275                 u4Tmp &= ~BIT24;\r
1276                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1277         }\r
1278         else\r
1279         {                       \r
1280                 /* Use H2C to set GNT_BT to LOW */\r
1281                 if(fwVer >= 0x180000)\r
1282                 {\r
1283                 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0)\r
1284                 {               \r
1285                         H2C_Parameter[0] = 0;\r
1286                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
1287                 }\r
1288                 }\r
1289                 else\r
1290                 {\r
1291                         // BT calibration check\r
1292                         while(cntBtCalChk <= 20)\r
1293                         {\r
1294                                 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);\r
1295                                 cntBtCalChk++;\r
1296                                 if(u1Tmp & BIT0)\r
1297                                 {\r
1298                                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", cntBtCalChk));\r
1299                                         delay_ms(50);\r
1300                                 }\r
1301                                 else\r
1302                                 {\r
1303                                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", cntBtCalChk));\r
1304                                         break;\r
1305                                 }\r
1306                         }\r
1307 \r
1308                         // set grant_bt to PTA\r
1309                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);\r
1310                 }\r
1311 \r
1312                 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc)\r
1313                 {\r
1314                         //set wlan_act control by PTA\r
1315                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); \r
1316                 }\r
1317 \r
1318                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
1319         }\r
1320         \r
1321         if(bUseExtSwitch)\r
1322         {\r
1323                 if(bInitHwCfg)\r
1324                 {\r
1325                         // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1326                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1327                         u4Tmp &=~BIT23;\r
1328                         u4Tmp |= BIT24;\r
1329                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1330 \r
1331                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); // fixed internal switch S1->WiFi, S0->BT\r
1332 \r
1333                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1334                         {\r
1335                                 //tell firmware "no antenna inverse"\r
1336                                 H2C_Parameter[0] = 0;\r
1337                                 H2C_Parameter[1] = 1;  //ext switch type\r
1338                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1339                         }\r
1340                         else\r
1341                         {\r
1342                                 //tell firmware "antenna inverse"\r
1343                                 H2C_Parameter[0] = 1;\r
1344                                 H2C_Parameter[1] = 1;  //ext switch type\r
1345                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1346                         }\r
1347                 }\r
1348                 \r
1349                 if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType))\r
1350                 {\r
1351                         // ext switch setting\r
1352                         switch(antPosType)\r
1353                         {\r
1354                                 case BTC_ANT_PATH_WIFI:\r
1355                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1356                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1357                                         else\r
1358                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1359                                         break;\r
1360                                 case BTC_ANT_PATH_BT:\r
1361                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1362                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1363                                         else                                    \r
1364                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1365                                         break;\r
1366                                 default:\r
1367                                 case BTC_ANT_PATH_PTA:\r
1368                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1369                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1370                                         else\r
1371                                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1372                                         break;\r
1373                         }\r
1374                 }\r
1375         }\r
1376         else\r
1377         {\r
1378                 if(bInitHwCfg)\r
1379                 {\r
1380                         // 0x4c[23]=1, 0x4c[24]=0  Antenna control by 0x64\r
1381                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1382                         u4Tmp |= BIT23;\r
1383                         u4Tmp &=~BIT24;       \r
1384                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1385 \r
1386                         //Fix Ext switch Main->S1, Aux->S0\r
1387                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); \r
1388 \r
1389                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1390                         {\r
1391         \r
1392                                 //tell firmware "no antenna inverse"\r
1393                                 H2C_Parameter[0] = 0;\r
1394                                 H2C_Parameter[1] = 0;  //internal switch type\r
1395                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1396                         }\r
1397                         else\r
1398                         {\r
1399                 \r
1400                                 //tell firmware "antenna inverse"\r
1401                                 H2C_Parameter[0] = 1;\r
1402                                 H2C_Parameter[1] = 0;  //internal switch type\r
1403                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1404                         }\r
1405                 }\r
1406         \r
1407                 if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType))\r
1408                 {\r
1409                         // internal switch setting\r
1410                         switch(antPosType)\r
1411                         {\r
1412                                 case BTC_ANT_PATH_WIFI:\r
1413                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1414                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
1415                                         else\r
1416                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);\r
1417                                         break;\r
1418                                 case BTC_ANT_PATH_BT:\r
1419                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1420                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);\r
1421                                         else\r
1422                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
1423                                         break;\r
1424                                 default:\r
1425                                 case BTC_ANT_PATH_PTA:\r
1426                                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1427                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);                                   \r
1428                                         else\r
1429                                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);\r
1430                                         break;\r
1431                         }\r
1432                 }\r
1433         }\r
1434 \r
1435         pCoexDm->preAntPosType = pCoexDm->curAntPosType;\r
1436 }\r
1437 \r
1438 VOID\r
1439 halbtc8723b1ant_SetAntPathDCut(\r
1440         IN      PBTC_COEXIST            pBtCoexist,\r
1441         IN      BOOLEAN                         bAntennaAux,    //For 1-Ant--> 1: Antenna at S0, 0: Antenna at S1. Set 0 for 2-Ant\r
1442         IN      BOOLEAN                         bExtSwitch,             // 1: Ext Switch (SPDT) exist on module, 0: no Ext Switch (SPDT) exist on module\r
1443         IN      BOOLEAN                         bTwoAntenna,    // 1: 2-Antenna, 0:1-Antenna\r
1444         IN      u1Byte                          antennaPos,             //Set Antenna Pos, For 1-Ant: BTC_ANT_PATH_WIFI, BTC_ANT_PATH_BT, BTC_ANT_PATH_PTA, For 2-Ant:BTC_ANT_WIFI_AT_MAIN, BTC_ANT_WIFI_AT_Aux\r
1445         IN      u1Byte                          wifiState               //BTC_WIFI_STAT_INIT, BTC_WIFI_STAT_IQK, BTC_WIFI_STAT_NORMAL_OFF, BTC_WIFI_STAT_MP_OFF, BTC_WIFI_STAT_NORMAL, BTC_WIFI_STAT_ANT_DIV\r
1446         )\r
1447 {\r
1448         u1Byte  dataLen=5;\r
1449         u1Byte  buf[6] = {0};\r
1450 \r
1451         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set BT Ant, bAntennaAux/bExtSwitch/bTwoAntenna/antennaPos/wifiState=%d/%d/%d/%d/%d\n",\r
1452                 bAntennaAux, bExtSwitch, bTwoAntenna, antennaPos, wifiState));\r
1453 \r
1454         buf[0] = dataLen; \r
1455         \r
1456         if(bAntennaAux)\r
1457                 buf[1] = 0x1;\r
1458         \r
1459         if(bExtSwitch)\r
1460                 buf[2] = 0x1;                   \r
1461         \r
1462         if(bTwoAntenna)\r
1463                 buf[3] = 0x1;\r
1464 \r
1465         buf[4] = antennaPos;\r
1466 \r
1467         buf[5] = wifiState;\r
1468         \r
1469         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_8723B_ANT, (PVOID)&buf[0]);    \r
1470 }\r
1471 \r
1472 VOID\r
1473 halbtc8723b1ant_SetFwPstdma(\r
1474         IN      PBTC_COEXIST            pBtCoexist,\r
1475         IN      u1Byte                  byte1,\r
1476         IN      u1Byte                  byte2,\r
1477         IN      u1Byte                  byte3,\r
1478         IN      u1Byte                  byte4,\r
1479         IN      u1Byte                  byte5\r
1480         )\r
1481 {\r
1482         u1Byte                  H2C_Parameter[5] ={0};\r
1483         u1Byte                  realByte1=byte1, realByte5=byte5;\r
1484         BOOLEAN                 bApEnable=FALSE;\r
1485 \r
1486         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
1487 \r
1488         if(bApEnable)\r
1489         {\r
1490                 if(byte1&BIT4 && !(byte1&BIT5))\r
1491                 {                       \r
1492                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], FW for 1Ant AP mode\n"));\r
1493                         realByte1 &= ~BIT4;\r
1494                         realByte1 |= BIT5;\r
1495 \r
1496                         realByte5 |= BIT5;\r
1497                         realByte5 &= ~BIT6;\r
1498                 }\r
1499         }\r
1500 \r
1501         H2C_Parameter[0] = realByte1;   \r
1502         H2C_Parameter[1] = byte2;       \r
1503         H2C_Parameter[2] = byte3;\r
1504         H2C_Parameter[3] = byte4;\r
1505         H2C_Parameter[4] = realByte5;\r
1506 \r
1507         pCoexDm->psTdmaPara[0] = realByte1;\r
1508         pCoexDm->psTdmaPara[1] = byte2;\r
1509         pCoexDm->psTdmaPara[2] = byte3;\r
1510         pCoexDm->psTdmaPara[3] = byte4;\r
1511         pCoexDm->psTdmaPara[4] = realByte5;\r
1512         \r
1513         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", \r
1514                 H2C_Parameter[0], \r
1515                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1516 \r
1517         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1518 }\r
1519 \r
1520 \r
1521 VOID\r
1522 halbtc8723b1ant_PsTdma(\r
1523         IN      PBTC_COEXIST            pBtCoexist,\r
1524         IN      BOOLEAN                 bForceExec,\r
1525         IN      BOOLEAN                 bTurnOn,\r
1526         IN      u1Byte                  type\r
1527         )\r
1528 {\r
1529         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1530         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1531         BOOLEAN                 bTurnOnByCnt=FALSE, bWifiBusy=FALSE, bWiFiNoisy=FALSE;\r
1532         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
1533         u1Byte                  psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val =  0x10;\r
1534         s1Byte                  nWiFiDurationAdjust = 0x0;\r
1535         static BOOLEAN   bPreWifiBusy=FALSE;\r
1536 \r
1537         //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1538         //      (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1539         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1540         pCoexDm->curPsTdma = type;\r
1541 \r
1542         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);      \r
1543 \r
1544         if (bWifiBusy != bPreWifiBusy)\r
1545         {\r
1546                 bForceExec = TRUE;      \r
1547                 bPreWifiBusy = bWifiBusy;\r
1548         }\r
1549 \r
1550         if (pCoexDm->bCurPsTdmaOn)\r
1551         {\r
1552                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
1553                                 pCoexDm->curPsTdma));\r
1554         }\r
1555         else\r
1556         {\r
1557                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(off, %d) **********\n", \r
1558                                 pCoexDm->curPsTdma));\r
1559         }\r
1560                         \r
1561         if(!bForceExec)\r
1562         {       \r
1563                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1564                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1565                         return;\r
1566         }\r
1567 \r
1568         if (pCoexSta->nScanAPNum <= 5)\r
1569                 nWiFiDurationAdjust = 5;\r
1570                 //nWiFiDurationAdjust = 2;\r
1571         else if  (pCoexSta->nScanAPNum >= 40)\r
1572                 nWiFiDurationAdjust = -15;      \r
1573         else if  (pCoexSta->nScanAPNum >= 20)\r
1574                 nWiFiDurationAdjust = -10;      \r
1575         \r
1576         if (!pCoexSta->bForceLpsOn)  //only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30\r
1577         {\r
1578                 psTdmaByte0Val = 0x61;  //no null-pkt\r
1579                 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot\r
1580                 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle\r
1581         }\r
1582         \r
1583         if (  (type == 3) || (type == 13) || (type == 14) )\r
1584         {\r
1585                 psTdmaByte4Val = psTdmaByte4Val & 0xbf;  //no dynamic slot for multi-profile\r
1586         \r
1587                 if (!bWifiBusy)\r
1588                         psTdmaByte4Val = psTdmaByte4Val | 0x1;  //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)\r
1589                 }\r
1590                  \r
1591         if (pBtLinkInfo->bSlaveRole == TRUE)\r
1592                 psTdmaByte4Val = psTdmaByte4Val | 0x1;  //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)\r
1593                 \r
1594         if(bTurnOn)\r
1595         {        \r
1596                 switch(type)\r
1597                 {\r
1598                         default:\r
1599                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);\r
1600                                 break;\r
1601                         case 1:\r
1602                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                                \r
1603                                 break;\r
1604                         case 2:\r
1605                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                        \r
1606                                 break;\r
1607                         case 3:\r
1608                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, psTdmaByte4Val);\r
1609                                 break;\r
1610                         case 4:\r
1611                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1612                                 break;\r
1613                         case 5:\r
1614                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x11);\r
1615                                 break;\r
1616                         case 6:\r
1617                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11);\r
1618                                 break;\r
1619                         case 7:\r
1620                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
1621                                 break;\r
1622                         case 8: \r
1623                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1624                                 break;\r
1625                         case 9: \r
1626                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);                             \r
1627                                 break;\r
1628                         case 10:        \r
1629                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
1630                                 break;\r
1631                         case 11:        \r
1632                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);                    \r
1633                                 break;\r
1634                         case 12:\r
1635                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);\r
1636                                 break;\r
1637                         case 13:\r
1638                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, psTdmaByte4Val);\r
1639                                 break;\r
1640                         case 14:\r
1641                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val);\r
1642                                 break;\r
1643                         case 15:\r
1644                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
1645                                 break;\r
1646                         case 16:\r
1647                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
1648                                 break;\r
1649                         case 18:\r
1650                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1651                                 break;                  \r
1652                         case 20:\r
1653                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10);\r
1654                                 break;\r
1655                         case 21:\r
1656                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);\r
1657                                 break;\r
1658                         case 22:\r
1659                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10);\r
1660                                 break;\r
1661                         case 23:\r
1662                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
1663                                 break;\r
1664                         case 24:\r
1665                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
1666                                 break;\r
1667                         case 25:\r
1668                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1669                                 break;\r
1670                         case 26:\r
1671                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1672                                 break;\r
1673                         case 27:\r
1674                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
1675                                 break;\r
1676                         case 28:\r
1677                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
1678                                 break;\r
1679                         case 29:\r
1680                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
1681                                 break;\r
1682                         case 30:\r
1683                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);\r
1684                                 break;\r
1685                         case 31:\r
1686                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
1687                                 break;\r
1688                         case 32:\r
1689                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);\r
1690                                 break;\r
1691                         case 33:\r
1692                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
1693                                 break;\r
1694                         case 34:\r
1695                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);\r
1696                                 break;\r
1697                         case 35:\r
1698                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);\r
1699                                 break;\r
1700                         case 36:\r
1701                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
1702                                 break;\r
1703                         case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving\r
1704                                 /* here softap mode screen off will cost 70-80mA for phone */\r
1705                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);\r
1706                                 break;  \r
1707                 }\r
1708         }\r
1709         else\r
1710         {               \r
1711 \r
1712                 // disable PS tdma\r
1713                 switch(type)\r
1714                 {\r
1715                         case 8: //PTA Control\r
1716                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1717                                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_PTA, BTC_WIFI_STAT_NORMAL);\r
1718                                 //halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1719                                 break;\r
1720                         case 0:\r
1721                         default:  //Software control, Antenna at BT side\r
1722                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1723                                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL);\r
1724                                 //halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1725                                 break;\r
1726 #if 0\r
1727                         case 9:   //Software control, Antenna at WiFi side\r
1728                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1729                                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_WIFI, BTC_WIFI_STAT_NORMAL);\r
1730                                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
1731                                 break;                  \r
1732 #endif\r
1733                 }\r
1734         }\r
1735         rssiAdjustVal =0;\r
1736         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
1737 \r
1738 \r
1739         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",\r
1740                 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948),   pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67)));\r
1741 \r
1742         // update pre state\r
1743         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1744         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1745 }\r
1746 \r
1747 BOOLEAN\r
1748 halbtc8723b1ant_IsCommonAction(\r
1749         IN      PBTC_COEXIST            pBtCoexist\r
1750         )\r
1751 {\r
1752         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1753 \r
1754         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1755         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1756 \r
1757         if(!bWifiConnected && \r
1758                 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1759         {\r
1760                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));\r
1761                 \r
1762                 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1763 \r
1764                 bCommon = TRUE;\r
1765         }\r
1766         else if(bWifiConnected && \r
1767                 (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1768         {\r
1769                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1770 \r
1771                 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1772 \r
1773                 bCommon = TRUE;\r
1774         }\r
1775         else if(!bWifiConnected && \r
1776                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1777         {\r
1778                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
1779 \r
1780                 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1781 \r
1782                 bCommon = TRUE;\r
1783         }\r
1784         else if(bWifiConnected && \r
1785                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1786         {\r
1787                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1788 \r
1789                 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1790 \r
1791                 bCommon = TRUE;\r
1792         }\r
1793         else if(!bWifiConnected && \r
1794                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
1795         {\r
1796                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
1797 \r
1798                 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1799                 \r
1800                 bCommon = TRUE;\r
1801         }\r
1802         else\r
1803         {\r
1804                 if (bWifiBusy)                  \r
1805                 {\r
1806                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
1807                 }\r
1808                 else\r
1809                 {\r
1810                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
1811                 }\r
1812                 \r
1813                 bCommon = FALSE;\r
1814         }\r
1815         \r
1816         return bCommon;\r
1817 }\r
1818 \r
1819 \r
1820 VOID\r
1821 halbtc8723b1ant_TdmaDurationAdjustForAcl(\r
1822         IN      PBTC_COEXIST            pBtCoexist,\r
1823         IN      u1Byte                          wifiStatus\r
1824         )\r
1825 {\r
1826         static s4Byte           up,dn,m,n,WaitCount;\r
1827         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1828         u1Byte                  retryCount=0, btInfoExt;\r
1829         static BOOLEAN  bPreWifiBusy=FALSE;\r
1830         BOOLEAN                 bWifiBusy = FALSE;\r
1831 \r
1832         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
1833 \r
1834         if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus) \r
1835                 bWifiBusy = TRUE;\r
1836         else\r
1837                 bWifiBusy = FALSE;              \r
1838 \r
1839         if( (BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1840                 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1841                 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1842         {\r
1843                 if( pCoexDm->curPsTdma != 1 &&\r
1844                         pCoexDm->curPsTdma != 2 &&\r
1845                         pCoexDm->curPsTdma != 3 &&\r
1846                         pCoexDm->curPsTdma != 9 )\r
1847                 {\r
1848                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1849                         pCoexDm->psTdmaDuAdjType = 9;\r
1850 \r
1851                         up = 0;\r
1852                         dn = 0;\r
1853                         m = 1;\r
1854                         n= 3;\r
1855                         result = 0;\r
1856                         WaitCount = 0;\r
1857                 }               \r
1858                 return;\r
1859         }\r
1860 \r
1861         if(!pCoexDm->bAutoTdmaAdjust)\r
1862         {\r
1863                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1864                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1865 \r
1866                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1867                 pCoexDm->psTdmaDuAdjType = 2;\r
1868                 //============\r
1869                 up = 0;\r
1870                 dn = 0;\r
1871                 m = 1;\r
1872                 n= 3;\r
1873                 result = 0;\r
1874                 WaitCount = 0;\r
1875         }\r
1876         else\r
1877         {\r
1878                 //accquire the BT TRx retry count from BT_Info byte2\r
1879                 retryCount = pCoexSta->btRetryCnt;\r
1880                 btInfoExt = pCoexSta->btInfoExt;\r
1881                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1882                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1883                 //      up, dn, m, n, WaitCount));\r
1884 \r
1885                 if ( (pCoexSta->lowPriorityTx) > 1150 ||  (pCoexSta->lowPriorityRx) > 1250 )\r
1886                         retryCount++;   \r
1887                 \r
1888                 result = 0;\r
1889                 WaitCount++; \r
1890                   \r
1891                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1892                 {\r
1893                         up++;\r
1894                         dn--;\r
1895 \r
1896                         if (dn <= 0)\r
1897                                 dn = 0;                          \r
1898 \r
1899                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1900                         {\r
1901                                 WaitCount = 0; \r
1902                                 n = 3;\r
1903                                 up = 0;\r
1904                                 dn = 0;\r
1905                                 result = 1; \r
1906                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1907                         }\r
1908                 }\r
1909                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1910                 {\r
1911                         up--; \r
1912                         dn++;\r
1913 \r
1914                         if (up <= 0)\r
1915                                 up = 0;\r
1916 \r
1917                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1918                         {\r
1919                                 if (WaitCount <= 2)\r
1920                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1921                                 else\r
1922                                         m = 1;\r
1923 \r
1924                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1925                                         m = 20;\r
1926 \r
1927                                 n = 3*m;\r
1928                                 up = 0;\r
1929                                 dn = 0;\r
1930                                 WaitCount = 0;\r
1931                                 result = -1; \r
1932                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1933                         }\r
1934                 }\r
1935                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1936                 {\r
1937                         if (WaitCount == 1)\r
1938                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1939                         else\r
1940                                 m = 1;\r
1941 \r
1942                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1943                                 m = 20;\r
1944 \r
1945                         n = 3*m;\r
1946                         up = 0;\r
1947                         dn = 0;\r
1948                         WaitCount = 0; \r
1949                         result = -1;\r
1950                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1951                 }\r
1952 \r
1953                 if(result == -1)\r
1954                 {\r
1955                         if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1956                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1957                         {\r
1958                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1959                                 pCoexDm->psTdmaDuAdjType = 9;\r
1960                         }\r
1961                         else if(pCoexDm->curPsTdma == 1)\r
1962                         {\r
1963                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1964                                 pCoexDm->psTdmaDuAdjType = 2;\r
1965                         }\r
1966                         else if(pCoexDm->curPsTdma == 2)\r
1967                         {\r
1968                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1969                                 pCoexDm->psTdmaDuAdjType = 9;\r
1970                         }\r
1971                         else if(pCoexDm->curPsTdma == 9)\r
1972                         {\r
1973                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1974                                 pCoexDm->psTdmaDuAdjType = 11;\r
1975                         }\r
1976                 }\r
1977                 else if(result == 1)\r
1978                 {\r
1979                         if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1980                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1981                         {\r
1982                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1983                                 pCoexDm->psTdmaDuAdjType = 9;\r
1984                         }\r
1985                         else if(pCoexDm->curPsTdma == 11)\r
1986                         {\r
1987                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1988                                 pCoexDm->psTdmaDuAdjType = 9;\r
1989                         }\r
1990                         else if(pCoexDm->curPsTdma == 9)\r
1991                         {\r
1992                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1993                                 pCoexDm->psTdmaDuAdjType = 2;\r
1994                         }\r
1995                         else if(pCoexDm->curPsTdma == 2)\r
1996                         {\r
1997                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1998                                 pCoexDm->psTdmaDuAdjType = 1;\r
1999                         }\r
2000                 }\r
2001                 else      //no change\r
2002                 {\r
2003                         /* Bryant Modify        \r
2004                         if(bWifiBusy != bPreWifiBusy)  //if busy / idle change\r
2005                         {\r
2006                                 bPreWifiBusy = bWifiBusy;\r
2007                                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);\r
2008                         }\r
2009                         */\r
2010                 \r
2011                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
2012                                 pCoexDm->curPsTdma));\r
2013                 }\r
2014 \r
2015                 if( pCoexDm->curPsTdma != 1 &&\r
2016                         pCoexDm->curPsTdma != 2 &&\r
2017                         pCoexDm->curPsTdma != 9 &&\r
2018                         pCoexDm->curPsTdma != 11 )\r
2019                 {\r
2020                         // recover to previous adjust type\r
2021                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2022                 }\r
2023         }\r
2024 }\r
2025 \r
2026 VOID\r
2027 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(\r
2028         IN      PBTC_COEXIST            pBtCoexist,\r
2029         IN      BOOLEAN                 bNewPsState\r
2030         )\r
2031 {\r
2032         u1Byte  lpsMode=0x0;\r
2033 \r
2034         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
2035         \r
2036         if(lpsMode)     // already under LPS state\r
2037         {\r
2038                 if(bNewPsState)         \r
2039                 {\r
2040                         // keep state under LPS, do nothing.\r
2041                 }\r
2042                 else\r
2043                 {\r
2044                         // will leave LPS state, turn off psTdma first\r
2045                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2046                 }\r
2047         }\r
2048         else                                            // NO PS state\r
2049         {\r
2050                 if(bNewPsState)\r
2051                 {\r
2052                         // will enter LPS state, turn off psTdma first\r
2053                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2054                 }\r
2055                 else\r
2056                 {\r
2057                         // keep state under NO PS state, do nothing.\r
2058                 }\r
2059         }\r
2060 }\r
2061 \r
2062 VOID\r
2063 halbtc8723b1ant_PowerSaveState(\r
2064         IN      PBTC_COEXIST            pBtCoexist,\r
2065         IN      u1Byte                          psType,\r
2066         IN      u1Byte                          lpsVal,\r
2067         IN      u1Byte                          rpwmVal\r
2068         )\r
2069 {\r
2070         BOOLEAN         bLowPwrDisable=FALSE;\r
2071         \r
2072         switch(psType)\r
2073         {\r
2074                 case BTC_PS_WIFI_NATIVE:\r
2075                         // recover to original 32k low power setting\r
2076                         bLowPwrDisable = FALSE;\r
2077                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2078                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
2079                         pCoexSta->bForceLpsOn = FALSE;\r
2080                         break;\r
2081                 case BTC_PS_LPS_ON:\r
2082                         halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
2083                         halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);                      \r
2084                         // when coex force to enter LPS, do not enter 32k low power.\r
2085                         bLowPwrDisable = TRUE;\r
2086                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2087                         // power save must executed before psTdma.                      \r
2088                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
2089                         pCoexSta->bForceLpsOn = TRUE;\r
2090                         break;\r
2091                 case BTC_PS_LPS_OFF:\r
2092                         halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
2093                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
2094                         pCoexSta->bForceLpsOn = FALSE;\r
2095                         break;\r
2096                 default:\r
2097                         break;\r
2098         }\r
2099 }\r
2100 \r
2101 VOID\r
2102 halbtc8723b1ant_ActionWifiOnly(\r
2103         IN      PBTC_COEXIST            pBtCoexist\r
2104         )\r
2105 {\r
2106         halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2107         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2108         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);\r
2109 }\r
2110 \r
2111 VOID\r
2112 halbtc8723b1ant_MonitorBtEnableDisable(\r
2113         IN      PBTC_COEXIST            pBtCoexist\r
2114         )\r
2115 {\r
2116         static BOOLEAN  bPreBtDisabled=FALSE;\r
2117         static u4Byte           btDisableCnt=0;\r
2118         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
2119 \r
2120         // This function check if bt is disabled\r
2121 \r
2122         if(     pCoexSta->highPriorityTx == 0 &&\r
2123                 pCoexSta->highPriorityRx == 0 &&\r
2124                 pCoexSta->lowPriorityTx == 0 &&\r
2125                 pCoexSta->lowPriorityRx == 0)\r
2126         {\r
2127                 bBtActive = FALSE;\r
2128         }\r
2129         if(     pCoexSta->highPriorityTx == 0xffff &&\r
2130                 pCoexSta->highPriorityRx == 0xffff &&\r
2131                 pCoexSta->lowPriorityTx == 0xffff &&\r
2132                 pCoexSta->lowPriorityRx == 0xffff)\r
2133         {\r
2134                 bBtActive = FALSE;\r
2135         }\r
2136         if(bBtActive)\r
2137         {\r
2138                 btDisableCnt = 0;\r
2139                 bBtDisabled = FALSE;\r
2140                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
2141                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
2142         }\r
2143         else\r
2144         {\r
2145                 btDisableCnt++;\r
2146                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
2147                                 btDisableCnt));\r
2148                 if(btDisableCnt >= 2)\r
2149                 {\r
2150                         bBtDisabled = TRUE;\r
2151                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
2152                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
2153                         halbtc8723b1ant_ActionWifiOnly(pBtCoexist);\r
2154                 }\r
2155         }\r
2156         if(bPreBtDisabled != bBtDisabled)\r
2157         {\r
2158                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
2159                         (bPreBtDisabled ? "disabled":"enabled"), \r
2160                         (bBtDisabled ? "disabled":"enabled")));\r
2161                 bPreBtDisabled = bBtDisabled;\r
2162                 if(!bBtDisabled)\r
2163                 {\r
2164                 }\r
2165                 else\r
2166                 {\r
2167                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
2168                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
2169                 }\r
2170         }\r
2171 }\r
2172 \r
2173 //=============================================\r
2174 //\r
2175 //      Software Coex Mechanism start\r
2176 //\r
2177 //=============================================\r
2178 \r
2179 // SCO only or SCO+PAN(HS)\r
2180 \r
2181 /*\r
2182 VOID\r
2183 halbtc8723b1ant_ActionSco(\r
2184         IN      PBTC_COEXIST            pBtCoexist\r
2185         )\r
2186 {\r
2187         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2188 }\r
2189 \r
2190 \r
2191 VOID\r
2192 halbtc8723b1ant_ActionHid(\r
2193         IN      PBTC_COEXIST            pBtCoexist\r
2194         )\r
2195 {\r
2196         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2197 }\r
2198 \r
2199 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
2200 VOID\r
2201 halbtc8723b1ant_ActionA2dp(\r
2202         IN      PBTC_COEXIST            pBtCoexist\r
2203         )\r
2204 {\r
2205         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2206 }\r
2207 \r
2208 VOID\r
2209 halbtc8723b1ant_ActionA2dpPanHs(\r
2210         IN      PBTC_COEXIST            pBtCoexist\r
2211         )\r
2212 {\r
2213         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2214 }\r
2215 \r
2216 VOID\r
2217 halbtc8723b1ant_ActionPanEdr(\r
2218         IN      PBTC_COEXIST            pBtCoexist\r
2219         )\r
2220 {\r
2221         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2222 }\r
2223 \r
2224 //PAN(HS) only\r
2225 VOID\r
2226 halbtc8723b1ant_ActionPanHs(\r
2227         IN      PBTC_COEXIST            pBtCoexist\r
2228         )\r
2229 {\r
2230         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2231 }\r
2232 \r
2233 //PAN(EDR)+A2DP\r
2234 VOID\r
2235 halbtc8723b1ant_ActionPanEdrA2dp(\r
2236         IN      PBTC_COEXIST            pBtCoexist\r
2237         )\r
2238 {\r
2239         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2240 }\r
2241 \r
2242 VOID\r
2243 halbtc8723b1ant_ActionPanEdrHid(\r
2244         IN      PBTC_COEXIST            pBtCoexist\r
2245         )\r
2246 {\r
2247         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2248 }\r
2249 \r
2250 // HID+A2DP+PAN(EDR)\r
2251 VOID\r
2252 halbtc8723b1ant_ActionHidA2dpPanEdr(\r
2253         IN      PBTC_COEXIST            pBtCoexist\r
2254         )\r
2255 {\r
2256         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2257 }\r
2258 \r
2259 VOID\r
2260 halbtc8723b1ant_ActionHidA2dp(\r
2261         IN      PBTC_COEXIST            pBtCoexist\r
2262         )\r
2263 {\r
2264         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2265 }\r
2266 \r
2267 */\r
2268 \r
2269 //=============================================\r
2270 //\r
2271 //      Non-Software Coex Mechanism start\r
2272 //\r
2273 //=============================================\r
2274 VOID\r
2275 halbtc8723b1ant_ActionBtWhckTest(\r
2276         IN      PBTC_COEXIST            pBtCoexist\r
2277         )\r
2278 {\r
2279         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2280         \r
2281         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2282         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2283         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2284 }\r
2285 \r
2286 VOID\r
2287 halbtc8723b1ant_ActionWifiMultiPort(\r
2288         IN      PBTC_COEXIST            pBtCoexist\r
2289         )\r
2290 {\r
2291         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2292         \r
2293         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2294         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2295         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2296 }\r
2297 \r
2298 VOID\r
2299 halbtc8723b1ant_ActionHs(\r
2300         IN      PBTC_COEXIST            pBtCoexist\r
2301         )\r
2302 {\r
2303         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2304         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2305 }\r
2306 \r
2307 VOID\r
2308 halbtc8723b1ant_ActionBtInquiry(\r
2309         IN      PBTC_COEXIST            pBtCoexist\r
2310         )\r
2311 {       \r
2312         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2313         BOOLEAN                 bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;\r
2314 \r
2315         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
2316         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2317         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2318         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
2319 \r
2320         if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )\r
2321         {\r
2322                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2323                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2324                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2325                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          \r
2326         }\r
2327         else if( (pBtLinkInfo->bScoExist) ||    (pBtLinkInfo->bHidExist) ||     (pBtLinkInfo->bA2dpExist)  )\r
2328         {\r
2329                 // SCO/HID/A2DP busy\r
2330                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2331                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2332                 \r
2333                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2334         }\r
2335         else if ( (pBtLinkInfo->bPanExist) || (bWifiBusy) )\r
2336         {\r
2337                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
2338 \r
2339                 //for BT inquiry/page fail after S4 resume\r
2340                 //halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);            \r
2341                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2342                 \r
2343                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2344         }\r
2345         else\r
2346         {\r
2347                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2348                 \r
2349                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2350                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2351                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);          \r
2352                 \r
2353 \r
2354                 //halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2355                 //halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);                                \r
2356         }\r
2357 }\r
2358 \r
2359 VOID\r
2360 halbtc8723b1ant_ActionBtScoHidOnlyBusy(\r
2361         IN      PBTC_COEXIST            pBtCoexist,\r
2362         IN      u1Byte                          wifiStatus\r
2363         )\r
2364 {\r
2365         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2366         BOOLEAN bWifiConnected=FALSE;\r
2367         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
2368 \r
2369         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2370 \r
2371         // tdma and coex table\r
2372 \r
2373         if(pBtLinkInfo->bScoExist)\r
2374         {\r
2375                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2376                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);\r
2377         }\r
2378         else //HID\r
2379         {\r
2380                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2381                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);\r
2382         }\r
2383 }\r
2384 \r
2385 VOID\r
2386 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(\r
2387         IN      PBTC_COEXIST            pBtCoexist,\r
2388         IN      u1Byte                          wifiStatus\r
2389         )\r
2390 {\r
2391         u1Byte          btRssiState;\r
2392         \r
2393         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2394         btRssiState = halbtc8723b1ant_BtRssiState(2, 28, 0);    \r
2395 \r
2396         if ( (pCoexSta->lowPriorityRx >= 950)  && (!pCoexSta->bUnderIps) )\r
2397         {\r
2398                 pBtLinkInfo->bSlaveRole = TRUE;\r
2399         }\r
2400         else\r
2401         {\r
2402                 pBtLinkInfo->bSlaveRole = FALSE;\r
2403         }\r
2404 \r
2405         if(pBtLinkInfo->bHidOnly)  //HID\r
2406         {\r
2407                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
2408                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2409                 return;\r
2410         }\r
2411         else if(pBtLinkInfo->bA2dpOnly)  //A2DP         \r
2412         {\r
2413                 if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)\r
2414                 {\r
2415                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2416                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2417                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2418                 }\r
2419                 else\r
2420                 {\r
2421                         halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
2422                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2423                         pCoexDm->bAutoTdmaAdjust = TRUE;\r
2424                 }\r
2425         }\r
2426         else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||\r
2427                        (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)\r
2428         {\r
2429                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2430                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2431                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2432         }\r
2433         else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist)  //HID+A2DP\r
2434         {\r
2435                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2436                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2437 \r
2438                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
2439         }\r
2440         else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)                 \r
2441         {\r
2442                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2443                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2444                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2445         }\r
2446         else\r
2447         {               \r
2448                 //BT no-profile busy (0x9)\r
2449                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);      \r
2450                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2451                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2452         }       \r
2453 }\r
2454 \r
2455 VOID\r
2456 halbtc8723b1ant_ActionWifiNotConnected(\r
2457         IN      PBTC_COEXIST            pBtCoexist\r
2458         )\r
2459 {\r
2460         // power save state\r
2461         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2462 \r
2463         // tdma and coex table\r
2464         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2465         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2466         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2467 }\r
2468 \r
2469 VOID\r
2470 halbtc8723b1ant_ActionWifiNotConnectedScan(\r
2471         IN      PBTC_COEXIST            pBtCoexist\r
2472         )\r
2473 {\r
2474         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2475         \r
2476         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2477 \r
2478         // tdma and coex table\r
2479         if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2480         {\r
2481                 if (pBtLinkInfo->bA2dpExist)\r
2482                 {\r
2483                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2484                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2485                 }\r
2486                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2487                 {\r
2488                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2489                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2490                 }\r
2491                 else\r
2492                 {\r
2493                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2494                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);                  \r
2495                 }\r
2496         }\r
2497         else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2498                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2499         {\r
2500                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2501                         BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2502         }\r
2503         else\r
2504         {\r
2505                 //Bryant Add\r
2506                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2507                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2508                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2509         }\r
2510 }\r
2511 \r
2512 VOID\r
2513 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(\r
2514         IN      PBTC_COEXIST            pBtCoexist\r
2515         )\r
2516 {\r
2517         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2518         \r
2519         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2520 \r
2521         // tdma and coex table\r
2522         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) ||  (pBtLinkInfo->bA2dpExist) )\r
2523         {\r
2524                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2525                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);           \r
2526         }\r
2527         else if (pBtLinkInfo->bPanExist)                        \r
2528         {\r
2529                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2530                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);           \r
2531         }\r
2532         else\r
2533         {\r
2534                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2535                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2536                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 2);\r
2537         }\r
2538 }\r
2539 \r
2540 VOID\r
2541 halbtc8723b1ant_ActionWifiConnectedScan(\r
2542         IN      PBTC_COEXIST            pBtCoexist\r
2543         )\r
2544 {\r
2545         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2546         \r
2547         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2548 \r
2549         // tdma and coex table\r
2550         if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2551         {\r
2552                 if (pBtLinkInfo->bA2dpExist)\r
2553                 {\r
2554                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2555                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2556                 }\r
2557                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2558                 {\r
2559                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2560                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2561                 }\r
2562                 else\r
2563                 {\r
2564                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2565                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2566         }\r
2567         }\r
2568         else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2569                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2570         {\r
2571                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2572                         BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2573         }\r
2574         else\r
2575         {\r
2576                 //Bryant Add\r
2577                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2578                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2579                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2580         }\r
2581 }\r
2582 \r
2583 VOID\r
2584 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(\r
2585         IN      PBTC_COEXIST            pBtCoexist\r
2586         )\r
2587 {\r
2588         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2589 \r
2590         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2591 \r
2592         // tdma and coex table\r
2593         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )\r
2594         {\r
2595                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2596                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2597         }\r
2598         else if(pBtLinkInfo->bPanExist)\r
2599         {\r
2600                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2601                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2602         }\r
2603         else\r
2604         {\r
2605                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2606                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2607                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2608         }\r
2609 }\r
2610 \r
2611 VOID\r
2612 halbtc8723b1ant_ActionWifiConnected(\r
2613         IN      PBTC_COEXIST            pBtCoexist\r
2614         )\r
2615 {\r
2616         BOOLEAN         bWifiBusy=FALSE;\r
2617         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2618         BOOLEAN         bUnder4way=FALSE, bApEnable=FALSE;\r
2619         u4Byte          wifiBw;\r
2620 \r
2621         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
2622 \r
2623         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
2624         if(bUnder4way)\r
2625         {\r
2626                 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2627                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
2628                 return;\r
2629         }\r
2630         \r
2631         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2632         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2633         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2634         if(bScan || bLink || bRoam)\r
2635         {\r
2636                 if(bScan)       \r
2637                         halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);\r
2638                 else\r
2639                         halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2640                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
2641                 return;\r
2642         }\r
2643 \r
2644         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
2645         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2646         \r
2647         // power save state\r
2648         if(!bApEnable && BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2649         {\r
2650                 if(pBtCoexist->btLinkInfo.bA2dpOnly)    //A2DP\r
2651                         {                       \r
2652                         if(!bWifiBusy)\r
2653                                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                               \r
2654                         else //busy\r
2655                         {\r
2656                                 if  (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH)  //no force LPS, no PS-TDMA, use pure TDMA\r
2657                                 {\r
2658                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2659                                 }\r
2660                                 else\r
2661                                 {\r
2662                                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);                                   \r
2663                                 }\r
2664                         }\r
2665                 }\r
2666                 else if ((pCoexSta->bPanExist == FALSE) && (pCoexSta->bA2dpExist == FALSE) && (pCoexSta->bHidExist == FALSE))\r
2667                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2668                 else\r
2669                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
2670         }\r
2671         else\r
2672                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2673 \r
2674         // tdma and coex table\r
2675         if(!bWifiBusy)\r
2676         {\r
2677                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2678                 {\r
2679                         halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
2680                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2681                 }\r
2682                 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2683                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2684                 {\r
2685                         halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2686                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2687                 }\r
2688                 else\r
2689                 {\r
2690                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2691                         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);\r
2692                         if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )\r
2693                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2694                         else\r
2695                                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);           \r
2696                 }\r
2697         }\r
2698         else\r
2699         {\r
2700                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2701                 {\r
2702                         halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2703                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2704                 }\r
2705                 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2706                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2707                 {\r
2708                         halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2709                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2710                 }\r
2711                 else \r
2712                 {\r
2713                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2714                         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);    \r
2715                         if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )\r
2716                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2717                         else\r
2718                                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7); \r
2719                 }\r
2720         }\r
2721 }\r
2722 \r
2723 VOID\r
2724 halbtc8723b1ant_RunSwCoexistMechanism(\r
2725         IN      PBTC_COEXIST            pBtCoexist\r
2726         )\r
2727 {\r
2728         u1Byte                          algorithm=0;\r
2729 \r
2730         algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);\r
2731         pCoexDm->curAlgorithm = algorithm;\r
2732 \r
2733         if(halbtc8723b1ant_IsCommonAction(pBtCoexist))\r
2734         {\r
2735 \r
2736         }\r
2737         else\r
2738         {\r
2739                 switch(pCoexDm->curAlgorithm)\r
2740                 {\r
2741                         case BT_8723B_1ANT_COEX_ALGO_SCO:\r
2742                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));\r
2743                                 //halbtc8723b1ant_ActionSco(pBtCoexist);\r
2744                                 break;\r
2745                         case BT_8723B_1ANT_COEX_ALGO_HID:\r
2746                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));\r
2747                                 //halbtc8723b1ant_ActionHid(pBtCoexist);\r
2748                                 break;\r
2749                         case BT_8723B_1ANT_COEX_ALGO_A2DP:\r
2750                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));\r
2751                                 //halbtc8723b1ant_ActionA2dp(pBtCoexist);\r
2752                                 break;\r
2753                         case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:\r
2754                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
2755                                 //halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist);\r
2756                                 break;\r
2757                         case BT_8723B_1ANT_COEX_ALGO_PANEDR:\r
2758                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
2759                                 //halbtc8723b1ant_ActionPanEdr(pBtCoexist);\r
2760                                 break;\r
2761                         case BT_8723B_1ANT_COEX_ALGO_PANHS:\r
2762                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));\r
2763                                 //halbtc8723b1ant_ActionPanHs(pBtCoexist);\r
2764                                 break;\r
2765                         case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:\r
2766                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
2767                                 //halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist);\r
2768                                 break;\r
2769                         case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:\r
2770                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
2771                                 //halbtc8723b1ant_ActionPanEdrHid(pBtCoexist);\r
2772                                 break;\r
2773                         case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
2774                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
2775                                 //halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
2776                                 break;\r
2777                         case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:\r
2778                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
2779                                 //halbtc8723b1ant_ActionHidA2dp(pBtCoexist);\r
2780                                 break;\r
2781                         default:\r
2782                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
2783                                 //halbtc8723b1ant_CoexAllOff(pBtCoexist);\r
2784                                 break;\r
2785                 }\r
2786                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
2787         }\r
2788 }\r
2789 \r
2790 VOID\r
2791 halbtc8723b1ant_RunCoexistMechanism(\r
2792         IN      PBTC_COEXIST            pBtCoexist\r
2793         )\r
2794 {\r
2795         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2796         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2797         BOOLEAN bIncreaseScanDevNum=FALSE;\r
2798         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
2799         BOOLEAN bMiracastPlusBt=FALSE;\r
2800         u1Byte  aggBufSize=5;\r
2801         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
2802         u4Byte  wifiLinkStatus=0;\r
2803         u4Byte  numOfWifiLink=0, wifiBw;\r
2804 \r
2805         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
2806 \r
2807         if(pBtCoexist->bManualControl)\r
2808         {\r
2809                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
2810                 return;\r
2811         }\r
2812 \r
2813         if(pBtCoexist->bStopCoexDm)\r
2814         {\r
2815                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
2816                 return;\r
2817         }\r
2818 \r
2819         if(pCoexSta->bUnderIps)\r
2820         {\r
2821                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
2822                 return;\r
2823         }\r
2824 \r
2825         if(pCoexSta->bBtWhckTest)\r
2826         {\r
2827                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT is under WHCK TEST!!!\n"));\r
2828                 halbtc8723b1ant_ActionBtWhckTest(pBtCoexist);\r
2829                 return;\r
2830         }\r
2831 \r
2832         if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
2833                 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2834                 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2835         {\r
2836                 bIncreaseScanDevNum = TRUE;\r
2837         }\r
2838 \r
2839         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);\r
2840         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2841 \r
2842         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
2843         numOfWifiLink = wifiLinkStatus>>16;\r
2844         \r
2845         if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))\r
2846         {\r
2847                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex],  Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );\r
2848 \r
2849                 if(pBtLinkInfo->bBtLinkExist)\r
2850                 {\r
2851                         halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);\r
2852                         bMiracastPlusBt = TRUE;\r
2853                 }\r
2854                 else\r
2855                 {\r
2856                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2857                         bMiracastPlusBt = FALSE;\r
2858                 }\r
2859                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
2860                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2861 \r
2862                 if ( (pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage) )\r
2863                 {\r
2864                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex],  BT Is Inquirying \n") );   \r
2865                         halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
2866                 }\r
2867                 else\r
2868                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
2869                 \r
2870                 return;\r
2871         }\r
2872         else\r
2873         {\r
2874                 bMiracastPlusBt = FALSE;\r
2875                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
2876         }\r
2877 \r
2878         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2879 \r
2880         if ( (pBtLinkInfo->bBtLinkExist) && (bWifiConnected) )\r
2881         {\r
2882                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1); \r
2883 \r
2884                 if(pBtLinkInfo->bScoExist)//if (pBtLinkInfo->bBtHiPriLinkExist)\r
2885                         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);   \r
2886                 else\r
2887                         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);\r
2888                 /*\r
2889                 if(pBtLinkInfo->bScoExist)\r
2890                         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);\r
2891                 else\r
2892                 {\r
2893                         if (BTC_WIFI_BW_HT40==wifiBw)\r
2894                         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x10);  \r
2895                 else\r
2896                         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);\r
2897                 }\r
2898                 */\r
2899 \r
2900                 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2901                 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist);  //just print debug message\r
2902         }\r
2903         else\r
2904         {\r
2905                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2906 \r
2907                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);\r
2908 \r
2909                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2910                 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); ////just print debug message\r
2911         }\r
2912         \r
2913         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2914         if(pCoexSta->bC2hBtInquiryPage)\r
2915         {\r
2916                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex],  BT Is Inquirying \n") );           \r
2917                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
2918                 return;\r
2919         }\r
2920         else if(bBtHsOn)\r
2921         {\r
2922                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
2923                 return;\r
2924         }\r
2925 \r
2926         \r
2927         if(!bWifiConnected)\r
2928         {\r
2929                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2930                 \r
2931                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
2932 \r
2933                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2934                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2935                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2936 \r
2937                 if(bScan || bLink || bRoam)\r
2938                 {\r
2939                          if (bScan)     \r
2940                                 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist); \r
2941                          else\r
2942                                 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);     \r
2943                 }\r
2944                 else\r
2945                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
2946         }\r
2947         else    // wifi LPS/Busy\r
2948         {\r
2949                 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
2950         }\r
2951 }\r
2952 \r
2953 u4Byte\r
2954 halbtc8723b1ant_Log2Base(\r
2955         IN      PBTC_COEXIST            pBtCoexist,\r
2956         IN      u4Byte                          val\r
2957         \r
2958         )\r
2959 {\r
2960         u1Byte  i,j;\r
2961         u4Byte  tmp, tmp2, val_integerdB=0, tindex, shiftcount=0;\r
2962         u4Byte  result,val_fractiondB=0,Table_fraction[21]= {0,432, 332, 274, 232, 200,\r
2963                                                                    174, 151,132,115,100,86,74,62,51,42,\r
2964                                                                    32,23,15,7,0};\r
2965 \r
2966         if (val == 0)\r
2967          return 0;\r
2968 \r
2969         tmp = val;\r
2970 \r
2971         while(1)\r
2972         {\r
2973                 if (tmp == 1)\r
2974                         break;  \r
2975                 else\r
2976                 {\r
2977                         tmp = (tmp >> 1);\r
2978                         shiftcount++;                           \r
2979                 }\r
2980         }\r
2981         \r
2982 \r
2983         val_integerdB = shiftcount+1;\r
2984 \r
2985         tmp2=1;\r
2986         for (j=1; j<= val_integerdB;j++)\r
2987           tmp2 = tmp2*2;                \r
2988         \r
2989         tmp = (val*100) /tmp2;\r
2990         tindex = tmp/5;\r
2991 \r
2992         if (tindex > 20)\r
2993          tindex = 20;\r
2994 \r
2995         val_fractiondB = Table_fraction[tindex];\r
2996 \r
2997         result = val_integerdB*100 - val_fractiondB;                    \r
2998 \r
2999         return (result);\r
3000 \r
3001 \r
3002 }\r
3003 \r
3004 \r
3005 \r
3006 VOID\r
3007 halbtc8723b1ant_InitCoexDm(\r
3008         IN      PBTC_COEXIST            pBtCoexist\r
3009         )\r
3010 {       \r
3011         // force to reset coex mechanism\r
3012 \r
3013         // sw all off\r
3014         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
3015         \r
3016         //halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
3017         //halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
3018 \r
3019         pCoexSta->popEventCnt = 0;\r
3020 }\r
3021 \r
3022 VOID\r
3023 halbtc8723b1ant_InitHwConfig(\r
3024         IN      PBTC_COEXIST            pBtCoexist,\r
3025         IN      BOOLEAN                         bBackUp,\r
3026         IN      BOOLEAN                         bWifiOnly\r
3027         )\r
3028 {\r
3029         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3030         u4Byte                          u4Tmp=0;//, fwVer;\r
3031         u2Byte                          u2Tmp=0;\r
3032         u1Byte                          u1Tmp=0, u1Tmpa=0, u1Tmpb=0;\r
3033         u1Byte                          H2C_Parameter[2] ={0};\r
3034 \r
3035         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
3036 \r
3037         pPsdScan->bIsAntDetEnable = FALSE;\r
3038 #if 0//move to BTC_MEDIA_CONNECT\r
3039         if(bBackUp)\r
3040         {\r
3041                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3042                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3043                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3044                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3045         }\r
3046 #endif\r
3047         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1);  //enable TBTT nterrupt\r
3048 \r
3049         // 0x790[5:0]=0x5       \r
3050         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);\r
3051         \r
3052         // Enable counter statistics\r
3053         //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); //0x76e[3] =1, WLAN_Act control by PTA\r
3054         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);\r
3055         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);\r
3056 \r
3057 \r
3058         //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
3059 \r
3060         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
3061         \r
3062         //Antenna config\r
3063         if(bWifiOnly)\r
3064                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, TRUE, FALSE);\r
3065         else\r
3066                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, TRUE, FALSE);\r
3067 \r
3068 #if 0\r
3069         if(bWifiOnly)\r
3070         {\r
3071                 halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_WIFI, BTC_WIFI_STAT_INIT);\r
3072                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
3073         }\r
3074         else\r
3075                 halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_INIT);           \r
3076 #endif\r
3077 \r
3078 \r
3079 \r
3080         // PTA parameter\r
3081         halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
3082 \r
3083         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
3084         u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
3085         u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
3086 \r
3087         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",\r
3088                         u4Tmp,  u1Tmpa, u1Tmpb));\r
3089 }\r
3090 \r
3091 VOID\r
3092 halbtc8723b1ant_ShowPSDData(\r
3093         IN      PBTC_COEXIST            pBtCoexist\r
3094         )\r
3095 {\r
3096         pu1Byte         cliBuf=pBtCoexist->cliBuf;\r
3097         u4Byte          nDeltaFreqPerPoint;\r
3098         u4Byte          freq,freq1,freq2,n=0,i=0, j=0, m=0, PsdRep1, PsdRep2;\r
3099         \r
3100         DbgPrint("xxxxxxxxxxxxxxxx DisplayAntIsolation()\n");\r
3101 \r
3102         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n============[Antenna Detection info]  (%d/%d)============\n",\r
3103                         pPsdScan->nPSDGenCount, pPsdScan->nPSDGenTotalCount);\r
3104         CL_PRINTF(cliBuf);\r
3105 \r
3106         if (pPsdScan->nPSDGenTotalCount == 0)\r
3107         {\r
3108                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n No Data !!\n");\r
3109                 CL_PRINTF(cliBuf);\r
3110                 return;\r
3111         }\r
3112 \r
3113         if (pPsdScan->nPSDPoint == 0)\r
3114                 nDeltaFreqPerPoint = 0;\r
3115         else                    \r
3116                 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;               \r
3117 \r
3118         if (pPsdScan->bIsPSDShowMaxOnly)\r
3119         {       \r
3120                 PsdRep1 = pPsdScan->nPSDMaxValue/100;\r
3121                 PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;\r
3122                                 \r
3123                 freq = ((pPsdScan->realcentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);\r
3124                 freq1 = freq/1000000;\r
3125                 freq2 = freq/1000 - freq1 * 1000;\r
3126 \r
3127                 if (freq2 < 100)        \r
3128                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.0%d MHz",  \r
3129                           freq1, freq2);\r
3130                 else\r
3131                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.%d MHz",  \r
3132                           freq1, freq2);\r
3133 \r
3134                 if (PsdRep2 < 10)       \r
3135                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.0%d dB, (%d/%d) \n",  \r
3136                           PsdRep1, PsdRep2, pPsdScan->nPSDGenCount, pPsdScan->nPSDGenTotalCount);\r
3137                 else\r
3138                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.%d dB, %d, (%d/%d)\n",  \r
3139                           PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue, pPsdScan->nPSDGenCount, pPsdScan->nPSDGenTotalCount);\r
3140                 \r
3141                 CL_PRINTF(cliBuf);\r
3142         }\r
3143         else\r
3144         {\r
3145                 m = pPsdScan->nPSDStartPoint;\r
3146                 n = pPsdScan->nPSDStartPoint;\r
3147                 i = 1;\r
3148                 j = 1;                          \r
3149 \r
3150          while(1)\r
3151          {\r
3152                 do\r
3153                 {\r
3154                         freq = ((pPsdScan->realcentFreq-20) * 1000000 + m * nDeltaFreqPerPoint);\r
3155                         freq1 = freq/1000000;\r
3156                         freq2 = freq/1000 - freq1 * 1000;\r
3157                         \r
3158                         if (i ==1)\r
3159                         {\r
3160                                 if (freq2 == 0)\r
3161                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.000", freq1);\r
3162                                 else if (freq2 < 100)   \r
3163                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.0%2d", freq1,freq2);\r
3164                                 else\r
3165                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.%3d", freq1,freq2);\r
3166                         }\r
3167                         else if  ( (i%8 == 0) || (m == pPsdScan->nPSDStopPoint) )\r
3168                         {\r
3169                                 if (freq2 == 0)\r
3170                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000\n", freq1);\r
3171                                 else if (freq2 < 100)   \r
3172                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d\n", freq1,freq2);\r
3173                                 else\r
3174                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d\n", freq1,freq2);\r
3175                         }                       \r
3176                         else\r
3177                         {\r
3178                                 if (freq2 == 0)\r
3179                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000", freq1);\r
3180                                 else if (freq2 < 100)   \r
3181                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d", freq1,freq2);\r
3182                                 else\r
3183                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d", freq1,freq2);\r
3184 }\r
3185 \r
3186                         i++;                                    \r
3187                         m++;\r
3188                         CL_PRINTF(cliBuf);\r
3189 \r
3190                 }while(  (i <= 8) && (m <= pPsdScan->nPSDStopPoint));   \r
3191                 \r
3192                 \r
3193                 do\r
3194                 {\r
3195                         PsdRep1 = pPsdScan->nPSDReport_MaxHold[n]/100;\r
3196                         PsdRep2 = pPsdScan->nPSDReport_MaxHold[n] - PsdRep1 * 100;\r
3197                                 \r
3198                         if (j ==1)\r
3199                         {\r
3200                                 if (PsdRep2 <10)\r
3201                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.0%d", PsdRep1,PsdRep2);\r
3202                                 else\r
3203                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.%d", PsdRep1,PsdRep2);\r
3204                         }\r
3205                         else if ( (j%8 == 0)  || (n == pPsdScan->nPSDStopPoint) )\r
3206                         {\r
3207                                 if (PsdRep2 <10)\r
3208                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d\n", PsdRep1,PsdRep2);\r
3209                                 else\r
3210                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d\n", PsdRep1,PsdRep2);\r
3211                         }\r
3212                         else\r
3213                         {\r
3214                                 if (PsdRep2 <10)\r
3215                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d", PsdRep1,PsdRep2);\r
3216                                 else\r
3217                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d", PsdRep1,PsdRep2);\r
3218                         }\r
3219 \r
3220                         j++;\r
3221                         n++;\r
3222                         CL_PRINTF(cliBuf);\r
3223                         \r
3224                 } while(  (j <= 8) && (n <= pPsdScan->nPSDStopPoint));          \r
3225 \r
3226                 if  ( (m > pPsdScan->nPSDStopPoint) || (n > pPsdScan->nPSDStopPoint) )\r
3227                  break;\r
3228                 else\r
3229                 {\r
3230                         i = 1;\r
3231                         j = 1;\r
3232                 }\r
3233                 \r
3234          }      \r
3235         }\r
3236 \r
3237 \r
3238 }\r
3239 \r
3240 u4Byte\r
3241 halbtc8723b1ant_GetPSDData(\r
3242         IN      PBTC_COEXIST            pBtCoexist,\r
3243         IN      u4Byte                          nPoint\r
3244         )\r
3245 {\r
3246         //reg 0x808[9:0]: FFT data x\r
3247         //reg 0x808[22]: 0-->1 to get 1 FFT data y\r
3248         //reg 0x8b4[15:0]: FFT data y report\r
3249 \r
3250         u4Byte val = 0, psd_report =0;\r
3251         \r
3252         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);\r
3253 \r
3254         val &= 0xffbffc00;\r
3255         val |= nPoint;\r
3256         \r
3257          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);\r
3258 \r
3259         val |= 0x00400000;\r
3260          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);\r
3261 \r
3262 \r
3263         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x8b4);\r
3264 \r
3265         psd_report = val & 0x0000ffff;\r
3266          \r
3267         return psd_report;\r
3268 }\r
3269 \r
3270 \r
3271 void\r
3272 halbtc8723b1ant_SweepPSDPoint(\r
3273 IN      PBTC_COEXIST                    pBtCoexist,\r
3274         IN      u4Byte                          centFreq,\r
3275         IN      u4Byte                          offset,\r
3276         IN      u4Byte                          span,\r
3277         IN      u4Byte                          points,\r
3278         IN      u4Byte                          avgnum\r
3279         )\r
3280 {\r
3281         u4Byte   i,val,n,k=0;\r
3282         u4Byte  nPoints=0, psd_report=0;\r
3283         u4Byte  nStartP=0, nStopP=0, nDeltaFreqPerPoint=156250;\r
3284         u4Byte    nPSDCenterFreq=20*10^6, freq,freq1,freq2;     \r
3285         BOOLEAN outloop = FALSE;\r
3286         u1Byte   flag = 0;      \r
3287         u4Byte  tmp, PsdRep1, PsdRep2;\r
3288 \r
3289         pPsdScan->bIsPSDRunning = TRUE;\r
3290         \r
3291         do\r
3292         {\r
3293                 switch(flag)\r
3294                 {\r
3295                    case 0:  //Get PSD parameters\r
3296                    default:     \r
3297                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), centFreq=0x%x, offset=0x%x, span=0x%x\n", \r
3298                              centFreq, offset, span);\r
3299 \r
3300                         pPsdScan->nPSDBandWidth = 40*1000000;\r
3301                         pPsdScan->nPSDPoint = points;\r
3302                         pPsdScan->nPSDStartBase = points/2; \r
3303                         pPsdScan->nPSDAvgNum = avgnum;\r
3304                         \r
3305                         nPoints = pPsdScan->nPSDPoint;\r
3306                         nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;\r
3307 \r
3308                         //PSD point setup\r
3309                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);\r
3310                         val &= 0xffff0fff;                              \r
3311                         \r
3312                         switch(pPsdScan->nPSDPoint)\r
3313                         {\r
3314                                 case 128:\r
3315                                         val |= 0x0;\r
3316                                         break;\r
3317                                 case 256:\r
3318                                 default:        \r
3319                                         val |=0x00004000;\r
3320                                         break;\r
3321                                 case 512:       \r
3322                                         val |= 0x00008000;\r
3323                                         break;\r
3324                                 case 1024:      \r
3325                                         val |= 0x0000c000;\r
3326                                         break;\r
3327                         }                       \r
3328                                         \r
3329                         switch(pPsdScan->nPSDAvgNum)\r
3330                         {\r
3331                                 case 1:\r
3332                                         val |= 0x0;\r
3333                                         break;\r
3334                                 case 8:                         \r
3335                                         val |=0x00001000;\r
3336                                         break;\r
3337                                 case 16:        \r
3338                                         val |= 0x00002000;\r
3339                                         break;\r
3340                                 case 32:\r
3341                                 default:        \r
3342                                         val |= 0x00003000;\r
3343                                         break;\r
3344                         }\r
3345                          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);\r
3346 \r
3347                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD BW= %d, DeltaFreq=%d\n"\r
3348                                 , pPsdScan->nPSDBandWidth, nDeltaFreqPerPoint);\r
3349                         flag = 1;\r
3350                         break;\r
3351                   case 1:         //calculate the PSD point index from freq/offset/span\r
3352                         nPSDCenterFreq = pPsdScan->nPSDBandWidth /2 +offset*(1000000);\r
3353                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD Center Freq = %d\n", (centFreq + offset));\r
3354                         \r
3355                         nStartP = pPsdScan->nPSDStartBase + (nPSDCenterFreq - span *(1000000)/2) /nDeltaFreqPerPoint;\r
3356                         pPsdScan->nPSDStartPoint = nStartP - pPsdScan->nPSDStartBase;\r
3357                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Start PSD Poin Matrix Index = %d\n", pPsdScan->nPSDStartPoint);\r
3358 \r
3359                         nStopP = pPsdScan->nPSDStartBase + (nPSDCenterFreq + span *(1000000)/2) /nDeltaFreqPerPoint;\r
3360                         pPsdScan->nPSDStopPoint = nStopP - pPsdScan->nPSDStartBase-1;\r
3361                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Stop PSD Poin Matrix Index = %d\n",pPsdScan->nPSDStopPoint);\r
3362 \r
3363                         flag = 2;\r
3364                         break;\r
3365                   case 2:  //set RF channel/BW/Mode\r
3366 \r
3367                         //set 3-wire off\r
3368                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);\r
3369                         val |= 0x00300000;\r
3370                          pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);\r
3371 \r
3372                         //CCK off\r
3373                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);\r
3374                         val &= 0xfeffffff;\r
3375                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);               \r
3376 \r
3377                         //Set RF channel\r
3378                        if (centFreq == 2484)\r
3379                                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, 0xe); //WiFi TRx Mask on\r
3380                         else\r
3381                                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, (centFreq-2412)/5 + 1); //WiFi TRx Mask on\r
3382 \r
3383                         //Set  RF mode = Rx, RF Gain = 0x8a0\r
3384                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x0, 0xfffff, 0x308a0);\r
3385 \r
3386                         //Set TRx mask off\r
3387                         //un-lock TRx Mask setup\r
3388                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);\r
3389                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);\r
3390 \r
3391                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3392 \r
3393                         flag = 3;\r
3394                         break;\r
3395                   case 3:\r
3396                         memset(pPsdScan->nPSDReport,0, pPsdScan->nPSDPoint*sizeof(u4Byte));\r
3397                         nStartP = pPsdScan->nPSDStartPoint + pPsdScan->nPSDStartBase;\r
3398                         nStopP = pPsdScan->nPSDStopPoint +  pPsdScan->nPSDStartBase + 1;\r
3399                                 \r
3400                         i = nStartP;\r
3401 \r
3402                         while (i < nStopP)\r
3403                         {\r
3404                                 if (i >= nPoints)\r
3405                                 {\r
3406                                         psd_report = halbtc8723b1ant_GetPSDData(pBtCoexist,i-nPoints);\r
3407                                 }\r
3408                                 else\r
3409                                 {\r
3410                                         psd_report = halbtc8723b1ant_GetPSDData(pBtCoexist,i);\r
3411                                 }\r
3412 \r
3413                                 if (psd_report == 0)\r
3414                                         tmp = 0;\r
3415                                 else\r
3416                                         //tmp =  20*log10((double)psd_report);\r
3417                                         //20*log2(x)/log2(10), log2Base return theresult of the psd_report*100\r
3418                                         tmp = 6 * halbtc8723b1ant_Log2Base(pBtCoexist, psd_report);\r
3419                                 \r
3420 \r
3421                                 n = i-pPsdScan->nPSDStartBase;\r
3422                                 pPsdScan->nPSDReport[n] =  tmp;\r
3423                                 PsdRep1 = pPsdScan->nPSDReport[n] /100;\r
3424                                 PsdRep2 = pPsdScan->nPSDReport[n] - PsdRep1 * 100;\r
3425                                 \r
3426                                 freq =  ((centFreq-20) * 1000000 + n * nDeltaFreqPerPoint);\r
3427                                 freq1 = freq/1000000;\r
3428                                 freq2 = freq/1000 - freq1 * 1000;\r
3429 \r
3430                                 if (freq2 < 100)\r
3431                                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.0%d MHz)", n, freq1, freq2);\r
3432                                 else\r
3433                                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.%d MHz)", n, freq1, freq2);\r
3434 \r
3435                                 if (PsdRep2 < 10)\r
3436                                         DbgPrint(", PSDReport = %d (%d.0%d dB)\n",psd_report, PsdRep1, PsdRep2);\r
3437                                 else\r
3438                                         DbgPrint(", PSDReport = %d (%d.%d dB)\n",psd_report, PsdRep1,PsdRep2);  \r
3439 \r
3440                                 i++;\r
3441 \r
3442                                 k=0;\r
3443 \r
3444                                 //Add Delay between PSD point\r
3445                                 while(1)\r
3446                                 {\r
3447                                         if (k++ > 20000)\r
3448                                          break;\r
3449                                 }\r
3450 \r
3451                                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint()==============\n");\r
3452                         }       \r
3453 \r
3454                         flag = 100;\r
3455                         break;\r
3456                   case 99:      //error\r
3457 \r
3458                         outloop = TRUE;\r
3459                         break;\r
3460                   case 100: //recovery \r
3461 \r
3462                         //set 3-wire on\r
3463                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);\r
3464                         val &=0xffcfffff;\r
3465                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);\r
3466 \r
3467                         //CCK on\r
3468                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);\r
3469                         val |= 0x01000000;\r
3470                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);       \r
3471 \r
3472                         //PSD off\r
3473                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);\r
3474                         val &=0xffbfffff;\r
3475                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x808,val);\r
3476                         \r
3477                         //TRx Mask on\r
3478                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);\r
3479                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);\r
3480 \r
3481                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);\r
3482                         \r
3483                         outloop = TRUE;\r
3484                         break;\r
3485 \r
3486                 }               \r
3487                         \r
3488         }while (!outloop);\r
3489 \r
3490 \r
3491 \r
3492         pPsdScan->bIsPSDRunning = FALSE;\r
3493 \r
3494 \r
3495 }\r
3496 \r
3497 VOID\r
3498 halbtc8723b1ant_AntennaDetection(\r
3499         IN      PBTC_COEXIST                    pBtCoexist,\r
3500         IN      u4Byte                                  centFreq,\r
3501         IN      u4Byte                                  offset,\r
3502         IN      u4Byte                                  span,\r
3503         IN      u4Byte                                  seconds\r
3504         )\r
3505 {\r
3506         u4Byte realseconds = 0, i=0, i_max=0, val_max=0, j;\r
3507 \r
3508         //Stop Coex DM\r
3509         pBtCoexist->bStopCoexDm = TRUE;\r
3510 \r
3511         //Set Antenna path, switch WiFi to un-certain antenna port\r
3512         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, FALSE);\r
3513 \r
3514         //Mailbox handshake\r
3515         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, 0x0);      \r
3516         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Set BT LE Tx\n");\r
3517 \r
3518         //sweep PSD\r
3519         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), \n");\r
3520         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), \n");\r
3521         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), \n");\r
3522 \r
3523         \r
3524         //Analysis Data\r
3525 \r
3526         do\r
3527         {\r
3528                 halbtc8723b1ant_SweepPSDPoint(pBtCoexist, centFreq, offset,span, BT_8723B_1ANT_ANTDET_PSD_POINTS, BT_8723B_1ANT_ANTDET_PSD_AVGNUM);     \r
3529                 \r
3530                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSDGenCount = %d\n ", pPsdScan->nPSDGenCount);\r
3531         \r
3532                 if (pPsdScan->nPSDGenCount == 0)\r
3533                 {\r
3534                         memcpy(pPsdScan->nPSDReport_MaxHold, pPsdScan->nPSDReport, BT_8723B_1ANT_ANTDET_PSD_POINTS*sizeof(u4Byte));\r
3535 \r
3536                         for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)\r
3537                         {\r
3538                                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i,  pPsdScan->nPSDReport_MaxHold[i]);\r
3539                         }\r
3540                 }       \r
3541                 else\r
3542                 {\r
3543                         for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)\r
3544                         {\r
3545                                 if (pPsdScan->nPSDReport[i] > pPsdScan->nPSDReport_MaxHold[i])\r
3546                                 pPsdScan->nPSDReport_MaxHold[i] = pPsdScan->nPSDReport[i];      \r
3547 \r
3548                                 //search Max Value\r
3549                                 if (i ==pPsdScan->nPSDStartPoint )\r
3550                                 {\r
3551                                         i_max = i;\r
3552                                         val_max = pPsdScan->nPSDReport_MaxHold[i];\r
3553                                 }\r
3554                                 else\r
3555                                 {\r
3556                                         if (pPsdScan->nPSDReport_MaxHold[i] > val_max)\r
3557                                         {\r
3558                                                 i_max = i;\r
3559                                                 val_max = pPsdScan->nPSDReport_MaxHold[i];\r
3560                                         }\r
3561                                 }\r
3562 \r
3563                                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i,  pPsdScan->nPSDReport_MaxHold[i]);\r
3564 \r
3565                         }\r
3566         \r
3567                         pPsdScan->nPSDMaxValuePoint = i_max;\r
3568                         pPsdScan->nPSDMaxValue = val_max;\r
3569 \r
3570                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i_Max = %d, PSDReport_Max = %d dB, TotalCnt = %d\n", pPsdScan->nPSDMaxValuePoint\r
3571                                         ,pPsdScan->nPSDMaxValue, pPsdScan->nPSDGenTotalCount);\r
3572                 }\r
3573 \r
3574                 if (pPsdScan->nPSDGenCount+1 <=  pPsdScan->realseconds)\r
3575                 {\r
3576                         pPsdScan->nPSDGenCount++;\r
3577                         pPsdScan->nPSDGenTotalCount++;\r
3578                 }\r
3579                 else\r
3580                 {\r
3581                         break;\r
3582                 }\r
3583 \r
3584         } while (1);\r
3585         //Set Antenna Path      \r
3586         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);\r
3587 \r
3588         //Resume Coex DM\r
3589         pBtCoexist->bStopCoexDm = FALSE;\r
3590 \r
3591 }\r
3592 \r
3593 \r
3594 //============================================================\r
3595 // work around function start with wa_halbtc8723b1ant_\r
3596 //============================================================\r
3597 //============================================================\r
3598 // extern function start with EXhalbtc8723b1ant_\r
3599 //============================================================\r
3600 VOID\r
3601 EXhalbtc8723b1ant_PowerOnSetting(\r
3602         IN      PBTC_COEXIST            pBtCoexist\r
3603         )\r
3604 {\r
3605         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3606         u1Byte u1Tmp=0x0;\r
3607         u2Byte u2Tmp=0x0;\r
3608 \r
3609         pBtCoexist->bStopCoexDm = TRUE;\r
3610 \r
3611         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);\r
3612 \r
3613         // enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.\r
3614         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);\r
3615         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);\r
3616 \r
3617         // set GRAN_BT = 1\r
3618         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);\r
3619         // set WLAN_ACT = 0\r
3620         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);     \r
3621 \r
3622         // \r
3623         // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)\r
3624         // Local setting bit define\r
3625         //      BIT0: "0" for no antenna inverse; "1" for antenna inverse \r
3626         //      BIT1: "0" for internal switch; "1" for external switch\r
3627         //      BIT2: "0" for one antenna; "1" for two antenna\r
3628         // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0\r
3629         if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
3630         {\r
3631                 // fixed at S0 for USB interface\r
3632                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
3633 \r
3634                 u1Tmp |= 0x1;   // antenna inverse\r
3635                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);\r
3636 \r
3637                 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;\r
3638         }\r
3639         else\r
3640         {\r
3641                 // for PCIE and SDIO interface, we check efuse 0xc3[6]\r
3642                 if(pBoardInfo->singleAntPath == 0)\r
3643                 {\r
3644                         // set to S1\r
3645                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);\r
3646                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;\r
3647                 }\r
3648                 else if(pBoardInfo->singleAntPath == 1)\r
3649                 {\r
3650                         // set to S0\r
3651                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
3652                         u1Tmp |= 0x1;   // antenna inverse\r
3653                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;\r
3654                 }\r
3655 \r
3656                 if(pBtCoexist->chipInterface == BTC_INTF_PCI)\r
3657                 {       \r
3658                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);\r
3659                 }\r
3660                 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)\r
3661                 {\r
3662                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);\r
3663                 }                       \r
3664         }\r
3665 }\r
3666 \r
3667 VOID\r
3668 EXhalbtc8723b1ant_PreLoadFirmware(\r
3669         IN      PBTC_COEXIST            pBtCoexist\r
3670         )\r
3671 {\r
3672 }\r
3673 \r
3674 VOID\r
3675 EXhalbtc8723b1ant_InitHwConfig(\r
3676         IN      PBTC_COEXIST            pBtCoexist,\r
3677         IN      BOOLEAN                         bWifiOnly\r
3678         )\r
3679 {\r
3680         halbtc8723b1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);\r
3681         pBtCoexist->bStopCoexDm = FALSE;\r
3682 }\r
3683 \r
3684 VOID\r
3685 EXhalbtc8723b1ant_InitCoexDm(\r
3686         IN      PBTC_COEXIST            pBtCoexist\r
3687         )\r
3688 {\r
3689         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
3690 \r
3691         pBtCoexist->bStopCoexDm = FALSE;\r
3692         \r
3693         halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
3694 \r
3695         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3696 }\r
3697 \r
3698 VOID\r
3699 EXhalbtc8723b1ant_DisplayCoexInfo(\r
3700         IN      PBTC_COEXIST            pBtCoexist\r
3701         )\r
3702 {\r
3703         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3704         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3705         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
3706         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
3707         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
3708         u2Byte                          u2Tmp[4];\r
3709         u4Byte                          u4Tmp[4];\r
3710         u4Byte                          faOfdm, faCck;\r
3711         u4Byte                          fwVer=0, btPatchVer=0;\r
3712         static u1Byte                   PopReportIn10s = 0;     \r
3713 \r
3714         if (pPsdScan->bIsAntDetEnable == TRUE)\r
3715         {\r
3716                 halbtc8723b1ant_ShowPSDData(pBtCoexist);\r
3717                 return;\r
3718         }\r
3719 \r
3720         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
3721         CL_PRINTF(cliBuf);\r
3722 \r
3723         if(pBtCoexist->bManualControl)\r
3724         {\r
3725                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
3726                 CL_PRINTF(cliBuf);\r
3727                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
3728                 CL_PRINTF(cliBuf);\r
3729         }\r
3730         if(pBtCoexist->bStopCoexDm)\r
3731         {\r
3732                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
3733                 CL_PRINTF(cliBuf);\r
3734                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
3735                 CL_PRINTF(cliBuf);\r
3736         }\r
3737 \r
3738         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:", \\r
3739                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);\r
3740         CL_PRINTF(cliBuf);      \r
3741         \r
3742         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
3743                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
3744         CL_PRINTF(cliBuf);\r
3745 \r
3746         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3747         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3748         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
3749                 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer);\r
3750         CL_PRINTF(cliBuf);\r
3751 \r
3752         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
3753                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
3754                 pCoexDm->wifiChnlInfo[2]);\r
3755         CL_PRINTF(cliBuf);\r
3756         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Wifi bHi-Pri/ CCK lock/ CCK ever-lock", \\r
3757                 (pCoexSta->bWiFiIsHighPriTask? "Yes":"No"),\r
3758                 (pCoexSta->bCCKLock? "Yes":"No"),\r
3759                 (pCoexSta->bCCKEverLock? "Yes":"No"));\r
3760         CL_PRINTF(cliBuf);\r
3761 \r
3762         // wifi status\r
3763         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
3764         CL_PRINTF(cliBuf);\r
3765         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
3766 \r
3767         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
3768         CL_PRINTF(cliBuf);\r
3769         \r
3770         PopReportIn10s++;\r
3771         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \\r
3772                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
3773                 (  (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
3774                 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);\r
3775         CL_PRINTF(cliBuf);\r
3776         \r
3777         if (PopReportIn10s >= 5)\r
3778         {\r
3779                 pCoexSta->popEventCnt = 0;      \r
3780                 PopReportIn10s = 0;\r
3781         }\r
3782         \r
3783         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d / %d", "SCO/HID/PAN/A2DP/Hi-Pri", \\r
3784                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist, pBtLinkInfo->bBtHiPriLinkExist);\r
3785         CL_PRINTF(cliBuf);\r
3786 \r
3787         if (pStackInfo->bProfileNotified)\r
3788         {\r
3789         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);      \r
3790         }\r
3791         else\r
3792         {\r
3793                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \\r
3794                 (pBtLinkInfo->bSlaveRole )? "Slave":"Master");\r
3795                 CL_PRINTF(cliBuf);      \r
3796         }       \r
3797 \r
3798         btInfoExt = pCoexSta->btInfoExt;\r
3799         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
3800                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
3801         CL_PRINTF(cliBuf);      \r
3802 \r
3803         for(i=0; i<BT_INFO_SRC_8723B_1ANT_MAX; i++)\r
3804         {\r
3805                 if(pCoexSta->btInfoC2hCnt[i])\r
3806                 {                               \r
3807                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b1Ant[i], \\r
3808                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
3809                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
3810                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
3811                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
3812                         CL_PRINTF(cliBuf);\r
3813                 }\r
3814         }\r
3815 \r
3816         if(!pBtCoexist->bManualControl)\r
3817         {\r
3818                 // Sw mechanism \r
3819                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
3820                 CL_PRINTF(cliBuf);\r
3821         \r
3822                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \\r
3823                         pCoexDm->bCurLowPenaltyRa);\r
3824                 CL_PRINTF(cliBuf);\r
3825 \r
3826                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
3827                         (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
3828                                 pBtCoexist->btInfo.aggBufSize);\r
3829                 CL_PRINTF(cliBuf);\r
3830                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
3831                                 pBtCoexist->btInfo.raMask);\r
3832                 CL_PRINTF(cliBuf);\r
3833 \r
3834                 // Fw mechanism         \r
3835                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
3836                 CL_PRINTF(cliBuf);      \r
3837 \r
3838                 psTdmaCase = pCoexDm->curPsTdma;\r
3839                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
3840                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
3841                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
3842                         pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
3843                 CL_PRINTF(cliBuf);\r
3844                 \r
3845                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \\r
3846                         pCoexSta->nCoexTableType);\r
3847                 CL_PRINTF(cliBuf);\r
3848                 \r
3849                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "IgnWlanAct", \\r
3850                         pCoexDm->bCurIgnoreWlanAct);\r
3851                 CL_PRINTF(cliBuf);\r
3852         \r
3853                 /*\r
3854                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
3855                         pCoexDm->errorCondition);\r
3856                 CL_PRINTF(cliBuf);\r
3857                 */\r
3858         }\r
3859 \r
3860         // Hw setting           \r
3861         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
3862         CL_PRINTF(cliBuf);      \r
3863 \r
3864         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
3865                 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
3866         CL_PRINTF(cliBuf);\r
3867 \r
3868         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3869         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3870         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3871         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3872         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
3873                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
3874         CL_PRINTF(cliBuf);\r
3875 \r
3876         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
3877         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);\r
3878         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
3879         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/0x880[29:25]", \\r
3880                 u1Tmp[0], u4Tmp[0],  (u4Tmp[1]&0x3e000000) >> 25);\r
3881         CL_PRINTF(cliBuf);\r
3882 \r
3883         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
3884         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
3885         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x764);\r
3886         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
3887         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x764 / 0x76e", \\r
3888                 u4Tmp[0], ((u1Tmp[0]&0x20)>> 5), (u4Tmp[1] & 0xffff), u1Tmp[1]);\r
3889         CL_PRINTF(cliBuf);\r
3890 \r
3891         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);\r
3892         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
3893         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);        \r
3894         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \\r
3895                 u4Tmp[0]&0x3, u4Tmp[1]&0xff, u4Tmp[2]&0x3);\r
3896         CL_PRINTF(cliBuf);\r
3897 \r
3898         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);\r
3899         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
3900         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
3901         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);\r
3902         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \\r
3903                 ((u1Tmp[0] & 0x8)>>3), u1Tmp[1], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[2]&0x1);\r
3904         CL_PRINTF(cliBuf);\r
3905 \r
3906         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
3907         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
3908         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
3909                 u4Tmp[0], u1Tmp[0]);\r
3910         CL_PRINTF(cliBuf);\r
3911 \r
3912         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
3913         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);\r
3914         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \\r
3915                 u4Tmp[0]&0xff, u1Tmp[0]);\r
3916         CL_PRINTF(cliBuf);\r
3917 \r
3918         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
3919         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
3920         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
3921         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);\r
3922 \r
3923         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);\r
3924         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
3925 \r
3926         faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \\r
3927                              ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;\r
3928         faCck = (u1Tmp[0] << 8) + u1Tmp[1];\r
3929         \r
3930         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \\r
3931                 u4Tmp[0]&0xffff, faOfdm, faCck);\r
3932         CL_PRINTF(cliBuf);\r
3933 \r
3934 \r
3935         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \\r
3936                 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);\r
3937         CL_PRINTF(cliBuf);\r
3938 \r
3939         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \\r
3940                 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);\r
3941         CL_PRINTF(cliBuf);      \r
3942 \r
3943         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
3944         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
3945         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
3946         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \\r
3947                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
3948         CL_PRINTF(cliBuf);\r
3949 \r
3950         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
3951                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
3952         CL_PRINTF(cliBuf);\r
3953         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
3954                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
3955         CL_PRINTF(cliBuf);\r
3956 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)\r
3957         //halbtc8723b1ant_MonitorBtCtr(pBtCoexist);\r
3958 #endif\r
3959         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
3960 }\r
3961 \r
3962 \r
3963 VOID\r
3964 EXhalbtc8723b1ant_IpsNotify(\r
3965         IN      PBTC_COEXIST            pBtCoexist,\r
3966         IN      u1Byte                  type\r
3967         )\r
3968 {\r
3969         u4Byte  u4Tmp=0;\r
3970 \r
3971         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
3972                 return;\r
3973 \r
3974         if(BTC_IPS_ENTER == type)\r
3975         {\r
3976                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
3977                 pCoexSta->bUnderIps = TRUE;\r
3978                 \r
3979                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
3980                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);\r
3981                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3982                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
3983         }\r
3984         else if(BTC_IPS_LEAVE == type)\r
3985         {\r
3986                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
3987 \r
3988                 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
3989                 halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
3990                 halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3991 \r
3992                 pCoexSta->bUnderIps = FALSE;\r
3993         }\r
3994 }\r
3995 \r
3996 VOID\r
3997 EXhalbtc8723b1ant_LpsNotify(\r
3998         IN      PBTC_COEXIST            pBtCoexist,\r
3999         IN      u1Byte                  type\r
4000         )\r
4001 {\r
4002         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
4003                 return;\r
4004 \r
4005         if(BTC_LPS_ENABLE == type)\r
4006         {\r
4007                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
4008                 pCoexSta->bUnderLps = TRUE;\r
4009         }\r
4010         else if(BTC_LPS_DISABLE == type)\r
4011         {\r
4012                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
4013                 pCoexSta->bUnderLps = FALSE;\r
4014         }\r
4015 }\r
4016 \r
4017 VOID\r
4018 EXhalbtc8723b1ant_ScanNotify(\r
4019         IN      PBTC_COEXIST            pBtCoexist,\r
4020         IN      u1Byte                  type\r
4021         )\r
4022 {\r
4023         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
4024         u4Byte  wifiLinkStatus=0;\r
4025         u4Byte  numOfWifiLink=0;\r
4026         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
4027         u1Byte  aggBufSize=5;\r
4028 \r
4029         u1Byte u1Tmpa, u1Tmpb;\r
4030         u4Byte u4Tmp;\r
4031 \r
4032         if(pBtCoexist->bManualControl ||\r
4033                 pBtCoexist->bStopCoexDm )\r
4034                 return;\r
4035 \r
4036         if(BTC_SCAN_START == type)\r
4037         {\r
4038                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
4039                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
4040 \r
4041                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue\r
4042                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);\r
4043                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
4044                 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
4045                 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
4046           \r
4047            \r
4048                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",\r
4049                         u4Tmp,  u1Tmpa, u1Tmpb));\r
4050         }\r
4051         else\r
4052         {\r
4053                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
4054                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
4055 \r
4056                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);              \r
4057         }\r
4058 \r
4059         if(pBtCoexist->btInfo.bBtDisabled)\r
4060                 return;\r
4061 \r
4062         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
4063         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4064 \r
4065         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
4066         \r
4067         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
4068         numOfWifiLink = wifiLinkStatus>>16;\r
4069         if(numOfWifiLink >= 2)\r
4070         {\r
4071                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
4072                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
4073                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
4074                 return;\r
4075         }\r
4076         \r
4077         if(pCoexSta->bC2hBtInquiryPage)\r
4078         {\r
4079                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
4080                 return;\r
4081         }\r
4082         else if(bBtHsOn)\r
4083         {\r
4084                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
4085                 return;\r
4086         }\r
4087 \r
4088         if(BTC_SCAN_START == type)\r
4089         {       \r
4090                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
4091                 if(!bWifiConnected)     // non-connected scan\r
4092                 {\r
4093                         halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);\r
4094                 }\r
4095                 else    // wifi is connected\r
4096                 {\r
4097                         halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);\r
4098                 }\r
4099         }\r
4100         else if(BTC_SCAN_FINISH == type)\r
4101         {\r
4102                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
4103                 if(!bWifiConnected)     // non-connected scan\r
4104                 {\r
4105                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
4106                 }\r
4107                 else\r
4108                 {\r
4109                         halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
4110                 }\r
4111         }\r
4112 }\r
4113 \r
4114 VOID\r
4115 EXhalbtc8723b1ant_ConnectNotify(\r
4116         IN      PBTC_COEXIST            pBtCoexist,\r
4117         IN      u1Byte                  type\r
4118         )\r
4119 {\r
4120         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
4121         u4Byte  wifiLinkStatus=0;\r
4122         u4Byte  numOfWifiLink=0;\r
4123         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
4124         u1Byte  aggBufSize=5;\r
4125 \r
4126         if(pBtCoexist->bManualControl ||\r
4127                 pBtCoexist->bStopCoexDm ||\r
4128                 pBtCoexist->btInfo.bBtDisabled )\r
4129                 return;\r
4130 \r
4131         if(BTC_ASSOCIATE_START == type)\r
4132         {\r
4133                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
4134                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue\r
4135                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);\r
4136                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));        \r
4137                  pCoexDm->nArpCnt = 0;\r
4138         }\r
4139         else\r
4140         {\r
4141                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
4142                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));       \r
4143                 //pCoexDm->nArpCnt = 0;\r
4144         }\r
4145 \r
4146         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
4147         numOfWifiLink = wifiLinkStatus>>16;\r
4148         if(numOfWifiLink >= 2)\r
4149         {\r
4150                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
4151                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
4152                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
4153                 return;\r
4154         }\r
4155 \r
4156         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
4157         if(pCoexSta->bC2hBtInquiryPage)\r
4158         {\r
4159                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
4160                 return;\r
4161         }\r
4162         else if(bBtHsOn)\r
4163         {\r
4164                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
4165                 return;\r
4166         }\r
4167 \r
4168         if(BTC_ASSOCIATE_START == type)\r
4169         {\r
4170                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));              \r
4171                 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);\r
4172         }\r
4173         else if(BTC_ASSOCIATE_FINISH == type)\r
4174         {\r
4175                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
4176                 \r
4177                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4178                 if(!bWifiConnected) // non-connected scan\r
4179                 {\r
4180                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
4181                 }\r
4182                 else\r
4183                 {\r
4184                         halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
4185                 }\r
4186         }\r
4187 }\r
4188 \r
4189 VOID\r
4190 EXhalbtc8723b1ant_MediaStatusNotify(\r
4191         IN      PBTC_COEXIST                    pBtCoexist,\r
4192         IN      u1Byte                          type\r
4193         )\r
4194 {\r
4195         u1Byte                  H2C_Parameter[3] ={0};\r
4196         u4Byte                  wifiBw;\r
4197         u1Byte                  wifiCentralChnl;\r
4198         BOOLEAN                 bWifiUnderBMode = FALSE;\r
4199 \r
4200         if(pBtCoexist->bManualControl ||\r
4201                 pBtCoexist->bStopCoexDm ||\r
4202                 pBtCoexist->btInfo.bBtDisabled )\r
4203                 return;\r
4204 \r
4205         if(BTC_MEDIA_CONNECT == type)\r
4206         {\r
4207                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
4208                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue\r
4209                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);\r
4210                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
4211 \r
4212                 //Set CCK Tx/Rx high Pri except 11b mode\r
4213                 if (bWifiUnderBMode)\r
4214                 {\r
4215                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx\r
4216                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); //CCK Rx\r
4217                 }\r
4218                 else\r
4219                 {\r
4220                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); //CCK Tx\r
4221                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx\r
4222                 }\r
4223                 \r
4224                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
4225                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
4226                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
4227                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
4228         }\r
4229         else\r
4230         {\r
4231                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
4232                 pCoexDm->nArpCnt = 0;\r
4233 \r
4234                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); //CCK Tx\r
4235                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); //CCK Rx\r
4236 \r
4237                 pCoexSta->bCCKEverLock = FALSE;\r
4238         }\r
4239 \r
4240         // only 2.4G we need to inform bt the chnl mask\r
4241         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
4242         if( (BTC_MEDIA_CONNECT == type) &&\r
4243                 (wifiCentralChnl <= 14) )\r
4244         {\r
4245                 //H2C_Parameter[0] = 0x1;\r
4246                 H2C_Parameter[0] = 0x0;\r
4247                 H2C_Parameter[1] = wifiCentralChnl;\r
4248                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
4249                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
4250                         H2C_Parameter[2] = 0x30;\r
4251                 else\r
4252                         H2C_Parameter[2] = 0x20;\r
4253         }\r
4254                 \r
4255         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
4256         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
4257         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
4258         \r
4259         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
4260                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
4261 \r
4262         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);\r
4263 }\r
4264 \r
4265 VOID\r
4266 EXhalbtc8723b1ant_SpecialPacketNotify(\r
4267         IN      PBTC_COEXIST                    pBtCoexist,\r
4268         IN      u1Byte                          type\r
4269         )\r
4270 {\r
4271         BOOLEAN bBtHsOn=FALSE;\r
4272         u4Byte  wifiLinkStatus=0;\r
4273         u4Byte  numOfWifiLink=0;\r
4274         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
4275         u1Byte  aggBufSize=5;\r
4276         \r
4277         if(pBtCoexist->bManualControl ||\r
4278                 pBtCoexist->bStopCoexDm ||\r
4279                 pBtCoexist->btInfo.bBtDisabled )\r
4280                 return;\r
4281 \r
4282         if( BTC_PACKET_DHCP == type || \r
4283                 BTC_PACKET_EAPOL == type ||\r
4284                 BTC_PACKET_ARP == type )\r
4285         {\r
4286                 if (BTC_PACKET_ARP == type)\r
4287                 {\r
4288                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet ARP notify\n"));            \r
4289 \r
4290                         pCoexDm->nArpCnt++;\r
4291                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));\r
4292                         \r
4293                         if(pCoexDm->nArpCnt >= 10) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) \r
4294                         {\r
4295                                 pCoexSta->bWiFiIsHighPriTask = FALSE;                                   \r
4296                         }                       \r
4297                         else\r
4298                         {\r
4299                                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
4300                         }\r
4301                 }\r
4302                 else\r
4303                 {\r
4304                         pCoexSta->bWiFiIsHighPriTask = TRUE;\r
4305                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));          \r
4306                 }\r
4307         } \r
4308         else\r
4309         {\r
4310                 pCoexSta->bWiFiIsHighPriTask = FALSE;\r
4311                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet [Type = %d] notify\n", type));\r
4312         }\r
4313 \r
4314         pCoexSta->specialPktPeriodCnt = 0;\r
4315 \r
4316         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
4317         numOfWifiLink = wifiLinkStatus>>16;\r
4318         if(numOfWifiLink >= 2)\r
4319         {\r
4320                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
4321                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
4322                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
4323                 return;\r
4324         }\r
4325 \r
4326         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
4327         if(pCoexSta->bC2hBtInquiryPage)\r
4328         {\r
4329                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
4330                 return;\r
4331         }\r
4332         else if(bBtHsOn)\r
4333         {\r
4334                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
4335                 return;\r
4336         }\r
4337 \r
4338         if( BTC_PACKET_DHCP == type ||\r
4339                 BTC_PACKET_EAPOL == type || \r
4340                 ( (BTC_PACKET_ARP == type ) && (pCoexSta->bWiFiIsHighPriTask) ) )\r
4341                 {\r
4342                 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
4343         }\r
4344 }\r
4345 \r
4346 VOID\r
4347 EXhalbtc8723b1ant_BtInfoNotify(\r
4348         IN      PBTC_COEXIST            pBtCoexist,\r
4349         IN      pu1Byte                 tmpBuf,\r
4350         IN      u1Byte                  length\r
4351         )\r
4352 {\r
4353         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4354         u1Byte                          btInfo=0;\r
4355         u1Byte                          i, rspSource=0;\r
4356         BOOLEAN                         bWifiConnected=FALSE;\r
4357         BOOLEAN                         bBtBusy=FALSE;\r
4358         \r
4359         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
4360 \r
4361         rspSource = tmpBuf[0]&0xf;\r
4362         if(rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)\r
4363                 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;\r
4364         pCoexSta->btInfoC2hCnt[rspSource]++;\r
4365 \r
4366         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
4367         for(i=0; i<length; i++)\r
4368         {\r
4369                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
4370                 if(i == 1)\r
4371                         btInfo = tmpBuf[i];\r
4372                 if(i == length-1)\r
4373                 {\r
4374                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
4375                 }\r
4376                 else\r
4377                 {\r
4378                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
4379                 }\r
4380         }\r
4381 \r
4382         // if 0xff, it means BT is under WHCK test\r
4383         if (btInfo == 0xff)\r
4384                 pCoexSta->bBtWhckTest = TRUE;\r
4385         else\r
4386                 pCoexSta->bBtWhckTest = FALSE;\r
4387 \r
4388         if(BT_INFO_SRC_8723B_1ANT_WIFI_FW != rspSource)\r
4389         {\r
4390                 pCoexSta->btRetryCnt =  // [3:0]\r
4391                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
4392 \r
4393                 if (pCoexSta->btRetryCnt >= 1)\r
4394                         pCoexSta->popEventCnt++;\r
4395 \r
4396                 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)\r
4397                         pCoexSta->bC2hBtPage = TRUE;\r
4398                 else\r
4399                         pCoexSta->bC2hBtPage = FALSE;                   \r
4400 \r
4401                 pCoexSta->btRssi =\r
4402                         pCoexSta->btInfoC2h[rspSource][3]*2-90;\r
4403                         //pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
4404 \r
4405                 pCoexSta->btInfoExt = \r
4406                         pCoexSta->btInfoC2h[rspSource][4];\r
4407                 \r
4408                 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);\r
4409                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);\r
4410                 if(!pCoexSta->bBtTxRxMask)\r
4411                 {\r
4412                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */                            \r
4413                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"));\r
4414                         pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);\r
4415                 }\r
4416                 \r
4417                 // Here we need to resend some wifi info to BT\r
4418                 // because bt is reset and loss of the info.\r
4419                 if(pCoexSta->btInfoExt & BIT1)\r
4420                 {                       \r
4421                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
4422                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4423                         if(bWifiConnected)\r
4424                         {\r
4425                                 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
4426                         }\r
4427                         else\r
4428                         {\r
4429                                 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4430                         }\r
4431                 }\r
4432                                 \r
4433                 if(pCoexSta->btInfoExt & BIT3)\r
4434                 {\r
4435                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
4436                         {\r
4437                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
4438                                 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
4439                         }\r
4440                 }\r
4441                 else\r
4442                 {\r
4443                         // BT already NOT ignore Wlan active, do nothing here.\r
4444                 }\r
4445 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)\r
4446                 if( (pCoexSta->btInfoExt & BIT4) )\r
4447                 {\r
4448                         // BT auto report already enabled, do nothing\r
4449                 }\r
4450                 else\r
4451                 {\r
4452                         halbtc8723b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
4453                 }\r
4454 #endif\r
4455         }\r
4456                 \r
4457         // check BIT2 first ==> check if bt is under inquiry or page scan\r
4458         if(btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)\r
4459                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
4460         else\r
4461                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
4462 \r
4463         // set link exist status\r
4464         if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))\r
4465         {\r
4466                 pCoexSta->bBtLinkExist = FALSE;\r
4467                 pCoexSta->bPanExist = FALSE;\r
4468                 pCoexSta->bA2dpExist = FALSE;\r
4469                 pCoexSta->bHidExist = FALSE;\r
4470                 pCoexSta->bScoExist = FALSE;\r
4471 \r
4472                 pCoexSta->bBtHiPriLinkExist = FALSE;\r
4473         }\r
4474         else    // connection exists\r
4475         {\r
4476                 pCoexSta->bBtLinkExist = TRUE;\r
4477                 if(btInfo & BT_INFO_8723B_1ANT_B_FTP)\r
4478                         pCoexSta->bPanExist = TRUE;\r
4479                 else\r
4480                         pCoexSta->bPanExist = FALSE;\r
4481                 if(btInfo & BT_INFO_8723B_1ANT_B_A2DP)\r
4482                         pCoexSta->bA2dpExist = TRUE;\r
4483                 else\r
4484                         pCoexSta->bA2dpExist = FALSE;\r
4485                 if(btInfo & BT_INFO_8723B_1ANT_B_HID)\r
4486                         pCoexSta->bHidExist = TRUE;\r
4487                 else\r
4488                         pCoexSta->bHidExist = FALSE;\r
4489                 if(btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)\r
4490                         pCoexSta->bScoExist = TRUE;\r
4491                 else\r
4492                         pCoexSta->bScoExist = FALSE;\r
4493 \r
4494                 if ( (pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) )\r
4495                 {\r
4496                         if (pCoexSta->highPriorityTx  + pCoexSta->highPriorityRx >= 160)                \r
4497                                 pCoexSta->bHidExist = TRUE;\r
4498                 }\r
4499 \r
4500                 //Add Hi-Pri Tx/Rx counter to avoid false detection\r
4501                 if ( ( (pCoexSta->bHidExist) || (pCoexSta->bScoExist) ) && (pCoexSta->highPriorityTx > 60)  &&  (pCoexSta->highPriorityRx > 60)\r
4502                           && (!pCoexSta->bC2hBtInquiryPage))\r
4503                         pCoexSta->bBtHiPriLinkExist = TRUE;\r
4504         }\r
4505 \r
4506         halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);\r
4507         \r
4508         btInfo = btInfo & 0x1f;  //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)\r
4509         \r
4510         if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))\r
4511         {\r
4512                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
4513                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
4514         }\r
4515         else if(btInfo == BT_INFO_8723B_1ANT_B_CONNECTION)      // connection exists but no busy\r
4516         {\r
4517                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;\r
4518                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
4519         }\r
4520         else if((btInfo&BT_INFO_8723B_1ANT_B_SCO_ESCO) ||\r
4521                 (btInfo&BT_INFO_8723B_1ANT_B_SCO_BUSY))\r
4522         {\r
4523                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;\r
4524                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
4525         }\r
4526         else if(btInfo&BT_INFO_8723B_1ANT_B_ACL_BUSY)\r
4527         {\r
4528                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
4529                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
4530                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;\r
4531                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
4532         }\r
4533         else\r
4534         {\r
4535                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;\r
4536                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
4537         }\r
4538 \r
4539         if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
4540                 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
4541                 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
4542                 bBtBusy = TRUE;\r
4543         else\r
4544                 bBtBusy = FALSE;\r
4545         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
4546 \r
4547         halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);\r
4548 }\r
4549 \r
4550 VOID\r
4551 EXhalbtc8723b1ant_RfStatusNotify(\r
4552         IN      PBTC_COEXIST                    pBtCoexist,\r
4553         IN      u1Byte                                  type\r
4554         )\r
4555 {\r
4556         u4Byte  u4Tmp;\r
4557         u1Byte  u1Tmpa,u1Tmpb, u1Tmpc;\r
4558         \r
4559         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], RF Status notify\n"));\r
4560 \r
4561         if(BTC_RF_ON == type)\r
4562         {\r
4563                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], RF is turned ON!!\n"));\r
4564                 pBtCoexist->bStopCoexDm = FALSE;\r
4565         }\r
4566         else if(BTC_RF_OFF == type)\r
4567         {\r
4568                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], RF is turned OFF!!\n"));\r
4569                 \r
4570                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
4571                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
4572                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);\r
4573                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
4574                 \r
4575                 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4576                 pBtCoexist->bStopCoexDm = TRUE;\r
4577 \r
4578                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
4579                 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
4580                 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
4581                 u1Tmpc = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
4582 \r
4583 \r
4584                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",\r
4585                         u4Tmp,  u1Tmpa, u1Tmpb, u1Tmpc));\r
4586 \r
4587         }\r
4588 }\r
4589 \r
4590 VOID\r
4591 EXhalbtc8723b1ant_HaltNotify(\r
4592         IN      PBTC_COEXIST                    pBtCoexist\r
4593         )\r
4594 {\r
4595         u4Byte  u4Tmp;\r
4596         \r
4597         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
4598 \r
4599         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
4600         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
4601         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);\r
4602         //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
4603 \r
4604         halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4605 \r
4606         EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4607 \r
4608         pBtCoexist->bStopCoexDm = TRUE; \r
4609 }\r
4610 \r
4611 VOID\r
4612 EXhalbtc8723b1ant_PnpNotify(\r
4613         IN      PBTC_COEXIST                    pBtCoexist,\r
4614         IN      u1Byte                          pnpState\r
4615         )\r
4616 {\r
4617         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));\r
4618 \r
4619         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
4620         {\r
4621                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));\r
4622 \r
4623                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
4624                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
4625                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);\r
4626                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
4627                 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
4628 \r
4629                 pBtCoexist->bStopCoexDm = TRUE;\r
4630         }\r
4631         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
4632         {\r
4633                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
4634                 pBtCoexist->bStopCoexDm = FALSE;\r
4635                 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
4636                 halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
4637                 halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
4638         }\r
4639 }\r
4640 \r
4641 VOID\r
4642 EXhalbtc8723b1ant_CoexDmReset(\r
4643         IN      PBTC_COEXIST                    pBtCoexist\r
4644         )\r
4645 {\r
4646         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], *****************Coex DM Reset*****************\n"));\r
4647 \r
4648         halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
4649         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
4650         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);\r
4651         halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
4652 }\r
4653 \r
4654 VOID\r
4655 EXhalbtc8723b1ant_Periodical(\r
4656         IN      PBTC_COEXIST                    pBtCoexist\r
4657         )\r
4658 {\r
4659         static u1Byte           disVerInfoCnt=0;\r
4660         u4Byte                          fwVer=0, btPatchVer=0;\r
4661         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4662         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4663 \r
4664         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
4665 \r
4666         if(disVerInfoCnt <= 5)\r
4667         {\r
4668                 disVerInfoCnt += 1;\r
4669                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4670                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
4671                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
4672                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
4673                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
4674                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4675                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4676                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
4677                         GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer));\r
4678                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4679         }\r
4680 \r
4681 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)\r
4682         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
4683         halbtc8723b1ant_MonitorBtEnableDisable(pBtCoexist);\r
4684 #else\r
4685         halbtc8723b1ant_MonitorBtCtr(pBtCoexist);\r
4686         halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist);\r
4687 \r
4688         if( halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||\r
4689                 pCoexDm->bAutoTdmaAdjust )\r
4690         {\r
4691 \r
4692                 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);        \r
4693         }\r
4694 \r
4695         pCoexSta->specialPktPeriodCnt++;\r
4696 \r
4697 /*\r
4698         if (pPsdScan->bIsAntDetEnable)\r
4699         {\r
4700                  if (pPsdScan->nPSDGenCount > pPsdScan->realseconds)\r
4701                         pPsdScan->nPSDGenCount = 0;\r
4702                  \r
4703                 halbtc8723b1ant_AntennaDetection(pBtCoexist, pPsdScan->realcentFreq,  pPsdScan->realoffset, pPsdScan->realspan,  pPsdScan->realseconds);        \r
4704                 pPsdScan->nPSDGenTotalCount +=2;\r
4705                 pPsdScan->nPSDGenCount += 2;\r
4706         }\r
4707 */              \r
4708 #endif\r
4709 }\r
4710 \r
4711 VOID\r
4712 EXhalbtc8723b1ant_AntennaDetection(\r
4713         IN      PBTC_COEXIST                    pBtCoexist,\r
4714         IN      u4Byte                                  centFreq,\r
4715         IN      u4Byte                                  offset,\r
4716         IN      u4Byte                                  span,\r
4717         IN      u4Byte                                  seconds\r
4718         )\r
4719 {\r
4720         pPsdScan->bIsAntDetEnable       = FALSE;\r
4721 \r
4722         //do antenna detection periodically (every 2 seconds)\r
4723         if (centFreq == 0)\r
4724         {\r
4725                 return;\r
4726         }\r
4727         else\r
4728         {       \r
4729                 //parse parameter\r
4730                 pPsdScan->realcentFreq = ((centFreq & 0xf000) >> 12) * 1000 + ((centFreq & 0xf00) >> 8) * 100 +\r
4731                                          ((centFreq & 0xf0) >> 4) * 10 + (centFreq & 0xf);\r
4732                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), real freq = %d\n", pPsdScan->realcentFreq);\r
4733                 \r
4734                 \r
4735                 pPsdScan->realoffset =( (offset & 0x70) >> 4) * 10 + (offset & 0xf);            \r
4736                 if (offset & 0x80)      \r
4737                         pPsdScan->realoffset = 0 - pPsdScan->realoffset;                                        \r
4738                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), real offst = %d\n", pPsdScan->realoffset);\r
4739 \r
4740                 if (span & 0x80)\r
4741                         pPsdScan->bIsPSDShowMaxOnly = TRUE;\r
4742                 else\r
4743                         pPsdScan->bIsPSDShowMaxOnly = FALSE;            \r
4744                 pPsdScan->realspan = ((span & 0x70) >> 4) * 10 + (span & 0xf);\r
4745                 DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), real span = %d\n", pPsdScan->realspan);\r
4746                 \r
4747                 if ( (pPsdScan->realcentFreq < 2412) || ( (pPsdScan->realcentFreq > 2472) && (pPsdScan->realcentFreq != 2484) ) )\r
4748                 {\r
4749                          DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), center freq is not valid!!\n");    \r
4750                          return;\r
4751                                 \r
4752                 }\r
4753                 else if ( ( (pPsdScan->realcentFreq - 2412) % 5 != 0 ) && (pPsdScan->realcentFreq != 2484) ) \r
4754                 {\r
4755                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), center freq is not valid!!\n");\r
4756                          return;\r
4757                 }                       \r
4758 \r
4759                 if ( (pPsdScan->realoffset > 20) || (pPsdScan->realoffset < -20) )\r
4760                 {\r
4761                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), freq offset is not valid!!\n");\r
4762                          return;                                \r
4763                 }                               \r
4764 \r
4765                 if (pPsdScan->realspan > 40)  \r
4766                 {\r
4767                         DbgPrint("xxxxxxxxxxxxxxxx SweepPSDPoint(), freq span is not valid!!\n");\r
4768                         return;         \r
4769                 }       \r
4770                 \r
4771                 pPsdScan->realseconds =( (seconds & 0xf0) >> 4) * 10 + (seconds & 0xf);         \r
4772                 pPsdScan->nPSDGenCount = 0;\r
4773                 pPsdScan->nPSDGenTotalCount= 0;\r
4774         }\r
4775 \r
4776 \r
4777         pPsdScan->bIsAntDetEnable       = TRUE;\r
4778 \r
4779         \r
4780         halbtc8723b1ant_AntennaDetection(pBtCoexist, pPsdScan->realcentFreq,   pPsdScan->realoffset, pPsdScan->realspan,  pPsdScan->realseconds);                       \r
4781 \r
4782         \r
4783 \r
4784 }\r
4785 \r
4786 VOID\r
4787 EXhalbtc8723b1ant_AntennaIsolation(\r
4788         IN      PBTC_COEXIST                    pBtCoexist,\r
4789         IN      u4Byte                                  centFreq,\r
4790         IN      u4Byte                                  offset,\r
4791         IN      u4Byte                                  span,\r
4792         IN      u4Byte                                  seconds\r
4793         )\r
4794 {\r
4795 \r
4796 \r
4797 }\r
4798 \r
4799 VOID\r
4800 EXhalbtc8723b1ant_PSDScan(\r
4801         IN      PBTC_COEXIST                    pBtCoexist,\r
4802         IN      u4Byte                                  centFreq,\r
4803         IN      u4Byte                                  offset,\r
4804         IN      u4Byte                                  span,\r
4805         IN      u4Byte                                  seconds\r
4806         )\r
4807 {\r
4808 \r
4809 \r
4810 }\r
4811 \r
4812 VOID\r
4813 EXhalbtc8723b1ant_DisplayAntIsolation(\r
4814         IN      PBTC_COEXIST                    pBtCoexist\r
4815         )\r
4816 {\r
4817         \r
4818         //halbtc8723b1ant_ShowPSDData(pBtCoexist);\r
4819 }\r
4820 \r
4821 \r
4822 #endif\r
4823 \r