xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usbhost/source3/usb_hid_p3/drvintpipe_3.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 #if defined(MSOS_TYPE_NOS)
79 #include "../USBHostConfig_3.h"
80 #include "../../include/datatype.h"
81 #include "../drvHost200_3.h"
82 #include "../drvHostLib_3.h"
83 #include "../drvUsbMain_3.h"
84 
85 #include "../../include/_drvUSB.h"
86 #include "../../include/hal_arch.h"
87 #include "../../include/hal_cache.h"
88 #include <string.h>
89 #include "../drvscsi_3.h"
90 
91 #include "MsCommon.h"
92 #include "MsIRQ.h"
93 #include "MsOS.h"
94 
95 #define USB_HID_INT_DBG(x) // x
96 #define USB_HID_INT_MSG(x)		MS_CRITICAL_MSG(x)
97 
98 extern void msAPI_Timer_ResetWDT(void);
99 
100 #define   FRAME_LIST_SIZE                           (256*4)
101 
102 Periodic_Frame_List_Structure  Host20_FramList_Port3 __attribute__ ((aligned (4096)));
103 Periodic_Frame_List_Structure   *pHost20_FramList_Port3;
104 qHD_Structure  Host20_qHD_List_Intr_Port3    __attribute__ ((aligned (32)));
105 qHD_Structure *pHost20_qHD_List_Intr_Port3;
106 extern  Host20_Attach_Device_Structure sAttachDevice_Port3;
107 //extern Host20_Attach_Device_Structure  *psAttachDevice_Port3;
108 extern UINT8 gSpeed_Port3;
109 extern U8 gUsbStatus_Port3;
110 
111 extern UINT8 flib_Host20_CheckingForResult_QHD_Port3(qHD_Structure *spTempqHD);
112 extern void ResetUsbHardwarePort3(void);
113 extern U8 usb_temp_buf_Port3[Scsi_Max_Transfer_Len];
114 
SetFrameList_Port3(UINT8 i)115 void SetFrameList_Port3(UINT8 i)
116 {
117     pHost20_FramList_Port3->sCell[i].bTerminal=0;
118     pHost20_FramList_Port3->sCell[i].bType=HOST20_HD_Type_QH;
119     //SetPointer(&(Host20_FramList.sCell[i].bLinkPointer3),VirtoPhyAddr((UINT16)pHost20_qHD_List_Intr));
120     pHost20_FramList_Port3->sCell[i].bLinkPointer = (VirtoPhyAddr((U32)pHost20_qHD_List_Intr_Port3)>>5);
121 }
122 
123 //====================================================================
124 // * Function Name: flib_Host20_Interrupt_Init
125 // * Description:
126 //   //Reserve=> <1>.If Periodic Enable => Disable Periodic
127 //   <2>.Disable all the Frame List (Terminal=1)
128 //   <3>.Hang the Interrupt-qHD-1 to Frame List
129 //
130 // * Input: wInterval=1~16 => Full Speed => 1ms ~ 32 sec
131 //                            High Speed => 125us ~ 40.96 sec
132 // * OutPut:
133 //====================================================================
flib_Host20_Interrupt_Init_Port3(UINT8 bAddr)134 void  flib_Host20_Interrupt_Init_Port3(UINT8 bAddr)
135 {
136     UINT32 i,j;
137     // UINT32 wSize;
138     UINT8 *pData;
139     //UINT16 wForceInterval=0;
140     UINT8 EndPaddr;
141     //struct usb_interface_descriptor *ip;
142 
143     //  ip=&dev->config.if_desc[0];
144 
145     //<1>.Disable the Periodic
146     flib_Host20_Periodic_Setting_Port3(HOST20_Disable);
147 
148     //<2>.Init qHD for Interrupt(7~9) Scan the ED
149 
150     mbHost20_USBCMD_FrameListSize_Set(HOST20_USBCMD_FrameListSize_256);
151     pHost20_qHD_List_Intr_Port3=(qHD_Structure*)KSEG02KSEG1(&Host20_qHD_List_Intr_Port3);
152     pHost20_FramList_Port3= (Periodic_Frame_List_Structure*) KSEG02KSEG1(&Host20_FramList_Port3);
153     //printf("pHost20_qHD_List_Intr: %X\n", pHost20_qHD_List_Intr);
154     MY_HAL_DCACHE_FLUSH((U32)&Host20_qHD_List_Intr_Port3, sizeof(qHD_Structure));
155     MY_HAL_DCACHE_FLUSH((U32)&Host20_FramList_Port3, sizeof(Periodic_Frame_List_Structure));
156 
157     pData=(UINT8*)pHost20_qHD_List_Intr_Port3;
158     for (j=0;j<sizeof(qHD_Structure);j++)
159         *(pData+j)=0;
160 
161     //  printf("battribute:%02bx\n", sAttachDevice.saCD[0].sInterface[0].sED[0].bED_bmAttributes);
162     EndPaddr=  sAttachDevice_Port3.saCD[0].sInterface[0].sED[0].bED_EndpointAddress & 0x7f;
163     USB_HID_INT_DBG(printf("interrupt addr:%02x\n",EndPaddr));
164     flib_Host20_Allocate_QHD_Port3(pHost20_qHD_List_Intr_Port3,HOST20_HD_Type_QH,bAddr,0,EndPaddr,8);//Address=0,Head=1,EndPt=0,Size
165 
166     pHost20_qHD_List_Intr_Port3->bHighBandwidth=1;
167     pHost20_qHD_List_Intr_Port3->bInterruptScheduleMask=1;
168     pHost20_qHD_List_Intr_Port3->bEdSpeed= gSpeed_Port3;
169     pHost20_qHD_List_Intr_Port3->bDataToggleControl=0;
170 
171     //SetPointer(&(pHost20_qHD_List_Intr->bNextQHDPointer3),VirtoPhyAddr((UINT16)pHost20_qHD_List_Intr));
172      pHost20_qHD_List_Intr_Port3->bNextQHDPointer=(VirtoPhyAddr((U32)pHost20_qHD_List_Intr_Port3)>>5);
173 
174      //pHost20_qHD_List_Control1->bNextQHDPointer=(((U32)pHost20_qHD_List_Intr)>>5);
175      //pHost20_qHD_List_Intr->bNextQHDPointer=(((U32)pHost20_qHD_List_Control0)>>5);
176 
177     //       pHost20_qHD_List_Intr->bNextQHDPointer=(((UINT32)pHost20_qHD_List_Intr)>>5);      //point to itself
178     pHost20_qHD_List_Intr_Port3->bTerminate=1;          //terminated
179 
180 
181     //    psHost20_FramList=&Host20_FramList;
182     //<3>.Link qHD to the FameListCell by wInterval
183     //    printf("clear frame list data \n");
184 
185     pData=(UINT8 *)pHost20_FramList_Port3;
186     for (j=0;j<sizeof(Periodic_Frame_List_Structure);j++)
187         *(pData+j)=0;
188 
189     // printf("OK\n");
190 
191     for (i=0;i< Host20_Preiodic_Frame_List_MAX ;i++)
192         pHost20_FramList_Port3->sCell[i].bTerminal=1;
193     //Find the Interval-X
194     //  Host20_FramList.sCell[0].bLinkPointer=((UINT32)(pHost20_qHD_List_Intr))>>5;
195 
196 
197     SetFrameList_Port3(0);
198     SetFrameList_Port3(50);
199     SetFrameList_Port3(100);
200     SetFrameList_Port3(150);
201     SetFrameList_Port3(200);
202 
203 
204     // printf("FrameList:%x\n",FRAME_LIST_DATA);
205     // printf("first QH:%lx\n",VirtoPhyAddr((UINT16)pHost20_qHD_List_Intr));
206 
207     //while (1){}
208  #if 0
209         x=0;
210         while(waIntervalMap[x]<wForceInterval)
211         {
212           x++;
213           if (x>10)
214              {
215                  printf("Interval Input Error...\n");
216                  return;
217              }
218           };
219 
220         for (i=0;i<Host20_Preiodic_Frame_List_MAX;i=i+waIntervalMap[x])
221              {
222                Host20_FramList.sCell[i].bLinkPointer=((UINT32)(pHost20_qHD_List_Intr))>>5;
223                Host20_FramList.sCell[i].bTerminal=0;
224                Host20_FramList.sCell[i].bType=HOST20_HD_Type_QH;
225              }
226 #endif
227 
228     //<4>.Set Periodic Base Address
229     //  printf("FrameListPhy:%lx\n",VirtoPhyAddr((UINT16)&Host20_FramList));
230 
231     USB_HID_INT_DBG(printf("pHost20_FramList: %lX\n", (U32)pHost20_FramList_Port3));
232     mwHost20_PeriodicBaseAddr_Set(VirtoPhyAddr((U32)pHost20_FramList_Port3));
233 
234 
235     //<5>.Enable the periodic
236     flib_Host20_Periodic_Setting_Port3(HOST20_Enable);
237 
238 }
239 //====================================================================
240 // * Function Name: flib_Host20_Periodic_Setting
241 // * Description:
242 // * Input:
243 // * OutPut:
244 //====================================================================
flib_Host20_Periodic_Setting_Port3(UINT8 bOption)245 void flib_Host20_Periodic_Setting_Port3(UINT8 bOption)
246 {
247     if (bOption==HOST20_Enable)
248     {
249         //<1>.If Already enable => return
250         if (mwHost20_USBSTS_PeriodicStatus_Rd()>0)
251             return ;
252 
253         //<2>.Disable Periodic
254         mbHost20_USBCMD_PeriodicEnable_Set();
255 
256         //<3>.Polling Status
257         // while(mwHost20_USBSTS_PeriodicStatus_Rd()==0);
258 
259     }
260     else if (bOption==HOST20_Disable)
261     {
262         //<1>.If Already Disable => return
263         if (mwHost20_USBSTS_PeriodicStatus_Rd()==0)
264             return ;
265 
266         //<2>.Enable Periodic
267         mbHost20_USBCMD_PeriodicEnable_Clr();
268 
269         //<3>.Polling Status
270         //      while(mwHost20_USBSTS_PeriodicStatus_Rd()>0);
271 
272     }
273               //  else
274                // {
275                   //  printf("??? Input Error 'flib_Host20_Periodic_Setting'...");
276                // }
277 }
278 
flib_Host20_Send_qTD2_Port3(qTD_Structure * spHeadqTD,qHD_Structure * spTempqHD,U16 wTimeOutSec)279 UINT8 flib_Host20_Send_qTD2_Port3(qTD_Structure  *spHeadqTD ,qHD_Structure  *spTempqHD,U16 wTimeOutSec)
280 {
281   UINT8 bExitLoop,bReturnValue;
282   qTD_Structure   *spNewDumyqTD;
283   qTD_Structure   *spOldDumyqTD;
284   qTD_Structure   *spReleaseqTD;
285   qTD_Structure   *spReleaseqTDNext;
286   qTD_Structure   *spLastqTD;
287   //UINT32 wDummyTemp;
288   //UINT32 xdata *pwData;
289   #ifdef ATV_SERISE_USE
290   UINT32 wTimes;
291   UINT32 StartTime=0;
292   #else
293   UINT16 wTimes;
294   UINT32 StartTime;
295   UINT32 LastTime;
296   UINT16 FrameIdx=0;
297 
298   #endif
299 
300   #ifdef ATV_SERISE_USE
301   wTimeOutSec=wTimeOutSec;
302   #endif
303 
304   //if (wTimeOutSec==0)
305   //{
306   //  DEBUG_USB(printf("error, timeout sec is zero\n"));
307   //}
308     spOldDumyqTD=(qTD_Structure*)PhytoVirAddr((( U32)(spTempqHD->bOverlay_NextqTD))<<5);
309 
310   //spTempqHD->bOverlay_Status|=HOST20_qTD_STATUS_Halted;
311   while (mbHost20_USBCMD_PeriodicEnable_Rd())
312   {
313     mbHost20_USBCMD_PeriodicEnable_Clr();
314   }
315 
316   //spHeadqTD->bTerminate=1;			//set to terminate
317   memcpy(spOldDumyqTD,spHeadqTD,Host20_qTD_SIZE);
318   //spOldDumyqTD->bStatus_Halted=1;
319 
320   //spOldDumyqTD->bStatus_Active=0;
321 
322   //<2>.Prepare new dumy qTD
323   spNewDumyqTD=spHeadqTD;
324   memset((void *)spNewDumyqTD ,0, Host20_qTD_SIZE);
325   spNewDumyqTD->bTerminate=1;
326   //spNewDumyqTD->bAlternateTerminate=1;
327   //spNewDumyqTD->bStatus_Halted=1;
328   //<3>.Find spLastqTD & link spLastqTD to NewDumyqTD & Set NewDumyqTD->T=1
329   spLastqTD=spOldDumyqTD;
330   while(spLastqTD->bTerminate==0) {
331          spLastqTD=(qTD_Structure*)PhytoVirAddr((( U32)(spLastqTD->bNextQTDPointer))<<5);
332 
333   };
334 
335   spLastqTD->bNextQTDPointer=VirtoPhyAddr(( U32)spNewDumyqTD)>>5;
336 
337   spLastqTD->bTerminate=0;
338 
339   //Link Alternate qTD pointer
340     spLastqTD->bAlternateQTDPointer=(VirtoPhyAddr(( U32)spNewDumyqTD)>>5);
341 
342   spLastqTD->bAlternateTerminate=0;
343 
344 
345 
346   //<4>.Set OldDumyqTD->Active=1
347   //gwLastqTDSendOK=0;
348   //sAttachDevice.psSendLastqTD=spLastqTD;
349   sAttachDevice_Port3.bSendStatusError=0;
350 
351   //Dump_QTD(spOldDumyqTD);
352   //Dump_QTD(spNewDumyqTD);
353 
354   while (mwHost20_USBSTS_Rd() & 0x3b)
355   {
356     mwHost20_USBSTS_Set(0x3b);      //clear interrupt, don't clear port change int
357   }
358   //bExitLoop=0;
359   //spOldDumyqTD->bStatus_Halted=0;
360   //spOldDumyqTD->bStatus_Halted=0;
361 
362 #if 0
363     printf("spOldDumyqTD: %X\n", spOldDumyqTD);
364     printf("bTerminate: %X\n", spOldDumyqTD->bTerminate);
365     printf("bNextQTDPointer: %X\n", spOldDumyqTD->bNextQTDPointer);
366     printf("bAlternateTerminate: %X\n", spOldDumyqTD->bAlternateTerminate);
367     printf("bAlternateQTDPointer: %X\n", spOldDumyqTD->bAlternateQTDPointer);
368     printf("bStatus_PingState: %X\n", spOldDumyqTD->bStatus_PingState);
369     printf("bStatus_SplitState: %X\n", spOldDumyqTD->bStatus_SplitState);
370     printf("bStatus_MissMicroFrame: %X\n", spOldDumyqTD->bStatus_MissMicroFrame);
371     printf("bStatus_Transaction_Err: %X\n", spOldDumyqTD->bStatus_Transaction_Err);
372     printf("bStatus_Babble: %X\n", spOldDumyqTD->bStatus_Babble);
373     printf("bStatus_Buffer_Err: %X\n", spOldDumyqTD->bStatus_Buffer_Err);
374     printf("bStatus_Halted: %X\n", spOldDumyqTD->bStatus_Halted);
375     printf("bStatus_Active: %X\n", spOldDumyqTD->bStatus_Active);
376     printf("bPID: %X\n", spOldDumyqTD->bPID);
377     printf("bErrorCounter: %X\n", spOldDumyqTD->bErrorCounter);
378     printf("CurrentPage: %X\n", spOldDumyqTD->CurrentPage);
379     printf("bInterruptOnComplete: %X\n", spOldDumyqTD->bInterruptOnComplete);
380     printf("bTotalBytes: %X\n", spOldDumyqTD->bTotalBytes);
381     printf("bDataToggle: %X\n", spOldDumyqTD->bDataToggle);
382     printf("ArrayBufferPointer_Word: %X\n", spOldDumyqTD->ArrayBufferPointer_Word[0]);
383 #endif
384     //flib_Host20_StopRun_Setting(HOST20_Enable);
385     //printf("RunStop: %X\n", mbHost20_USBCMD_RunStop_Rd());
386   spOldDumyqTD->bStatus_Active=1;
387 
388   while (mbHost20_USBCMD_PeriodicEnable_Rd()==0)
389   {
390     mbHost20_USBCMD_PeriodicEnable_Set();
391   }
392   //spTempqHD->bOverlay_Status&=~HOST20_qTD_STATUS_Halted;
393 
394   //wait until asynchronous scheduler is idle
395 
396   //mbHost20_USBCMD_RunStop_Set();
397 
398   //spTempqHD->bOverlay_Status&=~0x40;			//clr HALT bit, start this queue head
399   //XBYTE[0x2410]|=1;//start run
400   //wDummyTemp=0;
401   wTimes=0;
402   #ifndef ATV_SERISE_USE
403   StartTime=MsOS_GetSystemTime();
404    LastTime=StartTime;
405    FrameIdx=mwHost20_FrameIndex_Rd();
406   msAPI_Timer_ResetWDT();
407   #endif
408   //<5>.Waiting for result
409   //EAL=0;
410   while (1)
411   {
412     #ifdef ATV_SERISE_USE
413     wTimes++;
414     #endif
415     if ((spOldDumyqTD->bStatus_Active==0) &&
416 	    ( mwHost20_USBSTS_Rd()& HOST20_USBINTR_CompletionOfTransaction))              //wait until Status_Active become 0
417     {
418       bReturnValue=HOST20_OK;
419 
420       break;
421       //bExitLoop=1;
422       //printf("bReturn:%02bx\n",    bReturnValue);
423     }
424     //if (bExitLoop) break;
425     #if 1
426     if (mwHost20_USBSTS_Rd()&(HOST20_USBINTR_SystemError+HOST20_USBINTR_USBError))
427     {
428       bReturnValue=HOST20_OK;
429       //if (spOldDumyqTD->bStatus_Active==1)
430 	  //{
431 	  //  printf("something wrong..USBINTR:%02bx\n",mwHost20_USBSTS_Rd());
432 	  //  printf("QH status:%02bx\n",spTempqHD->bOverlay_Status);
433 	  //}
434       break;            //USB interrupt happened
435     }
436     #endif
437     #if 1
438     //if (gwOTG_Timer_Counter>wTimeOutSec)
439     //  wTimes++;
440     //if (wTimes > wTimeOutSec*400)
441     if (mwHost20_PORTSC_ConnectStatus_Rd()==0)
442     {
443         //return HOST20_FATAL;
444         bReturnValue = HOST20_FATAL;
445         break;
446     }
447     //if (mwHost20_PORTSC_ConnectChange_Rd())
448     //{
449     //  gDeviceFatalError=TRUE;
450     //  mwHost20_PORTSC_ConnectChange_Set();
451     //  return HOST20_FATAL;          //usb has been plug out and in
452     //}
453     #ifndef ATV_SERISE_USE
454 #if 1
455       if (MsOS_Timer_DiffTimeFromNow(LastTime) >(U32)300)     //over 1 mini sec
456         {
457 
458             if (mwHost20_FrameIndex_Rd()==FrameIdx)
459             {
460                 USB_HID_INT_MSG(printf("1C stop,timeout !!\n"));
461                 gUsbStatus_Port3=USB_TIMEOUT;         //ESD , USB hang,should be timeout
462                 bReturnValue=HOST20_FATAL;
463                 break;
464             }
465             FrameIdx=mwHost20_FrameIndex_Rd();
466             LastTime=MsOS_GetSystemTime();
467 
468         }
469 #endif
470     if (MsOS_Timer_DiffTimeFromNow(StartTime) > (U32)wTimeOutSec *1000)
471     #else
472     if(wTimes>0x80000)
473     #endif
474     {
475       #if 0
476       printf("\nQH1:\n");
477 	  Dump_Data(0xf800,0x30);
478 	  printf("\nQH2:\n");
479 	  Dump_Data(0xf840,0x30);
480 	  printf("\nQH3:\n");
481 	  Dump_Data(0xf880,0x30);
482 	  printf("\nQH4:\n");
483 	  Dump_Data(0xf8c0,0x30);
484 	  printf("\n");
485 	  Dump_Data(0xfa80,0x20);
486 	  printf("\n");
487 	  Dump_Data(0xfb00,0x20);
488 	  printf("\n");
489 	  Dump_Data(0xfae0,0x20);
490 	  printf("\n");
491 	  Dump_Data(0xfaa0,0x20);
492 	  printf("\n");
493 	  Dump_Data(0xfac0,0x20);
494 
495       printf("\nQH->%x\n",(U16)spTempqHD);
496       //Dump_Data((U16)spTempqHD,0x30);
497 
498       printf("\nqtd->\n");
499       Dump_Data((U16)spOldDumyqTD,0x20);
500 	  printf("\nEHCI REG:\n");
501       Dump_Data(0x2400,0x50);
502       #endif
503       bExitLoop=2;
504       bReturnValue=HOST20_FATAL;
505       gUsbStatus_Port3=USB_TIMEOUT;
506       USB_HID_INT_MSG(printf("USB_TIMEOUT\n"));
507       //gDeviceFatalError=TRUE;
508 
509       //MINI_DEBUG2(printf("Time Out:%02bx\n",XBYTE[gUHC_BASE+30]));
510       break;
511     }
512 
513     #endif
514     //}
515   }
516   #ifndef ATV_SERISE_USE
517   msAPI_Timer_ResetWDT();       //in case spend too much time at polling
518   #endif
519   while (mbHost20_USBCMD_PeriodicEnable_Rd())
520   {
521     mbHost20_USBCMD_PeriodicEnable_Clr();
522   }
523 
524   //<6>.Checking the Result
525   if (bReturnValue!=HOST20_FATAL)
526     bReturnValue=flib_Host20_CheckingForResult_QHD_Port3(spTempqHD);
527   if (bReturnValue==HOST20_TRANSACTION_ERROR)
528   {
529     //printf("Transaction Error\n");
530 
531     spTempqHD->bOverlay_Status=0;      //clear halt status
532     spTempqHD->bOverlay_CurrentqTD=VirtoPhyAddr(( U32)spNewDumyqTD)>>5;
533   }
534 
535   //<5>.Release the all the qTD (Not include spNewDumyqTD)
536   #if 1
537   spReleaseqTD=spOldDumyqTD;
538   do {
539     //spReleaseqTDNext=((UINT32)(spReleaseqTD->bNextQTDPointerL))<<5 + ((UINT32)(spReleaseqTD->bNextQTDPointerH))<<16  ;
540      spReleaseqTDNext=(qTD_Structure*)PhytoVirAddr(((U32)(spReleaseqTD->bNextQTDPointer))<<5);
541 
542         flib_Host20_ReleaseStructure_Port3(Host20_MEM_TYPE_qTD,(U32)spReleaseqTD);
543 
544     spReleaseqTD=spReleaseqTDNext;
545   } while(((UINT32)spReleaseqTD)!=((UINT32)spNewDumyqTD));
546   #endif
547 
548  return (bReturnValue);
549 }
550 #if 1
551 //====================================================================
552 // * Function Name: flib_Host20_Issue_Interrupt
553 // * Description:
554 // * Input:
555 // * OutPut:
556 //====================================================================
flib_Host20_Issue_Interrupt_Port3(U32 buf,U32 hwSize)557 U8  flib_Host20_Issue_Interrupt_Port3(U32 buf,U32 hwSize)
558 {
559     qTD_Structure *spTempqTD;
560     U32      mybuf =0, workbuf;
561     U8      bResult;
562 
563     if ( buf !=(U32) KSEG02KSEG1(buf) )
564     {
565         if (buf & 0x7)			//flush should be 8 bytes aligned
566         {
567             //	printf(" buf ");
568             #if 0
569             mybuf=(U32)msAPI_Memory_Allocate((hwSize+0xf)&~0xf, BUF_ID_USB_HOST );
570             {
571                     printf("Memory allocate failed\n");
572                     return HOST20_FATAL;
573             }
574             MY_HAL_DCACHE_FLUSH((U32)mybuf,(U32)((hwSize+0xf)&~0xf));
575             mybuf = (U32)KSEG02KSEG1(mybuf);
576             #else
577             mybuf = (U32)KSEG02KSEG1(usb_temp_buf_Port3);
578             #endif
579         }
580         else
581         {
582                 //printf(" fuh ");
583             MY_HAL_DCACHE_FLUSH((U32)buf,(U32)hwSize);		//flush buffer to uncached buffer
584             buf=(U32)KSEG02KSEG1(buf);
585         }
586     }
587     else
588     {
589         if (buf & 0xf)
590         {
591                 //   printf(" buf ");
592                 #if 0
593                 mybuf=(U32)msAPI_Memory_Allocate((hwSize+0xf)&~0xf, BUF_ID_USB_HOST );
594                 if ( mybuf == 0 )
595                 {
596                     printf("Memory allocate failed\n");
597                     return HOST20_FATAL;
598                 }
599                 MY_HAL_DCACHE_FLUSH((U32)mybuf,(U32)((hwSize+0xf)&~0xf));
600                 mybuf = (U32)KSEG02KSEG1(mybuf);
601                 #else
602                 mybuf = (U32)KSEG02KSEG1(usb_temp_buf_Port3);
603                 #endif
604         }
605     }
606 
607     if (mybuf==0)
608         workbuf=buf;        //use original buf
609     else
610         workbuf=mybuf;
611 
612     //<1>.Fill TD
613     spTempqTD =flib_Host20_GetStructure_Port3(Host20_MEM_TYPE_qTD); //The qTD will be release in the function "Send"
614     spTempqTD->bTotalBytes=hwSize;
615     spTempqTD->ArrayBufferPointer_Word[0] = VirtoPhyAddr(workbuf);
616 
617     //<2>.Analysis the Direction
618     spTempqTD->bPID=HOST20_qTD_PID_IN;
619 
620     //<3>.Send TD
621     bResult = flib_Host20_Send_qTD2_Port3(spTempqTD ,pHost20_qHD_List_Intr_Port3,3);
622 
623     if (mybuf)
624     {
625         memcpy((void*)buf,(void*)mybuf,hwSize);	//copy buffer
626         #if 0
627         mybuf = (U32)KSEG12KSEG0(mybuf);
628         msAPI_Memory_Free((void*)mybuf,BUF_ID_USB_HOST);
629         #endif
630     }
631 
632     return bResult;
633 }
634 #endif
635 #endif //#if defined(MSOS_TYPE_NOS)
636 
637