wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8723bs / hal / OUTSRC-BTCoexist / HalBtc8723a2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8723A Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/08/22 Cosa first check in.\r
8 // 2012/11/14 Cosa Revise for 8723A 2Ant out sourcing.\r
9 //\r
10 //============================================================\r
11 \r
12 //============================================================\r
13 // include files\r
14 //============================================================\r
15 #include "Mp_Precomp.h"\r
16 #if(BT_30_SUPPORT == 1)\r
17 //============================================================\r
18 // Global variables, these are static variables\r
19 //============================================================\r
20 static COEX_DM_8723A_2ANT       GLCoexDm8723a2Ant;\r
21 static PCOEX_DM_8723A_2ANT      pCoexDm=&GLCoexDm8723a2Ant;\r
22 static COEX_STA_8723A_2ANT      GLCoexSta8723a2Ant;\r
23 static PCOEX_STA_8723A_2ANT     pCoexSta=&GLCoexSta8723a2Ant;\r
24 \r
25 const char *const GLBtInfoSrc8723a2Ant[]={\r
26         "BT Info[wifi fw]",\r
27         "BT Info[bt rsp]",\r
28         "BT Info[bt auto report]",\r
29 };\r
30 \r
31 //============================================================\r
32 // local function proto type if needed\r
33 //============================================================\r
34 //============================================================\r
35 // local function start with halbtc8723a2ant_\r
36 //============================================================\r
37 BOOLEAN\r
38 halbtc8723a2ant_IsWifiIdle(\r
39         IN      PBTC_COEXIST            pBtCoexist\r
40         )\r
41 {\r
42         BOOLEAN         bWifiConnected=FALSE, bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
43 \r
44         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
45         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
46         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
47         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
48 \r
49         if(bWifiConnected)\r
50                 return FALSE;\r
51         if(bScan)\r
52                 return FALSE;\r
53         if(bLink)\r
54                 return FALSE;\r
55         if(bRoam)\r
56                 return FALSE;\r
57 \r
58         return TRUE;\r
59 }\r
60 \r
61 u1Byte\r
62 halbtc8723a2ant_BtRssiState(\r
63         u1Byte                  levelNum,\r
64         u1Byte                  rssiThresh,\r
65         u1Byte                  rssiThresh1\r
66         )\r
67 {\r
68         s4Byte                  btRssi=0;\r
69         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
70 \r
71         btRssi = pCoexSta->btRssi;\r
72 \r
73         if(levelNum == 2)\r
74         {                       \r
75                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
76                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
77                 {\r
78                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
79                         {\r
80                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
81                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
82                         }\r
83                         else\r
84                         {\r
85                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
86                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
87                         }\r
88                 }\r
89                 else\r
90                 {\r
91                         if(btRssi < rssiThresh)\r
92                         {\r
93                                 btRssiState = BTC_RSSI_STATE_LOW;\r
94                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
95                         }\r
96                         else\r
97                         {\r
98                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
99                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
100                         }\r
101                 }\r
102         }\r
103         else if(levelNum == 3)\r
104         {\r
105                 if(rssiThresh > rssiThresh1)\r
106                 {\r
107                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
108                         return pCoexSta->preBtRssiState;\r
109                 }\r
110                 \r
111                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
112                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
113                 {\r
114                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
115                         {\r
116                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
117                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
118                         }\r
119                         else\r
120                         {\r
121                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
122                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
123                         }\r
124                 }\r
125                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
126                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
127                 {\r
128                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
129                         {\r
130                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
131                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
132                         }\r
133                         else if(btRssi < rssiThresh)\r
134                         {\r
135                                 btRssiState = BTC_RSSI_STATE_LOW;\r
136                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
137                         }\r
138                         else\r
139                         {\r
140                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
141                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
142                         }\r
143                 }\r
144                 else\r
145                 {\r
146                         if(btRssi < rssiThresh1)\r
147                         {\r
148                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
149                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
150                         }\r
151                         else\r
152                         {\r
153                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
154                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
155                         }\r
156                 }\r
157         }\r
158                 \r
159         pCoexSta->preBtRssiState = btRssiState;\r
160 \r
161         return btRssiState;\r
162 }\r
163 \r
164 u1Byte\r
165 halbtc8723a2ant_WifiRssiState(\r
166         IN      PBTC_COEXIST            pBtCoexist,\r
167         IN      u1Byte                  index,\r
168         IN      u1Byte                  levelNum,\r
169         IN      u1Byte                  rssiThresh,\r
170         IN      u1Byte                  rssiThresh1\r
171         )\r
172 {\r
173         s4Byte                  wifiRssi=0;\r
174         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
175 \r
176         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
177         \r
178         if(levelNum == 2)\r
179         {\r
180                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
181                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
182                 {\r
183                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
184                         {\r
185                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
186                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
187                         }\r
188                         else\r
189                         {\r
190                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
191                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
192                         }\r
193                 }\r
194                 else\r
195                 {\r
196                         if(wifiRssi < rssiThresh)\r
197                         {\r
198                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
199                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
200                         }\r
201                         else\r
202                         {\r
203                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
204                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
205                         }\r
206                 }\r
207         }\r
208         else if(levelNum == 3)\r
209         {\r
210                 if(rssiThresh > rssiThresh1)\r
211                 {\r
212                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
213                         return pCoexSta->preWifiRssiState[index];\r
214                 }\r
215                 \r
216                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
217                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
218                 {\r
219                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
220                         {\r
221                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
222                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
223                         }\r
224                         else\r
225                         {\r
226                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
227                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
228                         }\r
229                 }\r
230                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
231                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
232                 {\r
233                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
234                         {\r
235                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
236                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
237                         }\r
238                         else if(wifiRssi < rssiThresh)\r
239                         {\r
240                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
241                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
242                         }\r
243                         else\r
244                         {\r
245                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
246                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
247                         }\r
248                 }\r
249                 else\r
250                 {\r
251                         if(wifiRssi < rssiThresh1)\r
252                         {\r
253                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
254                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
255                         }\r
256                         else\r
257                         {\r
258                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
259                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
260                         }\r
261                 }\r
262         }\r
263                 \r
264         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
265 \r
266         return wifiRssiState;\r
267 }\r
268 \r
269 VOID\r
270 halbtc8723a2ant_IndicateWifiChnlBwInfo(\r
271         IN      PBTC_COEXIST                    pBtCoexist,\r
272         IN      u1Byte                          type\r
273         )\r
274 {\r
275         u1Byte                  H2C_Parameter[3] ={0};\r
276         u4Byte                  wifiBw;\r
277         u1Byte                  wifiCentralChnl;\r
278         \r
279         // only 2.4G we need to inform bt the chnl mask\r
280         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
281         if( (BTC_MEDIA_CONNECT == type) &&\r
282                 (wifiCentralChnl <= 14) )\r
283         {\r
284                 H2C_Parameter[0] = 0x1;\r
285                 H2C_Parameter[1] = wifiCentralChnl;\r
286                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
287                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
288                         H2C_Parameter[2] = 0x30;\r
289                 else\r
290                         H2C_Parameter[2] = 0x20;\r
291         }\r
292                 \r
293         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
294         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
295         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
296         \r
297         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x19=0x%x\n", \r
298                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
299 \r
300         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x19, 3, H2C_Parameter);\r
301 }\r
302 \r
303 VOID\r
304 halbtc8723a2ant_QueryBtInfo(\r
305         IN      PBTC_COEXIST            pBtCoexist\r
306         )\r
307 {\r
308         u1Byte                  H2C_Parameter[1] ={0};\r
309 \r
310         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
311 \r
312         H2C_Parameter[0] |= BIT0;       // trigger\r
313 \r
314         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n", \r
315                 H2C_Parameter[0]));\r
316 \r
317         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x38, 1, H2C_Parameter);\r
318 }\r
319 u1Byte\r
320 halbtc8723a2ant_ActionAlgorithm(\r
321         IN      PBTC_COEXIST            pBtCoexist\r
322         )\r
323 {\r
324         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
325         BOOLEAN                         bBtHsOn=FALSE, bBtBusy=FALSE, bLimitedDig=FALSE;\r
326         u1Byte                          algorithm=BT_8723A_2ANT_COEX_ALGO_UNDEFINED;\r
327         u1Byte                          numOfDiffProfile=0;\r
328 \r
329         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
330 \r
331         //======================\r
332         // here we get BT status first\r
333         //======================\r
334         pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_IDLE;\r
335         \r
336         if((pStackInfo->bScoExist) ||(bBtHsOn) ||(pStackInfo->bHidExist))\r
337         {\r
338                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));\r
339                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
340         }\r
341         else\r
342         {\r
343                 // A2dp profile\r
344                 if( (pBtCoexist->stackInfo.numOfLink == 1) &&\r
345                         (pStackInfo->bA2dpExist) )\r
346                 {               \r
347                         if( (pCoexSta->lowPriorityTx+   pCoexSta->lowPriorityRx) < 100)\r
348                         {\r
349                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));\r
350                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
351                         }\r
352                         else\r
353                         {\r
354                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));\r
355                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
356                         }\r
357                 }\r
358                 // Pan profile\r
359                 if( (pBtCoexist->stackInfo.numOfLink == 1) &&\r
360                         (pStackInfo->bPanExist) )\r
361                 {               \r
362                         if((pCoexSta->lowPriorityTx+    pCoexSta->lowPriorityRx) < 600)\r
363                         {\r
364                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));\r
365                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
366                         }\r
367                         else\r
368                         {\r
369                                 if(pCoexSta->lowPriorityTx)\r
370                                 {\r
371                                         if((pCoexSta->lowPriorityRx /pCoexSta->lowPriorityTx)>9 )\r
372                                         {\r
373                                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));\r
374                                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
375                                         }\r
376                                 }\r
377                         }\r
378                         if(BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus)\r
379                         {\r
380                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN, set BT non-idle!!!\n"));\r
381                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
382                         }\r
383                 }\r
384                 // Pan+A2dp profile\r
385                 if( (pBtCoexist->stackInfo.numOfLink == 2) &&\r
386                         (pStackInfo->bA2dpExist) &&\r
387                         (pStackInfo->bPanExist) )\r
388                 {\r
389                         if((pCoexSta->lowPriorityTx+    pCoexSta->lowPriorityRx) < 600)\r
390                         {\r
391                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));\r
392                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
393                         }\r
394                         else\r
395                         {\r
396                                 if(pCoexSta->lowPriorityTx)\r
397                                 {\r
398                                         if((pCoexSta->lowPriorityRx /pCoexSta->lowPriorityTx)>9 )\r
399                                         {\r
400                                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));\r
401                                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
402                                         }\r
403                                 }\r
404                         }\r
405                         if(BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus)\r
406                         {\r
407                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));\r
408                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
409                         }\r
410                 }\r
411         }\r
412         if(BT_8723A_2ANT_BT_STATUS_IDLE != pCoexDm->btStatus)\r
413         {\r
414                 bBtBusy = TRUE;\r
415                 bLimitedDig = TRUE;\r
416         }\r
417         else\r
418         {\r
419                 bBtBusy = FALSE;\r
420                 bLimitedDig = FALSE;\r
421         }\r
422         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
423         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
424         //======================\r
425 \r
426         if(!pStackInfo->bBtLinkExist)\r
427         {\r
428                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No profile exists!!!\n"));\r
429                 return algorithm;\r
430         }\r
431 \r
432         if(pStackInfo->bScoExist)\r
433                 numOfDiffProfile++;\r
434         if(pStackInfo->bHidExist)\r
435                 numOfDiffProfile++;\r
436         if(pStackInfo->bPanExist)\r
437                 numOfDiffProfile++;\r
438         if(pStackInfo->bA2dpExist)\r
439                 numOfDiffProfile++;\r
440         \r
441         if(numOfDiffProfile == 1)\r
442         {\r
443                 if(pStackInfo->bScoExist)\r
444                 {\r
445                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));\r
446                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
447                 }\r
448                 else\r
449                 {\r
450                         if(pStackInfo->bHidExist)\r
451                         {\r
452                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));\r
453                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
454                         }\r
455                         else if(pStackInfo->bA2dpExist)\r
456                         {\r
457                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));\r
458                                 algorithm = BT_8723A_2ANT_COEX_ALGO_A2DP;\r
459                         }\r
460                         else if(pStackInfo->bPanExist)\r
461                         {\r
462                                 if(bBtHsOn)\r
463                                 {\r
464                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));\r
465                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANHS;\r
466                                 }\r
467                                 else\r
468                                 {\r
469                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));\r
470                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR;\r
471                                 }\r
472                         }\r
473                 }\r
474         }\r
475         else if(numOfDiffProfile == 2)\r
476         {\r
477                 if(pStackInfo->bScoExist)\r
478                 {\r
479                         if(pStackInfo->bHidExist)\r
480                         {\r
481                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));\r
482                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
483                         }\r
484                         else if(pStackInfo->bA2dpExist)\r
485                         {\r
486                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
487                                 algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
488                         }\r
489                         else if(pStackInfo->bPanExist)\r
490                         {\r
491                                 if(bBtHsOn)\r
492                                 {\r
493                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));\r
494                                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
495                                 }\r
496                                 else\r
497                                 {\r
498                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));\r
499                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
500                                 }\r
501                         }\r
502                 }\r
503                 else\r
504                 {\r
505                         if( pStackInfo->bHidExist &&\r
506                                 pStackInfo->bA2dpExist )\r
507                         {\r
508                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));\r
509                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
510                         }\r
511                         else if( pStackInfo->bHidExist &&\r
512                                 pStackInfo->bPanExist )\r
513                         {\r
514                                 if(bBtHsOn)\r
515                                 {\r
516                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));\r
517                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
518                                 }\r
519                                 else\r
520                                 {\r
521                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));\r
522                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
523                                 }\r
524                         }\r
525                         else if( pStackInfo->bPanExist &&\r
526                                 pStackInfo->bA2dpExist )\r
527                         {\r
528                                 if(bBtHsOn)\r
529                                 {\r
530                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));\r
531                                         algorithm = BT_8723A_2ANT_COEX_ALGO_A2DP;\r
532                                 }\r
533                                 else\r
534                                 {\r
535                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
536                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_A2DP;\r
537                                 }\r
538                         }\r
539                 }\r
540         }\r
541         else if(numOfDiffProfile == 3)\r
542         {\r
543                 if(pStackInfo->bScoExist)\r
544                 {\r
545                         if( pStackInfo->bHidExist &&\r
546                                 pStackInfo->bA2dpExist )\r
547                         {\r
548                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
549                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
550                         }\r
551                         else if( pStackInfo->bHidExist &&\r
552                                 pStackInfo->bPanExist )\r
553                         {\r
554                                 if(bBtHsOn)\r
555                                 {\r
556                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
557                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
558                                 }\r
559                                 else\r
560                                 {\r
561                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
562                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
563                                 }\r
564                         }\r
565                         else if( pStackInfo->bPanExist &&\r
566                                 pStackInfo->bA2dpExist )\r
567                         {\r
568                                 if(bBtHsOn)\r
569                                 {\r
570                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
571                                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
572                                 }\r
573                                 else\r
574                                 {\r
575                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
576                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
577                                 }\r
578                         }\r
579                 }\r
580                 else\r
581                 {\r
582                         if( pStackInfo->bHidExist &&\r
583                                 pStackInfo->bPanExist &&\r
584                                 pStackInfo->bA2dpExist )\r
585                         {\r
586                                 if(bBtHsOn)\r
587                                 {\r
588                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
589                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
590                                 }\r
591                                 else\r
592                                 {\r
593                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
594                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
595                                 }\r
596                         }\r
597                 }\r
598         }\r
599         else if(numOfDiffProfile >= 3)\r
600         {\r
601                 if(pStackInfo->bScoExist)\r
602                 {\r
603                         if( pStackInfo->bHidExist &&\r
604                                 pStackInfo->bPanExist &&\r
605                                 pStackInfo->bA2dpExist )\r
606                         {\r
607                                 if(bBtHsOn)\r
608                                 {\r
609                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
610 \r
611                                 }\r
612                                 else\r
613                                 {\r
614                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
615                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
616                                 }\r
617                         }\r
618                 }\r
619         }\r
620 \r
621         return algorithm;\r
622 }\r
623 \r
624 BOOLEAN\r
625 halbtc8723a2ant_NeedToDecBtPwr(\r
626         IN      PBTC_COEXIST            pBtCoexist\r
627         )\r
628 {\r
629         BOOLEAN         bRet=FALSE;\r
630         BOOLEAN         bBtHsOn=FALSE, bWifiConnected=FALSE;\r
631         s4Byte          btHsRssi=0;\r
632 \r
633         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn))\r
634                 return FALSE;\r
635         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected))\r
636                 return FALSE;\r
637         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi))\r
638                 return FALSE;\r
639 \r
640         if(bWifiConnected)\r
641         {\r
642                 if(bBtHsOn)\r
643                 {\r
644                         if(btHsRssi > 37)\r
645                         {\r
646                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], Need to decrease bt power for HS mode!!\n"));\r
647                                 bRet = TRUE;\r
648                         }\r
649                 }\r
650                 else\r
651                 {\r
652                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], Need to decrease bt power for Wifi is connected!!\n"));\r
653                         bRet = TRUE;\r
654                 }\r
655         }\r
656         \r
657         return bRet;\r
658 }\r
659 \r
660 VOID\r
661 halbtc8723a2ant_SetFwDacSwingLevel(\r
662         IN      PBTC_COEXIST            pBtCoexist,\r
663         IN      u1Byte                  dacSwingLvl\r
664         )\r
665 {\r
666         u1Byte                  H2C_Parameter[1] ={0};\r
667 \r
668         // There are several type of dacswing\r
669         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
670         H2C_Parameter[0] = dacSwingLvl;\r
671 \r
672         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
673         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x29=0x%x\n", H2C_Parameter[0]));\r
674 \r
675         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x29, 1, H2C_Parameter);\r
676 }\r
677 \r
678 VOID\r
679 halbtc8723a2ant_SetFwDecBtPwr(\r
680         IN      PBTC_COEXIST            pBtCoexist,\r
681         IN      BOOLEAN                 bDecBtPwr\r
682         )\r
683 {\r
684         u1Byte                  H2C_Parameter[1] ={0};\r
685         \r
686         H2C_Parameter[0] = 0;\r
687 \r
688         if(bDecBtPwr)\r
689         {\r
690                 H2C_Parameter[0] |= BIT1;\r
691         }\r
692 \r
693         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], decrease Bt Power : %s, FW write 0x21=0x%x\n", \r
694                 (bDecBtPwr? "Yes!!":"No!!"), H2C_Parameter[0]));\r
695 \r
696         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x21, 1, H2C_Parameter);    \r
697 }\r
698 \r
699 VOID\r
700 halbtc8723a2ant_DecBtPwr(\r
701         IN      PBTC_COEXIST            pBtCoexist,\r
702         IN      BOOLEAN                 bForceExec,\r
703         IN      BOOLEAN                 bDecBtPwr\r
704         )\r
705 {\r
706         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s Dec BT power = %s\n",  \r
707                 (bForceExec? "force to":""), ((bDecBtPwr)? "ON":"OFF")));\r
708         pCoexDm->bCurDecBtPwr = bDecBtPwr;\r
709 \r
710         if(!bForceExec)\r
711         {\r
712                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreDecBtPwr=%d, bCurDecBtPwr=%d\n", \r
713                         pCoexDm->bPreDecBtPwr, pCoexDm->bCurDecBtPwr));\r
714 \r
715                 if(pCoexDm->bPreDecBtPwr == pCoexDm->bCurDecBtPwr) \r
716                         return;\r
717         }\r
718         halbtc8723a2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->bCurDecBtPwr);\r
719 \r
720         pCoexDm->bPreDecBtPwr = pCoexDm->bCurDecBtPwr;\r
721 }\r
722 \r
723 VOID\r
724 halbtc8723a2ant_FwDacSwingLvl(\r
725         IN      PBTC_COEXIST            pBtCoexist,\r
726         IN      BOOLEAN                 bForceExec,\r
727         IN      u1Byte                  fwDacSwingLvl\r
728         )\r
729 {\r
730         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
731                 (bForceExec? "force to":""), fwDacSwingLvl));\r
732         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
733 \r
734         if(!bForceExec)\r
735         {\r
736                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n", \r
737                         pCoexDm->preFwDacSwingLvl, pCoexDm->curFwDacSwingLvl));\r
738 \r
739                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
740                         return;\r
741         }\r
742 \r
743         halbtc8723a2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
744 \r
745         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
746 }\r
747 \r
748 VOID\r
749 halbtc8723a2ant_SetSwRfRxLpfCorner(\r
750         IN      PBTC_COEXIST            pBtCoexist,\r
751         IN      BOOLEAN                 bRxRfShrinkOn\r
752         )\r
753 {\r
754         if(bRxRfShrinkOn)\r
755         {\r
756                 //Shrink RF Rx LPF corner\r
757                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
758                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xf0ff7);\r
759         }\r
760         else\r
761         {\r
762                 //Resume RF Rx LPF corner\r
763                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
764                 if(pBtCoexist->bInitilized)\r
765                 {\r
766                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
767                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
768                 }\r
769         }\r
770 }\r
771 \r
772 VOID\r
773 halbtc8723a2ant_RfShrink(\r
774         IN      PBTC_COEXIST            pBtCoexist,\r
775         IN      BOOLEAN                 bForceExec,\r
776         IN      BOOLEAN                 bRxRfShrinkOn\r
777         )\r
778 {\r
779         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
780                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
781         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
782 \r
783         if(!bForceExec)\r
784         {\r
785                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n", \r
786                         pCoexDm->bPreRfRxLpfShrink, pCoexDm->bCurRfRxLpfShrink));\r
787 \r
788                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
789                         return;\r
790         }\r
791         halbtc8723a2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
792 \r
793         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
794 }\r
795 \r
796 VOID\r
797 halbtc8723a2ant_SetSwPenaltyTxRateAdaptive(\r
798         IN      PBTC_COEXIST            pBtCoexist,\r
799         IN      BOOLEAN                 bLowPenaltyRa\r
800         )\r
801 {\r
802         u1Byte  tmpU1;\r
803 \r
804         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
805         tmpU1 |= BIT0;\r
806         if(bLowPenaltyRa)\r
807         {\r
808                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
809                 tmpU1 &= ~BIT2;\r
810         }\r
811         else\r
812         {\r
813                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
814                 tmpU1 |= BIT2;\r
815         }\r
816 \r
817         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
818 }\r
819 \r
820 VOID\r
821 halbtc8723a2ant_LowPenaltyRa(\r
822         IN      PBTC_COEXIST            pBtCoexist,\r
823         IN      BOOLEAN                 bForceExec,\r
824         IN      BOOLEAN                 bLowPenaltyRa\r
825         )\r
826 {\r
827         return;\r
828         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
829                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
830         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
831 \r
832         if(!bForceExec)\r
833         {\r
834                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
835                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
836 \r
837                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
838                         return;\r
839         }\r
840         halbtc8723a2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
841 \r
842         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
843 }\r
844 \r
845 VOID\r
846 halbtc8723a2ant_SetSwFullTimeDacSwing(\r
847         IN      PBTC_COEXIST            pBtCoexist,\r
848         IN      BOOLEAN                 bSwDacSwingOn,\r
849         IN      u4Byte                  swDacSwingLvl\r
850         )\r
851 {\r
852         if(bSwDacSwingOn)\r
853         {\r
854                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, swDacSwingLvl);\r
855         }\r
856         else\r
857         {\r
858                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
859         }\r
860 }\r
861 \r
862 \r
863 VOID\r
864 halbtc8723a2ant_DacSwing(\r
865         IN      PBTC_COEXIST            pBtCoexist,\r
866         IN      BOOLEAN                 bForceExec,\r
867         IN      BOOLEAN                 bDacSwingOn,\r
868         IN      u4Byte                  dacSwingLvl\r
869         )\r
870 {\r
871         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
872                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
873         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
874         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
875 \r
876         if(!bForceExec)\r
877         {\r
878                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n", \r
879                         pCoexDm->bPreDacSwingOn, pCoexDm->preDacSwingLvl,\r
880                         pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl));\r
881 \r
882                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
883                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
884                         return;\r
885         }\r
886         delay_ms(30);\r
887         halbtc8723a2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
888 \r
889         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
890         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
891 }\r
892 \r
893 VOID\r
894 halbtc8723a2ant_SetAdcBackOff(\r
895         IN      PBTC_COEXIST            pBtCoexist,\r
896         IN      BOOLEAN                 bAdcBackOff\r
897         )\r
898 {\r
899         if(bAdcBackOff)\r
900         {\r
901                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level On!\n"));\r
902                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a07611);\r
903         }\r
904         else\r
905         {\r
906                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level Off!\n"));                \r
907                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a05611);\r
908         }\r
909 }\r
910 \r
911 VOID\r
912 halbtc8723a2ant_AdcBackOff(\r
913         IN      PBTC_COEXIST            pBtCoexist,\r
914         IN      BOOLEAN                 bForceExec,\r
915         IN      BOOLEAN                 bAdcBackOff\r
916         )\r
917 {\r
918         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
919                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
920         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
921 \r
922         if(!bForceExec)\r
923         {\r
924                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAdcBackOff=%d, bCurAdcBackOff=%d\n", \r
925                         pCoexDm->bPreAdcBackOff, pCoexDm->bCurAdcBackOff));\r
926 \r
927                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
928                         return;\r
929         }\r
930         halbtc8723a2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
931 \r
932         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
933 }\r
934 \r
935 VOID\r
936 halbtc8723a2ant_SetAgcTable(\r
937         IN      PBTC_COEXIST            pBtCoexist,\r
938         IN      BOOLEAN                 bAgcTableEn\r
939         )\r
940 {\r
941         u1Byte          rssiAdjustVal=0;\r
942 \r
943         if(bAgcTableEn)\r
944         {\r
945                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));\r
946                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4e1c0001);\r
947                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4d1d0001);\r
948                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4c1e0001);\r
949                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4b1f0001);\r
950                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4a200001);\r
951                 \r
952                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xdc000);\r
953                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x90000);\r
954                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x51000);\r
955                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x12000);\r
956                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x00355);\r
957                 \r
958                 rssiAdjustVal = 6;\r
959         }\r
960         else\r
961         {\r
962                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));\r
963                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x641c0001);\r
964                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x631d0001);\r
965                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x621e0001);\r
966                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x611f0001);\r
967                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x60200001);\r
968 \r
969                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x32000);\r
970                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x71000);\r
971                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xb0000);\r
972                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xfc000);\r
973                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x30355);\r
974         }\r
975 \r
976         // set rssiAdjustVal for wifi module.\r
977         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
978 }\r
979 \r
980 \r
981 VOID\r
982 halbtc8723a2ant_AgcTable(\r
983         IN      PBTC_COEXIST            pBtCoexist,\r
984         IN      BOOLEAN                 bForceExec,\r
985         IN      BOOLEAN                 bAgcTableEn\r
986         )\r
987 {\r
988         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s %s Agc Table\n",  \r
989                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
990         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
991 \r
992         if(!bForceExec)\r
993         {\r
994                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n", \r
995                         pCoexDm->bPreAgcTableEn, pCoexDm->bCurAgcTableEn));\r
996 \r
997                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
998                         return;\r
999         }\r
1000         halbtc8723a2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
1001 \r
1002         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
1003 }\r
1004 \r
1005 VOID\r
1006 halbtc8723a2ant_SetCoexTable(\r
1007         IN      PBTC_COEXIST    pBtCoexist,\r
1008         IN      u4Byte          val0x6c0,\r
1009         IN      u4Byte          val0x6c8,\r
1010         IN      u1Byte          val0x6cc\r
1011         )\r
1012 {\r
1013         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1014         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1015 \r
1016         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1017         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1018 \r
1019         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1020         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1021 }\r
1022 \r
1023 VOID\r
1024 halbtc8723a2ant_CoexTable(\r
1025         IN      PBTC_COEXIST            pBtCoexist,\r
1026         IN      BOOLEAN                 bForceExec,\r
1027         IN      u4Byte                  val0x6c0,\r
1028         IN      u4Byte                  val0x6c8,\r
1029         IN      u1Byte                  val0x6cc\r
1030         )\r
1031 {\r
1032         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
1033                 (bForceExec? "force to":""), val0x6c0, val0x6c8, val0x6cc));\r
1034         pCoexDm->curVal0x6c0 = val0x6c0;\r
1035         pCoexDm->curVal0x6c8 = val0x6c8;\r
1036         pCoexDm->curVal0x6cc = val0x6cc;\r
1037 \r
1038         if(!bForceExec)\r
1039         {\r
1040                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
1041                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
1042                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
1043                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
1044         \r
1045                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1046                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1047                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1048                         return;\r
1049         }\r
1050         halbtc8723a2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c8, val0x6cc);\r
1051 \r
1052         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1053         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1054         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1055 }\r
1056 \r
1057 VOID\r
1058 halbtc8723a2ant_SetFwIgnoreWlanAct(\r
1059         IN      PBTC_COEXIST            pBtCoexist,\r
1060         IN      BOOLEAN                 bEnable\r
1061         )\r
1062 {\r
1063         u1Byte                  H2C_Parameter[1] ={0};\r
1064                 \r
1065         if(bEnable)\r
1066         {\r
1067                 H2C_Parameter[0] |= BIT0;               // function enable\r
1068         }\r
1069         \r
1070         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n", \r
1071                 H2C_Parameter[0]));\r
1072 \r
1073         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x25, 1, H2C_Parameter);    \r
1074 }\r
1075 \r
1076 VOID\r
1077 halbtc8723a2ant_IgnoreWlanAct(\r
1078         IN      PBTC_COEXIST            pBtCoexist,\r
1079         IN      BOOLEAN                 bForceExec,\r
1080         IN      BOOLEAN                 bEnable\r
1081         )\r
1082 {\r
1083         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1084                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1085         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1086 \r
1087         if(!bForceExec)\r
1088         {\r
1089                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
1090                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
1091 \r
1092                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1093                         return;\r
1094         }\r
1095         halbtc8723a2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1096 \r
1097         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1098 }\r
1099 \r
1100 VOID\r
1101 halbtc8723a2ant_SetFwPstdma(\r
1102         IN      PBTC_COEXIST            pBtCoexist,\r
1103         IN      u1Byte                  byte1,\r
1104         IN      u1Byte                  byte2,\r
1105         IN      u1Byte                  byte3,\r
1106         IN      u1Byte                  byte4,\r
1107         IN      u1Byte                  byte5\r
1108         )\r
1109 {\r
1110         u1Byte                  H2C_Parameter[5] ={0};\r
1111 \r
1112         H2C_Parameter[0] = byte1;       \r
1113         H2C_Parameter[1] = byte2;       \r
1114         H2C_Parameter[2] = byte3;\r
1115         H2C_Parameter[3] = byte4;\r
1116         H2C_Parameter[4] = byte5;\r
1117 \r
1118         pCoexDm->psTdmaPara[0] = byte1;\r
1119         pCoexDm->psTdmaPara[1] = byte2;\r
1120         pCoexDm->psTdmaPara[2] = byte3;\r
1121         pCoexDm->psTdmaPara[3] = byte4;\r
1122         pCoexDm->psTdmaPara[4] = byte5;\r
1123         \r
1124         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n", \r
1125                 H2C_Parameter[0], \r
1126                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1127 \r
1128         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3a, 5, H2C_Parameter);\r
1129 }\r
1130 \r
1131 VOID\r
1132 halbtc8723a2ant_PsTdma(\r
1133         IN      PBTC_COEXIST            pBtCoexist,\r
1134         IN      BOOLEAN                 bForceExec,\r
1135         IN      BOOLEAN                 bTurnOn,\r
1136         IN      u1Byte                  type\r
1137         )\r
1138 {\r
1139         u4Byte  btTxRxCnt=0;\r
1140 \r
1141         btTxRxCnt = pCoexSta->highPriorityTx+pCoexSta->highPriorityRx+\r
1142                                 pCoexSta->lowPriorityTx+pCoexSta->lowPriorityRx;\r
1143 \r
1144         if(btTxRxCnt > 3000)\r
1145         {               \r
1146                 pCoexDm->bCurPsTdmaOn = TRUE;\r
1147                 pCoexDm->curPsTdma = 8;\r
1148                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], turn ON PS TDMA, type=%d for BT tx/rx counters=%d(>3000)\n", \r
1149                         pCoexDm->curPsTdma, btTxRxCnt));\r
1150         }\r
1151         else\r
1152         {\r
1153                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1154                         (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));             \r
1155                 pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1156                 pCoexDm->curPsTdma = type;\r
1157         }\r
1158 \r
1159         if(!bForceExec)\r
1160         {\r
1161                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
1162                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
1163                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
1164                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
1165 \r
1166                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1167                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1168                         return;\r
1169         }       \r
1170         if(pCoexDm->bCurPsTdmaOn)\r
1171         {\r
1172                 switch(pCoexDm->curPsTdma)\r
1173                 {\r
1174                         case 1:\r
1175                         default:\r
1176                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x98);\r
1177                                 break;\r
1178                         case 2:\r
1179                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x98);\r
1180                                 break;\r
1181                         case 3:\r
1182                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x98);\r
1183                                 break;\r
1184                         case 4:\r
1185                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x5, 0x5, 0xe1, 0x80);\r
1186                                 break;\r
1187                         case 5:\r
1188                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x98);\r
1189                                 break;\r
1190                         case 6:\r
1191                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x98);\r
1192                                 break;\r
1193                         case 7:\r
1194                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x98);\r
1195                                 break;\r
1196                         case 8: \r
1197                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x5, 0x5, 0x60, 0x80);\r
1198                                 break;\r
1199                         case 9: \r
1200                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x98);\r
1201                                 break;\r
1202                         case 10:        \r
1203                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x98);\r
1204                                 break;\r
1205                         case 11:        \r
1206                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x98);\r
1207                                 break;\r
1208                         case 12:\r
1209                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x98);\r
1210                                 break;\r
1211                         case 13:\r
1212                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x98);\r
1213                                 break;\r
1214                         case 14:\r
1215                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x98);\r
1216                                 break;\r
1217                         case 15:\r
1218                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x98);\r
1219                                 break;\r
1220                         case 16:\r
1221                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x98);\r
1222                                 break;\r
1223                         case 17:\r
1224                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x80);\r
1225                                 break;\r
1226                         case 18:\r
1227                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x98);\r
1228                                 break;                  \r
1229                         case 19:\r
1230                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x98);\r
1231                                 break;\r
1232                         case 20:\r
1233                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x98);\r
1234                                 break;\r
1235                 }\r
1236         }\r
1237         else\r
1238         {\r
1239                 // disable PS tdma\r
1240                 switch(pCoexDm->curPsTdma)\r
1241                 {\r
1242                         case 0:\r
1243                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1244                                 break;\r
1245                         case 1:\r
1246                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1247                                 break;\r
1248                         default:\r
1249                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1250                                 break;\r
1251                 }\r
1252         }\r
1253 \r
1254         // update pre state\r
1255         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1256         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1257 }\r
1258 \r
1259 \r
1260 VOID\r
1261 halbtc8723a2ant_CoexAllOff(\r
1262         IN      PBTC_COEXIST            pBtCoexist\r
1263         )\r
1264 {\r
1265         // fw all off\r
1266         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1267         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1268         halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1269         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1270 \r
1271         // sw all off\r
1272         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1273         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1274         halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1275         halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1276         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1277 \r
1278         // hw all off\r
1279         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1280 }\r
1281 \r
1282 VOID\r
1283 halbtc8723a2ant_InitCoexDm(\r
1284         IN      PBTC_COEXIST            pBtCoexist\r
1285         )\r
1286 {\r
1287         // force to reset coex mechanism\r
1288         halbtc8723a2ant_CoexTable(pBtCoexist, FORCE_EXEC, 0x55555555, 0xffff, 0x3);\r
1289         halbtc8723a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1290         halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 0x20);\r
1291         halbtc8723a2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, FALSE);\r
1292         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
1293 \r
1294         halbtc8723a2ant_AgcTable(pBtCoexist, FORCE_EXEC, FALSE);\r
1295         halbtc8723a2ant_AdcBackOff(pBtCoexist, FORCE_EXEC, FALSE);\r
1296         halbtc8723a2ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE);\r
1297         halbtc8723a2ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE);\r
1298         halbtc8723a2ant_DacSwing(pBtCoexist, FORCE_EXEC, FALSE, 0xc0);\r
1299 }\r
1300 \r
1301 VOID\r
1302 halbtc8723a2ant_BtInquiryPage(\r
1303         IN      PBTC_COEXIST            pBtCoexist\r
1304         )\r
1305 {\r
1306         BOOLEAN bLowPwrDisable=TRUE;\r
1307         \r
1308         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1309 \r
1310         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1311         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1312         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1313 }\r
1314 \r
1315 VOID\r
1316 halbtc8723a2ant_BtEnableAction(\r
1317         IN      PBTC_COEXIST            pBtCoexist\r
1318         )\r
1319 {\r
1320         BOOLEAN         bWifiConnected=FALSE;\r
1321         \r
1322         // Here we need to resend some wifi info to BT\r
1323         // because bt is reset and loss of the info.                                            \r
1324         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1325         if(bWifiConnected)\r
1326         {\r
1327                 halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, BTC_MEDIA_CONNECT);\r
1328         }\r
1329         else\r
1330         {\r
1331                 halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
1332         }\r
1333 \r
1334         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
1335 }\r
1336 \r
1337 VOID\r
1338 halbtc8723a2ant_MonitorBtCtr(\r
1339         IN      PBTC_COEXIST            pBtCoexist\r
1340         )\r
1341 {\r
1342         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
1343         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
1344         u1Byte                  u1Tmp;\r
1345         \r
1346         regHPTxRx = 0x770;\r
1347         regLPTxRx = 0x774;\r
1348 \r
1349         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
1350         regHPTx = u4Tmp & bMaskLWord;\r
1351         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
1352 \r
1353         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
1354         regLPTx = u4Tmp & bMaskLWord;\r
1355         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
1356                 \r
1357         pCoexSta->highPriorityTx = regHPTx;\r
1358         pCoexSta->highPriorityRx = regHPRx;\r
1359         pCoexSta->lowPriorityTx = regLPTx;\r
1360         pCoexSta->lowPriorityRx = regLPRx;\r
1361 \r
1362         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
1363                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
1364         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
1365                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
1366 \r
1367         // reset counter\r
1368         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
1369 }\r
1370 \r
1371 VOID\r
1372 halbtc8723a2ant_MonitorBtEnableDisable(\r
1373         IN      PBTC_COEXIST            pBtCoexist\r
1374         )\r
1375 {\r
1376         static BOOLEAN  bPreBtDisabled=FALSE;\r
1377         static u4Byte   btDisableCnt=0;\r
1378         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1379 \r
1380         // This function check if bt is disabled\r
1381 \r
1382         if(     pCoexSta->highPriorityTx == 0 &&\r
1383                 pCoexSta->highPriorityRx == 0 &&\r
1384                 pCoexSta->lowPriorityTx == 0 &&\r
1385                 pCoexSta->lowPriorityRx == 0)\r
1386         {\r
1387                 bBtActive = FALSE;\r
1388         }\r
1389         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1390                 pCoexSta->highPriorityRx == 0xffff &&\r
1391                 pCoexSta->lowPriorityTx == 0xffff &&\r
1392                 pCoexSta->lowPriorityRx == 0xffff)\r
1393         {\r
1394                 bBtActive = FALSE;\r
1395         }\r
1396         if(bBtActive)\r
1397         {\r
1398                 btDisableCnt = 0;\r
1399                 bBtDisabled = FALSE;\r
1400                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1401                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
1402         }\r
1403         else\r
1404         {\r
1405                 btDisableCnt++;\r
1406                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1407                                 btDisableCnt));\r
1408                 if(btDisableCnt >= 2)\r
1409                 {\r
1410                         bBtDisabled = TRUE;\r
1411                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1412                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
1413                 }\r
1414         }\r
1415         if(bPreBtDisabled != bBtDisabled)\r
1416         {\r
1417                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
1418                         (bPreBtDisabled ? "disabled":"enabled"), \r
1419                         (bBtDisabled ? "disabled":"enabled")));\r
1420                 bPreBtDisabled = bBtDisabled;\r
1421                 if(!bBtDisabled)\r
1422                 {\r
1423                         halbtc8723a2ant_BtEnableAction(pBtCoexist);\r
1424                 }\r
1425         }\r
1426 }\r
1427 \r
1428 BOOLEAN\r
1429 halbtc8723a2ant_IsCommonAction(\r
1430         IN      PBTC_COEXIST            pBtCoexist\r
1431         )\r
1432 {\r
1433         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
1434         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE;\r
1435         BOOLEAN                 bLowPwrDisable=FALSE;\r
1436 \r
1437         if(!pStackInfo->bBtLinkExist)\r
1438         {\r
1439                 bLowPwrDisable = FALSE;\r
1440                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1441         }\r
1442         else\r
1443         {\r
1444                 bLowPwrDisable = TRUE;\r
1445                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1446         }\r
1447 \r
1448         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1449 \r
1450         if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1451                 BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus)\r
1452         {\r
1453                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi idle + Bt idle!!\n"));\r
1454                         \r
1455                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1456                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1457                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1458 \r
1459                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1460                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1461                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1462 \r
1463                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1464                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1465                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1466 \r
1467                 bCommon = TRUE;\r
1468         }\r
1469         else if(!halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1470                         (BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus) )\r
1471         {\r
1472                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-idle + BT idle!!\n"));\r
1473 \r
1474                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1475                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1476                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1477 \r
1478                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1479                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1480                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1481                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
1482 \r
1483                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1484                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1485                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1486 \r
1487                 bCommon = TRUE;\r
1488         }\r
1489         else if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1490                 (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1491         {\r
1492                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi idle + Bt connected idle!!\n"));\r
1493                 \r
1494                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1495                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1496                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1497 \r
1498                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1499                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1500                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1501                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1502 \r
1503                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1504                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1505                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1506 \r
1507                 bCommon = TRUE;\r
1508         }\r
1509         else if(!halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1510                 (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1511         {\r
1512                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-idle + Bt connected idle!!\n"));\r
1513 \r
1514                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1515                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1516                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1517 \r
1518                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1519                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1520                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1521                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1522 \r
1523                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1524                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1525                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1526 \r
1527                 bCommon = TRUE;\r
1528         }\r
1529         else if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1530                         (BT_8723A_2ANT_BT_STATUS_NON_IDLE == pCoexDm->btStatus) )\r
1531         {\r
1532                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi idle + BT non-idle!!\n"));\r
1533                 \r
1534                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1535                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1536                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1537 \r
1538                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1539                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1540                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1541                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1542 \r
1543                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1544                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1545                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1546                 \r
1547                 bCommon = TRUE;\r
1548         }\r
1549         else\r
1550         {\r
1551                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-idle + BT non-idle!!\n"));\r
1552                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1553                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1554                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1555                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1556                 \r
1557                 bCommon = FALSE;\r
1558         }\r
1559         \r
1560         return bCommon;\r
1561 }\r
1562 VOID\r
1563 halbtc8723a2ant_TdmaDurationAdjust(\r
1564         IN      PBTC_COEXIST            pBtCoexist,\r
1565         IN      BOOLEAN                 bScoHid,\r
1566         IN      BOOLEAN                 bTxPause,\r
1567         IN      u1Byte                  maxInterval\r
1568         )\r
1569 {\r
1570         static s4Byte           up,dn,m,n,WaitCount;\r
1571         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1572         u1Byte                  retryCount=0;\r
1573 \r
1574         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));\r
1575 \r
1576         if(pCoexDm->bResetTdmaAdjust)\r
1577         {\r
1578                 pCoexDm->bResetTdmaAdjust = FALSE;\r
1579                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1580                 {\r
1581                         if(bScoHid)\r
1582                         {\r
1583                                 if(bTxPause)\r
1584                                 {\r
1585                                         if(maxInterval == 1)\r
1586                                         {\r
1587                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1588                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
1589                                         }\r
1590                                         else if(maxInterval == 2)\r
1591                                         {\r
1592                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1593                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
1594                                         }\r
1595                                         else if(maxInterval == 3)\r
1596                                         {\r
1597                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1598                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
1599                                         }\r
1600                                         else\r
1601                                         {\r
1602                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1603                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1604                                         }\r
1605                                 }\r
1606                                 else\r
1607                                 {\r
1608                                         if(maxInterval == 1)\r
1609                                         {\r
1610                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1611                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
1612                                         }\r
1613                                         else if(maxInterval == 2)\r
1614                                         {\r
1615                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1616                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
1617                                         }\r
1618                                         else if(maxInterval == 3)\r
1619                                         {\r
1620                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1621                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1622                                         }\r
1623                                         else\r
1624                                         {\r
1625                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1626                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1627                                         }\r
1628                                 }\r
1629                         }\r
1630                         else\r
1631                         {\r
1632                                 if(bTxPause)\r
1633                                 {\r
1634                                         if(maxInterval == 1)\r
1635                                         {\r
1636                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1637                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
1638                                         }\r
1639                                         else if(maxInterval == 2)\r
1640                                         {\r
1641                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1642                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
1643                                         }\r
1644                                         else if(maxInterval == 3)\r
1645                                         {\r
1646                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1647                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1648                                         }\r
1649                                         else\r
1650                                         {\r
1651                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1652                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1653                                         }\r
1654                                 }\r
1655                                 else\r
1656                                 {\r
1657                                         if(maxInterval == 1)\r
1658                                         {\r
1659                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1660                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
1661                                         }\r
1662                                         else if(maxInterval == 2)\r
1663                                         {\r
1664                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1665                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
1666                                         }\r
1667                                         else if(maxInterval == 3)\r
1668                                         {\r
1669                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1670                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1671                                         }\r
1672                                         else\r
1673                                         {\r
1674                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1675                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1676                                         }\r
1677                                 }\r
1678                         }\r
1679                 }\r
1680                 //============\r
1681                 up = 0;\r
1682                 dn = 0;\r
1683                 m = 1;\r
1684                 n= 3;\r
1685                 result = 0;\r
1686                 WaitCount = 0;\r
1687         }\r
1688         else\r
1689         {\r
1690                 //accquire the BT TRx retry count from BT_Info byte2\r
1691                 retryCount = pCoexSta->btRetryCnt;\r
1692                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1693                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1694                         up, dn, m, n, WaitCount));\r
1695                 result = 0;\r
1696                 WaitCount++; \r
1697                   \r
1698                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1699                 {\r
1700                         up++;\r
1701                         dn--;\r
1702 \r
1703                         if (dn <= 0)\r
1704                                 dn = 0;                          \r
1705 \r
1706                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1707                         {\r
1708                                 WaitCount = 0; \r
1709                                 n = 3;\r
1710                                 up = 0;\r
1711                                 dn = 0;\r
1712                                 result = 1; \r
1713                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1714                         }\r
1715                 }\r
1716                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1717                 {\r
1718                         up--; \r
1719                         dn++;\r
1720 \r
1721                         if (up <= 0)\r
1722                                 up = 0;\r
1723 \r
1724                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1725                         {\r
1726                                 if (WaitCount <= 2)\r
1727                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1728                                 else\r
1729                                         m = 1;\r
1730 \r
1731                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1732                                         m = 20;\r
1733 \r
1734                                 n = 3*m;\r
1735                                 up = 0;\r
1736                                 dn = 0;\r
1737                                 WaitCount = 0;\r
1738                                 result = -1; \r
1739                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1740                         }\r
1741                 }\r
1742                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1743                 {\r
1744                         if (WaitCount == 1)\r
1745                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1746                         else\r
1747                                 m = 1;\r
1748 \r
1749                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1750                                 m = 20;\r
1751 \r
1752                         n = 3*m;\r
1753                         up = 0;\r
1754                         dn = 0;\r
1755                         WaitCount = 0; \r
1756                         result = -1;\r
1757                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1758                 }\r
1759 \r
1760                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));\r
1761                 if(maxInterval == 1)\r
1762                 {\r
1763                         if(bTxPause)\r
1764                         {\r
1765                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
1766 \r
1767                                 if(pCoexDm->curPsTdma == 1)\r
1768                                 {\r
1769                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1770                                         pCoexDm->psTdmaDuAdjType = 5;\r
1771                                 }\r
1772                                 else if(pCoexDm->curPsTdma == 2)\r
1773                                 {\r
1774                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1775                                         pCoexDm->psTdmaDuAdjType = 6;\r
1776                                 }\r
1777                                 else if(pCoexDm->curPsTdma == 3)\r
1778                                 {\r
1779                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1780                                         pCoexDm->psTdmaDuAdjType = 7;\r
1781                                 }\r
1782                                 else if(pCoexDm->curPsTdma == 4)\r
1783                                 {\r
1784                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1785                                         pCoexDm->psTdmaDuAdjType = 8;\r
1786                                 }\r
1787                                 if(pCoexDm->curPsTdma == 9)\r
1788                                 {\r
1789                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1790                                         pCoexDm->psTdmaDuAdjType = 13;\r
1791                                 }\r
1792                                 else if(pCoexDm->curPsTdma == 10)\r
1793                                 {\r
1794                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1795                                         pCoexDm->psTdmaDuAdjType = 14;\r
1796                                 }\r
1797                                 else if(pCoexDm->curPsTdma == 11)\r
1798                                 {\r
1799                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1800                                         pCoexDm->psTdmaDuAdjType = 15;\r
1801                                 }\r
1802                                 else if(pCoexDm->curPsTdma == 12)\r
1803                                 {\r
1804                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
1805                                         pCoexDm->psTdmaDuAdjType = 16;\r
1806                                 }\r
1807                                 \r
1808                                 if(result == -1)\r
1809                                 {                                       \r
1810                                         if(pCoexDm->curPsTdma == 5)\r
1811                                         {\r
1812                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1813                                                 pCoexDm->psTdmaDuAdjType = 6;\r
1814                                         }\r
1815                                         else if(pCoexDm->curPsTdma == 6)\r
1816                                         {\r
1817                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1818                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1819                                         }\r
1820                                         else if(pCoexDm->curPsTdma == 7)\r
1821                                         {\r
1822                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1823                                                 pCoexDm->psTdmaDuAdjType = 8;\r
1824                                         }\r
1825                                         else if(pCoexDm->curPsTdma == 13)\r
1826                                         {\r
1827                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1828                                                 pCoexDm->psTdmaDuAdjType = 14;\r
1829                                         }\r
1830                                         else if(pCoexDm->curPsTdma == 14)\r
1831                                         {\r
1832                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1833                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1834                                         }\r
1835                                         else if(pCoexDm->curPsTdma == 15)\r
1836                                         {\r
1837                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
1838                                                 pCoexDm->psTdmaDuAdjType = 16;\r
1839                                         }\r
1840                                 } \r
1841                                 else if (result == 1)\r
1842                                 {\r
1843                                         if(pCoexDm->curPsTdma == 8)\r
1844                                         {\r
1845                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1846                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1847                                         }\r
1848                                         else if(pCoexDm->curPsTdma == 7)\r
1849                                         {\r
1850                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1851                                                 pCoexDm->psTdmaDuAdjType = 6;\r
1852                                         }\r
1853                                         else if(pCoexDm->curPsTdma == 6)\r
1854                                         {\r
1855                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1856                                                 pCoexDm->psTdmaDuAdjType = 5;\r
1857                                         }\r
1858                                         else if(pCoexDm->curPsTdma == 16)\r
1859                                         {\r
1860                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1861                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1862                                         }\r
1863                                         else if(pCoexDm->curPsTdma == 15)\r
1864                                         {\r
1865                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1866                                                 pCoexDm->psTdmaDuAdjType = 14;\r
1867                                         }\r
1868                                         else if(pCoexDm->curPsTdma == 14)\r
1869                                         {\r
1870                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1871                                                 pCoexDm->psTdmaDuAdjType = 13;\r
1872                                         }\r
1873                                 }\r
1874                         }\r
1875                         else\r
1876                         {\r
1877                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
1878                                 if(pCoexDm->curPsTdma == 5)\r
1879                                 {\r
1880                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1881                                         pCoexDm->psTdmaDuAdjType = 1;\r
1882                                 }\r
1883                                 else if(pCoexDm->curPsTdma == 6)\r
1884                                 {\r
1885                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1886                                         pCoexDm->psTdmaDuAdjType = 2;\r
1887                                 }\r
1888                                 else if(pCoexDm->curPsTdma == 7)\r
1889                                 {\r
1890                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1891                                         pCoexDm->psTdmaDuAdjType = 3;\r
1892                                 }\r
1893                                 else if(pCoexDm->curPsTdma == 8)\r
1894                                 {\r
1895                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
1896                                         pCoexDm->psTdmaDuAdjType = 4;\r
1897                                 }\r
1898                                 if(pCoexDm->curPsTdma == 13)\r
1899                                 {\r
1900                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1901                                         pCoexDm->psTdmaDuAdjType = 9;\r
1902                                 }\r
1903                                 else if(pCoexDm->curPsTdma == 14)\r
1904                                 {\r
1905                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1906                                         pCoexDm->psTdmaDuAdjType = 10;\r
1907                                 }\r
1908                                 else if(pCoexDm->curPsTdma == 15)\r
1909                                 {\r
1910                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1911                                         pCoexDm->psTdmaDuAdjType = 11;\r
1912                                 }\r
1913                                 else if(pCoexDm->curPsTdma == 16)\r
1914                                 {\r
1915                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
1916                                         pCoexDm->psTdmaDuAdjType = 12;\r
1917                                 }\r
1918                                 \r
1919                                 if(result == -1)\r
1920                                 {\r
1921                                         if(pCoexDm->curPsTdma == 1)\r
1922                                         {\r
1923                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1924                                                 pCoexDm->psTdmaDuAdjType = 2;\r
1925                                         }\r
1926                                         else if(pCoexDm->curPsTdma == 2)\r
1927                                         {\r
1928                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1929                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1930                                         }\r
1931                                         else if(pCoexDm->curPsTdma == 3)\r
1932                                         {\r
1933                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
1934                                                 pCoexDm->psTdmaDuAdjType = 4;\r
1935                                         }\r
1936                                         else if(pCoexDm->curPsTdma == 9)\r
1937                                         {\r
1938                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1939                                                 pCoexDm->psTdmaDuAdjType = 10;\r
1940                                         }\r
1941                                         else if(pCoexDm->curPsTdma == 10)\r
1942                                         {\r
1943                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1944                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1945                                         }\r
1946                                         else if(pCoexDm->curPsTdma == 11)\r
1947                                         {\r
1948                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
1949                                                 pCoexDm->psTdmaDuAdjType = 12;\r
1950                                         }\r
1951                                 } \r
1952                                 else if (result == 1)\r
1953                                 {\r
1954                                         if(pCoexDm->curPsTdma == 4)\r
1955                                         {\r
1956                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1957                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1958                                         }\r
1959                                         else if(pCoexDm->curPsTdma == 3)\r
1960                                         {\r
1961                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1962                                                 pCoexDm->psTdmaDuAdjType = 2;\r
1963                                         }\r
1964                                         else if(pCoexDm->curPsTdma == 2)\r
1965                                         {\r
1966                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1967                                                 pCoexDm->psTdmaDuAdjType = 1;\r
1968                                         }\r
1969                                         else if(pCoexDm->curPsTdma == 12)\r
1970                                         {\r
1971                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1972                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1973                                         }\r
1974                                         else if(pCoexDm->curPsTdma == 11)\r
1975                                         {\r
1976                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1977                                                 pCoexDm->psTdmaDuAdjType = 10;\r
1978                                         }\r
1979                                         else if(pCoexDm->curPsTdma == 10)\r
1980                                         {\r
1981                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1982                                                 pCoexDm->psTdmaDuAdjType = 9;\r
1983                                         }\r
1984                                 }\r
1985                         }\r
1986                 }\r
1987                 else if(maxInterval == 2)\r
1988                 {\r
1989                         if(bTxPause)\r
1990                         {\r
1991                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
1992                                 if(pCoexDm->curPsTdma == 1)\r
1993                                 {\r
1994                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1995                                         pCoexDm->psTdmaDuAdjType = 6;\r
1996                                 }\r
1997                                 else if(pCoexDm->curPsTdma == 2)\r
1998                                 {\r
1999                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2000                                         pCoexDm->psTdmaDuAdjType = 6;\r
2001                                 }\r
2002                                 else if(pCoexDm->curPsTdma == 3)\r
2003                                 {\r
2004                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2005                                         pCoexDm->psTdmaDuAdjType = 7;\r
2006                                 }\r
2007                                 else if(pCoexDm->curPsTdma == 4)\r
2008                                 {\r
2009                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2010                                         pCoexDm->psTdmaDuAdjType = 8;\r
2011                                 }\r
2012                                 if(pCoexDm->curPsTdma == 9)\r
2013                                 {\r
2014                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2015                                         pCoexDm->psTdmaDuAdjType = 14;\r
2016                                 }\r
2017                                 else if(pCoexDm->curPsTdma == 10)\r
2018                                 {\r
2019                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2020                                         pCoexDm->psTdmaDuAdjType = 14;\r
2021                                 }\r
2022                                 else if(pCoexDm->curPsTdma == 11)\r
2023                                 {\r
2024                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2025                                         pCoexDm->psTdmaDuAdjType = 15;\r
2026                                 }\r
2027                                 else if(pCoexDm->curPsTdma == 12)\r
2028                                 {\r
2029                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2030                                         pCoexDm->psTdmaDuAdjType = 16;\r
2031                                 }\r
2032                                 if(result == -1)\r
2033                                 {\r
2034                                         if(pCoexDm->curPsTdma == 5) \r
2035                                         {\r
2036                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2037                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2038                                         }\r
2039                                         else if(pCoexDm->curPsTdma == 6)\r
2040                                         {\r
2041                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2042                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2043                                         }\r
2044                                         else if(pCoexDm->curPsTdma == 7)\r
2045                                         {\r
2046                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2047                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2048                                         }\r
2049                                         else if(pCoexDm->curPsTdma == 13)\r
2050                                         {\r
2051                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2052                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2053                                         }\r
2054                                         else if(pCoexDm->curPsTdma == 14)\r
2055                                         {\r
2056                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2057                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2058                                         }\r
2059                                         else if(pCoexDm->curPsTdma == 15)\r
2060                                         {\r
2061                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2062                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2063                                         }\r
2064                                 } \r
2065                                 else if (result == 1)\r
2066                                 {\r
2067                                         if(pCoexDm->curPsTdma == 8)\r
2068                                         {\r
2069                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2070                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2071                                         }\r
2072                                         else if(pCoexDm->curPsTdma == 7)\r
2073                                         {\r
2074                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2075                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2076                                         }\r
2077                                         else if(pCoexDm->curPsTdma == 6)\r
2078                                         {\r
2079                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2080                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2081                                         }                                       \r
2082                                         else if(pCoexDm->curPsTdma == 16)\r
2083                                         {\r
2084                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2085                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2086                                         }\r
2087                                         else if(pCoexDm->curPsTdma == 15)\r
2088                                         {\r
2089                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2090                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2091                                         }\r
2092                                         else if(pCoexDm->curPsTdma == 14)\r
2093                                         {\r
2094                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2095                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2096                                         }\r
2097                                 }\r
2098                         }\r
2099                         else\r
2100                         {\r
2101                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2102                                 if(pCoexDm->curPsTdma == 5)\r
2103                                 {\r
2104                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2105                                         pCoexDm->psTdmaDuAdjType = 2;\r
2106                                 }\r
2107                                 else if(pCoexDm->curPsTdma == 6)\r
2108                                 {\r
2109                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2110                                         pCoexDm->psTdmaDuAdjType = 2;\r
2111                                 }\r
2112                                 else if(pCoexDm->curPsTdma == 7)\r
2113                                 {\r
2114                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2115                                         pCoexDm->psTdmaDuAdjType = 3;\r
2116                                 }\r
2117                                 else if(pCoexDm->curPsTdma == 8)\r
2118                                 {\r
2119                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2120                                         pCoexDm->psTdmaDuAdjType = 4;\r
2121                                 }\r
2122                                 if(pCoexDm->curPsTdma == 13)\r
2123                                 {\r
2124                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2125                                         pCoexDm->psTdmaDuAdjType = 10;\r
2126                                 }\r
2127                                 else if(pCoexDm->curPsTdma == 14)\r
2128                                 {\r
2129                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2130                                         pCoexDm->psTdmaDuAdjType = 10;\r
2131                                 }\r
2132                                 else if(pCoexDm->curPsTdma == 15)\r
2133                                 {\r
2134                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2135                                         pCoexDm->psTdmaDuAdjType = 11;\r
2136                                 }\r
2137                                 else if(pCoexDm->curPsTdma == 16)\r
2138                                 {\r
2139                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2140                                         pCoexDm->psTdmaDuAdjType = 12;\r
2141                                 }\r
2142                                 if(result == -1)\r
2143                                 {\r
2144                                         if(pCoexDm->curPsTdma == 1)\r
2145                                         {\r
2146                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2147                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2148                                         }\r
2149                                         else if(pCoexDm->curPsTdma == 2)\r
2150                                         {\r
2151                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2152                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2153                                         }\r
2154                                         else if(pCoexDm->curPsTdma == 3)\r
2155                                         {\r
2156                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2157                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2158                                         }\r
2159                                         else if(pCoexDm->curPsTdma == 9)\r
2160                                         {\r
2161                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2162                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2163                                         }\r
2164                                         else if(pCoexDm->curPsTdma == 10)\r
2165                                         {\r
2166                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2167                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2168                                         }\r
2169                                         else if(pCoexDm->curPsTdma == 11)\r
2170                                         {\r
2171                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2172                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2173                                         }\r
2174                                 } \r
2175                                 else if (result == 1)\r
2176                                 {\r
2177                                         if(pCoexDm->curPsTdma == 4)\r
2178                                         {\r
2179                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2180                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2181                                         }\r
2182                                         else if(pCoexDm->curPsTdma == 3)\r
2183                                         {\r
2184                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2185                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2186                                         }\r
2187                                         else if(pCoexDm->curPsTdma == 2)\r
2188                                         {\r
2189                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2190                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2191                                         }\r
2192                                         else if(pCoexDm->curPsTdma == 12)\r
2193                                         {\r
2194                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2195                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2196                                         }\r
2197                                         else if(pCoexDm->curPsTdma == 11)\r
2198                                         {\r
2199                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2200                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2201                                         }\r
2202                                         else if(pCoexDm->curPsTdma == 10)\r
2203                                         {\r
2204                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2205                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2206                                         }\r
2207                                 }\r
2208                         }\r
2209                 }\r
2210                 else if(maxInterval == 3)\r
2211                 {\r
2212                         if(bTxPause)\r
2213                         {\r
2214                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2215                                 if(pCoexDm->curPsTdma == 1)\r
2216                                 {\r
2217                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2218                                         pCoexDm->psTdmaDuAdjType = 7;\r
2219                                 }\r
2220                                 else if(pCoexDm->curPsTdma == 2)\r
2221                                 {\r
2222                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2223                                         pCoexDm->psTdmaDuAdjType = 7;\r
2224                                 }\r
2225                                 else if(pCoexDm->curPsTdma == 3)\r
2226                                 {\r
2227                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2228                                         pCoexDm->psTdmaDuAdjType = 7;\r
2229                                 }\r
2230                                 else if(pCoexDm->curPsTdma == 4)\r
2231                                 {\r
2232                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2233                                         pCoexDm->psTdmaDuAdjType = 8;\r
2234                                 }\r
2235                                 if(pCoexDm->curPsTdma == 9)\r
2236                                 {\r
2237                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2238                                         pCoexDm->psTdmaDuAdjType = 15;\r
2239                                 }\r
2240                                 else if(pCoexDm->curPsTdma == 10)\r
2241                                 {\r
2242                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2243                                         pCoexDm->psTdmaDuAdjType = 15;\r
2244                                 }\r
2245                                 else if(pCoexDm->curPsTdma == 11)\r
2246                                 {\r
2247                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2248                                         pCoexDm->psTdmaDuAdjType = 15;\r
2249                                 }\r
2250                                 else if(pCoexDm->curPsTdma == 12)\r
2251                                 {\r
2252                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2253                                         pCoexDm->psTdmaDuAdjType = 16;\r
2254                                 }\r
2255                                 if(result == -1)\r
2256                                 {\r
2257                                         if(pCoexDm->curPsTdma == 5) \r
2258                                         {\r
2259                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2260                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2261                                         }\r
2262                                         else if(pCoexDm->curPsTdma == 6)\r
2263                                         {\r
2264                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2265                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2266                                         }\r
2267                                         else if(pCoexDm->curPsTdma == 7)\r
2268                                         {\r
2269                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2270                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2271                                         }\r
2272                                         else if(pCoexDm->curPsTdma == 13)\r
2273                                         {\r
2274                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2275                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2276                                         }\r
2277                                         else if(pCoexDm->curPsTdma == 14)\r
2278                                         {\r
2279                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2280                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2281                                         }\r
2282                                         else if(pCoexDm->curPsTdma == 15)\r
2283                                         {\r
2284                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2285                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2286                                         }\r
2287                                 } \r
2288                                 else if (result == 1)\r
2289                                 {\r
2290                                         if(pCoexDm->curPsTdma == 8)\r
2291                                         {\r
2292                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2293                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2294                                         }\r
2295                                         else if(pCoexDm->curPsTdma == 7)\r
2296                                         {\r
2297                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2298                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2299                                         }\r
2300                                         else if(pCoexDm->curPsTdma == 6)\r
2301                                         {\r
2302                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2303                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2304                                         }                                       \r
2305                                         else if(pCoexDm->curPsTdma == 16)\r
2306                                         {\r
2307                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2308                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2309                                         }\r
2310                                         else if(pCoexDm->curPsTdma == 15)\r
2311                                         {\r
2312                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2313                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2314                                         }\r
2315                                         else if(pCoexDm->curPsTdma == 14)\r
2316                                         {\r
2317                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2318                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2319                                         }\r
2320                                 }\r
2321                         }\r
2322                         else\r
2323                         {\r
2324                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2325                                 if(pCoexDm->curPsTdma == 5)\r
2326                                 {\r
2327                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2328                                         pCoexDm->psTdmaDuAdjType = 3;\r
2329                                 }\r
2330                                 else if(pCoexDm->curPsTdma == 6)\r
2331                                 {\r
2332                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2333                                         pCoexDm->psTdmaDuAdjType = 3;\r
2334                                 }\r
2335                                 else if(pCoexDm->curPsTdma == 7)\r
2336                                 {\r
2337                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2338                                         pCoexDm->psTdmaDuAdjType = 3;\r
2339                                 }\r
2340                                 else if(pCoexDm->curPsTdma == 8)\r
2341                                 {\r
2342                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2343                                         pCoexDm->psTdmaDuAdjType = 4;\r
2344                                 }\r
2345                                 if(pCoexDm->curPsTdma == 13)\r
2346                                 {\r
2347                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2348                                         pCoexDm->psTdmaDuAdjType = 11;\r
2349                                 }\r
2350                                 else if(pCoexDm->curPsTdma == 14)\r
2351                                 {\r
2352                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2353                                         pCoexDm->psTdmaDuAdjType = 11;\r
2354                                 }\r
2355                                 else if(pCoexDm->curPsTdma == 15)\r
2356                                 {\r
2357                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2358                                         pCoexDm->psTdmaDuAdjType = 11;\r
2359                                 }\r
2360                                 else if(pCoexDm->curPsTdma == 16)\r
2361                                 {\r
2362                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2363                                         pCoexDm->psTdmaDuAdjType = 12;\r
2364                                 }\r
2365                                 if(result == -1)\r
2366                                 {\r
2367                                         if(pCoexDm->curPsTdma == 1)\r
2368                                         {\r
2369                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2370                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2371                                         }\r
2372                                         else if(pCoexDm->curPsTdma == 2)\r
2373                                         {\r
2374                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2375                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2376                                         }\r
2377                                         else if(pCoexDm->curPsTdma == 3)\r
2378                                         {\r
2379                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2380                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2381                                         }\r
2382                                         else if(pCoexDm->curPsTdma == 9)\r
2383                                         {\r
2384                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2385                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2386                                         }\r
2387                                         else if(pCoexDm->curPsTdma == 10)\r
2388                                         {\r
2389                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2390                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2391                                         }\r
2392                                         else if(pCoexDm->curPsTdma == 11)\r
2393                                         {\r
2394                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2395                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2396                                         }\r
2397                                 } \r
2398                                 else if (result == 1)\r
2399                                 {\r
2400                                         if(pCoexDm->curPsTdma == 4)\r
2401                                         {\r
2402                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2403                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2404                                         }\r
2405                                         else if(pCoexDm->curPsTdma == 3)\r
2406                                         {\r
2407                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2408                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2409                                         }\r
2410                                         else if(pCoexDm->curPsTdma == 2)\r
2411                                         {\r
2412                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2413                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2414                                         }\r
2415                                         else if(pCoexDm->curPsTdma == 12)\r
2416                                         {\r
2417                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2418                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2419                                         }\r
2420                                         else if(pCoexDm->curPsTdma == 11)\r
2421                                         {\r
2422                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2423                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2424                                         }\r
2425                                         else if(pCoexDm->curPsTdma == 10)\r
2426                                         {\r
2427                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2428                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2429                                         }\r
2430                                 }\r
2431                         }\r
2432                 }\r
2433         }\r
2434 \r
2435         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2436         // then we have to adjust it back to the previous record one.\r
2437         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2438         {\r
2439                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2440                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2441                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2442 \r
2443                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2444                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2445                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2446                 \r
2447                 if( !bScan && !bLink && !bRoam)\r
2448                 {\r
2449                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2450                 }\r
2451                 else\r
2452                 {\r
2453                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
2454                 }\r
2455         }\r
2456 }\r
2457 \r
2458 // SCO only or SCO+PAN(HS)\r
2459 VOID\r
2460 halbtc8723a2ant_ActionSco(\r
2461         IN      PBTC_COEXIST            pBtCoexist\r
2462         )\r
2463 {\r
2464         u1Byte  wifiRssiState, wifiRssiState1;\r
2465         u4Byte  wifiBw;\r
2466 \r
2467         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2468                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2469         else    \r
2470                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2471         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2472         \r
2473         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2474         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2475         {\r
2476                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2477                 // fw mechanism\r
2478                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2479                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2480                 {\r
2481                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2482                 }\r
2483                 else\r
2484                 {\r
2485                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2486                 }\r
2487 \r
2488                 // sw mechanism         \r
2489                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2490                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2491                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2492         }\r
2493         else\r
2494         {\r
2495                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2496                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2497                 \r
2498                 // fw mechanism\r
2499                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2500                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2501                 {\r
2502                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2503                 }\r
2504                 else\r
2505                 {\r
2506                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2507                 }\r
2508                 \r
2509                 // sw mechanism\r
2510                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2511                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2512                 {\r
2513                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2514                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2515                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2516                 }\r
2517                 else\r
2518                 {\r
2519                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2520                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2521                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2522                 }               \r
2523         }\r
2524 }\r
2525 \r
2526 \r
2527 VOID\r
2528 halbtc8723a2ant_ActionHid(\r
2529         IN      PBTC_COEXIST            pBtCoexist\r
2530         )\r
2531 {\r
2532         u1Byte  wifiRssiState, wifiRssiState1;\r
2533         u4Byte  wifiBw;\r
2534 \r
2535         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2536                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2537         else    \r
2538                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2539         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2540 \r
2541         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2542         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2543         {\r
2544                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2545                 // fw mechanism\r
2546                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2547                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2548                 {\r
2549                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2550                 }\r
2551                 else\r
2552                 {\r
2553                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2554                 }\r
2555 \r
2556                 // sw mechanism\r
2557                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2558                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2559                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2560         }\r
2561         else\r
2562         {\r
2563                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2564                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2565 \r
2566                 // fw mechanism\r
2567                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2568                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2569                 {\r
2570                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2571                 }\r
2572                 else\r
2573                 {\r
2574                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2575                 }\r
2576 \r
2577                 // sw mechanism\r
2578                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2579                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2580                 {\r
2581                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2582                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2583                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2584                 }\r
2585                 else\r
2586                 {\r
2587                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2588                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2589                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2590                 }               \r
2591         }\r
2592 }\r
2593 \r
2594 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
2595 VOID\r
2596 halbtc8723a2ant_ActionA2dp(\r
2597         IN      PBTC_COEXIST            pBtCoexist\r
2598         )\r
2599 {\r
2600         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2601         u4Byte          wifiBw;\r
2602 \r
2603         btInfoExt = pCoexSta->btInfoExt;\r
2604 \r
2605         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2606                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2607         else    \r
2608                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2609         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2610         \r
2611         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2612         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2613         {\r
2614                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2615 \r
2616                 // fw mechanism\r
2617                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2618                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2619                 {\r
2620                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2621                         {\r
2622                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
2623                         }\r
2624                         else\r
2625                         {\r
2626                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
2627                         }\r
2628                 }\r
2629                 else\r
2630                 {\r
2631                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2632                         {\r
2633                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
2634                         }\r
2635                         else\r
2636                         {\r
2637                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
2638                         }\r
2639                 }\r
2640 \r
2641                 // sw mechanism         \r
2642                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2643                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2644                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2645         }\r
2646         else\r
2647         {\r
2648                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2649                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2650                 \r
2651                 // fw mechanism\r
2652                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2653                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2654                 {\r
2655                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2656                         {\r
2657                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
2658                         }\r
2659                         else\r
2660                         {\r
2661                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
2662                         }\r
2663                 }\r
2664                 else\r
2665                 {\r
2666                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2667                         {\r
2668                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
2669                         }\r
2670                         else\r
2671                         {\r
2672                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
2673                         }\r
2674                 }\r
2675                 \r
2676                 // sw mechanism\r
2677                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2678                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2679                 {\r
2680                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2681                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2682                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2683                 }\r
2684                 else\r
2685                 {\r
2686                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2687                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2688                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2689                 }               \r
2690         }\r
2691 }\r
2692 \r
2693 VOID\r
2694 halbtc8723a2ant_ActionPanEdr(\r
2695         IN      PBTC_COEXIST            pBtCoexist\r
2696         )\r
2697 {\r
2698         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2699         u4Byte          wifiBw;\r
2700         \r
2701         btInfoExt = pCoexSta->btInfoExt;\r
2702 \r
2703         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2704                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2705         else    \r
2706                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2707         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2708 \r
2709         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2710         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2711         {\r
2712                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2713                         \r
2714                 // fw mechanism\r
2715                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2716                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2717                 {\r
2718                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2719                 }\r
2720                 else\r
2721                 {\r
2722                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2723                 }\r
2724 \r
2725                 // sw mechanism\r
2726                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2727                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2728                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2729         }\r
2730         else\r
2731         {\r
2732                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2733                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2734                 \r
2735                 // fw mechanism\r
2736                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2737                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2738                 {\r
2739                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2740                 }\r
2741                 else\r
2742                 {\r
2743                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2744                 }\r
2745 \r
2746                 // sw mechanism\r
2747                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2748                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2749                 {\r
2750                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2751                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2752                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2753                 }\r
2754                 else\r
2755                 {\r
2756                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2757                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2758                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2759                 }\r
2760         }\r
2761 }\r
2762 \r
2763 \r
2764 //PAN(HS) only\r
2765 VOID\r
2766 halbtc8723a2ant_ActionPanHs(\r
2767         IN      PBTC_COEXIST            pBtCoexist\r
2768         )\r
2769 {\r
2770         u1Byte          wifiRssiState;\r
2771         u4Byte          wifiBw;\r
2772 \r
2773         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2774 \r
2775         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2776         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2777         {\r
2778                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2779 \r
2780                 // fw mechanism\r
2781                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2782                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2783                 {\r
2784                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2785                 }\r
2786                 else\r
2787                 {\r
2788                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2789                 }\r
2790                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2791 \r
2792                 // sw mechanism         \r
2793                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2794                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2795                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2796         }\r
2797         else\r
2798         {\r
2799                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2800 \r
2801                 // fw mechanism\r
2802                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2803                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2804                 {\r
2805                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2806                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2807                 }\r
2808                 else\r
2809                 {\r
2810                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2811                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2812                 }\r
2813 \r
2814                 // sw mechanism\r
2815                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2816                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2817                 {\r
2818                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2819                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2820                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2821                 }\r
2822                 else\r
2823                 {\r
2824                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2825                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2826                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2827                 }\r
2828         }\r
2829 }\r
2830 \r
2831 //PAN(EDR)+A2DP\r
2832 VOID\r
2833 halbtc8723a2ant_ActionPanEdrA2dp(\r
2834         IN      PBTC_COEXIST            pBtCoexist\r
2835         )\r
2836 {\r
2837         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2838         u4Byte          wifiBw;\r
2839 \r
2840         btInfoExt = pCoexSta->btInfoExt;\r
2841 \r
2842         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2843                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2844         else    \r
2845                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2846         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2847 \r
2848         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2849         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2850         {\r
2851                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2852 \r
2853                 // fw mechanism\r
2854                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2855                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2856                 {\r
2857                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2858                         {\r
2859                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2860                         }\r
2861                         else                            //a2dp edr rate\r
2862                         {\r
2863                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2864                         }\r
2865                 }\r
2866                 else\r
2867                 {\r
2868                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2869                         {\r
2870                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2871                         }\r
2872                         else                            //a2dp edr rate\r
2873                         {\r
2874                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2875                         }\r
2876                 }\r
2877 \r
2878                 // sw mechanism\r
2879                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2880                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2881                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2882         }\r
2883         else\r
2884         {\r
2885                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2886                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
2887                 \r
2888                 // fw mechanism\r
2889                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2890                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2891                 {\r
2892                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2893                         {\r
2894                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2895                         }\r
2896                         else                            //a2dp edr rate\r
2897                         {\r
2898                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2899                         }\r
2900                 }\r
2901                 else\r
2902                 {\r
2903                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2904                         {\r
2905                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2906                         }\r
2907                         else                            //a2dp edr rate\r
2908                         {\r
2909                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2910                         }\r
2911                 }\r
2912 \r
2913                 // sw mechanism\r
2914                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2915                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2916                 {\r
2917                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2918                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2919                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2920                 }\r
2921                 else\r
2922                 {\r
2923                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2924                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2925                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2926                 }\r
2927         }\r
2928 }\r
2929 \r
2930 VOID\r
2931 halbtc8723a2ant_ActionPanEdrHid(\r
2932         IN      PBTC_COEXIST            pBtCoexist\r
2933         )\r
2934 {\r
2935         u1Byte          wifiRssiState, wifiRssiState1;\r
2936         u4Byte          wifiBw;\r
2937 \r
2938         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2939                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2940         else    \r
2941                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2942         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2943 \r
2944         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2945         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2946         {\r
2947                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2948 \r
2949                 // fw mechanism\r
2950                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2951                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2952                 {\r
2953                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10); \r
2954                 }\r
2955                 else\r
2956                 {\r
2957                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14); \r
2958                 }\r
2959 \r
2960                 // sw mechanism\r
2961                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2962                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2963                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2964         }\r
2965         else\r
2966         {\r
2967                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2968                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2969                 \r
2970                 // fw mechanism\r
2971                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2972                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2973                 {\r
2974                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2975                 }\r
2976                 else\r
2977                 {\r
2978                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2979                 }\r
2980                 \r
2981                 // sw mechanism\r
2982                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2983                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2984                 {\r
2985                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2986                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2987                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2988                 }\r
2989                 else\r
2990                 {\r
2991                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2992                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2993                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2994                 }\r
2995         }\r
2996 }\r
2997 \r
2998 // HID+A2DP+PAN(EDR)\r
2999 VOID\r
3000 halbtc8723a2ant_ActionHidA2dpPanEdr(\r
3001         IN      PBTC_COEXIST            pBtCoexist\r
3002         )\r
3003 {\r
3004         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
3005         u4Byte          wifiBw;\r
3006 \r
3007         btInfoExt = pCoexSta->btInfoExt;\r
3008 \r
3009         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
3010                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
3011         else    \r
3012                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
3013         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
3014 \r
3015         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3016         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3017         {\r
3018                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
3019                         \r
3020                 // fw mechanism\r
3021                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3022                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3023                 {\r
3024                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3025                         {\r
3026                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
3027                         }\r
3028                         else                            //a2dp edr rate\r
3029                         {\r
3030                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3031                         }\r
3032                 }\r
3033                 else\r
3034                 {\r
3035                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3036                         {\r
3037                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
3038                         }\r
3039                         else                            //a2dp edr rate\r
3040                         {\r
3041                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3042                         }\r
3043                 }\r
3044                 \r
3045                 // sw mechanism\r
3046                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3047                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3048                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3049         }\r
3050         else\r
3051         {\r
3052                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
3053                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
3054                 \r
3055                 // fw mechanism\r
3056                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3057                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3058                 {\r
3059                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3060                         {\r
3061                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
3062                         }\r
3063                         else                            //a2dp edr rate\r
3064                         {\r
3065                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3066                         }\r
3067                 }\r
3068                 else\r
3069                 {\r
3070                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3071                         {\r
3072                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
3073                         }\r
3074                         else                            //a2dp edr rate\r
3075                         {\r
3076                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3077                         }\r
3078                 }\r
3079 \r
3080                 // sw mechanism\r
3081                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
3082                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
3083                 {\r
3084                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
3085                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3086                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3087                 }\r
3088                 else\r
3089                 {\r
3090                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3091                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
3092                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3093                 }\r
3094         }\r
3095 }\r
3096 \r
3097 VOID\r
3098 halbtc8723a2ant_ActionHidA2dp(\r
3099         IN      PBTC_COEXIST            pBtCoexist\r
3100         )\r
3101 {\r
3102         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
3103         u4Byte          wifiBw;\r
3104 \r
3105         btInfoExt = pCoexSta->btInfoExt;\r
3106 \r
3107         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
3108                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
3109         else    \r
3110                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
3111         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
3112 \r
3113         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3114         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3115         {\r
3116                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
3117                 \r
3118                 // fw mechanism\r
3119                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3120                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3121                 {\r
3122                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3123                         {\r
3124                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3125                         }\r
3126                         else                            //a2dp edr rate\r
3127                         {\r
3128                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 1);\r
3129                         }\r
3130                 }\r
3131                 else\r
3132                 {\r
3133                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3134                         {\r
3135                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3136                         }\r
3137                         else                            //a2dp edr rate\r
3138                         {\r
3139                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 1);\r
3140                         }\r
3141                 }\r
3142                 \r
3143                 // sw mechanism\r
3144                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3145                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3146                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3147         }\r
3148         else\r
3149         {\r
3150                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
3151                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
3152                 \r
3153                 // fw mechanism\r
3154                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3155                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3156                 {\r
3157                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3158                         {\r
3159                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3160                         }\r
3161                         else                            //a2dp edr rate\r
3162                         {\r
3163                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 1);\r
3164                         }\r
3165                 }\r
3166                 else\r
3167                 {\r
3168                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3169                         {\r
3170                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3171                         }\r
3172                         else                            //a2dp edr rate\r
3173                         {\r
3174                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 1);\r
3175                         }\r
3176                 }\r
3177 \r
3178                 // sw mechanism\r
3179                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
3180                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
3181                 {\r
3182                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
3183                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3184                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3185                 }\r
3186                 else\r
3187                 {\r
3188                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3189                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
3190                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3191                 }\r
3192         }\r
3193 }\r
3194 \r
3195 VOID\r
3196 halbtc8723a2ant_RunCoexistMechanism(\r
3197         IN      PBTC_COEXIST            pBtCoexist\r
3198         )\r
3199 {\r
3200         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3201         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3202         u1Byte                          algorithm=0;\r
3203 \r
3204         if(pBtCoexist->bManualControl)\r
3205         {\r
3206                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Manual control!!!\n"));\r
3207                 return;\r
3208         }\r
3209 \r
3210         if(pStackInfo->bProfileNotified)\r
3211         {\r
3212                 if(pCoexSta->bHoldForStackOperation)\r
3213                 {\r
3214                         // if bt inquiry/page/pair, do not execute.\r
3215                         return;\r
3216                 }\r
3217                 \r
3218                 algorithm = halbtc8723a2ant_ActionAlgorithm(pBtCoexist);\r
3219                 if(pCoexSta->bHoldPeriodCnt && (BT_8723A_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3220                 {\r
3221                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex],Hold BT inquiry/page scan setting (cnt = %d)!!\n", \r
3222                                 pCoexSta->bHoldPeriodCnt));\r
3223                         if(pCoexSta->bHoldPeriodCnt >= 6)\r
3224                         {\r
3225                                 pCoexSta->bHoldPeriodCnt = 0;\r
3226                                 // next time the coexist parameters should be reset again.\r
3227                         }\r
3228                         else\r
3229                                 pCoexSta->bHoldPeriodCnt++;\r
3230                         return;\r
3231                 }\r
3232 \r
3233                 pCoexDm->curAlgorithm = algorithm;\r
3234                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3235                 if(halbtc8723a2ant_IsCommonAction(pBtCoexist))\r
3236                 {\r
3237                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant common.\n"));\r
3238                         pCoexDm->bResetTdmaAdjust = TRUE;\r
3239                 }\r
3240                 else\r
3241                 {\r
3242                         if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3243                         {\r
3244                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3245                                         pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3246                                 pCoexDm->bResetTdmaAdjust = TRUE;\r
3247                         }\r
3248                         switch(pCoexDm->curAlgorithm)\r
3249                         {\r
3250                                 case BT_8723A_2ANT_COEX_ALGO_SCO:\r
3251                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3252                                         halbtc8723a2ant_ActionSco(pBtCoexist);\r
3253                                         break;\r
3254                                 case BT_8723A_2ANT_COEX_ALGO_HID:\r
3255                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3256                                         halbtc8723a2ant_ActionHid(pBtCoexist);\r
3257                                         break;\r
3258                                 case BT_8723A_2ANT_COEX_ALGO_A2DP:\r
3259                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3260                                         halbtc8723a2ant_ActionA2dp(pBtCoexist);\r
3261                                         break;\r
3262                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR:\r
3263                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3264                                         halbtc8723a2ant_ActionPanEdr(pBtCoexist);\r
3265                                         break;\r
3266                                 case BT_8723A_2ANT_COEX_ALGO_PANHS:\r
3267                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3268                                         halbtc8723a2ant_ActionPanHs(pBtCoexist);\r
3269                                         break;\r
3270                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3271                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3272                                         halbtc8723a2ant_ActionPanEdrA2dp(pBtCoexist);\r
3273                                         break;\r
3274                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR_HID:\r
3275                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3276                                         halbtc8723a2ant_ActionPanEdrHid(pBtCoexist);\r
3277                                         break;\r
3278                                 case BT_8723A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
3279                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
3280                                         halbtc8723a2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
3281                                         break;\r
3282                                 case BT_8723A_2ANT_COEX_ALGO_HID_A2DP:\r
3283                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
3284                                         halbtc8723a2ant_ActionHidA2dp(pBtCoexist);\r
3285                                         break;\r
3286                                 default:\r
3287                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));\r
3288                                         halbtc8723a2ant_CoexAllOff(pBtCoexist);\r
3289                                         break;\r
3290                         }\r
3291                         pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
3292                 }\r
3293         }\r
3294 }\r
3295 \r
3296 //============================================================\r
3297 // work around function start with wa_halbtc8723a2ant_\r
3298 //============================================================\r
3299 VOID\r
3300 wa_halbtc8723a2ant_MonitorC2h(\r
3301         IN      PBTC_COEXIST                    pBtCoexist\r
3302         )\r
3303 {\r
3304         u1Byte  tmp1b=0x0;\r
3305         u4Byte  curC2hTotalCnt=0x0;\r
3306         static u4Byte   preC2hTotalCnt=0x0, sameCntPollingTime=0x0;\r
3307 \r
3308         curC2hTotalCnt+=pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8723A_2ANT_BT_RSP];\r
3309 \r
3310         if(curC2hTotalCnt == preC2hTotalCnt)\r
3311         {\r
3312                 sameCntPollingTime++;\r
3313         }\r
3314         else\r
3315         {\r
3316                 preC2hTotalCnt = curC2hTotalCnt;\r
3317                 sameCntPollingTime = 0;\r
3318         }\r
3319 \r
3320         if(sameCntPollingTime >= 2)\r
3321         {\r
3322                 tmp1b = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x1af);\r
3323                 if(tmp1b != 0x0)\r
3324                 {\r
3325                         pCoexSta->c2hHangDetectCnt++;\r
3326                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x1af, 0x0);\r
3327                 }\r
3328         }\r
3329 }\r
3330 \r
3331 //============================================================\r
3332 // extern function start with EXhalbtc8723a2ant_\r
3333 //============================================================\r
3334 VOID\r
3335 EXhalbtc8723a2ant_InitHwConfig(\r
3336         IN      PBTC_COEXIST            pBtCoexist\r
3337         )\r
3338 {\r
3339         u4Byte  u4Tmp=0;\r
3340         u1Byte  u1Tmp=0;\r
3341 \r
3342         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
3343 \r
3344         // backup rf 0x1e value\r
3345         pCoexDm->btRf0x1eBackup = \r
3346                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
3347 \r
3348         // Enable counter statistics\r
3349         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
3350         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
3351         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
3352 }\r
3353 \r
3354 VOID\r
3355 EXhalbtc8723a2ant_InitCoexDm(\r
3356         IN      PBTC_COEXIST            pBtCoexist\r
3357         )\r
3358 {\r
3359         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
3360         \r
3361         halbtc8723a2ant_InitCoexDm(pBtCoexist);\r
3362 }\r
3363 \r
3364 VOID\r
3365 EXhalbtc8723a2ant_DisplayCoexInfo(\r
3366         IN      PBTC_COEXIST            pBtCoexist\r
3367         )\r
3368 {\r
3369         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3370         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3371         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
3372         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
3373         u4Byte                          u4Tmp[4];\r
3374         BOOLEAN                         bRoam=FALSE, bScan=FALSE, bLink=FALSE, bWifiUnder5G=FALSE;\r
3375         BOOLEAN                         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
3376         s4Byte                          wifiRssi=0, btHsRssi=0;\r
3377         u4Byte                          wifiBw, wifiTrafficDir;\r
3378         u1Byte                          wifiDot11Chnl, wifiHsChnl;\r
3379 \r
3380         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
3381         CL_PRINTF(cliBuf);\r
3382 \r
3383         if(!pBoardInfo->bBtExist)\r
3384         {\r
3385                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");\r
3386                 CL_PRINTF(cliBuf);\r
3387                 return;\r
3388         }\r
3389 \r
3390         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
3391                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
3392         CL_PRINTF(cliBuf);      \r
3393         \r
3394         if(pBtCoexist->bManualControl)\r
3395         {\r
3396                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");\r
3397                 CL_PRINTF(cliBuf);\r
3398         }\r
3399         \r
3400         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
3401                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
3402         CL_PRINTF(cliBuf);\r
3403 \r
3404         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3405         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);\r
3406         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);\r
3407         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \\r
3408                 wifiDot11Chnl, wifiHsChnl, bBtHsOn);\r
3409         CL_PRINTF(cliBuf);\r
3410 \r
3411         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \\r
3412                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
3413                 pCoexDm->wifiChnlInfo[2]);\r
3414         CL_PRINTF(cliBuf);\r
3415 \r
3416         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
3417         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);\r
3418         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \\r
3419                 wifiRssi, btHsRssi);\r
3420         CL_PRINTF(cliBuf);\r
3421 \r
3422         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
3423         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
3424         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
3425         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \\r
3426                 bLink, bRoam, bScan);\r
3427         CL_PRINTF(cliBuf);\r
3428 \r
3429         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
3430         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3431         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
3432         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
3433         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s ", "Wifi status", \\r
3434                 (bWifiUnder5G? "5G":"2.4G"),\r
3435                 ((BTC_WIFI_BW_LEGACY==wifiBw)? "Legacy": (((BTC_WIFI_BW_HT40==wifiBw)? "HT40":"HT20"))),\r
3436                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")));\r
3437         CL_PRINTF(cliBuf);\r
3438 \r
3439         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
3440                 ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus)? "idle":(  (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy"))),\r
3441                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
3442         CL_PRINTF(cliBuf);\r
3443         \r
3444         if(pStackInfo->bProfileNotified)\r
3445         {                       \r
3446                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
3447                         pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
3448                 CL_PRINTF(cliBuf);      \r
3449 \r
3450                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
3451         }\r
3452 \r
3453         btInfoExt = pCoexSta->btInfoExt;\r
3454         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
3455                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
3456         CL_PRINTF(cliBuf);      \r
3457 \r
3458         for(i=0; i<BT_INFO_SRC_8723A_2ANT_MAX; i++)\r
3459         {\r
3460                 if(pCoexSta->btInfoC2hCnt[i])\r
3461                 {                               \r
3462                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a2Ant[i], \\r
3463                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
3464                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
3465                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
3466                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
3467                         CL_PRINTF(cliBuf);\r
3468                 }\r
3469         }\r
3470 \r
3471         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "write 0x1af=0x0 num", \\r
3472                 pCoexSta->c2hHangDetectCnt);\r
3473         CL_PRINTF(cliBuf);\r
3474         \r
3475         // Sw mechanism \r
3476         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
3477         CL_PRINTF(cliBuf);\r
3478         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \\r
3479                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
3480         CL_PRINTF(cliBuf);\r
3481         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
3482                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
3483         CL_PRINTF(cliBuf);\r
3484 \r
3485         // Fw mechanism         \r
3486         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
3487         CL_PRINTF(cliBuf);      \r
3488         \r
3489         if(!pBtCoexist->bManualControl)\r
3490         {\r
3491                 psTdmaCase = pCoexDm->curPsTdma;\r
3492                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \\r
3493                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
3494                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
3495                         pCoexDm->psTdmaPara[4], psTdmaCase);\r
3496                 CL_PRINTF(cliBuf);\r
3497         \r
3498                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
3499                         pCoexDm->bCurDecBtPwr, pCoexDm->bCurIgnoreWlanAct);\r
3500                 CL_PRINTF(cliBuf);\r
3501         }\r
3502 \r
3503         // Hw setting           \r
3504         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
3505         CL_PRINTF(cliBuf);      \r
3506 \r
3507         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
3508                 pCoexDm->btRf0x1eBackup);\r
3509         CL_PRINTF(cliBuf);\r
3510 \r
3511         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
3512         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x783);\r
3513         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x796);\r
3514         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \\r
3515                 u1Tmp[0], u1Tmp[1], u1Tmp[2]);\r
3516         CL_PRINTF(cliBuf);\r
3517 \r
3518         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
3519         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \\r
3520                 u4Tmp[0]);\r
3521         CL_PRINTF(cliBuf);\r
3522 \r
3523         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
3524         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
3525                 u1Tmp[0]);\r
3526         CL_PRINTF(cliBuf);\r
3527 \r
3528         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
3529         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
3530         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
3531                 u4Tmp[0], u1Tmp[0]);\r
3532         CL_PRINTF(cliBuf);\r
3533 \r
3534         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x484);\r
3535         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \\r
3536                 u4Tmp[0]);\r
3537         CL_PRINTF(cliBuf);\r
3538 \r
3539         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
3540         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
3541                 u4Tmp[0]);\r
3542         CL_PRINTF(cliBuf);\r
3543 \r
3544         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
3545         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
3546         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
3547         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xdac);\r
3548         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \\r
3549                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);\r
3550         CL_PRINTF(cliBuf);\r
3551 \r
3552         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
3553         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
3554         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
3555         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
3556         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
3557                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
3558         CL_PRINTF(cliBuf);\r
3559 \r
3560         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \\r
3561                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
3562         CL_PRINTF(cliBuf);\r
3563         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
3564                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
3565         CL_PRINTF(cliBuf);\r
3566 \r
3567         // Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang\r
3568         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x41b);\r
3569         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x41b (mgntQ hang chk == 0xf)", \\r
3570                 u1Tmp[0]);\r
3571         CL_PRINTF(cliBuf);      \r
3572 \r
3573         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
3574 }\r
3575 \r
3576 \r
3577 VOID\r
3578 EXhalbtc8723a2ant_IpsNotify(\r
3579         IN      PBTC_COEXIST            pBtCoexist,\r
3580         IN      u1Byte                  type\r
3581         )\r
3582 {\r
3583         if(BTC_IPS_ENTER == type)\r
3584         {\r
3585                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
3586                 halbtc8723a2ant_CoexAllOff(pBtCoexist);\r
3587         }\r
3588         else if(BTC_IPS_LEAVE == type)\r
3589         {\r
3590                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
3591                 //halbtc8723a2ant_InitCoexDm(pBtCoexist);\r
3592         }\r
3593 }\r
3594 \r
3595 VOID\r
3596 EXhalbtc8723a2ant_LpsNotify(\r
3597         IN      PBTC_COEXIST            pBtCoexist,\r
3598         IN      u1Byte                  type\r
3599         )\r
3600 {\r
3601         if(BTC_LPS_ENABLE == type)\r
3602         {\r
3603                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
3604         }\r
3605         else if(BTC_LPS_DISABLE == type)\r
3606         {\r
3607                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
3608         }\r
3609 }\r
3610 \r
3611 VOID\r
3612 EXhalbtc8723a2ant_ScanNotify(\r
3613         IN      PBTC_COEXIST            pBtCoexist,\r
3614         IN      u1Byte                  type\r
3615         )\r
3616 {\r
3617         if(BTC_SCAN_START == type)\r
3618         {\r
3619                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
3620         }\r
3621         else if(BTC_SCAN_FINISH == type)\r
3622         {\r
3623                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
3624         }\r
3625 }\r
3626 \r
3627 VOID\r
3628 EXhalbtc8723a2ant_ConnectNotify(\r
3629         IN      PBTC_COEXIST            pBtCoexist,\r
3630         IN      u1Byte                  type\r
3631         )\r
3632 {\r
3633         if(BTC_ASSOCIATE_START == type)\r
3634         {\r
3635                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
3636         }\r
3637         else if(BTC_ASSOCIATE_FINISH == type)\r
3638         {\r
3639                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
3640         }\r
3641 }\r
3642 \r
3643 VOID\r
3644 EXhalbtc8723a2ant_MediaStatusNotify(\r
3645         IN      PBTC_COEXIST                    pBtCoexist,\r
3646         IN      u1Byte                          type\r
3647         )\r
3648 {\r
3649         if(BTC_MEDIA_CONNECT == type)\r
3650         {\r
3651                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
3652         }\r
3653         else\r
3654         {\r
3655                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
3656         }\r
3657 \r
3658         halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, type);\r
3659 }\r
3660 \r
3661 VOID\r
3662 EXhalbtc8723a2ant_SpecialPacketNotify(\r
3663         IN      PBTC_COEXIST                    pBtCoexist,\r
3664         IN      u1Byte                          type\r
3665         )\r
3666 {\r
3667         if(type == BTC_PACKET_DHCP)\r
3668         {\r
3669                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));\r
3670         }\r
3671 }\r
3672 \r
3673 VOID\r
3674 EXhalbtc8723a2ant_BtInfoNotify(\r
3675         IN      PBTC_COEXIST            pBtCoexist,\r
3676         IN      pu1Byte                 tmpBuf,\r
3677         IN      u1Byte                  length\r
3678         )\r
3679 {\r
3680         u1Byte                  btInfo=0;\r
3681         u1Byte                  i, rspSource=0;\r
3682         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
3683         BOOLEAN                 bWifiConnected=FALSE, bBtHsOn=FALSE;\r
3684 \r
3685         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
3686         \r
3687         rspSource = BT_INFO_SRC_8723A_2ANT_BT_RSP;\r
3688         pCoexSta->btInfoC2hCnt[rspSource]++;\r
3689 \r
3690         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
3691         for(i=0; i<length; i++)\r
3692         {\r
3693                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
3694                 if(i == 0)\r
3695                         btInfo = tmpBuf[i];\r
3696                 if(i == length-1)\r
3697                 {\r
3698                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
3699                 }\r
3700                 else\r
3701                 {\r
3702                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
3703                 }\r
3704         }\r
3705 \r
3706         if(BT_INFO_SRC_8723A_2ANT_WIFI_FW != rspSource)\r
3707         {\r
3708                 pCoexSta->btRetryCnt =\r
3709                         pCoexSta->btInfoC2h[rspSource][1];\r
3710 \r
3711                 pCoexSta->btRssi =\r
3712                         pCoexSta->btInfoC2h[rspSource][2]*2+10;\r
3713 \r
3714                 pCoexSta->btInfoExt = \r
3715                         pCoexSta->btInfoC2h[rspSource][3];\r
3716         }\r
3717                 \r
3718         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3719         // check BIT2 first ==> check if bt is under inquiry or page scan\r
3720         if(btInfo & BT_INFO_8723A_2ANT_B_INQ_PAGE)\r
3721         {\r
3722                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
3723         }\r
3724         else\r
3725         {\r
3726                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
3727         }\r
3728 }\r
3729 \r
3730 VOID\r
3731 EXhalbtc8723a2ant_StackOperationNotify(\r
3732         IN      PBTC_COEXIST                    pBtCoexist,\r
3733         IN      u1Byte                          type\r
3734         )\r
3735 {\r
3736         if(BTC_STACK_OP_INQ_PAGE_PAIR_START == type)\r
3737         {\r
3738                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], StackOP Inquiry/page/pair start notify\n"));\r
3739                 pCoexSta->bHoldForStackOperation = TRUE;\r
3740                 pCoexSta->bHoldPeriodCnt = 1;\r
3741                 halbtc8723a2ant_BtInquiryPage(pBtCoexist);\r
3742         }\r
3743         else if(BTC_STACK_OP_INQ_PAGE_PAIR_FINISH == type)\r
3744         {\r
3745                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], StackOP Inquiry/page/pair finish notify\n"));\r
3746                 pCoexSta->bHoldForStackOperation = FALSE;\r
3747         }\r
3748 }\r
3749 \r
3750 VOID\r
3751 EXhalbtc8723a2ant_HaltNotify(\r
3752         IN      PBTC_COEXIST                    pBtCoexist\r
3753         )\r
3754 {\r
3755         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
3756 \r
3757         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3758         EXhalbtc8723a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3759 }\r
3760 \r
3761 VOID\r
3762 EXhalbtc8723a2ant_Periodical(\r
3763         IN      PBTC_COEXIST                    pBtCoexist\r
3764         )\r
3765 {\r
3766         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], 2Ant Periodical!!\n"));\r
3767 \r
3768         // work around for c2h hang\r
3769         wa_halbtc8723a2ant_MonitorC2h(pBtCoexist);\r
3770         \r
3771         halbtc8723a2ant_QueryBtInfo(pBtCoexist);\r
3772         halbtc8723a2ant_MonitorBtCtr(pBtCoexist);\r
3773         halbtc8723a2ant_MonitorBtEnableDisable(pBtCoexist);\r
3774 \r
3775         halbtc8723a2ant_RunCoexistMechanism(pBtCoexist);\r
3776 }\r
3777 \r
3778 \r
3779 #endif\r
3780 \r