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

📄 chap_9.c

📁 ISP1181MCU_FW_Ver1.01.zip是基于飞利浦ISP1181的USB HOST开发板固件源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	UCHAR   bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
	USHORT  wFeature = ControlData.DeviceRequest.wValue;

	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	if(dir)
		Chap9_StallEP0InControlRead();

	if( ControlData.DeviceRequest.wLength == 0 )
	{
		switch(bRecipient)
		{
		case USB_RECIPIENT_DEVICE:
			if(wFeature == USB_FEATURE_REMOTE_WAKEUP)
			{
				bD13flags.bits.remote_wakeup = 0;
				Chap9_SingleTransmitEP0(0, 0);
			}
			else
				Chap9_StallEP0InControlWrite();

			break;
		case USB_RECIPIENT_ENDPOINT:
			if(wFeature == USB_FEATURE_ENDPOINT_STALL)
			{
				if( ControlData.DeviceRequest.wIndex == 0x00 )
					endp = -1;
				else
					endp = (UCHAR)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);

				Hal4D13_SetEndpointStatus(endp+1, 0);
				Chap9_SingleTransmitEP0(0, 0);
			}
			else
				Chap9_StallEP0InControlWrite();
			break;
		default:
			Chap9_StallEP0InControlWrite();
			break;
		}
	}
	else
		Chap9_StallEP0InControlWrite();
}

void Chap9_SetFeature(void)
{
	UCHAR   endp;
	UCHAR   bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
	USHORT  wFeature = ControlData.DeviceRequest.wValue;

	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;

	if(dir)
		Chap9_StallEP0InControlRead();

	if( ControlData.DeviceRequest.wLength == 0 )
	{
		switch(bRecipient)
		{
		case USB_RECIPIENT_DEVICE:
			if(wFeature == USB_FEATURE_REMOTE_WAKEUP)
			{
				bD13flags.bits.remote_wakeup = 1;
				Chap9_SingleTransmitEP0(0, 0);
			}
			else
			{
				Chap9_StallEP0InControlWrite();
			}
			break;
		case USB_RECIPIENT_ENDPOINT:
			if( wFeature == USB_FEATURE_ENDPOINT_STALL)
			{
				if( ControlData.DeviceRequest.wIndex == 0x00 )
					endp = -1;
				else
					endp = (UCHAR)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);

				Hal4D13_SetEndpointStatus(endp+1, D13REG_EPSTS_STALL);
				Chap9_SingleTransmitEP0(0, 0);
			}
			else
			{
				Hal4D13_SetEndpointStatus(endp+1, 0);
				Chap9_SingleTransmitEP0(0, 0);
			}
			break;
		default:
			Chap9_StallEP0InControlWrite();
			break;
		}
	}
	else
		Chap9_StallEP0InControlWrite();
}

void Chap9_SetAddress(void)
{
//Jan12, always disable interrupt of 8051
//			only enable when necessary: LowerIRQL()
//Feb6, the new device address is activated when the host ACK the empty pkt
//	Hal4D13_GetAddress();

		Hal4D13_SetAddressEnable((UCHAR)(ControlData.DeviceRequest.wValue &
				DEVICE_ADDRESS_MASK), 1);
		Chap9_SingleTransmitEP0(0, 0);
//Feb6
//	Hal4D13_GetAddress();

/*
	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;

	if(dir)
		Chap9_StallEP0InControlRead();

	if( ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 0 )
	{
//New address have to be valid after status stage.
		RaiseIRQL();
		if(!ControlData.Abort)
		{
			Hal4D13_SetAddressEnable((UCHAR)(ControlData.DeviceRequest.wValue &
				DEVICE_ADDRESS_MASK), 1);
		}
		LowerIRQL();

		
		// Minimize the MISSING Window for SETUP Packet
		// Here give a chance to ISR whose interrupt is caused by Setup Packet
	
		Chap9_SingleTransmitEP0(0, 0);
	}
	else
		Chap9_StallEP0InControlWrite();
*/

}  


void Chap9_GetDescriptor(void)
{
	UCHAR   bDescriptor = MSB(ControlData.DeviceRequest.wValue);
	UCHAR   bDescriptorIndex = LSB(ControlData.DeviceRequest.wValue);

	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	if(!(dir))
		Chap9_StallEP0InControlWrite();

	switch(bDescriptor)
	{
	case USB_DEVICE_DESCRIPTOR_TYPE:
		Chap9_BurstTransmitEP0((unsigned char code *)&DeviceDescr, sizeof(USB_DEVICE_DESCRIPTOR));
		break;
	case USB_CONFIGURATION_DESCRIPTOR_TYPE:
		Chap9_BurstTransmitEP0((unsigned char code *)&ConfigDescr, CONFIG_DESCRIPTOR_LENGTH);
		break;
	case USB_STRING_DESCRIPTOR_TYPE:
		switch(bDescriptorIndex)
		{
		case STR_INDEX_LANGUAGE:
			Chap9_BurstTransmitEP0((unsigned char code *)&strLanguage, sizeof(USB_STRING_LANGUAGE_DESCRIPTOR));
			break;
		case STR_INDEX_MANUFACTURER:
			Chap9_BurstTransmitEP0((unsigned char code *)&strManufacturer, sizeof(USB_STRING_MANUFACTURER_DESCRIPTOR));
			break;
		case STR_INDEX_PRODUCT:
			Chap9_BurstTransmitEP0((unsigned char code *)&strProduct, sizeof(USB_STRING_PRODUCT_DESCRIPTOR));
			break;
		case STR_INDEX_SERIALNUMBER:
			Chap9_BurstTransmitEP0((unsigned char code *)&ConfigDescr, sizeof(CONFIG_DESCRIPTOR_LENGTH));
			break;
		case STR_INDEX_CONFIGURATION:
			Chap9_BurstTransmitEP0((unsigned char code *)&strConfiguration, sizeof(USB_STRING_CONFIGURATION_DESCRIPTOR) );
			break;
		case STR_INDEX_INTERFACE:
			Chap9_BurstTransmitEP0((unsigned char code *)&strInterface, sizeof(USB_STRING_INTERFACE_DESCRIPTOR) );
			break;
		default:
			Chap9_StallEP0InControlRead();
			break;
		}
	case USB_INTERFACE_DESCRIPTOR_TYPE:
	case USB_ENDPOINT_DESCRIPTOR_TYPE:
	case USB_POWER_DESCRIPTOR_TYPE:
	default:
		Chap9_StallEP0InControlRead();
		break;
	}

}

void Chap9_GetConfiguration(void)
{
	UCHAR   c = bD13flags.bits.configuration;

	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	if(!(dir))
		Chap9_StallEP0InControlWrite();

	if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 1)
		Chap9_SingleTransmitEP0(&c, 1);
	else
		Chap9_StallEP0InControlRead();

}

void Chap9_SetConfiguration(void)
{
	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	ALTERNATIVE_SETTING = 0;
	if(dir)
		Chap9_StallEP0InControlWrite();

	if(ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 0)
	{
		if (ControlData.DeviceRequest.wValue == 0) 
		{
			/* put device in unconfigured state */
			bD13flags.bits.configuration = 0; /* This flag should be set before Unconfig and Config */
			Hal4D13_UnconfigDevice();
			/*
			// Minimize the MISSING Window for SETUP Packet
			// Here give a chance to ISR whose interrupt is caused by Setup Packet
			*/
			Chap9_SingleTransmitEP0(0, 0);
		} 
		else if (ControlData.DeviceRequest.wValue == 1) 
		{
			/* Configure device */
			bD13flags.bits.configuration = 1; /* This flag should be set before Unconfig and Config */
			Hal4D13_UnconfigDevice();
			Hal4D13_ConfigDevice();
			/*
			// Minimize the MISSING Window for SETUP Packet
			// Here give a chance to ISR whose interrupt is caused by Setup Packet
			*/
			Chap9_SingleTransmitEP0(0, 0);
		} 
		else
			Chap9_StallEP0InControlWrite();
	}
	else
		Chap9_StallEP0InControlWrite();
}

void Chap9_GetInterface(void)
{
//	UCHAR txdat = 0;        /* Only/Current interface = 0 */
	UCHAR	c;
	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	if(!(dir))
		Chap9_StallEP0InControlWrite();
//WW MUST CHECK DATA HERE!!!
	if ((ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0 && ControlData.DeviceRequest.wLength == 1))
		Chap9_SingleTransmitEP0(&ALTERNATIVE_SETTING, 1);      //txdat
	else
		Chap9_StallEP0InControlRead();
//SUSPEND, AFTER ENUM, ENABLE SUSPEND INT
//dec4, to make Int & bulk EPs work
//Jan16
//feb8
	Hal4D13_SetIntEnable(D13REG_INTSRC_EP0OUT\
				|D13REG_INTSRC_EP0IN\
				|D13REG_INTSRC_EP03\
				|D13REG_INTSRC_EP04\
				|D13REG_INTSRC_SUSPEND\
				|D13REG_INTSRC_BUSRESET);
//Feb9
//	c = Hal4D13_GetAddress();

}

