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

📄 ohcihcd.bak

📁 RDC R2886 USB Ehci ohc测试源码,paradigm c++上运行测试
💻 BAK
📖 第 1 页 / 共 4 页
字号:
	Ctl_Setup->wValue = num;
	Ctl_Setup->wIndex = 0x0000;
	Ctl_Setup->wLength = 0x0000;
	
	ohci_Ctl_TD1->hwINFO = TD_DP_SETUP|TD_T_DATA0|TD_DI;//0x02400000L;
	ohci_Ctl_TD1->hwNextTD = 0;
	ohci_Ctl_TD1->hwCBP = (UpperAddr(Ctl_Setup) << 16) + LowerAddr(Ctl_Setup);
	ohci_Ctl_TD1->hwBE = ohci_Ctl_TD1->hwCBP + sizeof(setup_format) - 1;
	
	//Status Stage
	ohci_Ctl_TD3->hwINFO = TD_DP_IN|TD_T_DATA1|TD_DI;//0x02480000L;
	ohci_Ctl_TD3->hwNextTD = 0;
	ohci_Ctl_TD3->hwCBP = 0;
	ohci_Ctl_TD3->hwBE = 0;	//Out 0 bytes

	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD3);
	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD1);
	
	//Set Control_Filled
	Temp = ohci_regs->cmdstatus | OHCI_CLF;
	DWordWrite(&ohci_regs->cmdstatus, Temp);
	
	do{} while(DoneHeadClear == FALSE);
}

void OHCI_Init_BulkLoop()
{
	u32 Temp;
	
	//Setup Stage
	Ctl_Setup->bmRequestType = 0x40;
	Ctl_Setup->bRequest = 0x03;
	Ctl_Setup->wValue = 0x2EC3;
	Ctl_Setup->wIndex = 0x0000;
	Ctl_Setup->wLength = 0x0000;
	
	ohci_Ctl_TD1->hwINFO = TD_DP_SETUP|TD_T_DATA0|TD_DI;//0x02400000L;
	ohci_Ctl_TD1->hwNextTD = 0;
	ohci_Ctl_TD1->hwCBP = (UpperAddr(Ctl_Setup) << 16) + LowerAddr(Ctl_Setup);
	ohci_Ctl_TD1->hwBE = ohci_Ctl_TD1->hwCBP + sizeof(setup_format) - 1;
	
	//Status Stage
	ohci_Ctl_TD3->hwINFO = TD_DP_IN|TD_T_DATA1|TD_DI;//0x02480000L;
	ohci_Ctl_TD3->hwNextTD = 0;
	ohci_Ctl_TD3->hwCBP = 0;
	ohci_Ctl_TD3->hwBE = 0;	//Out 0 bytes
	
	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD3);
	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD1);
	
	//Set Control_Filled
	Temp = ohci_regs->cmdstatus | OHCI_CLF;
	DWordWrite(&ohci_regs->cmdstatus, Temp);
	
	do{} while(DoneHeadClear == FALSE);
}

BOOL DoOHCIControlTransfer()
{
 	static char buf[30];
 	char buf1[26]={"Doing Control transfer..."};
 	char *p, *q;
 	int i;

   	//dev_des->bLength=0x40;
	//Get device descriptor
	if(OHCI_Get_Device_Descriptor(dev_des->bLength) == FALSE)
		return FALSE;
	
	//Get Configuration descriptor
	if(dev_des->bNumConfigurations != 0)
		if(OHCI_Get_Configuration_Desc(0x09) == FALSE)
			return FALSE;

	//Get LANGID String Descriptor
	if((dev_des->iManufacturer != 0) || (dev_des->iProduct != 0) ||(dev_des->iSerialNumber != 0))
		if(OHCI_Get_String_Desc(0) == FALSE)
			return FALSE;

	//Get String 3 Descriptor
	if(dev_des->iSerialNumber != 0)
		if(OHCI_Get_String_Desc(dev_des->iSerialNumber) == FALSE)
			return FALSE;

	//Get Configuration, interface, endpoint descriptor
	if(dev_des->bNumConfigurations != 0)
		if(OHCI_Get_Configuration_Desc(0xFF) == FALSE)
			return FALSE;

	//Get LANGID String Descriptor
	if((dev_des->iManufacturer != 0) || (dev_des->iProduct != 0) ||(dev_des->iSerialNumber != 0))
		if(OHCI_Get_String_Desc(0) == FALSE)
			return FALSE;

	//Get String 2 Descriptor
	if(dev_des->iProduct != 0)
		if(OHCI_Get_String_Desc(dev_des->iProduct) == FALSE)
			return FALSE;

	//Get LANGID String Descriptor
	if((dev_des->iManufacturer != 0) || (dev_des->iProduct != 0) ||(dev_des->iSerialNumber != 0))
		if(OHCI_Get_String_Desc(0) == FALSE)
			return FALSE;

	//Get String 2 Descriptor
	if(dev_des->iManufacturer != 0)
		if(OHCI_Get_String_Desc(dev_des->iManufacturer) == FALSE)
			return FALSE;

	//Get device descriptor
	if(OHCI_Get_Device_Descriptor(dev_des->bLength) == FALSE)
		return FALSE;

	//Get Configuration descriptor
	if(dev_des->bNumConfigurations != 0)
		if(OHCI_Get_Configuration_Desc(0x09) == FALSE)
			return FALSE;
		
	//Get Configuration, interface, endpoint descriptor
	if(dev_des->bNumConfigurations != 0)
		if(OHCI_Get_Configuration_Desc(cfg_des->wTotalLength) == FALSE)
			return FALSE;

	//Set Configuration
	OHCI_Set_Configuration(cfg_des->bConfigurationValue);

	ControlCnt++;
	if(ControlCnt == 0x0000){
		p=buf;
		q=buf1;
		for(i=0;i<sizeof(buf1);i++)
			*p++ = *q++;
		*p++ = 10;
		*p++ = 13;
		UART_SendData(buf, sizeof(buf));
	}

	return TRUE;
}

