📄 lib_host20.c
字号:
//====================================================================
// * Function Name: flib_Host20_Periodic_Setting
// * Description:
// * Input:
// * OutPut:
//====================================================================
void flib_Host20_Periodic_Setting(UINT8 bOption)
{
if (bOption==HOST20_Enable) {
//<1>.If Already enable => return
if (mwHost20_USBSTS_PeriodicStatus_Rd()>0)
return ;
//<2>.Disable Periodic
mbHost20_USBCMD_PeriodicEnable_Set();
//<3>.Polling Status
while(mwHost20_USBSTS_PeriodicStatus_Rd()==0);
}
else if (bOption==HOST20_Disable) {
//<1>.If Already Disable => return
if (mwHost20_USBSTS_PeriodicStatus_Rd()==0)
return ;
//<2>.Enable Periodic
mbHost20_USBCMD_PeriodicEnable_Clr();
//<3>.Polling Status
while(mwHost20_USBSTS_PeriodicStatus_Rd()>0);
}
else {
printf("??? Input Error 'flib_Host20_Periodic_Setting'...");
while(1);
}
}
//====================================================================
// * Function Name: flib_Host20_PortBusReset
// * Description:
// <1>.Waiting for HCHalted=0
// <2>.Write PortEnable=0(Reserved for Faraday-IP)
// <3>.Write PortReset=0
// <4>.Wait time
// <5>.Write PortReset=0
// <6>.Waiting for IRS->PortChangeDetect
// * Input:
// * OutPut:
//====================================================================
UINT8 flib_Host20_PortBusReset(void)
{
UINT8 bResetDuringRun,bExitLoop;
//UINT8 bDisableAsynchronous=0;
//john : remove force speed
//flib_Host20_ForceSpeed(bForceSpeed);
//<1>.Disable RunStop
bResetDuringRun=0;
// john, Don'T need to reset Host when port reset
//if (mbHost20_USBCMD_RunStop_Rd()>0) {
// flib_Host20_StopRun_Setting(HOST20_Disable);
// bDisableAsynchronous=1;
//}
//<2>.Write PortReset=0
mwHost20_PORTSC_PortReset_Set();
//<3>.Wait time=>55ms
flib_Host20_TimerEnable(55);
//<4>.Write PortReset=0
sAttachDevice.bPortReset=1;
mwHost20_PORTSC_PortReset_Clr();
//<5>.Waiting for IRS->PortChangeDetect
bExitLoop=0;
flib_Host20_TimerEnable_UnLock(200); //1sec //john reduce delay 1
do {
if (mwHost20_PORTSC_PortReset_Rd()==0)
bExitLoop=1;
if (gwOTG_Timer_Counter>2) {
flib_Host20_TimerDisable_UnLock();
printf("??? Error waiting for Bus Reset Fail...==> Reset HW Control\n");
mbHost20_USBCMD_HCReset_Set();
while(mbHost20_USBCMD_HCReset_Rd()==1);
return (1);
}
} while(bExitLoop==0);
flib_Host20_TimerDisable_UnLock();
//<6>.Enable RunStop Bit
flib_Host20_StopRun_Setting(HOST20_Enable);
//<7>.Detect Speed
sAttachDevice.bSpeed= mwOTG20_Control_HOST_SPD_TYP_Rd();
//<8>.Delay 20 ms
flib_Host20_TimerEnable(20);//After Reset => Host must reserve 20 ms for Device init
// john, Don'T need to reset Host when port reset
//if (bDisableAsynchronous==1) { //Bruce;;06292005;
// //Enable the Asynchronous Schedule
// flib_Host20_Asynchronous_Setting(HOST20_Enable);
//}
return (0);
}
//====================================================================
// * Function Name: flib_OTGH_RemoteWakeEnable
// * Description:
// * Input:
// * OutPut:
//====================================================================
UINT8 flib_OTGH_RemoteWakeEnable(void)
{
UINT8 bCMD[8];
UINT8 baTemp[2];
//<Step1>.Get Power/RemoteWakeUp status
flib_Host20_Control_Command_Request(bCMD,0x80,HOST20_CONTROL_GetStatus,0,0,2);
flib_Host20_Issue_Control (1,bCMD,2,baTemp);
//Bit0=0 => Power From VBUS
//Bit0=1 => Power From Device
//Bit1=0 => RemoteWakeUp Disable
//Bit1=1 => RemoteWakeUp Enable
if ((baTemp[0]&BIT1)==0) {//Enable Remote Wakeup(SetFeature)
flib_Host20_Control_Command_Request(bCMD,0x00,HOST20_CONTROL_SetFeature,1,0,0);//Bruce;;08032005;;For Remote Wake Up
flib_Host20_Issue_Control (1,bCMD,2,baTemp);
//Get Status again
flib_Host20_Control_Command_Request(bCMD,0x80,HOST20_CONTROL_GetStatus,0,0,2);
flib_Host20_Issue_Control (1,bCMD,2,baTemp);
if ((baTemp[0]&BIT1)==0) {
printf("??? Remote Wake Up Enable Fail... (SetFeature Fail)\n");
return (0);
}
}
printf(">>>Step1:Enable Remote Wake Up PASS... \n");
sAttachDevice.bRemoteWakeUpDetected=0;
return (1);
}
//====================================================================
// * Function Name: flib_Host20_RemoteWakeUp_Processing
// * Description:
// <1>.Delay 20 ms
// <2>.Write PORTSC->ForcePortResume=0
// <3>.Waiting for the ForcePortResume=0
// <4>.Checking the Suspend Status
// * Input:
// * OutPut:
//====================================================================
void flib_Host20_RemoteWakeUp_Processing(void)
{
//<1>.Delay 20 ms
flib_Host20_TimerEnable(20);
//<2>.Write PORTSC->ForcePortResume=0 (Host should not issue the PortChange interrupt)
mwHost20_PORTSC_ForceResume_Clr();
//<3>.Waiting for the ForcePortResume=0
while(mwHost20_PORTSC_ForceResume_Rd()>0);
//<4>.Enable Run
flib_Host20_StopRun_Setting(HOST20_Enable);
//<5>.Checking the Suspend Status
sAttachDevice.bSuspend=0;
sAttachDevice.bRemoteWakeUpDetected=0;
}
//====================================================================
// * Function Name: flib_Host20_Suspend
// * Description:
// <1>.Make sure PortEnable=1
// <2>.Write PORTSC->Suspend=1
// <3>.Waiting for the ISR->PORTSC->Suspend=1
// * Input:
// * OutPut: 0:OK
// 1:Fail
//====================================================================
UINT8 flib_Host20_Suspend(void)
{
if (mbHost20_USBCMD_RunStop_Rd()==0)
return(1);
//<1>.Make sure PortEnable
if (mwHost20_PORTSC_EnableDisable_Rd()==0)
return(1);
//Start;;Bruce;;06282005;;Make sure the Async schedule is disbale
if (mbHost20_USBCMD_AsynchronousEnable_Rd()>0) {//Disable the Asynchronous Schedule
mbHost20_USBCMD_AsynchronousEnable_Clr();
while (mwHost20_USBSTS_AsynchronousStatus_Rd()>0);
}
//End;;Bruce;;06282005;;Make sure the Async schedule is disbale
//<2>.Write PORTSC->Suspend=1
flib_Host20_StopRun_Setting(HOST20_Disable);//For Faraday HW request
//<3>.Write PORTSC->Suspend=1
mwHost20_PORTSC_ForceSuspend_Set();
//<4>.Waiting for the PORTSC->Suspend=1
while (mwHost20_PORTSC_ForceSuspend_Rd()==0);
return (0);
}
//====================================================================
// * Function Name: flib_Host20_Resume
// * Description:
// <1>.Make Sure PORTSC->Suspend =1
// <2>.Delay 10 ms
// <3>.Write PORTSC->ForcePortResume=1
// <4>.Delay 20 ms
// <5>.Write PORTSC->ForcePortResume=0 (Host should not issue the PortChange interrupt)
// * Input:
// * OutPut:
//====================================================================
UINT8 flib_Host20_Resume(void)
{
//<1>.Make Sure PORTSC->Suspend =1
if (mwHost20_PORTSC_ForceSuspend_Rd()==1) {
printf("??? System is not in the suspend state.\n");
while(1);
}
//<2>.Delay 10 ms for status of "PORTSC->Suspend"
flib_Host20_TimerEnable(10);
//<3>.Write PORTSC->ForcePortResume=1
mwHost20_PORTSC_ForceResume_Set();
//<4>.Delay 20 ms
flib_Host20_TimerEnable(20);
//<5>.Write PORTSC->ForcePortResume=0 (Host should not issue the PortChange interrupt)
mwHost20_PORTSC_ForceResume_Clr();
//<6>.Waiting for the ForcePortResume=0
while (mwHost20_PORTSC_ForceResume_Rd()>0);
//<7>.Enable RunStop Bit
flib_Host20_StopRun_Setting(HOST20_Enable);
//<7>.Checking the Suspend Status
if (mwHost20_PORTSC_ForceSuspend_Rd()>0) {
printf("??? Error ...(After Resume, the Suspend Status should be 0.)\n");
while(1);
}
else
sAttachDevice.bSuspend=0;
//Bruce;;06292005;;Enable Asynchronous
flib_Host20_Asynchronous_Setting(HOST20_Enable);
return (1);
}
//====================================================================
// * Function Name: flib_Host20_RemoteWakeUp
// * Description:
// <1>.Delay 20 ms
// <2>.Write PORTSC->ForcePortResume=0
// <3>.Waiting for the ForcePortResume=0
// <4>.Checking the Suspend Status
// * Input:
// * OutPut:
//====================================================================
void flib_Host20_RemoteWakeUp(void)
{
//<1>.Delay 20 ms
flib_Host20_TimerEnable(20);
//<2>.Write PORTSC->ForcePortResume=0 (Host should not issue the PortChange interrupt)
mwHost20_PORTSC_ForceResume_Clr();
//<3>.Waiting for the ForcePortResume=0
while(mwHost20_PORTSC_ForceResume_Rd()>0);
//<4>.Checking the Suspend Status
if (mwHost20_PORTSC_ForceSuspend_Rd()>0) {
printf("??? Error ...(After Resume, the Suspend Status should be 0.)\n");
while(1);
}
else
sAttachDevice.bSuspend=0;
}
//************************************************************************************************************
//************************************************************************************************************
// *** Group-2:Host Function ***
//*************************************************************************************************************
//************************************************************************************************************
//====================================================================
// * Function Name: flib_Host20_Waiting_Result
// * Description:
// * Input:
// * OutPut:
//====================================================================
UINT8 flib_Host20_Waiting_Result(void)
{
return (1);
}
//====================================================================
// * Function Name: flib_Host20_Control_Command_Request
// * Description:
// * Input: none
// * OutPut: none
//====================================================================
void flib_Host20_Control_Command_Request(Host20_Control_Command_Structure *pbCMD,UINT8 bmRequestType_Temp,UINT8 bRequest_Temp,UINT16 wValue_Temp,UINT16 wIndex_Temp,UINT16 wLength_Temp)
{
UINT8 i;
UINT8 *pbTemp;
pbTemp=pbCMD;
for (i=0;i<8;i++)
*pbTemp++=0x00;
pbCMD->bmRequestType=bmRequestType_Temp; //Byte-0:In/Standard/Device
pbCMD->bRequest=bRequest_Temp;
pbCMD->wValueLow=(UINT8)wValue_Temp;
pbCMD->wValueHigh=(UINT8)(wValue_Temp>>8);
pbCMD->wIndexLow=(UINT8)wIndex_Temp;
pbCMD->wIndexHigh=(UINT8)(wIndex_Temp>>8);
pbCMD->wLengthLow=(UINT8)wLength_Temp;
pbCMD->wLengthHigh=(UINT8)(wLength_Temp>>8);
}
//====================================================================
//flib_Host20_Issue_Control_ByMode
// * Description:
// * Input: bModeSelect=0 => (Setup) -> (In X bytes) -> (Out 0 bytes)
// bModeSelect=1 => (setup) -> (In 0 bytes)
// bModeSelect=2 => (Setup) -> (Out X bytes) -> (In 0 bytes)
// * OutPut:
//====================================================================
UINT8 flib_Host20_Issue_Control_ByMode (UINT8 bEdNum,UINT8* pbCmd,UINT16 hwDataSize,UINT8* pbData,UINT8 bModeSelect)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -