usbhost.c

来自「RDC R2886 USB Ehci ohc测试源码,paradigm c++上」· C语言 代码 · 共 1,293 行 · 第 1/3 页

C
1,293 行
字号

	}

  	//Scheduling Overrun
	if (ints & OHCI_INTR_SO) {
		DWordWrite(&ohci_regs->intrstatus, OHCI_INTR_SO);
	}

	//Start of frame
	if (ints & OHCI_INTR_SF) { 
		DWordWrite(&ohci_regs->intrstatus, OHCI_INTR_SF);
	}

	//Frame number overflow
	if (ints & OHCI_INTR_FNO) { 
		DWordWrite(&ohci_regs->intrstatus, OHCI_INTR_FNO);
	}

	//Root hub status change, Port status change
	if (ints & OHCI_INTR_RHSC) {
		//Root hub status change
		if((rhs = DWordRead(&ohci_regs->status)) != 0) {
			rhs = rhs;
		}
		//Port status change, just handle port 1
		else if((rhpt1s = DWordRead(&ohci_regs->portstatus[USB_Port])) != 0) {
			if(rhpt1s & RH_PS_PRSC) {	//Port reset status change
				DWordWrite(&ohci_regs->portstatus[USB_Port], RH_PS_PRSC);

				if((rhpt1s & RH_PS_CCS) == RH_PS_CCS){	//Check is connect
					g_OHCIAttach = 1;
				}
			}
			if(rhpt1s & RH_PS_CSC){		//Port connect status change
				if(rhpt1s & RH_PS_CCS) {
					//port reset
      			mdelay(110);
            	DWordWrite(&ohci_regs->portstatus[USB_Port], RH_PS_PRS);
               mdelay(70);
               
               if((rhpt1s & RH_PS_LSDA) == RH_PS_LSDA) 	//low speed device attach
               {
               	p=buf;
                  q=buf5;
                  for(i=0;i<sizeof(buf5);i++)
                  *p++ = *q++;
                  *p++ = 10;
					  	*p++ = 13;

					 	UART_SendData(buf, sizeof(buf));
                  DeviceSpeed = 1;
               }
               else
               {
                  p=buf;
                  q=buf3;
                  for(i=0;i<sizeof(buf3);i++)
                     *p++ = *q++;
                  *p++ = 10;
                  *p++ = 13;
						UART_SendData(buf, sizeof(buf));
                  DeviceSpeed=0;
               }
               DWordWrite(&ohci_regs->portstatus[USB_Port], RH_PS_PES);	//Port1 Status, set port enable
					g_OHCIAttach = 1;
				}
				else if(rhpt1s & RH_PS_PESC) {
					if((rhpt1s & RH_PS_CCS) == RH_PS_CCS){
               	if((rhpt1s & RH_PS_LSDA) == RH_PS_LSDA) 	//low speed device attach
                  {
                  	p=buf;
                     q=buf5;
                     for(i=0;i<sizeof(buf5);i++)
							*p++ = *q++;
							*p++ = 10;
							*p++ = 13;
							UART_SendData(buf, sizeof(buf));
                     DeviceSpeed=1;
                  }
                  else
                  {
                  	p=buf;
                     q=buf3;
                     for(i=0;i<sizeof(buf3);i++)
                        *p++ = *q++;
                     *p++ = 10;
                     *p++ = 13;
							UART_SendData(buf, sizeof(buf));
                     DeviceSpeed=0;
                  }
						g_OHCIAttach = 1;
					}
					else{
               	if((rhpt1s & RH_PS_LSDA) == RH_PS_LSDA) 	//low speed device deattach
                  {
                  	p=buf;
                     q=buf6;
                     for(i=0;i<sizeof(buf6);i++)
							*p++ = *q++;
							*p++ = 10;
							*p++ = 13;
							UART_SendData(buf, sizeof(buf));
                     DeviceSpeed=1;
                  }
                  else
                  {
                     p=buf;
                     q=buf4;
                     for(i=0;i<sizeof(buf4);i++)
                        *p++ = *q++;
                     *p++ = 10;
                     *p++ = 13;
                     UART_SendData(buf, sizeof(buf));
                     DeviceSpeed=0;
					   }
						g_OHCIAttach = 0;
						OHCI_DeviceAttach_Init = FALSE;
                  HighSpeed_Owner = TRUE;
				}
				DWordWrite(&ohci_regs->portstatus[USB_Port], RH_PS_PESC);
			}
		else{
            	if((rhpt1s & RH_PS_LSDA) == RH_PS_LSDA) 	//low speed device deattach
               {
               	p=buf;
                  q=buf6;
                  for(i=0;i<sizeof(buf6);i++)
                  	*p++ = *q++;
                  *p++ = 10;
                  *p++ = 13;
                  UART_SendData(buf, sizeof(buf));
                  DeviceSpeed=1;
               }
               else
               {
               	p=buf;
                  q=buf4;
                  for(i=0;i<sizeof(buf4);i++)
                  	*p++ = *q++;
                  *p++ = 10;
                  *p++ = 13;
                  UART_SendData(buf, sizeof(buf));
                  DeviceSpeed=0;
               }
               g_OHCIAttach = 0;
               OHCI_DeviceAttach_Init = FALSE;
               HighSpeed_Owner = TRUE;
            }
				DWordWrite(&ohci_regs->portstatus[USB_Port], RH_PS_CSC);
			}
		}
	}
Exit_INTB_ISR:
	DWordWrite(&ohci_regs->intrstatus, ints);
	outport(INT_EOI,0x8000);    // ;;write to EOI
}

// INTD, For EHCI
void _interrupt EHCI_Isr()
{
 	u32 ints, rhpt1s;
 	static char buf[32];
 	char buf1[28]={"High Speed device attach..."};
 	char buf2[28]={"High Speed device detach..."};
 	char *p, *q;
 	int i;

   INTB_Cnt++;

	ints=inport(INT_INSERV);    //read in-service register

	//EHCI ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//Check Interrupt Status
	ints = DWordRead(&ehci_regs->status);

   if (ints == ~(u32)0)
		goto Exit_INTA_ISR;

	if (ints & STS_FLR) {
		DWordWrite(&ehci_regs->status, STS_FLR);
	}
	if (ints & STS_PCD) {		//Port change detect

   	rhpt1s = DWordRead(&ehci_regs->port_status[USB_Port]);

		if(rhpt1s & PORT_CSC)		//Connect status change
			DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_CSC));
		if(rhpt1s & PORT_CONNECT) {
			/* start controller operations */
			DWordWrite(&ehci_regs->command, (0x00080000L | CMD_RUN));	//CMD_ASE
			do{} while((DWordRead(&ehci_regs->status) & CMD_RUN) == CMD_RUN);
         mdelay(110);
			//Port reset
			DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_RESET));
			mdelay(50);
			DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT));

			//Wait reset complete
			do{} while((DWordRead(&ehci_regs->port_status[USB_Port]) & PORT_RESET) == PORT_RESET);

			if((DWordRead(&ehci_regs->port_status[USB_Port]) & (PORT_CONNECT|PORT_PE)) == (PORT_CONNECT|PORT_PE)){
				p=buf;
				q=buf1;
				for(i=0;i<sizeof(buf1);i++)
					*p++ = *q++;
				*p++ = 10;
				*p++ = 13;
				UART_SendData(buf, sizeof(buf));
				g_PortAttach = 1;
            
			}
			//Full speed device attach
			else if((DWordRead(&ehci_regs->port_status[USB_Port]) & (PORT_LineStatus|PORT_CONNECT|PORT_PE))
				== (PORT_J_State|PORT_CONNECT)){
				DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_OWNER));
				DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_OWNER|PORT_CSC));
				HighSpeed_Owner = FALSE;
			}
         else if((DWordRead(&ehci_regs->port_status[USB_Port]) & (PORT_LineStatus|PORT_CONNECT|PORT_PE))
				== (PORT_K_State|PORT_CONNECT)){
				DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_OWNER));
				DWordWrite(&ehci_regs->port_status[USB_Port], (EHCI_PORT_INIT|PORT_OWNER|PORT_CSC));
				HighSpeed_Owner = FALSE;
			}
		}
		else{
      outport(0x80,0xff);
			p=buf;
			q=buf2;
			for(i=0;i<sizeof(buf2);i++)
				*p++ = *q++;
			*p++ = 10;
			*p++ = 13;
			UART_SendData(buf, sizeof(buf));
		
			g_PortAttach = 0;
			DeviceAttach_Init = FALSE;
		}
			
		DWordWrite(&ehci_regs->status, STS_PCD);	//Clear Port change detect
	}
	if (ints & STS_INT) {
		Do_TD_Complete = 1;
		DWordWrite(&ehci_regs->status, STS_INT);	//Clear USBINT
	}
	if (ints & STS_ERR) {
		if((ehci_Ctl_TD1->hw_token & 0xFF) != 0)
			ErrorCnt = 1;
		else if((ehci_Ctl_TD2->hw_token & 0xFF) != 0)
			ErrorCnt = 2;
		else if((ehci_Ctl_TD3->hw_token & 0xFF) != 0)
			ErrorCnt = 3;

		DWordWrite(&ehci_regs->status, STS_ERR);	//Clear USBINT
	}

Exit_INTA_ISR:
	outport(INT_EOI,0x8000);    // ;;write to EOI
}