void Chap9_SetInterface(void)
{
/*	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;

	if(dir)
		Chap9_StallEP0InControlRead();
*/
//ww suport alternative i/f
	if (ControlData.DeviceRequest.wValue == 1 && ControlData.DeviceRequest.wIndex == 0)
	{
		Chap9_SingleTransmitEP0(0,0);
		ALTERNATIVE_SETTING = 1;
	}
	else if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
	{
		Chap9_SingleTransmitEP0(0,0);
		ALTERNATIVE_SETTING = 0;
	}
	else
		Chap9_StallEP0InControlWrite();

//ww alternative setting
//Jan5	
/*	UCHAR   dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;

	if(dir)
		Chap9_StallEP0InControlRead();

//ww suport alternative i/f
	if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
	{
		ALTERNATIVE_SETTING = 0;
		Chap9_SingleTransmitEP0(0,0);
	}
//ww alternative setting
	else if (ControlData.DeviceRequest.wValue == 1 && ControlData.DeviceRequest.wIndex == 0)
	{
		ALTERNATIVE_SETTING = 1;
		Chap9_SingleTransmitEP0(0,0);
	}
	else
		Chap9_StallEP0InControlWrite();
*/
}

/*
   //*************************************************************************
   // Chap9 support functions
   //*************************************************************************
*/

void Chap9_StallEP0(void)
{
	UCHAR dir;
	dir = ControlData.DeviceRequest.bmRequestType & USB_REQUEST_DIR_MASK;
	if(dir)
		Hal4D13_StallEP0InControlRead();
	else
		Hal4D13_StallEP0InControlWrite();
//Jan12

//	RaiseIRQL();
//	if(!ControlData.Abort)
		bD13flags.bits.DCP_state = USBFSM4DCP_STALL;
//	LowerIRQL();

}

void Chap9_StallEP0InControlWrite(void)
{
	Hal4D13_StallEP0InControlWrite();
//Jan12
//	RaiseIRQL();
//	if(!ControlData.Abort)
		bD13flags.bits.DCP_state = USBFSM4DCP_STALL;
//	LowerIRQL();

}

void Chap9_StallEP0InControlRead(void)
{
	Hal4D13_StallEP0InControlRead();
//Jan12
//	RaiseIRQL();
//	if(!ControlData.Abort)
		bD13flags.bits.DCP_state = USBFSM4DCP_STALL;
//	LowerIRQL();

}

void Chap9_SingleTransmitEP0(PUCHAR buf, USHORT len)
{

	Hal4D13_SingleTransmitEP0(buf, len);

//	RaiseIRQL();
//	if(!ControlData.Abort)
//	{
		ControlData.wLength = ControlData.wCount = len;
		bD13flags.bits.DCP_state = USBFSM4DCP_HANDSHAKE;
//	}
//	LowerIRQL();
}

void Chap9_BurstTransmitEP0(unsigned char code * pRomData, USHORT len)
{
	ControlData.wCount = 0;
	if(ControlData.wLength > len)
		ControlData.wLength = len;

	ControlData.Addr.pData = pRomData;

	if( ControlData.wLength >= EP0_PACKET_SIZE)
	{
		Hal4D13_WriteEndpoint(EPINDEX4EP0_CONTROL_IN, ControlData.Addr.pData, EP0_PACKET_SIZE);
			/*
			//	Minimize the MISSING Window for SETUP Packet
			// Here give a chance to ISR whose interrupt is caused by Setup Packet
			*/
//		RaiseIRQL();
//		if(!ControlData.Abort)
//		{
			ControlData.wCount += EP0_PACKET_SIZE;
			bD13flags.bits.DCP_state = USBFSM4DCP_DATAIN;
//		}
//		LowerIRQL();
	}
	else
	{
		Hal4D13_WriteEndpoint(EPINDEX4EP0_CONTROL_IN, ControlData.Addr.pData, ControlData.wLength);
			/*
			// Minimize the MISSING Window for SETUP Packet
			// Here give a chance to ISR whose interrupt is caused by Setup Packet
			*/
//		RaiseIRQL();
//		if(!ControlData.Abort)
//		{
			ControlData.wCount += ControlData.wLength;
			bD13flags.bits.DCP_state = USBFSM4DCP_HANDSHAKE;
//		}
//		LowerIRQL();
	}
}

⌨️ 快捷键说明

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