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

📄 lib596.c

📁 utisoftware c code for linux,机卡分离方案。
💻 C
字号:
#include "linux/module.h"
#include  "defusr.h"
#include  "macusr.h"
#include  "libassp.h"
#include  "extern.h"
#include "def_ep.h"


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Reset default control pipe
 *-----------------------------------------------------------------------------
 * Declaration	: void resetDCP(void)
 *-----------------------------------------------------------------------------
 * Argument		: void
 *-----------------------------------------------------------------------------
 * Return		: void
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
void resetDCP(void)
{
	USBWR(CFIFOSEL, DCPtbl[0]);						/* CFIFO Port Select Register  (0x1E) */
	USBWR(DCPCFG,   DCPtbl[1]);						/* DCP Configuration Register  (0x5C) */
	USBWR(DCPMAXP,  UsbMaxPacketSize + UsbAddress);	/* DCP Maxpacket Size Register (0x5E) */

	/*
	 * DCP FIFO Clear, etc ...
	 */
}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Reset endpoint
 *-----------------------------------------------------------------------------
 * Declaration	: void resetEP(U8 Con_Num)
 *-----------------------------------------------------------------------------
 * Argument		: U8 Con_Num		; Configuration Number
 *-----------------------------------------------------------------------------
 * Return		: void
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
void resetEP(U8 Con_Num)
{
	U16		i, pipe, buf;
	U16		*tbl;
	REGP	*reg;

	/* Pipe Setting */
	if( isHiSpeed() == YES ) {
		tbl = (U16 *)(EPtbl_Hi);
	} else {
		tbl = (U16 *)(EPtbl_Full);
	}

	PipeTblClear();

	for( i = 0; tbl[i] != 0xFFFF; i += EPL ) {
		pipe = (tbl[i + 0] & CURPIPE);				/* Pipe Number */
		PipeTbl[pipe] = (U8)(tbl[i + 1] & EPNUM);	/* Endpoint Number */

		/* Interrupt Disable */
		USB_CLR_PAT(BRDYENB, BIT(pipe));			/* Ready Interrupt Disable */
		USB_CLR_PAT(NRDYENB, BIT(pipe));			/* NotReady Interrupt Disable */
		USB_CLR_PAT(BEMPENB, BIT(pipe));			/* Empty/SizeErr Interrupt Disable */

		/* PID = NAK */
		reg = (REGP *)(PIPECTR_ADR + ((pipe-1) * 2));
		USBWR(*reg, PID_NAK);						/* PID=NAK */
		USB_SET_PAT(*reg, ACLRM);
		USB_CLR_PAT(*reg, ACLRM);
		/* CurrentPIPE Clear */
		USBRD(CFIFOSEL,  buf);
		if( (buf & CURPIPE) == pipe )
			USB_CLR_PAT(CFIFOSEL,  CURPIPE);
		USBRD(D0FIFOSEL, buf);
		if( (buf & CURPIPE) == pipe )
			USB_CLR_PAT(D0FIFOSEL, CURPIPE);
		USBRD(D1FIFOSEL, buf);
		if( (buf & CURPIPE) == pipe )
			USB_CLR_PAT(D1FIFOSEL, CURPIPE);

		/* PIPE Configuration */
		USBWR(PIPESEL,  pipe);
		USBWR(PIPECFG,  tbl[i+1]);
		USBWR(PIPEBUF,  tbl[i+2]);
		USBWR(PIPEMAXP, tbl[i+3] | UsbAddress);
		USBWR(PIPEPERI, tbl[i+4]);

		/* Change peripheral dir -> host dir */
		if( (tbl[i+1] & DIR) == DIR_P_IN )
			USB_MDF_PAT(PIPECFG, DIR_H_IN,  DIR);	/* DIR_P_IN  -> DIR_H_IN */
		else
			USB_MDF_PAT(PIPECFG, DIR_H_OUT, DIR);	/* DIR_P_OUT -> DIR_H_OUT */

		/* Buffer Clear */
		USBWR(*reg, ACLRM);							/* ACLRM=1 */
		delay_10us(1);								/* Wait 100ns */
		USBWR(*reg, SQCLR);							/* ACLR=0, SQCLR=1 */

		/* init Global */
		Buffer_Write_Data_Flag[pipe] = DATA_NONE;
		Buffer_Read_Data_Flag[pipe]  = DATA_NONE;
		Buffer_Read_Data_Size[pipe]  = 0;

	}

#if 1
	/*DMA */
/*		USBWR(DMA0CFG,BBURST|SPLIT_DACK_ONLY|PKTM|DENDE);
		USBWR(DMA1CFG,BBURST|SPLIT_DACK_ONLY|DENDE);
		USBWR(D0FIFOSEL,DCLRM|DREQE|MBW_8|PIPE1);
		USBWR(D1FIFOSEL,DCLRM|DREQE|MBW_8|PIPE2);*/
		
		USBWR(DMA1CFG,BBURST|SPLIT_DACK_ONLY|PKTM|DENDE);
		USBWR(DMA0CFG,BBURST|SPLIT_DACK_ONLY|DENDE);
		USBWR(D1FIFOSEL,DCLRM|DREQE|MBW_8|PIPE1);
		USBWR(D0FIFOSEL,DCLRM|DREQE|MBW_8|PIPE2);
		
/*		ClearIntR(PIPE1);
		EnableIntR(PIPE1);
		ClearIntR(PIPE2);
		EnableIntR(PIPE2);*/
		
		ClearIntNR(PIPE1);
		EnableIntNR(PIPE1);
		ClearIntNR(PIPE2);
		EnableIntNR(PIPE2);

		SetEpPid(PIPE2, PID_BUF);
		SetEpPid(PIPE1, PID_BUF);
	/*	DMA_RW (PIPE2); */
#endif

#if 1
	/*ClearIntR(PIPE6);
	EnableIntR(PIPE6);*/
	ClearIntR(PIPE7);
	EnableIntR(PIPE7);								/* Enable Ready Interrupt */
#endif


}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Return IN data size
 *-----------------------------------------------------------------------------
 * Declaration	: U16 dataInSize(U16 Pipe)
 *-----------------------------------------------------------------------------
 * Argument		: U16				; Pipe Number
 *-----------------------------------------------------------------------------
 * Return		: U16				; IN Data Size
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
U16 dataInSize(U16 Pipe)
{
	U16	size, buffer;

	USBWR(PIPESEL, Pipe);							/* pipe select */
	USBRD(PIPECFG, buffer);							/* read CNTMD */
	if( buffer & CNTMD ) {
		USBRD(PIPEBUF, buffer);						/* read Buf_size */
		size = ((buffer >> 10) + 1) * 64;			/* Buffer Size */
	} else {
		USBRD(PIPEMAXP, buffer);					/* read MXPS */
		size = (buffer & MXPS);						/* Max Packet Size */
	}
	return size;
}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Get max packet size
 *-----------------------------------------------------------------------------
 * Declaration	: U16 getMaxPacketSize(U16 Pipe)
 *-----------------------------------------------------------------------------
 * Argument		: U16				; Pipe Number
 *-----------------------------------------------------------------------------
 * Return		: U16				; Max Packet Size
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
U16 getMaxPacketSize(U16 Pipe)
{
	U16	mxps, buffer;

	USBWR(PIPESEL, Pipe);							/* pipe select */
	USBRD(PIPEMAXP, buffer);						/* read MXPS */
	mxps = (buffer & MXPS);							/* Max Packet Size */
	return mxps;
}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Return DCP max packet size
 *-----------------------------------------------------------------------------
 * Declaration	: U16 dcpMaxPacketSize(void)
 *-----------------------------------------------------------------------------
 * Argument		: void
 *-----------------------------------------------------------------------------
 * Return		: U16				; Max Packet Size
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
U16 dcpMaxPacketSize(void)
{
	U16	max_size, cntmode, buffer;

	USBRD(DCPCFG, cntmode);
	if( cntmode & CNTMD ) {							/* continuation transmit */
		max_size = 256;								/* Buffer Size */
	} else {										/* not continuation transmit */
		USBRD(DCPMAXP, buffer);
		max_size = buffer & MAXP;					/* MaxPacketSize */
	}
	return max_size;
}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: reset USB ASSP
 *-----------------------------------------------------------------------------
 * Declaration	: void resetAssp(void)
 *-----------------------------------------------------------------------------
 * Argument		: void
 *-----------------------------------------------------------------------------
 * Return		: void
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
void resetAssp(void)
{
#if SPEED_MODE == HI_ENABLE
	USB_SET_PAT(SYSCFG,  HSE);						/* Hi-Speed Mode */
#endif

#if PCUT_MODE == PCUT_USE
	USB_SET_PAT(SYSCFG,  ATCKM);					/* Auto Clock Mode enable */
#else
  #if ATCKM_MODE == ATCKM_USE
	USB_SET_PAT(SYSCFG,  ATCKM);					/* Auto Clock Mode enable */
  #endif
#endif

#if FIFO_ENDIAN == BIG_ENDIAN
	USB_SET_PAT(PINCFG,  BIGEND);
#endif

#if VIF_SET == VIF3
	USB_SET_PAT(PINCFG,  LDRV);						/* 3.3V -> LDRV=1 */
#endif

#if 0
	USB_SET_PAT(INTENB1, INTL);						/* INT level sense */

	USB_SET_PAT(SOFCFG,  SOF_125US);				/* SOF 125us Frame Signal */
	USB_SET_PAT(SOFCFG,  SOF_1MS);					/* SOF   1ms Frame Signal */

	USB_SET_PAT(FRMNUM,  SOFRM);					/* SOF output mode */

	USB_SET_PAT(DMA0CFG, DREQA);					/* DREQ High Active */
	USB_SET_PAT(DMA1CFG, DREQA);
	USB_SET_PAT(DMA0CFG, DACKA);					/* DACK High Active */
	USB_SET_PAT(DMA1CFG, DACKA);
	USB_SET_PAT(DMA0CFG, DENDA);					/* DEND High Active */
	USB_SET_PAT(DMA1CFG, DENDA);
#endif
}


#if PCUT_MODE == PCUT_USE
U16	usbRHST;
U16	usbDVSQ;
U16	usbADDR;
U16	usbSQMON;

/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Register Backup
 *-----------------------------------------------------------------------------
 * Declaration	: void reg_backup(void)
 *-----------------------------------------------------------------------------
 * Argument		: void
 *-----------------------------------------------------------------------------
 * Return		: void
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
void reg_backup(void)
{
	U16	buf;

	USBRD(RECOVER, usbADDR);						/* USB address */
	USBRD(INTSTS0, usbDVSQ);						/* USB device state */
	USBRD(DVSTCTR, usbRHST);						/* USB speed */

	usbSQMON = 0x00;								/* SQMON bit Backup */
	USBRD(PIPE1CTR, buf); if( buf & SQMON ) usbSQMON |= 0x02;
	USBRD(PIPE2CTR, buf); if( buf & SQMON ) usbSQMON |= 0x04;
	USBRD(PIPE3CTR, buf); if( buf & SQMON ) usbSQMON |= 0x08;
	USBRD(PIPE4CTR, buf); if( buf & SQMON ) usbSQMON |= 0x10;
	USBRD(PIPE5CTR, buf); if( buf & SQMON ) usbSQMON |= 0x20;
	USBRD(PIPE6CTR, buf); if( buf & SQMON ) usbSQMON |= 0x40;
	USBRD(PIPE7CTR, buf); if( buf & SQMON ) usbSQMON |= 0x80;
}


/*""FUNC COMMENT""*************************************************************
 *-----------------------------------------------------------------------------
 * Function		: Register Recover
 *-----------------------------------------------------------------------------
 * Declaration	: void reg_recover(void)
 *-----------------------------------------------------------------------------
 * Argument		: void
 *-----------------------------------------------------------------------------
 * Return		: void
 *-----------------------------------------------------------------------------
 * Note			:
 *-----------------------------------------------------------------------------
 *""FUNC COMMENT END""********************************************************/
void reg_recover(void)
{
	U16	buf;

	if( (usbDVSQ & DVSQS) != DS_POWR ) {
		buf	 = usbADDR & USBADDR;					/* USB address */
		buf	|= ((usbDVSQ & DVSQS) << 4);			/* USB device state */
		if( (usbRHST & RHST) == HSMODE )			/* USB speed */
			buf |= STSR_HI;
		USBWR(RECOVER, buf);
	}

	resetAssp();
	resetDCP();
	if( ConfigNum != 0 )
		resetEP(ConfigNum);

	if( usbSQMON & 0x02 ) USBWR(PIPE1CTR, SQSET);	/* SQMON bit Recover */
	if( usbSQMON & 0x04 ) USBWR(PIPE2CTR, SQSET);
	if( usbSQMON & 0x08 ) USBWR(PIPE3CTR, SQSET);
	if( usbSQMON & 0x10 ) USBWR(PIPE4CTR, SQSET);
	if( usbSQMON & 0x20 ) USBWR(PIPE5CTR, SQSET);
	if( usbSQMON & 0x40 ) USBWR(PIPE6CTR, SQSET);
	if( usbSQMON & 0x80 ) USBWR(PIPE7CTR, SQSET);

	enableINT_Assp();								/* Interrupt Enable */
}
#endif

⌨️ 快捷键说明

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