XilinxProcessorIPLib/drivers/usbpsu/examples/xusb_ch9_composite.c
s32 Usb_SetConfigurationApp(struct Usb_DevData *InstancePtr,
		SetupPacket *SetupData)
{
	s32 RetVal;
	u16 MaxPktSize;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct composite_dev *dev = (struct composite_dev *)ch9_ptr->data_ptr;

	if (InstancePtr->Speed == USB_SPEED_SUPER)
		MaxPktSize = 1024;
	else
		MaxPktSize = 512;

	if ((SetupData->wValue && 0xff) ==  1) {

		struct storage_if *f = &(dev->f_storage);

		/* Endpoint enables - not needed for Control EP */
		RetVal = EpEnable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_IN, MaxPktSize, USB_EP_TYPE_BULK);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable BULK IN Ep\r\n");
			return XST_FAILURE;
		}

		RetVal = EpEnable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_OUT, MaxPktSize, USB_EP_TYPE_BULK);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable BULK OUT Ep\r\n");
			return XST_FAILURE;
		}

		RetVal = EpEnable(InstancePtr->PrivateData, KEYBOARD_EP,
				USB_EP_DIR_IN, MaxPktSize,
				USB_EP_TYPE_INTERRUPT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable Interrupt IN Ep\r\n");
			return XST_FAILURE;
		}

		SetConfigDone(InstancePtr->PrivateData, 1U);

		/*
		 * As per Mass storage specification we receive 31 byte length
		 * Command Block Wrapper first. So lets make OUT Endpoint ready
		 * to receive it. OUT Ep Handler will be called when data is
		 * received
		 */
		EpBufferRecv(InstancePtr->PrivateData, STORAGE_EP,
				(u8 *)&(f->cbw), sizeof(f->cbw));
	} else {

		/* Endpoint disables - not needed for Control EP */
		RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
				USB_EP_DIR_OUT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable ISOC OUT Ep\r\n");
			return XST_FAILURE;
		}

		RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable ISOC IN Ep\r\n");
			return XST_FAILURE;
		}

		/* Endpoint disables - not needed for Control EP */
		RetVal = EpDisable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable BULK IN Ep\r\n");
			return XST_FAILURE;
		}

		RetVal = EpDisable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_OUT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable BULK OUT Ep\r\n");
			return XST_FAILURE;
		}

		RetVal = EpDisable(InstancePtr->PrivateData, KEYBOARD_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable Interrupt IN Ep\r\n");
			return XST_FAILURE;
		}

		SetConfigDone(InstancePtr->PrivateData, 0U);
	}

	return XST_SUCCESS;
}
/****************************************************************************/
/**
* This function is called by Chapter9 handler when SET_CONFIGURATION command
* is received from Host.
*
* @param	InstancePtr is pointer to Usb_DevData instance.
* @param	SetupData is the setup packet received from Host.
*
* @return	- XST_SUCCESS if successful,
*		- XST_FAILURE if unsuccessful.
*
*****************************************************************************/
This function is called by Chapter9 handler when SET_CONFIGURATION command
is received from Host.
This function is called by Chapter9 handler when SET_CONFIGURATION command is received from Host .
s32 Usb_SetConfigurationApp(struct Usb_DevData *InstancePtr,
		SetupPacket *SetupData)
{
	s32 RetVal;
	u16 MaxPktSize;
	USBCH9_DATA *ch9_ptr =
		(USBCH9_DATA *)Get_DrvData(InstancePtr->PrivateData);
	struct composite_dev *dev = (struct composite_dev *)ch9_ptr->data_ptr;
	if (InstancePtr->Speed == USB_SPEED_SUPER)
		MaxPktSize = 1024;
	else
		MaxPktSize = 512;
	if ((SetupData->wValue && 0xff) ==  1) {
		struct storage_if *f = &(dev->f_storage);
		RetVal = EpEnable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_IN, MaxPktSize, USB_EP_TYPE_BULK);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable BULK IN Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpEnable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_OUT, MaxPktSize, USB_EP_TYPE_BULK);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable BULK OUT Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpEnable(InstancePtr->PrivateData, KEYBOARD_EP,
				USB_EP_DIR_IN, MaxPktSize,
				USB_EP_TYPE_INTERRUPT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to enable Interrupt IN Ep\r\n");
			return XST_FAILURE;
		}
		SetConfigDone(InstancePtr->PrivateData, 1U);
		EpBufferRecv(InstancePtr->PrivateData, STORAGE_EP,
				(u8 *)&(f->cbw), sizeof(f->cbw));
	} else {
		RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
				USB_EP_DIR_OUT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable ISOC OUT Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpDisable(InstancePtr->PrivateData, ISO_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable ISOC IN Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpDisable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable BULK IN Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpDisable(InstancePtr->PrivateData, STORAGE_EP,
				USB_EP_DIR_OUT);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable BULK OUT Ep\r\n");
			return XST_FAILURE;
		}
		RetVal = EpDisable(InstancePtr->PrivateData, KEYBOARD_EP,
				USB_EP_DIR_IN);
		if (RetVal != XST_SUCCESS) {
			xil_printf("failed to disable Interrupt IN Ep\r\n");
			return XST_FAILURE;
		}
		SetConfigDone(InstancePtr->PrivateData, 0U);
	}
	return XST_SUCCESS;
}
s32 Usb_SetConfigurationApp ( struct Usb_DevData * InstancePtr , SetupPacket * SetupData ) { s32 RetVal ; u16 MaxPktSize ; USBCH9_DATA * ch9_ptr = ( USBCH9_DATA * ) Get_DrvData ( InstancePtr -> PrivateData ) ; struct composite_dev * dev = ( struct composite_dev * ) ch9_ptr -> data_ptr ; if ( InstancePtr -> Speed == USB_SPEED_SUPER ) MaxPktSize = 1024 ; else MaxPktSize = 512 ; if ( ( SetupData -> wValue && 0xff ) == 1 ) { struct storage_if * f = & ( dev -> f_storage ) ; RetVal = EpEnable ( InstancePtr -> PrivateData , STORAGE_EP , USB_EP_DIR_IN , MaxPktSize , USB_EP_TYPE_BULK ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpEnable ( InstancePtr -> PrivateData , STORAGE_EP , USB_EP_DIR_OUT , MaxPktSize , USB_EP_TYPE_BULK ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpEnable ( InstancePtr -> PrivateData , KEYBOARD_EP , USB_EP_DIR_IN , MaxPktSize , USB_EP_TYPE_INTERRUPT ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } SetConfigDone ( InstancePtr -> PrivateData , 1U ) ; EpBufferRecv ( InstancePtr -> PrivateData , STORAGE_EP , ( u8 * ) & ( f -> cbw ) , sizeof ( f -> cbw ) ) ; } else { RetVal = EpDisable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpDisable ( InstancePtr -> PrivateData , ISO_EP , USB_EP_DIR_IN ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpDisable ( InstancePtr -> PrivateData , STORAGE_EP , USB_EP_DIR_IN ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpDisable ( InstancePtr -> PrivateData , STORAGE_EP , USB_EP_DIR_OUT ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } RetVal = EpDisable ( InstancePtr -> PrivateData , KEYBOARD_EP , USB_EP_DIR_IN ) ; if ( RetVal != XST_SUCCESS ) { xil_printf ( " \r \n " ) ; return XST_FAILURE ; } SetConfigDone ( InstancePtr -> PrivateData , 0U ) ; } return XST_SUCCESS ; }
This function is called by Chapter9 handler when SET_CONFIGURATION command
is received from Host.
This function is called by Chapter9 handler when SET_CONFIGURATION command is received from Host .
/* Endpoint enables - not needed for Control EP */ /*
		 * As per Mass storage specification we receive 31 byte length
		 * Command Block Wrapper first. So lets make OUT Endpoint ready
		 * to receive it. OUT Ep Handler will be called when data is
		 * received
		 */ /* Endpoint disables - not needed for Control EP */ /* Endpoint disables - not needed for Control EP */