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