void _interrupt UartIsr()
{
 	u16 status, temp;
 	static char buf[30];
 	char buf1[26]={"Doing Control transfer..."};
 	char buf2[26]={"Doing SCSI Command......."};
 	char buf3[26]={"Doing Bulk Loop.........."};
   char buf4[26]={"Doing Interrupt Loop....."};
   char buf5[26]={"Stop Interrupt Loop......"};
   char buf6[26]={"Doing Isochronous Loop..."};
   char buf7[26]={"Stop Isochronous Loop...."};
 	char *p, *q;
 	int i;

	status=inport(INT_INSERV);    //read in-service register
	
	//Check Interrupt Status
	status = inport(PCBBase+LSR);
	
	if(status & 0x01)
	{
		temp = inport(PCBBase+RBR);
		if(temp !=13) 
		{
			outport(PCBBase+THR, temp);
			
			UartBuf[UartCnt] = temp;
			UartCnt++;
		}
		else 
		{
			outport(PCBBase+THR, 10);
			outport(PCBBase+THR, 13);
			
			if(UartBuf[0] == 's')
			{
				if(UartBuf[1] == '1')
					DoTest_Mode(1);
				if(UartBuf[1] == '2')
					DoTest_Mode(2);
				if(UartBuf[1] == '3')
					DoTest_Mode(3);
				if(UartBuf[1] == '4')
					DoTest_Mode(4);
				if(UartBuf[1] == '5')
					DoTest_Mode(5);
			}
			else if(UartBuf[0] == 'e')
				EndTest_Mode();
			else if(UartBuf[0] == 'c')
			{
				if(UartBuf[1] == 's' && UartBuf[2] == 't')
				{
					p=buf;
					q=buf1;
					for(i=0;i<sizeof(buf1);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
					ControlCnt = 0;
					Init_ControlDescriptor();
               				OHCI_DeviceAttach_Init = FALSE;	//re initial
					ControlStart = TRUE;
				}
				else if(UartBuf[1] == 's' && UartBuf[2] == 'p')
					if(ControlStart == TRUE)
					{
						ControlStart = FALSE;
						SendDesc2UART();
					}
			}
			else if(UartBuf[0] == 'b')
			{
				if(UartBuf[1] == 's' && UartBuf[2] == 's' && UartBuf[3] == 't'){
					if((dev_des->idVendor != 0x1463) && (dev_des->idProduct != 0x05CB))	//Normal bulk SCSI command
						q=buf2;
					else
						q=buf3;
					
					p=buf;
					for(i=0;i<sizeof(buf2);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
					SCSICnt = 0;
					SCSIStart = TRUE;
				}
				else if(UartBuf[1] == 's' && UartBuf[2] == 's' && UartBuf[3] == 'p'){
					if(SCSIStart == TRUE){
						SCSIStart = FALSE;
						SendSCSI2UART();
					}
				}
			}
         else if(UartBuf[0] == 'i')
         {
         	if(UartBuf[1] == 's' && UartBuf[2] == 't')
				{
					p=buf;
					q=buf4;
					for(i=0;i<sizeof(buf4);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
               IntTransferStart = 1;
					
				}
            else if(UartBuf[1] == 's' && UartBuf[2] == 'p')
            {
            	p=buf;
					q=buf5;
					for(i=0;i<sizeof(buf5);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
               IntTransferStart = 0;
               IntInitOK=0;
               //disable periodic schedule
               DWordWrite(&ohci_regs->control, (OHCI_CONTROL_INIT | OHCI_USB_OPER));
               //unlink interrupt vector
            	for(i=0;i<32;i++)
               	ohci_hcca->int_table[i]=1;

            }
            else if(UartBuf[1] == 's' && UartBuf[2] == 'o' && UartBuf[3] == 's')
            {
               p=buf;
					q=buf6;
					for(i=0;i<sizeof(buf6);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
               ISOTransferStart=1;

            }
            else if(UartBuf[1] == 's' && UartBuf[2] == 'o' && UartBuf[3] == 'p')
            {
            	p=buf;
					q=buf7;
					for(i=0;i<sizeof(buf7);i++)
						*p++ = *q++;
					*p++ = 10;
					*p++ = 13;
					UART_SendData(buf, sizeof(buf));
               ISOTransferStart=0;
					ISOInitOK=0;
               //disable periodic schedule
               DWordWrite(&ohci_regs->control, (OHCI_CONTROL_INIT | OHCI_USB_OPER));

               //unlink interrupt vector
            	for(i=0;i<32;i++)
               	ohci_hcca->int_table[i]=0;
            }
         }

			for(i=0;i<10;i++)
				UartBuf[i] = 0;
			UartCnt = 0;
		}
	}
		
//Exit_UART1_ISR:	
	temp = temp;
	outport(INT_EOI,0x8000);    // ;;write to EOI
}

⌨️ 快捷键说明

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