void InitISOEDTD(void)
{
	char __far *Host_memory_ptr;
   int i;

   //Allocate TD format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_td_t)+32);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x1F) & ~0x1F);

	ohci_ISO_TD0 = (ohci_itd *) Host_memory_ptr;

	ohci_ISO_TD0->hwINFO = 0;
	ohci_ISO_TD0->hwCBP = 0;
	ohci_ISO_TD0->hwNextTD = 0;
	ohci_ISO_TD0->hwBE = 0;


	//Allocate EP0 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_ed_t)+16);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0xF) & ~0xF);

	ohci_EpISO = (ohci_ed_t *) Host_memory_ptr;

   ohci_EpISO->hwINFO = 0x03ff0000L|ED_D_IN|ED_F|ED_EN_1|ED_FA_3;  	//addr3, enp1
	ohci_EpISO->hwTailP = 0;
	ohci_EpISO->hwHeadP = 0;
	ohci_EpISO->hwNextED = 0;

	//InsertEmptyTD(ohci_EpISO, ohci_ISO_TD0);
   //InsertEmptyTD
   ohci_EpISO->hwTailP = ohci_EpISO->hwHeadP = (UpperAddr(ohci_ISO_TD0) << 16) + LowerAddr(ohci_ISO_TD0);

   //Allocate EP1 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_ed_t)+16);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0xF) & ~0xF);

	ohci_EpISO1 = (ohci_ed_t *) Host_memory_ptr;

   ohci_EpISO1->hwINFO = 0x03ff0000L|ED_D_IN|ED_F|ED_EN_1|ED_FA_3;  	//addr3, enp1
	ohci_EpISO1->hwTailP = 0;
	ohci_EpISO1->hwHeadP = 0;
	ohci_EpISO1->hwNextED = 0;

	//InsertEmptyTD
   ohci_EpISO1->hwTailP = ohci_EpISO1->hwHeadP = (UpperAddr(ohci_ISO_TD0) << 16) + LowerAddr(ohci_ISO_TD0);

   //Allocate EP2 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_ed_t)+16);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0xF) & ~0xF);

	ohci_EpISO2 = (ohci_ed_t *) Host_memory_ptr;

   ohci_EpISO2->hwINFO = 0x03ff0000L|ED_D_IN|ED_F|ED_EN_1|ED_FA_3;  	//addr3, enp1
	ohci_EpISO2->hwTailP = 0;
	ohci_EpISO2->hwHeadP = 0;
	ohci_EpISO2->hwNextED = 0;

	//InsertEmptyTD
   ohci_EpISO2->hwTailP = ohci_EpISO2->hwHeadP = (UpperAddr(ohci_ISO_TD0) << 16) + LowerAddr(ohci_ISO_TD0);


   //Allocate EP3 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_ed_t)+16);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0xF) & ~0xF);

	ohci_EpISO3 = (ohci_ed_t *) Host_memory_ptr;

   ohci_EpISO3->hwINFO = 0x03ff0000L|ED_D_IN|ED_F|ED_EN_1|ED_FA_3;  	//addr3, enp1
	ohci_EpISO3->hwTailP = 0;
	ohci_EpISO3->hwHeadP = 0;
	ohci_EpISO3->hwNextED = 0;

	//InsertEmptyTD
   ohci_EpISO3->hwTailP = ohci_EpISO3->hwHeadP = (UpperAddr(ohci_ISO_TD0) << 16) + LowerAddr(ohci_ISO_TD0);

   //Allocate TD1 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_itd)+32);	//sizeof ohci_itd + 32
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x1F) & ~0x1F);
	ohci_ISO_TD1 = (ohci_itd *) Host_memory_ptr;

   //Allocate TD2 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_td_t)+32);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x1F) & ~0x1F);
	ohci_ISO_TD2 = (ohci_itd *) Host_memory_ptr;

   //Allocate TD3 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_td_t)+32);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x1F) & ~0x1F);
	ohci_ISO_TD3 = (ohci_itd *) Host_memory_ptr;

   //Allocate TD4 format structure
	Host_memory_ptr = (char *)malloc(sizeof(ohci_td_t)+32);	//sizeof ohci_ed_t + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x1F) & ~0x1F);
	ohci_ISO_TD4 = (ohci_itd *) Host_memory_ptr;

   //Allocate Data buffer1
	Host_memory_ptr = (char *)malloc(MAXBufSize+1024);	//640byte + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x3FF) & ~0x3FF);
	ISODataBuf1 = Host_memory_ptr;

   //Allocate Data buffer2
	Host_memory_ptr = (char *)malloc(MAXBufSize+1024);	//640byte + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x3FF) & ~0x3FF);
	ISODataBuf2 = Host_memory_ptr;

   //Allocate Data buffer3
	Host_memory_ptr = (char *)malloc(MAXBufSize+1024);	//640byte + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x3FF) & ~0x3FF);
	ISODataBuf3 = Host_memory_ptr;

   //Allocate Data buffer4
	Host_memory_ptr = (char *)malloc(MAXBufSize+1024);	//640byte + 16
	Host_memory_ptr = (char *) (((unsigned long)Host_memory_ptr + 0x3FF) & ~0x3FF);
	ISODataBuf4 = Host_memory_ptr;

   for(i=0;i<MAXBufSize;i++)
   {
   	ISODataBuf1[i]=0;
      ISODataBuf2[i]=0;
      ISODataBuf3[i]=0;
      ISODataBuf4[i]=0;
   }

   //Init TD1 format
   ohci_ISO_TD1->hwINFO = TD_NOTACCESSED|0x02000000L;	//
	ohci_ISO_TD1->hwNextTD = 0;
	ohci_ISO_TD1->hwCBP = (UpperAddr(ISODataBuf1) << 16) + LowerAddr(ISODataBuf1);
	ohci_ISO_TD1->hwBE = ohci_ISO_TD1->hwCBP + MAXBufSize -1;
   ohci_ISO_TD1->hwPSW[0] = (u16)(ohci_ISO_TD1->hwCBP & 0xFFF);
   ohci_ISO_TD1->hwPSW[1] = (u16)(ohci_ISO_TD1->hwCBP & 0xFFF)+0x100;
   ohci_ISO_TD1->hwPSW[2] = (u16)(ohci_ISO_TD1->hwCBP & 0xFFF)+0x200;
   ohci_ISO_TD1->hwPSW[3] = (u16)((ohci_ISO_TD1->hwCBP & 0xFFF)+MAXBufSize-1);
   ohci_ISO_TD1->hwPSW[4] = 0x00;
   ohci_ISO_TD1->hwPSW[5] = 0x00;
   ohci_ISO_TD1->hwPSW[6] = 0x00;
   ohci_ISO_TD1->hwPSW[7] = 0x00;
   //Init TD2 format
   ohci_ISO_TD2->hwINFO = 0x8|TD_NOTACCESSED|0x02000000L;	//
	ohci_ISO_TD2->hwNextTD = 0;
	ohci_ISO_TD2->hwCBP = (UpperAddr(ISODataBuf2) << 16) + LowerAddr(ISODataBuf2);
	ohci_ISO_TD2->hwBE = ohci_ISO_TD2->hwCBP + MAXBufSize -1;
   ohci_ISO_TD2->hwPSW[0] = (u16)(ohci_ISO_TD2->hwCBP & 0xFFF);
   ohci_ISO_TD2->hwPSW[1] = (u16)(ohci_ISO_TD2->hwCBP & 0xFFF)+0x100;
   ohci_ISO_TD2->hwPSW[2] = (u16)((ohci_ISO_TD2->hwCBP & 0xFFF)+0x200);
   ohci_ISO_TD2->hwPSW[3] = (u16)((ohci_ISO_TD2->hwCBP & 0xFFF)+MAXBufSize-1);
   ohci_ISO_TD2->hwPSW[4] = 0;
   ohci_ISO_TD2->hwPSW[5] = 0x00;
   ohci_ISO_TD2->hwPSW[6] = 0x00;
   ohci_ISO_TD2->hwPSW[7] = 0x00;

   //Init TD3 format
   ohci_ISO_TD3->hwINFO = 0x10|TD_NOTACCESSED|0x02000000L;//0x03540000L;
	ohci_ISO_TD3->hwNextTD = 0;
	ohci_ISO_TD3->hwCBP = (UpperAddr(ISODataBuf3) << 16) + LowerAddr(ISODataBuf3);
	ohci_ISO_TD3->hwBE = ohci_ISO_TD3->hwCBP + MAXBufSize -1;	//In 640 bytes
   ohci_ISO_TD3->hwPSW[0] = (u16)(ohci_ISO_TD3->hwCBP & 0xFFF);
   ohci_ISO_TD3->hwPSW[1] = (u16)(ohci_ISO_TD3->hwCBP & 0xFFF)+0x100;
   ohci_ISO_TD3->hwPSW[2] = (u16)((ohci_ISO_TD3->hwCBP & 0xFFF)+0x200);
   ohci_ISO_TD3->hwPSW[3] = (u16)((ohci_ISO_TD3->hwCBP & 0xFFF)+MAXBufSize-1);
   ohci_ISO_TD3->hwPSW[4] = 0;
   ohci_ISO_TD3->hwPSW[5] = 0x00;
   ohci_ISO_TD3->hwPSW[6] = 0x00;
   ohci_ISO_TD3->hwPSW[7] = 0x00;

   //Init TD4 format
   ohci_ISO_TD4->hwINFO = 0x18|TD_NOTACCESSED|0x02000000L;//0x03540000L;
	ohci_ISO_TD4->hwNextTD = 0;
	ohci_ISO_TD4->hwCBP = (UpperAddr(ISODataBuf4) << 16) + LowerAddr(ISODataBuf4);
	ohci_ISO_TD4->hwBE = ohci_ISO_TD4->hwCBP + MAXBufSize -1;	//In 640 bytes
   ohci_ISO_TD4->hwPSW[0] = (u16)(ohci_ISO_TD4->hwCBP & 0xFFF);
   ohci_ISO_TD4->hwPSW[1] = (u16)(ohci_ISO_TD4->hwCBP & 0xFFF)+0x100;
   ohci_ISO_TD4->hwPSW[2] = (u16)((ohci_ISO_TD4->hwCBP & 0xFFF)+0x200);
   ohci_ISO_TD4->hwPSW[3] = (u16)((ohci_ISO_TD4->hwCBP & 0xFFF)+MAXBufSize-1);
   ohci_ISO_TD4->hwPSW[4] = 0;
   ohci_ISO_TD4->hwPSW[5] = 0x00;
   ohci_ISO_TD4->hwPSW[6] = 0x00;
   ohci_ISO_TD4->hwPSW[7] = 0x00;

   AddingiTDtoED(ohci_EpISO,ohci_ISO_TD1);
   AddingiTDtoED(ohci_EpISO1,ohci_ISO_TD2);
   AddingiTDtoED(ohci_EpISO2,ohci_ISO_TD3);
   AddingiTDtoED(ohci_EpISO3,ohci_ISO_TD4);

   //link to hcca interrupt table
   for(i=0;i<8;i++)
   	ohci_hcca->int_table[i]= (UpperAddr(ohci_EpISO) << 16) + LowerAddr(ohci_EpISO);
   for(i=8;i<16;i++)
   	ohci_hcca->int_table[i]= (UpperAddr(ohci_EpISO1) << 16) + LowerAddr(ohci_EpISO1);
   for(i=16;i<24;i++)
   	ohci_hcca->int_table[16]= (UpperAddr(ohci_EpISO2) << 16) + LowerAddr(ohci_EpISO2);
   for(i=24;i<32;i++)
   	ohci_hcca->int_table[24]= (UpperAddr(ohci_EpISO3) << 16) + LowerAddr(ohci_EpISO3);

}

