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

📄 otgcontroller.c

📁 FIC8120方案的 StartCell_Driver
💻 C
📖 第 1 页 / 共 3 页
字号:
               printf("@@@ Drop VBUS ok...\n");                   
            }
       		        
       		//<2>.Checking SRP detect Bit
            mdwOTGC_Control_A_SRP_RESP_TYPE_Set(A_SRP_RESP_TYPE_DATA_LINE); 
            mdwOTGC_Control_A_SRP_DET_EN_Set();
            printf("@@@ Enable the A_SRP_DET(Data Line Plusing) ok...\n");                        

            //<3>.
            printf("@@@ <1>.Waiting for SRP to enter the Periphral mode(Data Line Pulsing...)\n");      
            printf("@@@ <2>.Init HNP \n");      
            printf("@@@ <3>.Waiting for Role Change to enter periphral mode \n");                          
                        
            //<1>.A Init SRP  
            // flib_OTGH_RemoteWakeEnable();
            OTGC_A_WaitingRoleChange();        
       		break;     
         case 8:             
            mdwOTGC_Control_A_SRP_DET_EN_Clr();
            printf("@@@ Disable the SRP Detect ok...\n");                    
       	    break;               			
         case 9 :            
            mdwOTGC_Control_A_BUS_DROP_Clr(); //Exit when Current Role = Host
            mdwOTGC_Control_A_BUS_REQ_Set();
            printf("@@@ Drive VBUS ok...\n");
       	    break;  
         case 10:             
            OTGC_A_Bus_Drop();
            printf("@@@ Drop VBUS ok...\n");
       	    break;             					
         case 11:  
            mbHost20_USBCMD_HCReset_Set();
            while(mbHost20_USBCMD_HCReset_Rd()>0);
            printf(">>> Host Controller Reset OK...\n");
       	    break;  
         case 12:  
            bOPT_Device_A_Auto=1;
       	    break;    
         case 13:  
            OTGH_Error_Handle();
       	    break;       
         //john : remove force speed
         //case 14:             
         //        printf("********************************\n");                     
         //        printf("<0>.Disable \n");                        
         //        printf("<1>.Enable\n");
         //        printf(">>> Input:");  
         //        scanf("%d",&bTemp);         
         //        bForceSpeed=bTemp;
         //        if (bTemp==0)
         //           mdwOTGC_Control_711MA_Phy_Issue_Clr();
         //        else
         //           mdwOTGC_Control_711MA_Phy_Issue_Set();       
       	 //break;      

         case 15:             
            printf("********* FPGA Half Speed ***************\n");                     
            printf("<0>.Disable(AHB Clk >= 30) \n");                        
            printf("<1>.Enable (AHB Clk < 30) \n");
            printf(">>> Input:");  
            scanf("%d",&bTemp);         
            if (bTemp==0)
               mwPeri20_Control_HALFSPEEDEnable_Clr();
            else
               mwPeri20_Control_HALFSPEEDEnable_Set();           
       	    break;  	          
         }//switch(Item)        
     }
     else {
        //<2>.For Peripheral        
        OTGP_main(0,0,0); //Exit 1.when Role Change 2.when polling VBUS_VLD=0  
 
        if (flib_OTGH_Init(300,1,1)==0) {    //john 0,1)==0) {
           OTGC_A_Bus_Drop();
           OTGC_A_WaitingRoleChange();
        }
        else {
		   printf("   @@@ Device-A exit the Peripheral mode...\n");  
           if (bRoleChangeAutoTestEnable>0)
              flib_Host20_Enumerate(1,3);
        }
    }
}

//*****************************************************************************
//*****************************************************************************
//***********************  Group-4:Device-B   *********************************
//*****************************************************************************
//*****************************************************************************


//============================================================================= ok
//		OTGC_B_SRP_Init()
//		Description:<1>.Generate SRP
//			        <2>.Waiting for the SRP Done Interrupt
//                  <3>.Waiting for the VBUS-Turn-on
//		input: none
//		output: 0:Fail
//              1:OK
//=============================================================================
UINT8 OTGC_B_SRP_Init(void)
{
   INT32U wTimer_ms;
   INT8U  bExitFlag;

   printf("OTGC_B_SRP_Init\n");

   //Checking for Line State
#if 0
   if (mwHost20_PORTSC_LineStatus_Rd()!=0)
   {
      printf("??? Fail => 711MA Phy spec: Line State!=0, can not issue SRP...\n");
      return(0) ;	
   }
#endif

   //<1>.Generate SRP
   OTG.B_bBSRPDN=0;
   //Bruce;;OPT;; mdwOTGC_Control_B_DSCHG_VBUS_Set();
   mUsbUnPLGClr();//Bruce;;12162004;;unplug issue;;
       
   mdwOTGC_Control_B_BUS_REQ_Set();

   //<2>.Waiting for the SRP Done Interrupt   
   while(OTG.B_bBSRPDN!=1); // <A>.The done interrupt
 
   //<3>.Waiting for the VBUS-Turn-on 
   bExitFlag=0;
   // wTemp=0;
   flib_Host20_TimerEnable(10);                   //1.Delay 10 ms
   wTimer_ms=0;
       
   // while(mdwOTGC_Control_B_SESS_VLD_Rd()==0); //==>For Peter  
   do{
      if (mdwOTGC_Control_A_VBUS_VLD_Rd()>0)   //2.Waiting for VBUS Valid  
         bExitFlag=1;
         
      flib_Host20_TimerEnable(1);//delay 1ms
      wTimer_ms++;
      if (wTimer_ms>100)   //04212004;;from 10000       // Case1:Waiting for 10 sec=10000  
      {                                         
         bExitFlag=2; 
      }         
   }while(bExitFlag==0);    
       
   if (bExitFlag==2)
   {//Type-A do not turn on the bus
      printf(">>> OTG-B:Device-A NotResponding(Waiting Drive VBUS Fail)...\n");	
      return(0) ;	
   }
   return (1);
}


//============================================================================= ok
//		OTGC_B_HNP_Init()
//		Description:Enter Peripheral mode to response the command from Host
//                  <1>.Get OTG Descriptor 
//			        <2>.SetFeature
//		input: none
//		output: 0:HNP Fail
//              1:HNP ok
//=============================================================================
UINT8 OTGC_B_HNP_Init(void)
{
   printf("OTGC_B_HNP_Init\n");
   //<1>.Response the GetDescriptor/SetFeature (Waitting for the HNP)
   //<2.1>.Host will Get Descriptor
   //<2.2>.Host will set feature   
   OTGP_main(1,1,0);

   //<2>.If Role Change Fail => Clear the HNP_Enable to avoid the HNP
   if (OTG.CurrentRole==1) //Current Role => Change to Peripheral
   {
      mdwOTGC_Control_B_HNP_EN_Clr();
      mdwOTGC_Control_B_BUS_REQ_Clr();

      printf("exit OTGC_B_HNP_Init\n");
      return(0); 
   }
   else {
      printf("exit OTGC_B_HNP_Init\n");
	  return(1); 
   }
}

//============================================================================
//		OTGC_B_Menu()
//		Description:For type B menu
//                  <1>.Device-B/Host
//			        <2>.Device-B/Peripheral
//		input: none
//		output: 
//              
//=============================================================================
void OTGC_B_Menu(void)
{
   char Item;
   UINT8 bTemp;
   UINT8 bNotSupport=0;	
	
   if (OTG.CurrentRole==0) {//<1>.For Host
      if (mdwOTGC_Control_A_VBUS_VLD_Rd()>0) {
         printf("@@@ Device-B enter the Host Mode...\n");
         //OTG.bHostISRType=1;
         if (flib_OTGH_Init(2000,2,0)==1) {   //john 10000,1,0)==1) {
            if (flib_Host20_Enumerate(1,3)==2) {
               printf("??? OTG-B:OTG-A Device not support...\n");
               bNotSupport=1;
            }
                 
            if (OTGC_Device_Not_Support_Then_Return==1) {
               if (bNotSupport==0)   
                  if (bRoleChangeAutoTestEnable==0)
                     OTGH_AP_Main();
            }
            else  
               OTGH_AP_Main();            
         }
            
         if (sAttachDevice.bSpeed==0)
            flib_Host20_Close(1);//For Full Speed
         else
         	flib_Host20_Close(0);//For High Speed

         //while(OTG.CurrentRole==0);
	     while(mdwOTGC_Control_CROLE_Rd()==0);
         OTG.CurrentRole=1;    
      }
      else 
         printf("!!! Please Drive the VBUS...");
   }
   else {//<2>.For Peripheral
      if (OTGC_VBS_Valid()>0) {
         OTGP_main(1,1,0);
      }
      else {
         printf("************************** Peripheral Mode ***********************\n");  
         printf(" -- Normal--\n"); 
         printf("   1.Peripheral Mode (Path Test)\n");
         printf("   2.Peripheral Mode (VBUS off=>Still in the peripheral mode )\n"); 
         printf("   3.Reflash\n"); 
		 //john : remove force speed
         //printf("   4.Force Host to Full-Low/High Speed\n");         
         printf("   5.Request 'Role Change'\n"); 
         printf("   6.Request 'Role Change' Auto-Test x times\n"); 
         printf("   7.Dump Memory\n"); 
		 //john
         //printf("   8.711MA Full Speed issue temp solution Enable/Disable\n"); 
         printf("   9.FPGA Half Speed (HCLK < 30 ==> Enable)((HCLK >= 30 ==> Disable)\n");
         printf("******************************************************************\n"); 
         
         if (wRoleChangeAutoTestCounter>=wRoleChangeAutoTestCounter_Input)
         {
	        bRoleChangeAutoTestEnable=0;
            wRoleChangeAutoTestCounter=0;
         }
         
         if (bRoleChangeAutoTestEnable>0)
            Item=5;
         else
         {  
            printf(">>> (Device-B / Peripheral Mode) Input Command : ");  
            scanf("%d",&Item); 
            printf("\n");        
         }
         
         switch(Item)               
         {                       
          		case 1 :            
                         printf("@@@ Device-B Enter Peripheral Mode...\n");
                         OTGP_main(1,1,0); //Exit 1.when Role Change 2.when polling VBUS_VLD=0 
                        
          			break;     		
          		                    
  
                                     
          		case 2:             
                          printf("@@@ Device-B Enter Peripheral Mode(For CV Test),Exit when 'RoleChange'...\n");
                          printf("@@@ CV Test will use GPIO to input the event'Remote Wake Up'(Active-Low), \n");
                          OTGP_main(1,1,1);
          			     
          			break;            
          


          		case 3:             
                         printf("@@@ Device-B Reflash...\n");
          			break;        

                //john : remove force speed
         	    //case 4:             
                //    printf("********************************\n");                     
                //    printf("<0>.Clear All .\n");                        
                //    printf("<1>.Force Full-Low Speed .\n");
                //    printf("<2>.Force High Speed .\n");      
                //    printf(">>> Input:");  
                //    scanf("%d",&bTemp);         
                //    bForceSpeed=bTemp;
                //    flib_Host20_ForceSpeed(bForceSpeed);
                //    
       			//break;                    			

                case 6: 
                   printf(">>> Auto Test times(x>0): ");  
                   scanf("%d",&wRoleChangeAutoTestCounter_Input);         
                   printf("\n");
                   bRoleChangeAutoTestEnable=1;
                   wRoleChangeAutoTestCounter=0;
                case 5:        
                   if (bRoleChangeAutoTestEnable>0) {
				      wRoleChangeAutoTestCounter++;
                      printf("=================>>>Role Change Auto Test Counter=%d \n",wRoleChangeAutoTestCounter);  
                      flib_Host20_TimerEnable(100); //johnreduce delay time 500
                   }
                         
                   printf("@@@ Device-B generate SRP/HNP...\n");
                         
                   if (OTGC_B_SRP_Init()==1) {
                      if (OTGC_B_HNP_Init()==0) //Exit when Current Role = Host     
                         printf("??? OTG-B HNP Fail(Device Not Responding)...\n");
                   }   
                   else 
					  printf("??? OTG-B SRP Fail...\n");                 
          		   break;         

          		case 7:             
                        OTGH_Error_Handle();
          			break;        

                //john : remove force speed
         	    //case 8:             
                //    printf("********************************\n");                     
                //    printf("<0>.Disable \n");                        
                //    printf("<1>.Enable\n");
                //    printf(">>> Input:");  
                //    scanf("%d",&bTemp);         
                //    bForceSpeed=bTemp;
                //    if (bTemp==0)
                //       mdwOTGC_Control_711MA_Phy_Issue_Clr();
                //    else
                //       mdwOTGC_Control_711MA_Phy_Issue_Set();
                //    
       		    // break;      

         	case 9:             
                    printf("********* FPGA Half Speed ***************\n");                     
                    printf("<0>.Disable(AHB Clk >= 30) \n");                        
                    printf("<1>.Enable (AHB Clk < 30) \n");
                    printf(">>> Input:");  
                    scanf("%d",&bTemp);         
                    if (bTemp==0)
                       mwPeri20_Control_HALFSPEEDEnable_Clr();
                    else
                       mwPeri20_Control_HALFSPEEDEnable_Set();
                    
       			break;                    			
            }//switch(Item)
         }//if (mdwOTGC_Control_A_VBUS_VLD_Rd()>0)
    } 
}


⌨️ 快捷键说明

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