⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lib_host20.c

📁 GM8120 linux driver.
💻 C
📖 第 1 页 / 共 5 页
字号:
         spTempqTD->bStatus_Active=0;         spTempqTD2->bStatus_Active=1;                //<D>.Send 2 qTD         bReturnValue=flib_Host20_Send_qTD(spTempqTD ,psHost20_qHD_List_Control[bEdNum],5);         if (bReturnValue>0)            return (bReturnValue);         break;      //<4.3>.Case-3:'Setup/Out/In'      case 3:		// set descriptor         //<A>.Out Packet         spTempqTD2->bPID=HOST20_qTD_PID_OUT;                   //Bit8~9            spTempqTD2->bTotalBytes=wDataSize;           //Bit16~30            spTempqTD2->bDataToggle=1;            //Bit31          spTempqTD2->ArrayBufferPointer_Word[0]=(*pwPageAddress)+wCurrentOffset;          spTempqTD2->ArrayBufferPointer_Word[1]=*(pwPageAddress+1);            spTempqTD2->ArrayBufferPointer_Word[2]=*(pwPageAddress+2);            spTempqTD2->ArrayBufferPointer_Word[3]=*(pwPageAddress+3);            spTempqTD2->ArrayBufferPointer_Word[4]=*(pwPageAddress+4);                        		 //<B>.In packet         spTempqTD3->bPID=HOST20_qTD_PID_IN;                   //Bit8~9            spTempqTD3->bTotalBytes=0;           //Bit16~30            spTempqTD3->bDataToggle=1;            //Bit31          spTempqTD3->ArrayBufferPointer_Word[0]=bpDataPage3;          //<C>.Link Pointer         spTempqTD->bNextQTDPointer=(((UINT32)spTempqTD2)>>5);         spTempqTD->bAlternateQTDPointer=(((UINT32)spTempqTD2)>>5);                      spTempqTD2->bNextQTDPointer=(((UINT32)spTempqTD3)>>5);         spTempqTD2->bAlternateQTDPointer=(((UINT32)spTempqTD3)>>5);                      spTempqTD->bTerminate=0;         spTempqTD->bAlternateTerminate=0;                      spTempqTD2->bTerminate=0;         spTempqTD2->bAlternateTerminate=0;                       spTempqTD->bStatus_Active=0;         spTempqTD2->bStatus_Active=1;         spTempqTD3->bStatus_Active=1;                //<D>.Send 3 qTD         bReturnValue=flib_Host20_Send_qTD(spTempqTD ,psHost20_qHD_List_Control[bEdNum],5);         if (bReturnValue>0)            return (bReturnValue);         break;      default:	     break;   }   return (0);}//====================================================================// * Function Name: flib_Host20_Issue_Bulk                          // * Description: Input data must be 4K-Alignment //               <1>.MaxSize=20 K//               <2>.Support Only 1-TD// * Input: // * OutPut: //====================================================================UINT8  flib_Host20_Issue_Bulk (UINT8 bArrayListNum,UINT16 hwSize,UINT32 *pwBufferArray,UINT32 wOffset,UINT8 bDirection){   qTD_Structure *spTempqTD;   //<1>.Fill TD   spTempqTD =flib_Host20_GetStructure(Host20_MEM_TYPE_qTD); //The qTD will be release in the function "Send"   spTempqTD->bTotalBytes=hwSize;              spTempqTD->ArrayBufferPointer_Word[0]=(UINT32)((*pwBufferArray++)+wOffset);    spTempqTD->ArrayBufferPointer_Word[1]=(UINT32)*pwBufferArray++;    spTempqTD->ArrayBufferPointer_Word[2]=(UINT32)*pwBufferArray++;    spTempqTD->ArrayBufferPointer_Word[3]=(UINT32)*pwBufferArray++;    spTempqTD->ArrayBufferPointer_Word[4]=(UINT32)*pwBufferArray++;    //<2>.Analysis the Direction    if (bDirection)                spTempqTD->bPID=HOST20_qTD_PID_IN;                else      spTempqTD->bPID=HOST20_qTD_PID_OUT;              //<3>.Send TD   return (flib_Host20_Send_qTD(spTempqTD ,psHost20_qHD_List_Bulk[bArrayListNum],1000));}//====================================================================// * Function Name: flib_Host20_ISO_Init                          // * Description: //   <1>.Init FrameList//   <2>.Enable Periotic schedule//// * Input: // * OutPut: //====================================================================void  flib_Host20_ISO_Init (void){ UINT32 i;  // <1>.Init FrameList for (i=0;i<1024;i++)           {      if (sAttachDevice.bDeviceOnHub==0)          psHost20_FramList->sCell[i].bType=HOST20_HD_Type_iTD;           else          psHost20_FramList->sCell[i].bType=HOST20_HD_Type_siTD;                                 psHost20_FramList->sCell[i].bLinkPointer=0;      psHost20_FramList->sCell[i].bTerminal=1;                       } //<2>.Set Periodic Base Address		   mwHost20_PeriodicBaseAddr_Set(Host20_STRUCTURE_Preiodic_Frame_List_BASE_ADDRESS);	 //<2>.Enable the periodic        flib_Host20_Periodic_Setting(HOST20_Enable);}//====================================================================// * Function Name: flib_Host20_Issue_ISO                          // * Description: //   1.Mult=1 => MaxPacketSize = 256,512,1024//     Mult=2 => MaxPacketSize = 128//     Mult=3 => MaxPacketSize = 64//   2.Suppose 1024 iTD //// * Input: //     UINT8 bAddress//     UINT8 bEndPt//     UINT32 wMaxPacketSize//     UINT32 wSize//     UINT32 *pwBufferArray//     UINT32 wOffset//     UINT8 bDirection)//// * OutPut: //====================================================================UINT32 wRandomFrameStart=200;//393;UINT32 wISOOTGIn_Counter=0;void flib_Host20_Issue_ISO(UINT8 bCheckResult,UINT32 wEndPt,UINT32 wMaxPacketSize,UINT32 wSize                            ,UINT32 *pwBufferArray,UINT32 wOffset,UINT8 bDirection,UINT8 bMult){  UINT32 wRemainSize,wCurrentOffset,wCurrentBufferNum,wCurrentLength,wiTDNum,wFrameNumber,i,wOriginalFrameNumber,wDummyTemp;  UINT8  bCurrentTransactionNum,bCurrentPageNum,bTransactionNumMax,bExitFlag;  iTD_Structure  *spTempiTD;  UINT32 *pwLastTransaction;  UINT32 wCurrentBufferNum1,wCurrentBufferNum3,j,wCurrentBufferNum2,wCurrentBufferNum4;  UINT32 *pwData;                //<2>.Allocate the iTD for the Data Buffer        wRemainSize=wSize;        wCurrentBufferNum=0;        wiTDNum=0;        wCurrentOffset=wOffset;        while(wRemainSize)        {         //<2.1>.Allocate iTD         psDevice_AP->wISOiTDAddress[wiTDNum]=flib_Host20_GetStructure(Host20_MEM_TYPE_iTD);         spTempiTD=psDevice_AP->wISOiTDAddress[wiTDNum];         spTempiTD->ArrayBufferPointer_Word[0].bMultiFunction|=(wEndPt<<8);         spTempiTD->ArrayBufferPointer_Word[0].bMultiFunction|=psDevice_AP->bAdd;         spTempiTD->ArrayBufferPointer_Word[1].bMultiFunction=(bDirection<<11);         spTempiTD->ArrayBufferPointer_Word[1].bMultiFunction|=wMaxPacketSize;         spTempiTD->ArrayBufferPointer_Word[2].bMultiFunction=bMult;                  bCurrentTransactionNum=0;         bCurrentPageNum=0;         spTempiTD->ArrayBufferPointer_Word[bCurrentPageNum].bBufferPointer                      =((UINT32)*(pwBufferArray+wCurrentBufferNum)>>12);            if (psDevice_AP->bSpeed==0)            bTransactionNumMax=1;//For Full Speed         else         	bTransactionNumMax=8;//For High Speed                  //<2.2>.Fill iTD         while ((wRemainSize)&&(bCurrentTransactionNum<bTransactionNumMax))             {             //Fill iTD             if (wRemainSize<(wMaxPacketSize*bMult))                 {printf(">>> Length must be the X*wMaxPacketSize*bMult\n");               	   while(1);             	  }             else                   wCurrentLength=wMaxPacketSize*bMult;                                                 spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bLength=wCurrentLength;             spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bStatus=HOST20_iTD_Status_Active;	             spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bInterruptOnComplete=0;	             spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bPageSelect=bCurrentPageNum;	             spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bOffset=wCurrentOffset;                                            //Maintain the wRemainSize/bCurrentPageNum/wCurrentOffset/wCurrentBufferNum                        wRemainSize=wRemainSize-wCurrentLength;               wCurrentOffset=wCurrentOffset+wCurrentLength;               if (wCurrentOffset>=4096)                   {                   bCurrentPageNum++;	                   wCurrentBufferNum++;                   spTempiTD->ArrayBufferPointer_Word[bCurrentPageNum].bBufferPointer                            =((UINT32)*(pwBufferArray+wCurrentBufferNum)>>12);                                         wCurrentOffset=wCurrentOffset-4096;	                   }               //Set the finish Complete-Interrupt              if (wRemainSize==0)                 {spTempiTD->ArrayStatus_Word[bCurrentTransactionNum].bInterruptOnComplete=1;	                  pwLastTransaction=&(spTempiTD->ArrayStatus_Word[bCurrentTransactionNum]);                 }                            bCurrentTransactionNum++;                               }//while ((wRemainSize)&&(bCurrentTransactionNum<8))                              //<2.3>.Maintain Variable       wiTDNum++;       if (wiTDNum>512)           {printf(">>> Waring...iTD Number >512... \n"); 	            while(1);           }        } //while(wRemainSize)   //<3>.Hang the qTD to the FrameList                     //<3.1>.Read the Current Frame List//Critical Time Period Start ---------------------------------------------------              psDevice_AP->bSendStatusError=0;#if 0 //Waiting for FrameList=0~10;           wCurrentBufferNum1=(mwHost20_FrameIndex_Rd()>>3)&0x000003FF;  //wCurrentBufferNum1       if ((wCurrentBufferNum1>10)&(wCurrentBufferNum1<1020))          {gwFrameList0Interrupt=0;           mwHost20_USBSTS_FrameRollover_Set();           mwHost20_USBINTR_FrameRollover_Set();            do{               }while(gwFrameList0Interrupt==0);           mwHost20_USBINTR_FrameRollover_Clr();           }       wCurrentBufferNum1=mwHost20_FrameIndex14Bit_Rd()>>3;           //wCurrentBufferNum1              wOriginalFrameNumber=wRandomFrameStart++;                      if (wRandomFrameStart>500)             wRandomFrameStart=200;             #else  //Waiting for FrameList=0~10;            wCurrentBufferNum1=mwHost20_FrameIndex14Bit_Rd()>>3;         wOriginalFrameNumber=(mwHost20_FrameIndex_Rd()>>3);                  wOriginalFrameNumber=wOriginalFrameNumber+20;//300         #endif  //Waiting for FrameList=0~10;           	    pwData=(UINT32*)0x90100080;	    *pwData=0X200;                           //<3.2>.Hang the qTD to the Current Frame + 100 ms      //   wInterruptMask=mwOTG20_Interrupt_Mask_Rd();      //   mwOTG20_Interrupt_Mask_Set(0);         wCurrentBufferNum2=mwHost20_FrameIndex14Bit_Rd()>>3;           //wCurrentBufferNum2                      wFrameNumber=wOriginalFrameNumber;         for (i=0;i<wiTDNum;i++)                   {              if (wFrameNumber>1023)                  wFrameNumber=wFrameNumber-1024;                           psHost20_FramList->sCell[wFrameNumber].bLinkPointer=(UINT32)(psDevice_AP->wISOiTDAddress[i])>>5;              psHost20_FramList->sCell[wFrameNumber].bTerminal=0;                           wFrameNumber++;             }                     //<4>.Waiting for the Complete the processing iTDs         gwLastiTDSendOK=0;         psDevice_AP->bISOTransferEnable=1;        wISOOTGIn_Counter++;       //wCurrentBufferNum2=mwHost20_FrameIndex14Bit_Rd()>>3;    //   if (wISOOTGIn_Counter==2)    //       mwHost20_CurrentAsynchronousAddr_Set(0xFFFFFFFF);                          wCurrentBufferNum3=(mwHost20_FrameIndex14Bit_Rd())>>3; //wCurrentBufferNum3                                  //  mwOTG20_Interrupt_Mask_Set(wInterruptMask);        bExitFlag=0;             do            {             wDummyTemp++;             if (wDummyTemp>1000)          	            	{            	wDummyTemp=0;	            	if (gwLastiTDSendOK==1)            	    bExitFlag=1;	            	}             	            }       while(bExitFlag==0);       //  while(((*pwLastTransaction)&0x80000000)>0);         psDevice_AP->bISOTransferEnable=0;                  if (psDevice_AP->bSendStatusError==1)            {            psDevice_AP->bSendStatusError=0;	            printf("???USB Error... Halt the system...\n ");	            while(1);            }//Critical Time Period End ---------------------------------------------------                wCurrentBufferNum4=(mwHost20_FrameIndex14Bit_Rd())>>3; //wCurrentBufferNum4                       //<5>.Checking for the complete        if (bCheckResult)           {            for (i=0;i<wiTDNum;i++)                      {                 spTempiTD=psDevice_AP->wISOiTDAddress[i];                 for (j=0;j<bTransactionNumMax;j++)                     {if (spTempiTD->ArrayStatus_Word[j].bLength>0)                        {                        printf("??? Error Transaction Length > 0 (iTD Address=0x%x / Length=%d)... \n",(UINT32)(spTempiTD),(UINT32)(spTempiTD->ArrayStatus_Word[j].bLength));                                    while(1);	                        }                     }                   }           }   //<5>.Retire the iTD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -