📄 hwinit.c
字号:
//usb_hs2_ulpi_interface_configure
temp = (DWORD *)&portsc;
*temp = INREG32(&pRegs->H2.PORTSC);
portsc.LS = 0x2;
portsc.PTS = 0x2;
DEBUGMSG(1, (TEXT("USBH2 *temp 0x%X\r\n"), *temp ));
// Keep this comment as to configure for the Full Speed Testing
// Configure this to Full Speed for testing purpose
//portsc.PFSC = 0x1;
//portsc.PTC = 0x6;
OUTREG32(&pRegs->H2.PORTSC, *temp);
//usb_h2_interrupt_enable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
ctrl.H2WIE = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
//usb_h2_power_mask_enable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
ctrl.H2PM = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
// usb_h2_tll_disable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
ctrl.H2DT = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
// usb_bypass_inactive
temp=(DWORD *)&ctrl;
*temp=0;
ctrl.BPE=1; // Bypass Enable bit, clear it
CLRREG32(&pRegs->USB_CTRL, *temp);
//uh2_setmode
temp = (DWORD *)&cmd;
*temp = INREG32(&pRegs->H2.USBCMD);
cmd.RST = 1;
OUTREG32(&pRegs->H2.USBCMD, *temp);
while (INREG32(&pRegs->H2.USBCMD)& (0x1 << 1));
temp = (DWORD *)&mode;
*temp = INREG32(&pRegs->H2.USBMODE);
mode.CM = 0x3;
OUTREG32(&pRegs->H2.USBMODE, *temp);
Sleep(10);
if ((INREG32(&pRegs->H2.USBMODE)& 0x3) != 0x3)
{
DEBUGMSG(1, (TEXT("USBMode setting failure\r\n")));
return;
}
//uh2_power_on_port1
if (INREG32(&pRegs->H2.HCSPARAMS) &(0x1 << 4))
{
temp = (DWORD *)&portsc;
*temp = INREG32(&pRegs->H2.PORTSC);
DEBUGMSG(1, (TEXT("USBH2 PORTSC 0x%X\r\n"), *temp ));
portsc.PP = 1;
OUTREG32(&pRegs->H2.PORTSC, *temp);
}
else
DEBUGMSG(1, (TEXT("Host does not control power\r\n")));
//uh2_controller_reset
temp=(DWORD *)&cmd;
*temp=0;
cmd.RST=1;
CLRREG32(&pRegs->H2.USBCMD, *temp);
*temp = INREG32(&pRegs->H2.USBCMD);
cmd.RST=1;
OUTREG32(&pRegs->H2.USBCMD, *temp);
while (INREG32(&pRegs->H2.USBCMD) & (0x1 << 1));
temp = (DWORD *)&mode;
*temp = INREG32(&pRegs->H2.USBMODE);
mode.CM = 0x3;
OUTREG32(&pRegs->H2.USBMODE, *temp);
Sleep(10);
while ((INREG32(&pRegs->H2.USBMODE)& 0x3) != 0x3);
//#define H2_TEST_MODE
#ifdef H2_TEST_MODE
DEBUGMSG(1, (TEXT("+H2_TestMode\r\n")));
// Disable async and periodic schedule
// Disable async and periodic schedule
temp = (DWORD *)&cmd;
*temp = 0;
*temp = INREG32(&pRegs->H2.USBCMD);
*temp = *temp & ~0x30;
OUTREG32(&pRegs->H2.USBCMD, *temp);
DEBUGMSG(1, (TEXT("USBCMD after setting = 0x%x\r\n"), INREG32(&pRegs->H2.USBCMD)));
// Go to suspend mode, please
temp = (DWORD *)&portsc;
*temp = 0;
*temp = INREG32(&pRegs->H2.PORTSC);
*temp |= 0x00000080;
OUTREG32(&pRegs->H2.PORTSC, *temp);
// Set to TEST_MODE, please
temp = (DWORD *)&portsc;
*temp = 0;
*temp = INREG32(&pRegs->H2.PORTSC);
portsc.PTC = 0x4; // PTC = 4 -> test pattern
OUTREG32(&pRegs->H2.PORTSC, *temp);
DEBUGMSG(1, (TEXT("PORTSC after setting = 0x%x\r\n"), INREG32(&pRegs->H2.PORTSC)));
// Set run/stop bit now
temp = (DWORD *)&cmd;
*temp = 0;
*temp = INREG32(&pRegs->H2.USBCMD);
cmd.RS = 1;
OUTREG32(&pRegs->H2.USBCMD, *temp);
DEBUGMSG(1, (TEXT("-H2_TestMode\r\n")));
// Richard asks me to do, loop forever!!
while(1);
#endif
return;
}
//-----------------------------------------------------------------------------
//
// Function: ConfigOTG
//
// This function is to configure the USB OTG Core.
//
// Parameters:
// pRegs - Pointer to 3 USB Core Registers
//
// Returns:
// NULL
//
//-----------------------------------------------------------------------------
static void ConfigOTG(CSP_USB_REGS *pRegs, int speed)
{
USB_PORTSC_T portsc;
USB_CTRL_T ctrl;
USB_USBMODE_T mode;
USB_USBCMD_T cmd;
DWORD *temp;
DEBUGMSG(1, (TEXT("...... CONFIG OTG ......\r\n")));
// Stop the controller first
{
USB_USBCMD_T cmd;
DWORD * temp = (DWORD *)&cmd;
*temp = INREG32(&pRegs->OTG.USBCMD);
DEBUGMSG(1, (TEXT("...... Stop the controller......*temp 0x%x\r\n"),*temp));
cmd.RS = 0;
OUTREG32(&pRegs->OTG.USBCMD, *temp);
while ((INREG32(&pRegs->OTG.USBCMD) & 0x1) == 0x1)
{
DEBUGMSG(1, (TEXT(" StopOTG USBCMD = 0x%x\r\n"), (INREG32(&pRegs->OTG.USBCMD))));
Sleep(100);
}
DEBUGMSG(1, (TEXT("...... After Stop the controller......*temp 0x%x\r\n"),*temp));
}
// Do a reset first no matter what
{
USB_USBCMD_T cmd;
DWORD * temp = (DWORD *)&cmd;
*temp = INREG32(&pRegs->OTG.USBCMD);
DEBUGMSG(1, (TEXT("...... Before reset the controller......*temp 0x%x\r\n"),*temp));
cmd.RST = 1;
OUTREG32(&pRegs->OTG.USBCMD, *temp);
while ((INREG32(&pRegs->OTG.USBCMD) & 0x1<<1) == (0x1<<1))
{
DEBUGMSG(1, (TEXT("ResetOTG USBCMD= 0x%x\r\n"), (INREG32(&pRegs->OTG.USBCMD))));
Sleep(100);
}
DEBUGMSG(1, (TEXT("...... After reset the controller......*temp 0x%x\r\n"),*temp));
}
//usb_otg_ulpi_interface_configure
temp = (DWORD *)&portsc;
*temp = INREG32(&pRegs->OTG.PORTSC);
DEBUGMSG(1, (TEXT("usb_otg_ulpi_interface_configure *temp 0X%X\r\n"), *temp));
if (speed == FULL_SPEED)
{
DEBUGMSG(1, (TEXT("+ConfigOTG Full speed \r\n")));
portsc.PTS = 0x3;
}
else
{
DEBUGMSG(1, (TEXT("+ConfigOTG High speed \r\n")));
portsc.LS = 0x2;
portsc.PTS = 0x2;
// Configure this to Full Speed for testing purpose
//portsc.PFSC = 0x1;
//portsc.PTC = 0x6;
}
OUTREG32(&pRegs->OTG.PORTSC, *temp);
DEBUGMSG(1, (TEXT("ConfigOTG: Write to USBCTRL register \r\n")));
// usb_ulpi_interrupt_enable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
if (speed == FULL_SPEED)
ctrl.OUIE = 0;
else
{
DEBUGMSG(1, (TEXT("usb_ulpi_interrupt_enable \r\n")));
ctrl.OUIE = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
}
// usb_otg_interrupt_enable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
DEBUGMSG(1, (TEXT("usb_otg_interrupt_enable \r\n")));
ctrl.OWIE = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
// usb_otg_power_mask_enable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
DEBUGMSG(1, (TEXT("usb_otg_power_mask_enable \r\n")));
ctrl.OPM = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
// usb_otg_tll_disable
temp = (DWORD *)&ctrl;
*temp = INREG32(&pRegs->USB_CTRL);
ctrl.H1DT = 1;
OUTREG32(&pRegs->USB_CTRL, *temp);
// usb_bypass_inactive
temp = (DWORD *)&ctrl;
*temp=0;
ctrl.BPE=1; // Bypass Enable bit, clear it
CLRREG32(&pRegs->USB_CTRL, *temp);
DEBUGMSG(1, (TEXT("ConfigOTG: USBCMD\r\n")));
// otg_setmode
temp = (DWORD *)&cmd;
*temp = INREG32(&pRegs->OTG.USBCMD);
cmd.RST = 1;
OUTREG32(&pRegs->OTG.USBCMD, *temp);
while (INREG32(&pRegs->OTG.USBCMD)& (0x1 << 1));
DEBUGMSG(1, (TEXT("ConfigOTG: USBMODE\r\n")));
temp = (DWORD *)&mode;
*temp = INREG32(&pRegs->OTG.USBMODE);
mode.CM = 0x3;
OUTREG32(&pRegs->OTG.USBMODE, *temp);
Sleep(10);
if ((INREG32(&pRegs->OTG.USBMODE)& 0x3) != 0x3)
{
DEBUGMSG(1, (TEXT("USBMode setting failure\r\n")));
return;
}
DEBUGMSG(1, (TEXT("ConfigOTG: PORTSC\r\n")));
// otg_power_on_port1
if (INREG32(&pRegs->OTG.HCSPARAMS) &(0x1 << 4))
{
DWORD mask = (0x1<<1) + (0x1<<3)+(0x1<<5);
CLRREG32(&pRegs->OTG.PORTSC, mask);
temp = (DWORD *)&portsc;
*temp = INREG32(&pRegs->OTG.PORTSC);
portsc.PP = 1;
OUTREG32(&pRegs->OTG.PORTSC, *temp);
}
else
DEBUGMSG(1, (TEXT("Host does not control power\r\n")));
/////////////////////////////////////////////////////////////////////////////////////////////
//#define OTG_TEST_MODE 1
DEBUGMSG(1, (TEXT("ConfigOTG: Stop the controller first ....\r\n")));
{
// Stop the controller first
DWORD *temp = (DWORD *)&cmd;
*temp = INREG32(&pRegs->OTG.USBCMD);
DEBUGMSG(1, (TEXT("ConfigOTG: Reset the controoler ....&pRegs->OTG.USBCMD 0x%x *temp 0x%x\r\n"),&pRegs->OTG.USBCMD, *temp));
cmd.RS=0;
OUTREG32(&pRegs->OTG.USBCMD, *temp);
DEBUGMSG(1, (TEXT("after Reset controller ....*temp 0x%x\r\n"), *temp));
Sleep(100);
DEBUGMSG(1, (TEXT("after sleep controller ....*temp 0x%x\r\n"), *temp));
}
// Handshake to wait for Halted
while ((INREG32(&pRegs->OTG.USBSTS) & 0x1000) != 0x1000);
{
DEBUGMSG(1, (TEXT(" OTG.USBSTS 0x%x\r\n"),pRegs->OTG.USBSTS ));
}
DEBUGMSG(1, (TEXT("ConfigOTG: USBINTR\r\n")));
// Enable interrupts
OUTREG32(&pRegs->OTG.USBINTR, 0x5ff);
DEBUGMSG(1, (TEXT("-ConfigOTG\r\n")));
}
//-----------------------------------------------------------------------------
//
// Function: gfnGetOTGGroup
//
// This function is to return the OTG Group
//
// Parameters:
// NULL
//
// Returns:
// the OTG Group Name, that is used for creating the mode switching event semaphore
// the value is reading from registry
//
//-----------------------------------------------------------------------------
TCHAR *gfnGetOTGGroup(void)
{
return (gszOTGGroup);
}
//-----------------------------------------------------------------------------
//
// Function: gfnIsOTGSupport
//
// This function is whether to have OTG support
//
// Parameters:
// NULL
//
// Returns:
// 0 - Not OTG Support, 1 - OTG Support
//
//-----------------------------------------------------------------------------
DWORD gfnIsOTGSupport(void)
{
DEBUGMSG(1, (TEXT("#### will return gdwOTGSupport = 0x%x\r\n"), gdwOTGSupport));
return gdwOTGSupport;
}
//-----------------------------------------------------------------------------
//
// Function: InitializeTransceiver
//
// This function is to configure the USB Transceiver, register the interrupt
//
// Parameters:
// NULL
//
// Returns:
// TRUE - success, FALSE - failure
//
//-----------------------------------------------------------------------------
BOOL InitializeTransceiver(PCSP_USB_REGS* regs, DWORD * phyregs,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -