XilinxProcessorIPLib/drivers/usbpsu/examples/xusb_freertos_composite_example.c
static int XUsbCompositeExample(struct Usb_DevData *UsbInstPtr, XScuGic *IntrInstPtr,
		struct composite_dev *dev, u16 DeviceId, u16 IntcDeviceID, u16 UsbIntrId)
{
	s32 Status;
	Usb_Config *UsbConfigPtr;

	xil_printf("USB Composite Device Start...\r\n");

	/* Initialize the USB driver so that it's ready to use,
	 * specify the controller ID that is generated in xparameters.h
	 */
	UsbConfigPtr = LookupConfig(DeviceId);
	if (NULL == UsbConfigPtr)
		return XST_FAILURE;

	/* We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example.  For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */
	Status = CfgInitialize(UsbInstPtr, UsbConfigPtr,
			UsbConfigPtr->BaseAddress);
	if (XST_SUCCESS != Status)
		return XST_FAILURE;

	/* hook up chapter9 handler */
	Set_Ch9Handler(UsbInstPtr->PrivateData, Ch9Handler);

	/* Set the disconnect event handler */
	Set_Disconnect(UsbInstPtr->PrivateData, Usb_DisconnectHandler);

	/* Set the reset event handler */
	Set_RstHandler(UsbInstPtr->PrivateData, Usb_ResetHandler);

	/* Assign the data to usb driver */
	Set_DrvData(UsbInstPtr->PrivateData, &composite_data);

	/* Initialize the DFU instance structure */
	dev->f_dfu.InstancePtr = UsbInstPtr;

	/* Set DFU state to APP_IDLE */
	Usb_DfuSetState(&dev->f_dfu, STATE_APP_IDLE);

	/* Set the DFU descriptor pointers, so we can use it when in DFU mode */
	dev->f_dfu.total_transfers = 0;
	dev->f_dfu.total_bytes_dnloaded = 0;
	dev->f_dfu.total_bytes_uploaded = 0;

	/* set handler for in endpoint, will be called when data is sent*/
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN,
			Usb_AudioInHandler);

	/* set handler for out endpoint, will be called when data is recv*/
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT,
			Usb_AudioOutHandler);

	set_audio_transfer_size(&dev->f_audio);

	/* Mass storage endpoint event hadler registration */
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_OUT,
			Usb_StorageOutHandler);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_IN,
			Usb_StorageInHandler);

	/* Keyboard endpoint event hadler */
	SetEpHandler(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN,
			Usb_KeyboardInHabdler);
	/* setup interrupts */
	Status = SetupInterruptSystem(UsbInstPtr->PrivateData, IntcDeviceID,
			UsbIntrId, (void *)IntrInstPtr);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;

	/* Start the controller so that Host can see our device */
	Usb_Start(UsbInstPtr->PrivateData);

	while (1) {
		BaseType_t Ret;
		u32 Notification;

		Ret = xTaskNotifyWait(0x00, 0x00, &Notification, portMAX_DELAY);
		if (Ret == pdTRUE) {
			if (Notification & KEYBOARD_CONFIG) {
				struct keyboard_if *f = &dev->f_keyboard;

				xTaskCreate(prvKeyboardTask, (const char *) "Keyboard Task",
						configMINIMAL_STACK_SIZE,
						UsbInstPtr, tskIDLE_PRIORITY,
						&(f->xKeyboardTask));
			}

			if (Notification & KEYBOARD_UNCONFIG) {
				struct keyboard_if *f = &dev->f_keyboard;

				EpDisable(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN);
				vSemaphoreDelete(f->xSemaphore);
				vTaskDelete(f->xKeyboardTask);
			}

			if (Notification & MSG_CONFIG) {
				struct storage_if *f = &dev->f_storage;

				xTaskCreate(prvSCSITask, (const char *) "SCSI Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 2, &(f->xSCSITask));
			}

			if (Notification & MSG_UNCONFIG) {
				struct storage_if *f = &dev->f_storage;

				EpDisable(UsbInstPtr->PrivateData, STORAGE_EP,
						USB_EP_DIR_IN);
				EpDisable(UsbInstPtr->PrivateData, STORAGE_EP,
						USB_EP_DIR_OUT);

				vSemaphoreDelete(f->xSemaphore);
				vTaskDelete(f->xSCSITask);
			}

			if (Notification & RECORD_START) {
				struct audio_if *f = &(dev->f_audio);

				xTaskCreate(prvRecordTask, (const char *) "Record Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 3, &(f->xRecordTask));
			}

			if (Notification & PLAY_START) {
				struct audio_if *f = &(dev->f_audio);

				xTaskCreate(prvPlayBackTask, (const char *) "PlayBack Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 3, &(f->xPlayTask));
			}

			if (Notification & RECORD_STOP) {
				struct audio_if *f = &(dev->f_audio);

				StreamOff(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN);
				EpDisable(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN);
				if (f->xSemaphoreRecord) {
					vSemaphoreDelete(f->xSemaphoreRecord);
					vTaskDelete(f->xRecordTask);
				}
			}

			if (Notification & PLAY_STOP) {
				struct audio_if *f = &(dev->f_audio);

				StreamOff(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);
				EpDisable(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);
				if (f->xSemaphorePlay) {
					vSemaphoreDelete(f->xSemaphorePlay);
					vTaskDelete(f->xPlayTask);
				}
			}
		}
	}
}
/****************************************************************************/
/**
* This function is implementing USB AUDIO-DFU composte example.
*
* @param	UsbInstPtr USB instance pointer.
*		IntrInstPtr Interrupt controller instance pointer
*		DeviceId USB Device ID
*		IntcDeviceID Interrupt controller Device ID
*
* @return 	- XST_SUCCESS if successful,
*		- XST_FAILURE if unsuccessful.
*
* @note		None.
*
*****************************************************************************/
This function is implementing USB AUDIO-DFU composte example.
This function is implementing USB AUDIO - DFU composte example .
static int XUsbCompositeExample(struct Usb_DevData *UsbInstPtr, XScuGic *IntrInstPtr,
		struct composite_dev *dev, u16 DeviceId, u16 IntcDeviceID, u16 UsbIntrId)
{
	s32 Status;
	Usb_Config *UsbConfigPtr;
	xil_printf("USB Composite Device Start...\r\n");
	UsbConfigPtr = LookupConfig(DeviceId);
	if (NULL == UsbConfigPtr)
		return XST_FAILURE;
	Status = CfgInitialize(UsbInstPtr, UsbConfigPtr,
			UsbConfigPtr->BaseAddress);
	if (XST_SUCCESS != Status)
		return XST_FAILURE;
	Set_Ch9Handler(UsbInstPtr->PrivateData, Ch9Handler);
	Set_Disconnect(UsbInstPtr->PrivateData, Usb_DisconnectHandler);
	Set_RstHandler(UsbInstPtr->PrivateData, Usb_ResetHandler);
	Set_DrvData(UsbInstPtr->PrivateData, &composite_data);
	dev->f_dfu.InstancePtr = UsbInstPtr;
	Usb_DfuSetState(&dev->f_dfu, STATE_APP_IDLE);
	dev->f_dfu.total_transfers = 0;
	dev->f_dfu.total_bytes_dnloaded = 0;
	dev->f_dfu.total_bytes_uploaded = 0;
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN,
			Usb_AudioInHandler);
	SetEpHandler(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT,
			Usb_AudioOutHandler);
	set_audio_transfer_size(&dev->f_audio);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_OUT,
			Usb_StorageOutHandler);
	SetEpHandler(UsbInstance.PrivateData, STORAGE_EP, USB_EP_DIR_IN,
			Usb_StorageInHandler);
	SetEpHandler(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN,
			Usb_KeyboardInHabdler);
	Status = SetupInterruptSystem(UsbInstPtr->PrivateData, IntcDeviceID,
			UsbIntrId, (void *)IntrInstPtr);
	if (Status != XST_SUCCESS)
		return XST_FAILURE;
	Usb_Start(UsbInstPtr->PrivateData);
	while (1) {
		BaseType_t Ret;
		u32 Notification;
		Ret = xTaskNotifyWait(0x00, 0x00, &Notification, portMAX_DELAY);
		if (Ret == pdTRUE) {
			if (Notification & KEYBOARD_CONFIG) {
				struct keyboard_if *f = &dev->f_keyboard;
				xTaskCreate(prvKeyboardTask, (const char *) "Keyboard Task",
						configMINIMAL_STACK_SIZE,
						UsbInstPtr, tskIDLE_PRIORITY,
						&(f->xKeyboardTask));
			}
			if (Notification & KEYBOARD_UNCONFIG) {
				struct keyboard_if *f = &dev->f_keyboard;
				EpDisable(UsbInstPtr->PrivateData, KEYBOARD_EP, USB_EP_DIR_IN);
				vSemaphoreDelete(f->xSemaphore);
				vTaskDelete(f->xKeyboardTask);
			}
			if (Notification & MSG_CONFIG) {
				struct storage_if *f = &dev->f_storage;
				xTaskCreate(prvSCSITask, (const char *) "SCSI Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 2, &(f->xSCSITask));
			}
			if (Notification & MSG_UNCONFIG) {
				struct storage_if *f = &dev->f_storage;
				EpDisable(UsbInstPtr->PrivateData, STORAGE_EP,
						USB_EP_DIR_IN);
				EpDisable(UsbInstPtr->PrivateData, STORAGE_EP,
						USB_EP_DIR_OUT);
				vSemaphoreDelete(f->xSemaphore);
				vTaskDelete(f->xSCSITask);
			}
			if (Notification & RECORD_START) {
				struct audio_if *f = &(dev->f_audio);
				xTaskCreate(prvRecordTask, (const char *) "Record Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 3, &(f->xRecordTask));
			}
			if (Notification & PLAY_START) {
				struct audio_if *f = &(dev->f_audio);
				xTaskCreate(prvPlayBackTask, (const char *) "PlayBack Task",
						configMINIMAL_STACK_SIZE, UsbInstPtr,
						tskIDLE_PRIORITY + 3, &(f->xPlayTask));
			}
			if (Notification & RECORD_STOP) {
				struct audio_if *f = &(dev->f_audio);
				StreamOff(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN);
				EpDisable(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_IN);
				if (f->xSemaphoreRecord) {
					vSemaphoreDelete(f->xSemaphoreRecord);
					vTaskDelete(f->xRecordTask);
				}
			}
			if (Notification & PLAY_STOP) {
				struct audio_if *f = &(dev->f_audio);
				StreamOff(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);
				EpDisable(UsbInstPtr->PrivateData, ISO_EP, USB_EP_DIR_OUT);
				if (f->xSemaphorePlay) {
					vSemaphoreDelete(f->xSemaphorePlay);
					vTaskDelete(f->xPlayTask);
				}
			}
		}
	}
}
static int XUsbCompositeExample ( struct Usb_DevData * UsbInstPtr , XScuGic * IntrInstPtr , struct composite_dev * dev , u16 DeviceId , u16 IntcDeviceID , u16 UsbIntrId ) { s32 Status ; Usb_Config * UsbConfigPtr ; xil_printf ( " \r \n " ) ; UsbConfigPtr = LookupConfig ( DeviceId ) ; if ( NULL == UsbConfigPtr ) return XST_FAILURE ; Status = CfgInitialize ( UsbInstPtr , UsbConfigPtr , UsbConfigPtr -> BaseAddress ) ; if ( XST_SUCCESS != Status ) return XST_FAILURE ; Set_Ch9Handler ( UsbInstPtr -> PrivateData , Ch9Handler ) ; Set_Disconnect ( UsbInstPtr -> PrivateData , Usb_DisconnectHandler ) ; Set_RstHandler ( UsbInstPtr -> PrivateData , Usb_ResetHandler ) ; Set_DrvData ( UsbInstPtr -> PrivateData , & composite_data ) ; dev -> f_dfu . InstancePtr = UsbInstPtr ; Usb_DfuSetState ( & dev -> f_dfu , STATE_APP_IDLE ) ; dev -> f_dfu . total_transfers = 0 ; dev -> f_dfu . total_bytes_dnloaded = 0 ; dev -> f_dfu . total_bytes_uploaded = 0 ; SetEpHandler ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_IN , Usb_AudioInHandler ) ; SetEpHandler ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT , Usb_AudioOutHandler ) ; set_audio_transfer_size ( & dev -> f_audio ) ; SetEpHandler ( UsbInstance . PrivateData , STORAGE_EP , USB_EP_DIR_OUT , Usb_StorageOutHandler ) ; SetEpHandler ( UsbInstance . PrivateData , STORAGE_EP , USB_EP_DIR_IN , Usb_StorageInHandler ) ; SetEpHandler ( UsbInstPtr -> PrivateData , KEYBOARD_EP , USB_EP_DIR_IN , Usb_KeyboardInHabdler ) ; Status = SetupInterruptSystem ( UsbInstPtr -> PrivateData , IntcDeviceID , UsbIntrId , ( void * ) IntrInstPtr ) ; if ( Status != XST_SUCCESS ) return XST_FAILURE ; Usb_Start ( UsbInstPtr -> PrivateData ) ; while ( 1 ) { BaseType_t Ret ; u32 Notification ; Ret = xTaskNotifyWait ( 0x00 , 0x00 , & Notification , portMAX_DELAY ) ; if ( Ret == pdTRUE ) { if ( Notification & KEYBOARD_CONFIG ) { struct keyboard_if * f = & dev -> f_keyboard ; xTaskCreate ( prvKeyboardTask , ( const char * ) " " , configMINIMAL_STACK_SIZE , UsbInstPtr , tskIDLE_PRIORITY , & ( f -> xKeyboardTask ) ) ; } if ( Notification & KEYBOARD_UNCONFIG ) { struct keyboard_if * f = & dev -> f_keyboard ; EpDisable ( UsbInstPtr -> PrivateData , KEYBOARD_EP , USB_EP_DIR_IN ) ; vSemaphoreDelete ( f -> xSemaphore ) ; vTaskDelete ( f -> xKeyboardTask ) ; } if ( Notification & MSG_CONFIG ) { struct storage_if * f = & dev -> f_storage ; xTaskCreate ( prvSCSITask , ( const char * ) " " , configMINIMAL_STACK_SIZE , UsbInstPtr , tskIDLE_PRIORITY + 2 , & ( f -> xSCSITask ) ) ; } if ( Notification & MSG_UNCONFIG ) { struct storage_if * f = & dev -> f_storage ; EpDisable ( UsbInstPtr -> PrivateData , STORAGE_EP , USB_EP_DIR_IN ) ; EpDisable ( UsbInstPtr -> PrivateData , STORAGE_EP , USB_EP_DIR_OUT ) ; vSemaphoreDelete ( f -> xSemaphore ) ; vTaskDelete ( f -> xSCSITask ) ; } if ( Notification & RECORD_START ) { struct audio_if * f = & ( dev -> f_audio ) ; xTaskCreate ( prvRecordTask , ( const char * ) " " , configMINIMAL_STACK_SIZE , UsbInstPtr , tskIDLE_PRIORITY + 3 , & ( f -> xRecordTask ) ) ; } if ( Notification & PLAY_START ) { struct audio_if * f = & ( dev -> f_audio ) ; xTaskCreate ( prvPlayBackTask , ( const char * ) " " , configMINIMAL_STACK_SIZE , UsbInstPtr , tskIDLE_PRIORITY + 3 , & ( f -> xPlayTask ) ) ; } if ( Notification & RECORD_STOP ) { struct audio_if * f = & ( dev -> f_audio ) ; StreamOff ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_IN ) ; EpDisable ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_IN ) ; if ( f -> xSemaphoreRecord ) { vSemaphoreDelete ( f -> xSemaphoreRecord ) ; vTaskDelete ( f -> xRecordTask ) ; } } if ( Notification & PLAY_STOP ) { struct audio_if * f = & ( dev -> f_audio ) ; StreamOff ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT ) ; EpDisable ( UsbInstPtr -> PrivateData , ISO_EP , USB_EP_DIR_OUT ) ; if ( f -> xSemaphorePlay ) { vSemaphoreDelete ( f -> xSemaphorePlay ) ; vTaskDelete ( f -> xPlayTask ) ; } } } } }
This function is implementing USB AUDIO-DFU composte example.
This function is implementing USB AUDIO - DFU composte example .
/* Initialize the USB driver so that it's ready to use,
	 * specify the controller ID that is generated in xparameters.h
	 */ /* We are passing the physical base address as the third argument
	 * because the physical and virtual base address are the same in our
	 * example.  For systems that support virtual memory, the third
	 * argument needs to be the virtual base address.
	 */ /* hook up chapter9 handler */ /* Set the disconnect event handler */ /* Set the reset event handler */ /* Assign the data to usb driver */ /* Initialize the DFU instance structure */ /* Set DFU state to APP_IDLE */ /* Set the DFU descriptor pointers, so we can use it when in DFU mode */ /* set handler for in endpoint, will be called when data is sent*/ /* set handler for out endpoint, will be called when data is recv*/ /* Mass storage endpoint event hadler registration */ /* Keyboard endpoint event hadler */ /* setup interrupts */ /* Start the controller so that Host can see our device */