📄 host20_ap.c
字号:
/////////////////////////////////////////////////////////////////////////////////// File name: OTGHost_AP.C// Version: 1.1// Date: 2005/01/31//// Author: Bruce// Email: // Phone: (03) 578-7888// Company: Faraday Tech. Corp.//// **Description: // The program support the Faraday USB path Test. // 1.Control/Bulk/Interrupt/ISO// 2.Suspend/Resume/RemoteWakeup// 3.Hot Plug/Cold Plug/Static Enumeration///////////////////////////////////////////////////////////////////////////////#include <stdlib.h>#include <stdarg.h>#include <stdio.h>#include <string.h>#include "chipset.h" #include "flib.h" #include "Lib_Host20.h" #include "Host20_AP.H"#include "Host20_AP_HID.H"#include "Host20_AP_Camera.H"OTGH_PT_CONTROL_Struct sOTGH_PT_Control;OTGH_PT_INT_Struct sOTGH_PT_INT;OTGH_PT_ISO_Struct sOTGH_PT_ISO;OTGH_PT_BLK_Struct *sOTGH_PT_BLK;UINT8 HOST_AP_CONTROL_VENDOR_IN[] = {0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x01}; UINT8 HOST_AP_CONTROL_VENDOR_OUT[] = {0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x01}; //************************************************************************************************************//************************************************************************************************************// *** Group-1:4 Transfers Test Function ***//*************************************************************************************************************//************************************************************************************************************//====================================================================// * Function Name: OTGH_Error_Handle// * Description: // * Input: none// * OutPut: none//====================================================================void OTGH_Error_Handle(void){ UINT8 Item; UINT32 u32Start,u32Length; UINT32 *pu32Data; do{ printf("******** Error Handle **************\n"); printf("1.Dump Memory \n"); printf("2.Exit \n"); printf("**********************\n"); printf(">>>Select:\n"); scanf("%d",(char *)&Item); switch(Item) { case 1: //Dump memory printf(">>>Input Start Address:0x"); scanf("%x",(char *)&u32Start); printf("\n"); printf(">>>Input Length:0x"); scanf("%x",(char *)&u32Length); printf("\n"); if (u32Length>0) { printf("********** Dump Memory ********************\n"); pu32Data=u32Start; do {//Print data pu32Data=((UINT32)pu32Data) & 0xFFFFFFF0; printf("0x%x ==> 0x%x, 0x%x, 0x%x, 0x%x \n" ,(UINT32) (pu32Data),*(pu32Data),*(pu32Data+1),*(pu32Data+2),*(pu32Data+3) ); if (u32Length>=16) u32Length-=16; pu32Data+=4; }while(u32Length>=16); } break; } printf("\n"); }while(Item!=2);}//====================================================================// * Function Name: OTGH_PT_Bulk_SendCBW // * Description: The sub function call of Bulk-CBW// <1>.Prepare the CBW data // <2>.Issue the Bulk-Out command // * Input: // <1>.UINT32 wLength// <2>.UINT16 hwStartAdd// <3>.UINT32 wTagNum// <4>.UINT8 bDataDir// * OutPut: none//====================================================================void OTGH_PT_Bulk_SendCBW(UINT32 wLength, UINT16 hwStartAdd, UINT32 wTagNum , UINT8 bDataDir){ Host20_BufferPointerArray_Structure aTemp; //<1>.Prepare the CBW data sOTGH_PT_BLK->sCBW.u32Signature = OTGH_PT_CBW_SIGNATE; sOTGH_PT_BLK->sCBW.u32DataTransferLength=wLength; sOTGH_PT_BLK->sCBW.u32Tag=wTagNum; sOTGH_PT_BLK->sCBW.u8CB[0]=(UINT8)hwStartAdd; sOTGH_PT_BLK->sCBW.u8CB[1]=(UINT8)(hwStartAdd>>8); if (bDataDir==0) sOTGH_PT_BLK->sCBW.u8Flags = 0x00 ; //0 => Out else sOTGH_PT_BLK->sCBW.u8Flags = 0x80; //john 0x01 ; //0 => In aTemp.BufferPointerArray[0]=(UINT32)(&(sOTGH_PT_BLK->sCBW.u32Signature)); aTemp.BufferPointerArray[1]=0; aTemp.BufferPointerArray[2]=0; aTemp.BufferPointerArray[3]=0; aTemp.BufferPointerArray[4]=0; //<2>.Issue the Bulk-Out command flib_Host20_Issue_Bulk (sOTGH_PT_BLK->bOutQHDArrayNum,31,(&aTemp.BufferPointerArray[0]),0,OTGH_Dir_Out);}//====================================================================// * Function Name: OTGH_PT_Bulk_SendCSW // * Description: The sub function call of Bulk-CSW// <1>.Issue the Bulk-IN Command// <2>.Check the data-Tag// <3>.Check the data-Signature// <4>.Checking Status OTGH_PT_CSW_PASS// * Input: none// * OutPut: none//====================================================================void OTGH_PT_Bulk_ReceiveCSW(void){ UINT32 wCBWTag,wCSWTag; Host20_BufferPointerArray_Structure aTemp; //<1>.Issue the Bulk-IN Command aTemp.BufferPointerArray[0]=(UINT32)(&(sOTGH_PT_BLK->sCSW.u32Signature)); aTemp.BufferPointerArray[1]=0; aTemp.BufferPointerArray[2]=0; aTemp.BufferPointerArray[3]=0; aTemp.BufferPointerArray[4]=0; flib_Host20_Issue_Bulk (sOTGH_PT_BLK->bInQHDArrayNum,13,&(aTemp.BufferPointerArray[0]),0,OTGH_Dir_IN); //<2>.Check the data-Tag wCBWTag=(UINT32)(sOTGH_PT_BLK->sCBW.u32Tag); wCSWTag=(UINT32)(sOTGH_PT_BLK->sCSW.u32Tag); if (wCBWTag!=wCSWTag) { printf(">>> Error: Received CSW->Tag fail (Expected data:0x%x / Received Data:0x%x)\n",(UINT32)(wCBWTag),(UINT32)(wCSWTag)); OTGH_Error_Handle(); } //<3>.Check the data-Signature if ((sOTGH_PT_BLK->sCSW.u32Signature)!=OTGH_PT_CSW_SIGNATE) { printf(">>> Error: Received CSW->Signature fail (Expected data:%d / Received Data:%d)\n",OTGH_PT_CSW_SIGNATE,(UINT32)(sOTGH_PT_BLK->sCSW.u32Tag)); OTGH_Error_Handle(); } //<4>.Checking Status OTGH_PT_CSW_PASS if ((sOTGH_PT_BLK->sCSW.u8Status)!=OTGH_PT_CSW_PASS) { printf(">>> Error: Received CSW->Status fail (Expected data:%d / Received Data:%d)\n",OTGH_PT_CSW_PASS,sOTGH_PT_BLK->sCSW.u8Status); OTGH_Error_Handle(); } }//====================================================================// * Function Name: OTGH_PT_Control_Command // * Description: // <1>.Get_Configuration // <2>.Get_Interface// <3>.Set_Interface// <4>.Get_Status// <5>.Set_Feature// <6>.Get_Status-2// <7>.Clear_Feature// <8>.Get_Status-2// * Input: none// * OutPut: none//====================================================================void OTGH_PT_Control_Command(void){ Host20_Control_Command_Structure bCMD; UINT8 bTemp; UINT16 hwTemp; UINT32 wInputCounter,wCounter; if (OTGH_PT_ADVANCE_TEST==0) { wInputCounter=10; }else { printf(">>> Please Input Control Command counter:"); scanf("%d",&wInputCounter); printf("\n"); } wCounter=0; do{ wCounter++; printf("******************* Test Control Command Counter = %d ***************************\n",wCounter); //<1>.Get_Configuration flib_Host20_Control_Command_Request(&bCMD,0x80,HOST20_CONTROL_GetConfiguration,0,0,1); flib_Host20_Issue_Control(1,&bCMD,0x01,&(bTemp)); if (bTemp==1) printf(">>> Get_Configuration(%d) Test ==> PASS \n",bTemp); else printf(">>> Get_Configuration(%d) Test ==> Fail \n",bTemp); //<2>.Get_Interface flib_Host20_Control_Command_Request(&bCMD,0x81,HOST20_CONTROL_GetInterface,0,0,1);//1=>Interface flib_Host20_Issue_Control(1,&bCMD,0x01,&(bTemp));//Size=1 byte if (bTemp==0) printf(">>> Get_Interface(%d) Test ==> PASS \n",bTemp); else printf(">>> Get_Interface(%d) Test ==> Fail \n",bTemp); //<3>.Set_Interface flib_Host20_Control_Command_Request(&bCMD,0x01,HOST20_CONTROL_SetInterface,0,0,0); flib_Host20_Issue_Control(1,&bCMD,0x00,&(bTemp));//Size=0 byte printf(">>> Set_Interface to 0 Finish ==> PASS \n"); //<2>.Get_Interface again flib_Host20_Control_Command_Request(&bCMD,0x81,HOST20_CONTROL_GetInterface,0,0,1);//1=>Interface flib_Host20_Issue_Control(1,&bCMD,0x01,&(bTemp));//Size=1 byte if (bTemp==0) printf(">>> Get_Interface(%d) Test ==> PASS \n",bTemp); else printf(">>> Get_Interface(%d) Test ==> Fail \n",bTemp); //<4>.Get_Status //<4.1>.Get Power/RemoteWakeUp status flib_Host20_Control_Command_Request(&bCMD,0x80,HOST20_CONTROL_GetStatus,0,0,2); //Bit0=0 => Power From VBUS //Bit0=1 => Power From Device //Bit1=0 => RemoteWakeUp Disable //Bit1=1 => RemoteWakeUp Enable flib_Host20_Issue_Control(1,&bCMD,0x02,&(hwTemp)); if (hwTemp==1) { printf(">>> Get_Status(%d)(Power/RemoteWakeUp) Test ==> PASS \n",hwTemp); printf(" (Bit0=1 => Power From Device)\n"); printf(" (Bit1=0 => RemoteWakeUp Disable)\n"); } else printf(">>> Get_Status(%d) (Power/RemoteWakeUp) Test ==> Fail \n",hwTemp); //<4.2>.Get Endpoint status flib_Host20_Control_Command_Request(&bCMD,0x82,HOST20_CONTROL_GetStatus,0,0,2); //Bit0=0 => Not Halt //Bit0=1 => Halt flib_Host20_Issue_Control(1,&bCMD,0x02,&(hwTemp)); if (hwTemp==0) { printf(">>> Get_Status(%d) (Endpoint status) Test ==> PASS \n",hwTemp); printf(" (Bit0=0 => Not Halt)\n"); } else printf(">>> Get_Status(%d) (Endpoint status) Test ==> Fail \n",hwTemp); //<5>.Set_Feature flib_Host20_Control_Command_Request(&bCMD,0x00,HOST20_CONTROL_SetFeature,1,0,0); flib_Host20_Issue_Control(1,&bCMD,0x00,&(bTemp)); printf(">>> Set_Feature to 'RemoteWakeUp Enable' ==> PASS \n"); //<6>.Get status 'Power/RemoteWakeUp' flib_Host20_Control_Command_Request(&bCMD,0x80,HOST20_CONTROL_GetStatus,0,0,2); //Bit1=0 => RemoteWakeUp Disable //Bit1=1 => RemoteWakeUp Enable flib_Host20_Issue_Control(1,&bCMD,0x02,&(hwTemp)); if (hwTemp==3) { printf(">>> Get_Status (%d)(Power/RemoteWakeUp) Test ==> PASS \n",hwTemp); printf(" (Bit0=1 => Power From Device)\n"); printf(" (Bit1=0 => RemoteWakeUp Disable)\n"); } else printf(">>> Get_Status (%d)(Power/RemoteWakeUp) Test ==> Fail \n",hwTemp); //<7>.Clear_Feature flib_Host20_Control_Command_Request(&bCMD,0x00,HOST20_CONTROL_ClearFeature,1,0,0); flib_Host20_Issue_Control(1,&bCMD,0x00,&(bTemp)); printf(">>> Clear_Feature to 'RemoteWakeUp Disable' ==> PASS\n"); //<8>.Get status 'Power/RemoteWakeUp' flib_Host20_Control_Command_Request(&bCMD,0x80,HOST20_CONTROL_GetStatus,0,0,2); //Bit1=0 => RemoteWakeUp Disable //Bit1=1 => RemoteWakeUp Enable flib_Host20_Issue_Control(1,&bCMD,0x02,&(hwTemp)); if (hwTemp==1) printf(">>> Get_Status(%d) (Power/RemoteWakeUp) Test ==> PASS \n",hwTemp); else printf(">>> Get_Status(%d)(Power/RemoteWakeUp) Test ==> Fail \n",hwTemp); }while(wCounter<wInputCounter); }//====================================================================// * Function Name: OTGH_PT_Control_Path_Init // * Description: Control Path Test Init// * Input: none// * OutPut: none//====================================================================void OTGH_PT_Control_Path_Init(void){ sOTGH_PT_Control.wMaxSize = 4*1024*5; sOTGH_PT_Control.pbDataPage[0]=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); sOTGH_PT_Control.pbDataPage[1]=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); sOTGH_PT_Control.pbDataPage[2]=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); sOTGH_PT_Control.pbDataPage[3]=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER); sOTGH_PT_Control.pbDataPage[4]=flib_Host20_GetStructure(Host20_MEM_TYPE_4K_BUFFER);}//====================================================================// * Function Name: OTGH_PT_Control_Path_Close // * Description: Close the Control Path Test// * Input: none// * OutPut: none//====================================================================void OTGH_PT_Control_Path_Close(void){ //Release data buffer flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,sOTGH_PT_Control.pbDataPage[0]); flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,sOTGH_PT_Control.pbDataPage[1]); flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,sOTGH_PT_Control.pbDataPage[2]); flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,sOTGH_PT_Control.pbDataPage[3]); flib_Host20_ReleaseStructure(Host20_MEM_TYPE_4K_BUFFER,sOTGH_PT_Control.pbDataPage[4]); }//====================================================================// * Function Name: OTGH_PT_Control_Path // * Description: The Bulk path test function call// <1>.Decide => In/Out// <2>.Issue the Control (Data-In)// <3>.If Control (Data-In) then Compare Data// <4>.Issue the Control (Data-Out)// <5>.Goto Step1// PS:1.Data range:0~255// 2.Max Data Size => Depend on init (4096/20K)// 3.Size = increment (1~4096)//// * Input: none// * OutPut: none//====================================================================void OTGH_PT_Control_Path(void){ UINT32 wRandomSize,wOffset,wCounter,wRandomSizeMax,wInputCounter,i,wOffsetMax,wDecrementInterval; UINT8 bCMD[8]; UINT8 *pbTemp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -