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

📄 pe_usb.c

📁 FIC8120方案的 StartCell_Driver
💻 C
📖 第 1 页 / 共 5 页
字号:
	        			u16OTGTxRxCounter = u8OTGString40DescriptorEX[0];
			 		break;
			 		
			 	case 0x50:
			        	pu8OTGDescriptorEX = &u8OTGString50DescriptorEX[0];
	        			u16OTGTxRxCounter = u8OTGString50DescriptorEX[0];
			 		break;
			 		
			 	default:
	        			return FALSE;
			}
			 break;	
       	default:
	        	return FALSE;
	}

	if (u16OTGTxRxCounter > ControlOTGCmd.Length)
		u16OTGTxRxCounter = ControlOTGCmd.Length;

	eOTGCxCommand = CMD_SET_DESCRIPTOR;
	return TRUE;
}          	


///////////////////////////////////////////////////////////////////////////////
//		vGet_OTGconfiguration()
//		Description:
//			1. Send 1 bytes configuration value to host.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vGet_OTGconfiguration(void)
{
	INT8U u8Tmp[2];
	u8Tmp[0] = u8OTGConfigValue;
	vOTGCxFWr( u8Tmp, 1);

	eOTGCxFinishAction = ACT_DONE;
}


///////////////////////////////////////////////////////////////////////////////
//		bSet_OTGconfiguration()
//		Description:
//			1. Get 1 bytes configuration value from host.
//			2-1. if(value == 0) then device return to address state
//			2-2. if(value match descriptor table)
//					then config success & Clear all EP toggle bit
//			2-3	 else stall this command
//		input: none
//		output: TRUE or FALSE
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSet_OTGconfiguration(void)
{

	if ((INT8U)ControlOTGCmd.Value == 0)
	{
		u8OTGConfigValue = 0;
		mUsbCfgClr();
	}
	else
	{
		if (mUsbOTGHighSpeedST())					// First judge HS or FS??
		{
			if ((INT8U)ControlOTGCmd.Value > HS_CONFIGURATION_NUMBER)
				return FALSE;
			u8OTGConfigValue = (INT8U)ControlOTGCmd.Value;
			vOTGClrEPxFIFOxReg();
			vOTGFIFO_EPxCfg_HS();
			mUsbSOFMaskHS();
		}
		else
		{
			if ((INT8U)ControlOTGCmd.Value > FS_CONFIGURATION_NUMBER)
				return FALSE;
			u8OTGConfigValue = (INT8U)ControlOTGCmd.Value;
			vOTGFIFO_EPxCfg_FS();
			mUsbSOFMaskFS();
		}
		mUsbCfgSet();
		vOTGClrEPx();
	}

	if ((INT8U)ControlOTGCmd.Value == 1)			// Card Reader App.
	{
#if (OTG_AP_Satus	 == Bulk_AP)
	#if(Bulk_Satus == Bulk_FIFO_SingleDir)
		{
		 mUsbIntF2OUTEn();
		}
	#elif(Bulk_Satus == Bulk_FIFO_BiDir)	
              	

		mUsbIntF0OUTEn();
		mUsbIntF2INEn();
		mUsbIntF3OUTEn();
	#endif
		mUsbIntF0INDis();
#endif		


#if (OTG_AP_Satus	 == Interrupt_AP)
		mUsbIntF0INEn();	
		if(bOTGHighSpeed)
			mUsbIntF2OUTEn();	
		else
			mUsbIntF1OUTEn();		
#endif		


#if (OTG_AP_Satus == IsochronousIN_AP)
		
		mUsbIntF0INEn();
#endif

#if (OTG_AP_Satus == IsochronousOUT_AP)

		mUsbIntF0OUTEn();
#endif
	}

	eOTGCxFinishAction = ACT_DONE;
	return TRUE;
}


///////////////////////////////////////////////////////////////////////////////
//		bGet_OTGinterface()
//		Description:
//			Getting interface
//		input: none
//		output: TRUE or FALSE
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bGet_OTGinterface(void)
{
	INT8U u8Tmp[2];
	if (mUsbCfgST() == 0)
		return FALSE;

	// If there exists many interfaces, Interface0,1,2,...N,
	// You must check & select the specific one
	switch (u8OTGConfigValue)
	{
		#if (HS_CONFIGURATION_NUMBER >= 1)
		// Configuration 1
		case 1:
			if (ControlOTGCmd.Index > HS_C1_INTERFACE_NUMBER)
				return FALSE;
			break;
		#endif
		#if (HS_CONFIGURATION_NUMBER >= 2)
		// Configuration 2
		case 2:
			if (ControlOTGCmd.Index > HS_C2_INTERFACE_NUMBER)
				return FALSE;
			break;
		#endif
		default:
			return FALSE;
	}

	u8Tmp[0] = u8OTGInterfaceAlternateSetting;
	vOTGCxFWr( u8Tmp, 1);

	eOTGCxFinishAction = ACT_DONE;
	return TRUE;
}

///////////////////////////////////////////////////////////////////////////////
//		bSet_OTGinterface()
//		Description:
//			1-1. If (the device stays in Configured state)
//					&(command match the alternate setting)
//						then change the interface
//			1-2. else stall it
//		input: none
//		output: TRUE or FALSE
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSet_OTGinterface(void)
{
	if (mUsbCfgST() )
	{
//		if(u8OTGMessageLevel & MESS_INFO)
//		{
//	   		printf("L%x: EP0Cmd:", u8LineOTGCount ++);		
//		}
		// If there exists many interfaces, Interface0,1,2,...N,
		// You must check & select the specific one
		switch (ControlOTGCmd.Index)
		{
			case 0:	// Interface0
				if((INT8U)ControlOTGCmd.Value == u8ConfigOTGDescriptorEX[12])
				{
					u8OTGInterfaceValue = (INT8U)ControlOTGCmd.Index;
					u8OTGInterfaceAlternateSetting = (INT8U)ControlOTGCmd.Value;
					vOTGClrEPxFIFOxReg();
					if (mUsbOTGHighSpeedST())					// First judge HS or FS??
						vOTGFIFO_EPxCfg_HS();
					else
						vOTGFIFO_EPxCfg_FS();
					vOTGClrEPx();
					eOTGCxFinishAction = ACT_DONE;
					return TRUE;
				}
			case 1:	// Interface1
			case 2:	// Interface2
			default:
				break;
		}
	}
	return FALSE;

}



///////////////////////////////////////////////////////////////////////////////
//		bSynch_OTGframe()
//		Description:
//			1. If the EP is a Iso EP, then return the 2 bytes Frame number.
//				 else stall this command
//		input: none
//		output: TRUE or FALSE
///////////////////////////////////////////////////////////////////////////////
BOOLEAN bSynch_OTGframe(void)
{
	INT8S TransferType;
	INT16U u16Tmp;

	TransferType = -1;
	// Does the Endpoint support Isochronous transfer type? 
	switch(ControlOTGCmd.Index)
	{
		case 1:		// EP1
			TransferType = u8ConfigOTGDescriptorEX[22] & 0x03;
			break;
#if 0				
		case 2:		// EP2
			TransferType = u8ConfigOTGDescriptorEX[29] & 0x03;
			break;

		case 3:		// EP3
			TransferType = u8ConfigOTGDescriptorEX[36] & 0x03;
			break;
			
		case 4:		// EP4
			TransferType = u8ConfigOTGDescriptorEX[43] & 0x03;
			break;	

		case 5:		// EP5
			TransferType = u8ConfigOTGDescriptorEX[50] & 0x03;
			break;	
#endif			
		default:
			break;
	}

	if (TransferType == 1)	// Isochronous
	{
		u16Tmp = mUsbFrameNo();
		vOTGCxFWr( &u16Tmp, 2);

		eOTGCxFinishAction = ACT_DONE;
		return TRUE;
	}
	else
		return FALSE;
}


///////////////////////////////////////////////////////////////////////////////
//		vOTGEP0TxData()
//		Description:
//			1. Send data(max or short packet) to host.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTGEP0TxData(void)
{
	INT8U u8temp;

	if(u16OTGTxRxCounter < EP0MAXPACKETSIZE)
		u8temp = (INT8U)u16OTGTxRxCounter;
	else
		u8temp = EP0MAXPACKETSIZE;

	u16OTGTxRxCounter -= (INT16U)u8temp;

	// Transmit u8Temp bytes data
	   vOTGCxFWr( pu8OTGDescriptorEX, u8temp);
	pu8OTGDescriptorEX = pu8OTGDescriptorEX + u8temp;
	
	eOTGCxFinishAction = ACT_DONE;
	// end of the data stage
	if (u16OTGTxRxCounter == 0)
	{
		eOTGCxCommand = CMD_VOID;
	}
}

///////////////////////////////////////////////////////////////////////////////
//		vOTGEP0RxData()
//		Description:
//			1. Receive data(max or short packet) from host.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTGEP0RxData(void)
{
	INT8U u8temp;

	if(u16OTGTxRxCounter < EP0MAXPACKETSIZE)
		u8temp = (INT8U)u16OTGTxRxCounter;
	else
		u8temp = EP0MAXPACKETSIZE;

	u16OTGTxRxCounter -= (INT16U)u8temp;
	vOTGCxFRd(pu8OTGDescriptorEX , u8temp);	
	pu8OTGDescriptorEX = pu8OTGDescriptorEX + u8temp;

	// end of the data stage
	if (u16OTGTxRxCounter == 0)
	{
		eOTGCxCommand = CMD_VOID;
		eOTGCxFinishAction = ACT_DONE;
	}
}

///////////////////////////////////////////////////////////////////////////////
//		vOTGClrEPx()
//		Description:
//			1. Clear all endpoint Toggle Bit
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTGClrEPx(void)
{
	  INT8U u8ep;

	// Clear All EPx Toggle Bit
	for (u8ep = 1; u8ep <= FOTG200_Periph_MAX_EP; u8ep ++)
	{
		mUsbEPinRsTgSet(u8ep);
		mUsbEPinRsTgClr(u8ep);
	}
	for (u8ep = 1; u8ep <= FOTG200_Periph_MAX_EP; u8ep ++)
	{
		mUsbEPoutRsTgSet(u8ep);
		mUsbEPoutRsTgClr(u8ep);
	}
}

///////////////////////////////////////////////////////////////////////////////
//		vOTGClrEPxFIFOxReg()
//		Description:
//			1. Clear all endpoint & FIFO register setting
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTGClrEPxFIFOxReg(void)
{
	INT8U u8ep;
	for (u8ep = 1; u8ep <= FOTG200_Periph_MAX_EP; u8ep ++)
	{
		mUsbEPMxPtSzClr(u8ep,DIRECTION_IN);	
		mUsbEPMxPtSzClr(u8ep,DIRECTION_OUT);	
	}
	mUsbEPMapAllClr();
	mUsbFIFOMapAllClr();
	mUsbFIFOConfigAllClr();
}

///////////////////////////////////////////////////////////////////////////////
//		vOTG_ISO_SeqErr()
//		Description:
//			1. FOTG200 Device Detects High bandwidth isochronous Data PID sequential error.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTG_ISO_SeqErr(void)
{
	INT8U u8Tmp = mUsbIntIsoSeqErrRd();
	INT8U i;
	mUsbIntIsoSeqErrSetClr(u8Tmp);

	for(i = 1; i < 8; i ++)
	{
		if(u8Tmp & (BIT0 << i))
		{
			if(u8OTGMessageLevel & MESS_INFO)
			{
			   	printf("L%x: EP%x Isochronous Sequential Error\n", u8LineOTGCount ++, i);
			}
		}
	}

}

///////////////////////////////////////////////////////////////////////////////
//		vOTG_ISO_SeqAbort()
//		Description:
//			1. FOTG200 Device Detects High bandwidth isochronous Data PID sequential abort.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTG_ISO_SeqAbort(void)
{
	INT8U u8Tmp = mUsbIntIsoSeqAbortRd();		
	INT8U i;
	mUsbIntIsoSeqAbortSetClr(u8Tmp);

	for(i = 1; i < 8; i ++)
	{
		if(u8Tmp & (BIT0 << i))
		{
			if(u8OTGMessageLevel & MESS_INFO)
			{
			   	printf("L%x: EP%x Isochronous Sequential Abort\n", u8LineOTGCount ++, i);
			}
		}
	}

}

///////////////////////////////////////////////////////////////////////////////
//		vOTG_TX0Byte()
//		Description:
//			1. Send 0 byte data to host.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTG_TX0Byte(void)
{
	INT8U u8Tmp = mUsbIntTX0ByteRd();
	INT8U i;
	mUsbIntTX0ByteSetClr(u8Tmp);

	for(i = 1; i < 8; i ++)
	{
		if(u8Tmp & (BIT0 << i))
		{
			if(u8OTGMessageLevel & MESS_INFO)
			{
//			   	printf("L%x: EP%x IN data 0 byte to host\n", u8LineOTGCount ++, i);
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
//		vOTG_RX0Byte()
//		Description:
//			1. Receive 0 byte data from host.
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTG_RX0Byte(void)
{
	INT8U u8Tmp = mUsbIntRX0ByteRd();
	INT8U i;
	mUsbIntRX0ByteSetClr(u8Tmp);

	for(i = 1; i < 8; i ++)
	{
		if(u8Tmp & (BIT0 << i))
		{
			if(u8OTGMessageLevel & MESS_ERROR)
			{
			   	printf("L%x: EP%x OUT data 0 byte to Device\n", u8LineOTGCount ++, i);
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
//		vOTGCheckDMA()
//		Description: Check OTG DMA finish or error
//		input: none
//		output: none
///////////////////////////////////////////////////////////////////////////////
void vOTGCheckDMA(void)
{

  // UINT8 *pData;  

#if 0
	if(eUsbOTGMassStorageState == STATE_CB_DATA_IN)
		mUsbFIFODone(FIFO0);
#endif

⌨️ 快捷键说明

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