void OHCI_Set_Interface(u16 num)
{
	u32 Temp;

	//Setup Stage
	Ctl_Setup->bmRequestType = 0x01;
	Ctl_Setup->bRequest = 0x0B;
	Ctl_Setup->wValue = num;
	Ctl_Setup->wIndex = 0x0000;
	Ctl_Setup->wLength = 0x0000;

	ohci_Ctl_TD1->hwINFO = TD_DP_SETUP|TD_T_DATA0|TD_DI;//0x02400000L;
	ohci_Ctl_TD1->hwNextTD = 0;
	ohci_Ctl_TD1->hwCBP = (UpperAddr(Ctl_Setup) << 16) + LowerAddr(Ctl_Setup);
	ohci_Ctl_TD1->hwBE = ohci_Ctl_TD1->hwCBP + sizeof(setup_format) - 1;

	//Status Stage
	ohci_Ctl_TD3->hwINFO = TD_DP_IN|TD_T_DATA1|TD_DI;//0x02480000L;
	ohci_Ctl_TD3->hwNextTD = 0;
	ohci_Ctl_TD3->hwCBP = 0;
	ohci_Ctl_TD3->hwBE = 0;	//Out 0 bytes

	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD3);
	AddingTDtoED(ohci_Ep0, ohci_Ctl_TD1);

	//Set Control_Filled
	Temp = ohci_regs->cmdstatus | OHCI_CLF;
	DWordWrite(&ohci_regs->cmdstatus, Temp);

	do{} while(DoneHeadClear == FALSE);
}

//ISO control transfer
void ISOControlTransfer(int dir, u16 wValue, int len)
{
	u32 Temp;

   //Setup Stage
   if(dir==0)	//0:set
		Ctl_Setup->bmRequestType = 0x40;
   else
      Ctl_Setup->bmRequestType = 0xC0;
	Ctl_Setup->bRequest = 0x04;
	Ctl_Setup->wValue = wValue;
	Ctl_Setup->wIndex = 0x0000;
	Ctl_Setup->wLength = len;

	ohci_Ctl_TD1->hwINFO = TD_DP_SETUP|TD_T_DATA0|TD_DI;//0x02400000L;
	ohci_Ctl_TD1->hwNextTD = 0;
	ohci_Ctl_TD1->hwCBP = (UpperAddr(Ctl_Setup) << 16) + LowerAddr(Ctl_Setup);
	ohci_Ctl_TD1->hwBE = ohci_Ctl_TD1->hwCBP + sizeof(setup_format) - 1;

	//Data Stage

⌨️ 快捷键说明

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