📄 usbsig.c
字号:
uart_put_str( "Usb reset ----------------------------------------------------" );
#endif
USB_SET_PAT(DVSTCTR, USBRST); /* USB Bus Reset Enable */
delay_xms(50); /* wait */
USB_SET_PAT(DVSTCTR, UACT); /* SOF out enable */
USB_CLR_PAT(DVSTCTR, USBRST); /* USB Bus Reset Disable */
MemClear();
UsbMaxPacketSize = 64; /* Hi-Speed 64byte */
resetDCP(); /* Default Control PIPE reset */
USBRD(DVSTCTR, buffer);
buffer = buffer & RHST;
#ifdef UART_USE
uart_put_cr( " PASS!" );
uart_put_str( " Reset handshake result: " );
switch( buffer ) {
case HSMODE: uart_put_cr( "Hi-speed" ); break;
case FSMODE: uart_put_cr( "Full-speed" ); break;
default: uart_put_cr( "\033[41mERROR\033[0m" ); break;
}
uart_put_cr( "" );
#endif
return(buffer);
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB remotewakeup
*-----------------------------------------------------------------------------
* Declaration : void usb_remotewakeup(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_remotewakeup(void)
{
U16 buf;
/* SET FEATURE */
if( ControlNoWrite(0x0300, 0x0001, 0x0000, 0x0000) != SACK )
return; /* Device is not support RemoteWakeup */
delay_xms(1); /* wait */
USB_SET_PAT(DVSTCTR, RWUPE); /* RWUPE=1 */
USB_CLR_PAT(DVSTCTR, UACT); /* SOF off (suspend) */
USB_CLR_STS(INTSTS1, BCHG); /* Status Clear */
delay_xms(3); /* wait */
/* Wait BUS condition change */
while( 1 ) {
USBRD(INTSTS1, buf);
if( buf & BCHG )
break;
}
delay_xms(20); /* wait */
USB_CLR_PAT(DVSTCTR, RESUME); /* RESUME bit off */
USB_CLR_PAT(DVSTCTR, RWUPE); /* RWUPE=0 */
USB_SET_PAT(DVSTCTR, UACT); /* SOF on */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB resume
*-----------------------------------------------------------------------------
* Declaration : void usb_resume(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_resume(void)
{
#ifdef UART_USE
// uart_put_cr( "Resume -------------------------------------------------------" );
#endif
startClock();
USB_SET_PAT(DVSTCTR, RESUME); /* RESUME bit on */
delay_xms(20); /* wait */
USB_CLR_PAT(DVSTCTR, RESUME); /* RESUME bit off */
USB_SET_PAT(DVSTCTR, UACT); /* SOF on */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB suspend
*-----------------------------------------------------------------------------
* Declaration : void usb_suspend(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_suspend(void)
{
#ifdef UART_USE
// uart_put_cr( "Suspend ------------------------------------------------------" );
#endif
USB_CLR_PAT(DVSTCTR, UACT); /* SOF OFF */
stopClock();
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Wait USB ASSP ready
*-----------------------------------------------------------------------------
* Declaration : void waitAssp(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void waitAssp(void)
{
register U16 buf;
do {
USBWR(SYSCFG, USBE);
USBRD(SYSCFG, buf);
} while( (buf & USBE) != USBE );
USBWR(SYSCFG, 0x0); /* SW reset */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Start Clock
*-----------------------------------------------------------------------------
* Declaration : void startClock(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void startClock(void)
{
#if ATCKM_MODE == ATCKM_USE
waitClockReady();
#else
delay_1ms(); /* wait 1.5ms */
delay_1ms();
restartClock();
#endif
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Restart Clock
*-----------------------------------------------------------------------------
* Declaration : void restartClock(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void restartClock(void)
{
USB_SET_PAT(SYSCFG, RCKE); /* RCK Enable */
USB_SET_PAT(SYSCFG, PLLC); /* PLL Control Enable */
delay_10us(1); /* wait 10us */
USB_SET_PAT(SYSCFG, SCKE); /* SCLK Enable */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Stop Clock
*-----------------------------------------------------------------------------
* Declaration : void stopClock(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void stopClock(void)
{
USB_CLR_PAT(SYSCFG, SCKE); /* SCLK Disable */
delay_10us(1); /* wait 300ns */
USB_CLR_PAT(SYSCFG, PLLC); /* PLL Control Disable */
USB_CLR_PAT(SYSCFG, RCKE); /* RCK Disable */
delay_10us(1); /* wait 300ns */
}
#if ATCKM_MODE == ATCKM_USE
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Wait USB ASSP clock ready
*-----------------------------------------------------------------------------
* Declaration : void waitClockReady(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void waitClockReady(void)
{
register U16 buf;
while( 1 ) {
USBRD(SYSCFG, buf);
if( (buf & SCKE) == SCKE ) {
break; /* SCLK ON */
}
}
}
#endif
void TSPIP_Config_SD(void)
{
U16 buff;
USBWR(FPGA4, 0x0200);
USBRD(FPGA0, buff);
USBWR(FPGA1, 0x0001);
USBRD(FPGA0, buff);
USBWR(FPGA0, 0xE032);
USBRD(FPGA0, buff);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -