📄 usbsig.c
字号:
#include "defusr.h"
#include "macusr.h"
#include "def596.h"
#include "extern.h"
#include "libassp.h"
//#include "sttbx.h"
#include <linux/kernel.h>
extern U8 UsbDeviceTS[4];
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Initialize USB ASSP
*-----------------------------------------------------------------------------
* Declaration : void initAssp(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_enumerate(void)
{
// U16 stat;
usb_busreset();
delay_xms(50); /* wait */
/* GET DESCRIPTOR (Device descriptor) (8bytes) */
if( ControlRead(0x0680, 0x0100, 0x0000, 8, (U8 *)UsbDeviceDesc) != SACK )
return;
UsbMaxPacketSize = (U16)UsbDeviceDesc[7]; /* Max Packet Size */
resetDCP(); /* Default Control PIPE reset */
/* ---------------------------------------------------- */
/* GET DESCRIPTOR (Device descriptor) (18bytes) */
/* */
/* Please write a code here. */
/* ---------------------------------------------------- */
/* ---------------------------------------------------- */
/* GET DESCRIPTOR (Configuration descriptor) (255bytes) */
/* */
/* Please write a code here. */
/* ---------------------------------------------------- */
if (ControlRead (0x0680,0x0200,0x0000,256,(U8 *)UsbConfigDesc) !=SACK)
return;
if (ControlRead (0x0680,0x0100,0x0000,18,(U8 *)UsbDeviceDesc) !=SACK)
return;
/* ---------------------------------------------------- */
/* SET ADDRESS (USB_ADR) */
/* */
/* Please write a code here. */
/* ---------------------------------------------------- */
delay_xms(50); /* wait */
if (ControlNoWrite(0x0500,0x0001,0x0000,0) != SACK)
return;
UsbAddress = USB_ADR << 14; /* Set Address */
resetDCP(); /* Default Control PIPE reset */
delay_xms(200); /* wait */
/* SET CONFIGURATION (1) */
/* */
/* Please write a code here. */
/* ---------------------------------------------------- */
if (ControlNoWrite(0x0900,(U16) UsbConfigDesc[5],0x0000,0) != SACK)
return;
delay_xms(200);
if (ControlRead (0x0cc0,0x0,0x0472,1,(U8 *)UsbDeviceVer) !=SACK)
return;
delay_xms(200);
ConfigNum = 1;
if (ControlWrite(0x0c40,0,0x477,4,(U8 *)UsbDeviceTS)!= SACK)
return;
delay_xms(200);
resetEP(ConfigNum); /* PIPE1-7 reset */
BchgFlg = NO;
printk(KERN_INFO "enumerate success\n");
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Initialize USB ASSP
*-----------------------------------------------------------------------------
* Declaration : void initAssp(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void initAssp(void)
{
USB_MDF_PAT(SYSCFG, XIN, XTAL); /* Crystal Select */
USB_SET_PAT(SYSCFG, USBE); /* USB module operation enable */
resetAssp(); /* ASSP Initialize */
enableINT_Assp(); /* Interrupt Enable */
USB_SET_PAT(SYSCFG, (DCFM | DMRPD | FSRPC)); /* HOST mode */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : Check Atacch
*-----------------------------------------------------------------------------
* Declaration : U16 ChkAttach(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : U16 ; ON : Attached
* : ; OFF : not Attached
*-----------------------------------------------------------------------------
* Note : Please change for your SYSTEM
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
U16 ChkAttach(void)
{
register U16 buf1, buf2, buf3;
BchgFlg = YES;
#if 0
do {
USBRD(SYSSTS, buf1);
delay_xms(50);
USBRD(SYSSTS, buf2);
delay_xms(50);
USBRD(SYSSTS, buf3);
STTBX_Print(("BchgFlg=%d\n", BchgFlg));
} while( ((buf1 & LNST) != (buf2 & LNST)) || ((buf1 & LNST) != (buf3 & LNST)) );
if( (buf1 & LNST) == 0x01 )
return YES;
return NO;
#endif
/* return NO; */
#if 1
USBRD(SYSSTS, buf1);
delay_xms(50);
USBRD(SYSSTS, buf2);
delay_xms(50);
USBRD(SYSSTS, buf3);
if( ((buf1 & LNST) != (buf2 & LNST)) || ((buf1 & LNST) != (buf3 & LNST)) )
return NO;
if( (buf1 & LNST) == 0x01 )
return YES;
return NO;
#endif
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB attach
*-----------------------------------------------------------------------------
* Declaration : void usb_attach(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_attach(void)
{
#ifdef UART_USE
// uart_put_cr( "Attach -------------------------------------------------------" );
#endif
USB_CLR_STS(INTSTS1, BCHG); /* Status Clear */
USB_CLR_PAT(INTENB1, BCHGE); /* disable */
#if PCUT_MODE
resetAssp(); /* ASSP Initialize */
enableINT_Assp(); /* Interrupt Enable */
PcutMode = NO;
#else
USB_SET_PAT(SYSCFG, XCKE); /* External Clock Enable */
startClock();
#endif
enableINT_Assp(); /* Interrupt Enable */
/* FIFO Clear, etc ... */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB detach
*-----------------------------------------------------------------------------
* Declaration : void usb_detach(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : void
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
void usb_detach(void)
{
#ifdef UART_USE
// uart_put_cr( "Detach -------------------------------------------------------" );
#endif
ConfigNum = 0;
UsbAddress = 0;
stopClock();
#if PCUT_MODE == PCUT_USE
PcutMode = YES;
USB_SET_PAT(SYSCFG, PCUT); /* PCUT Enable */
#else
USB_CLR_PAT(SYSCFG, XCKE); /* External Clock Disable */
USB_CLR_PAT(SYSCFG, USBE); /* USB Reset */
USB_SET_PAT(SYSCFG, USBE); /* USB Enable */
enableINT_Assp(); /* Interrupt Enable */
#endif
USB_CLR_STS(INTSTS1, BCHG); /* Status Clear */
USB_SET_PAT(INTENB1, BCHGE); /* enable */
}
/*""FUNC COMMENT""*************************************************************
*-----------------------------------------------------------------------------
* Function : USB bus reset
*-----------------------------------------------------------------------------
* Declaration : U16 usb_busreset(void)
*-----------------------------------------------------------------------------
* Argument : void
*-----------------------------------------------------------------------------
* Return : U16 ; RHST
*-----------------------------------------------------------------------------
* Note :
*-----------------------------------------------------------------------------
*""FUNC COMMENT END""********************************************************/
U16 usb_busreset(void)
{
U16 buffer;
#ifdef UART_USE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -