📄 otgcontroller.c
字号:
}
}
else {//For Type-B Interrupt
if (wINTStatus&OTGC_INT_BSRPDN) {//B-Type => SRP done interrupt => then set global variable
OTG.B_bBSRPDN=1;
}
}
} //end of " if (wINTStatus&OTGC_INT_IDCHG) "
}
//*****************************************************************************
//*****************************************************************************
//*********************** Group-3:Device-A **********************************
//*****************************************************************************
//*****************************************************************************
//============================================================================= ok
// OTGC_A_PHY_Reset()
// Description:
// input: none
// output: none
//=============================================================================
void OTGC_A_PHY_Reset(void)
{
//Reset Phy
//waiting for mdwOTGC_Control_B_SESS_END_Rd
printf(">>> Waiting for B_SESS_END & Phy Reset...(under 5sec)\n");
do{
flib_Host20_TimerEnable(10);
}while(mdwOTGC_Control_B_SESS_END_Rd()==0);
mwOTG20_Control_Phy_Reset_Set();
flib_Host20_TimerEnable(1);
mwOTG20_Control_Phy_Reset_Clr();
}
//============================================================================= ok
// OTGC_A_Bus_Drop()
// Description:It will Drop the VBUS
// <1>.Step1:Close the OTG-Host
// <2>.Step2:Set Host function State to 'Reset Mode'
// <3>.Step3:Set register 'A_BUS_DROP'
// input: none
// output: none
//=============================================================================
void OTGC_A_Bus_Drop(void)
{
flib_Host20_Close(0);
mdwOTGC_Control_A_BUS_REQ_Clr();
mdwOTGC_Control_A_BUS_DROP_Set(); //Exit when Current Role = Host
//Reset Phy
//OTGC_A_PHY_Reset(); //YPING mark
}
//============================================================================= ok
// OTGC_A_Bus_Drive()
// Description:
// input: none
// output: none
//=============================================================================
void OTGC_A_Bus_Drive(void)
{
//OTGC_A_PHY_Reset();
mdwOTGC_Control_A_BUS_DROP_Clr(); //Exit when Current Role = Host
mdwOTGC_Control_A_BUS_REQ_Set();
printf("@@@ Drive VBUS ok...\n");
}
//============================================================================= ok
// OTGC_A_SRP_Init()
// Description:Device A generate the SRP procedure
// <1>.Waiting for the A-SRP-Done Interrupt
// <2>.Turn on the V Bus
// <3>.Issue Bus reset
// input: none
// output: UINT8 0:Fail 1:OK
//=============================================================================
UINT8 OTGC_A_SRP_Init(void)
{
UINT8 bResult=0;
printf("@@@ Device-A Waiting for the SRP...Count=%d\n",gWaitingSRPCounter);
gWaitingSRPCounter++;
//<1>.Waiting for the A-SRP-Done Interrupt
while(OTG.A_bASRPDET==0);
OTG.A_bASRPDET=0;
//<2>.Turn on the V Bus
mdwOTGC_Control_A_BUS_DROP_Clr();
mdwOTGC_Control_A_BUS_REQ_Set();
//<3>.Issue Bus reset
bResult=flib_OTGH_Init(10000,1,0); //john 0,0);
if (bResult==1)
return (1);
else
return (0);
}
//============================================================================= ok
// OTGC_A_HNP_Init()
// Description:Device A generate the HNP procedure
// <1>.Get OTG Descriptor
// <2>.Set register "A_SET_B_HNP_EN"
// <3>.Set Feature to peripheral
// <4>.Go to suspend
// <5>.Waiting for Role Change...
// input: none
// output: INT8U 0:Fail / 1:OK
//=============================================================================
INT8U OTGC_A_HNP_Init(void)
{
UINT8 bCMD[8];
UINT8 bOTGData[3] ;
UINT8 bResult;
UINT8 bExitFlag;
UINT32 wTimer_ms;
//<1>.Enumurate the Device ...
if (flib_Host20_Enumerate(0,3)==0) { //Set configuration to 0 & Set Address to 1
printf("??? Enumerate Fail...\n");
flib_Host20_Suspend();
return (0);
}
//<2>.Set register "A_SET_B_HNP_EN"
if (((UINT8)(sAttachDevice.sOTG.bED_OTG_bAttributes))!=OTGH_SRP_HNP_Enable) {
printf("??? Device-B do not support SRP/HNP (%d)\n",(UINT8)(sAttachDevice.sOTG.bED_OTG_bAttributes));
flib_Host20_Suspend();
return (0);
}
//Turn on D+
mUsbUnPLGClr();//Bruce;;12162004;;unplug issue;;
mdwOTGC_Control_A_SET_B_HNP_EN_Set();
//<3>.Set Feature to peripheral
memcpy(bCMD,OTGH_SET_FEATURE_OTG,8);
//bResult=flib_OTGH_Issue_Control(1,bCMD,0x00,bOTGData);
bResult=flib_Host20_Issue_Control (1,bCMD,0x00,bOTGData);
if (bResult!=0) {//<3.1>.SetFeature Fail
printf("??? SetFeature Fail, Device-B Do not Support HNP...(%d)\n",bResult);
//<3.2>.Recover to original situation
mdwOTGC_Control_A_SET_B_HNP_EN_Clr();
//<3.3>.Delay 1 ms
flib_Host20_TimerEnable(1);
//<3.4>.Suspend the system
flib_Host20_Suspend();
//<3.5>.Return 0
return (0);
}
printf(">>> Device-A suspend & exit host Mode\n");
//<4>.Go to suspend
flib_Host20_Suspend();
//<5>.Pre-Init peripheral
OTGP_init(0);//Do not init AP
//<6>.Waiting for Role Change... / or For resume signal
wTimer_ms=0;
bExitFlag=0;
do{
//Checking for Resume from Peripheral
// if (flib_OTGH_Checking_RemoteWakeUp()==1) //0=>Do not Print data / 0=> Normal Enumerate
// {
// flib_Host20_TimerEnable(1);
// flib_Host20_Suspend();
// return(0);
// }
//Checking the VBUS
if (mdwOTGC_Control_A_VBUS_VLD_Rd()==0)
if (OTGC_VBS_Valid()==0)
return (0);
if (OTG.CurrentRole==1)
return(1);
//Checking for Role Change
} while(bExitFlag==0);
return(1);
}
//============================================================================= ok
// OTGC_A_WaitingRoleChange()
// Description:<1>.Call function 'SRP'
// <2>.Call function 'HNP'
// input: none
// output: none
//=============================================================================
void OTGC_A_WaitingRoleChange(void)
{
if (OTGC_A_SRP_Init()>0) {
//<1>.A Init HNP
if (OTGC_A_HNP_Init()==0)
printf("??? Device-B Request Role Change Fail(HNP Fail)...\n");
}
else
printf("??? Device-B Request Role Change Fail(SRP Fail)...(Device Not Support...)\n");
}
//============================================================================= ok
// OTGC_A_Menu()
// Description:This menu is for the Device-A
// <1>.Device-A/Host
// <2>.Device-A/Peripheral
// input: none
// output: none
//=============================================================================
void OTGC_A_Menu(void)
{
char Item;
UINT8 bTemp;
OTG.A_bASRPDET=0;
if (OTG.CurrentRole==0) {//<1>.For Host
printf("****************** Device-A:Host Mode ***************************\n");
printf(" -- Normal--\n");
printf(" 1.Host Mode (OTG Path Test)\n");
printf(" 3.Reflash\n");
//john : remove force speed
//printf(" 4.Force Host to Full-Low/High Speed\n");
printf(" -- SRP/HNP --\n");
printf(" 5.Waiting for Role Change(SRP+HNP)(VBUS) \n");
printf(" 6.Waiting for Role Change(SRP+HNP)(VBUS)Auto-Test x times \n");
printf(" 7.Waiting for Role Change(SRP+HNP)(Data Line) \n");
printf(" 8.Disable the SRP Detect\n");
printf(" 9.Drive VBUS\n");
printf(" 10.Drop the VBUS\n");
printf(" 11.Reset Host Controller\n");
printf(" 12.OPT-Device-A Test-Auto\n");
printf(" 13.Dump Memory\n");
//john : remove force speed
//printf(" 14.711MA Full Speed issue temp solution Enable/Disable\n");
printf(" 15.FPGA Half Speed (HCLK < 30 ==> Enable)((HCLK >= 30 ==> Disable)\n");
printf(" -- Status \n");
printf(" **VBUS:0x%x **SRP_DET:0x%x ** SRP_DET_TYPE:0x%x \n",(UINT32)(mdwOTGC_Control_A_VBUS_VLD_Rd()),(UINT32)(mdwOTGC_Control_A_SRP_DET_EN_Rd()),(UINT32)(mdwOTGC_Control_A_SRP_RESP_TYPE_Rd()));
printf(" **Host-Connect:0x%x ** ID/Role:0x%x \n",(UINT32)(mwHost20_PORTSC_Rd()),(UINT32)(mdwOTGC_Control_Rd()));
printf("******************************************************************\n");
OTG.A_APLGRMV=0;
OTG.A_BPLGRMV=0;
OTG.IDCHG=0;
if (wRoleChangeAutoTestCounter>=wRoleChangeAutoTestCounter_Input) {
bRoleChangeAutoTestEnable=0;
wRoleChangeAutoTestCounter=0;
}
if (bRoleChangeAutoTestEnable>0)
Item=5;
else {
if (bOPT_Device_A_Auto==1)
Item=5;
else {
printf(">>> (Device-A / Host Mode) Input Command : ");
scanf("%d",&Item);
printf("\n");
}
}
switch(Item) {
case 1 :
//<1>.Turn On VBUS
OTG.bVBUSAlwaysOn=1;
//if (mdwOTGC_Control_A_VBUS_VLD_Rd()==0)
// {
mdwOTGC_Control_A_BUS_DROP_Clr(); //Exit when Current Role = Host
mdwOTGC_Control_A_BUS_REQ_Set();
printf("@@@ Drive VBUS ok...\n");
// }
//<2>.Waiting for Connect
printf("@@@ Enter DRD Host Mode...\n");
printf("@@@ Waiting for Device Connect...\n");
while(mwHost20_PORTSC_ConnectStatus_Rd()==0);
if (flib_OTGH_Init(10000,0,0)==1) {
flib_Host20_Enumerate(1,3);
OTGH_AP_Main();
OTGC_A_Bus_Drop();
printf("@@@ Drop VBUS ok...\n");
OTG.bVBUSAlwaysOn=0;
}
break;
case 3:
printf("@@@ Reflash the status...\n");
if (OTG.A_APLGRMV>0)
printf(" @@@ Cable-Mini-A remove...\n");
if (OTG.A_BPLGRMV>0)
printf(" @@@ Cable-Mini-B remove...\n");
if (OTG.IDCHG>0)
printf(" @@@ ID Change ...\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(500);
}
//<1>.Checking VBUS
if (mdwOTGC_Control_A_VBUS_VLD_Rd()>0) {
OTGC_A_Bus_Drop();
printf("@@@ Drop VBUS ok...\n");
}
//<2>.Checking SRP detect Bit
mdwOTGC_Control_A_SRP_RESP_TYPE_Clr();
mdwOTGC_Control_A_SRP_DET_EN_Set();
printf("@@@ Enable the SRP-VBUS Detect ok...\n");
//<3>.
printf("@@@ <1>.Waiting for SRP to enter the Periphral mode (VBUS 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 7:
//<1>.Checking VBUS
if (mdwOTGC_Control_A_VBUS_VLD_Rd()>0) {
OTGC_A_Bus_Drop();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -