usbTask.c 3.37 KB
#include "os_config.h"

#include "c_def.h"
#include "debug.h"
#include "oem.h"

#include "regmap.h"
#ifdef USB_HOST_ENABLE

#include "mem_reloc.h"

#include "app_timer.h"
#include "tools.h"
#include "IRP.h"
#include "usbd.h"
#include "message.h"

#ifdef USB_DEV_ENABLE
#include "usb.h"
#endif

#include "otg.h"
#include "interrupt.h"


void task_usbotg(void *pvParameters) __INTERNAL_RAM_TEXT;


//extern TX_THREAD thread_usbotg;
extern int dstk_IRPprocess( IRP *irp );
int AOAstack_irpProcess( IRP *irp );
extern int iap2stk_IRPprocess( IRP *irp );

#ifdef SYSTEM_CRASH_CHECK_ENABLE
volatile U8 task_usbotg_check_cnt;
#endif

void task_usbotg(void *pvParameters)
{
	UINT ret;
	U32 data[WIDTH_OF_USBMSG_QUEUE];
	IRP * irp = (IRP *)data;

#ifdef USB_INT_CHANGEs_TO_LEVEL1
	SOFT5_INT_ENABLE;
#endif

/*
#ifdef USB_DEV_ENABLE
	usbd_init();
	hstk_init();
	hcd_init();
	otg_init();

	daudio_init();
	denum_init();
	dstk_init();
	dcd_init();
#else

#if 0
	usbd_init();
	usbd_open();

	hstk_init();
	hcd_init();

	otg_init();
	otg_open();
#endif

#endif
*/

	//debug
	//hid_test();

	while(1)
	{
	#ifdef SYSTEM_CRASH_CHECK_ENABLE
		task_usbotg_check_cnt = 1;
	#endif

		//ret = tx_queue_receive( &gUsbQueue, (void *)msg, TX_WAIT_FOREVER );
		ret = QUEUE_USB_RECEIVE;

		DBG_assert( TX_SUCCESS == ret );

		switch( irp->target )
		{
		case enIRP_USB_OPEN:

		#if 0
			usbd_init();
			usbd_open();

			hstk_init();
			hcd_init();

			otg_init();
			otg_open();
		#endif

		#ifndef	OTG_FORCE_FULL_SPEED
			usb_highspeed_flag = TRUE;
		#endif

			irp->target	=	enIRPT_USBD;
			irp->type	=	enIRP_USBHOST_START;
			usbd_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;

		case enIRP_USB_CLOSE:
			irp->target	=	enIRPT_USBD;
			irp->type	=	enIRP_USBHOST_STOP;
			usbd_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}

		#if 0
			//usbd_fini();
			//usbd_clsoe();

			//hstk_fini();
			hcd_close();

			//otg_fini();
			otg_close();
		#endif

			break;

		case enIRPT_USBD:
			//DBG_Printf("enIRPT_USBD\n");
			
		#ifndef	OTG_FORCE_FULL_SPEED
			usb_highspeed_flag = TRUE;
		#endif

			usbd_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;

		case enIRPT_MSC_CLASS:
			mscClass_IRPprocess( irp );
			if( irp->complete != NULL ) {
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;


	#if 0
		case enIRPT_HUB:
			hub_IRPprocess( irp );
			break;
	#endif
			
	#ifdef PTP_MTP_CLASS
		case enIRPT_MTP:
			mtpClass_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;
	#endif

	#ifdef USB_DEV_ENABLE
		case enIRPT_DEV_STACK:
		#ifndef	OTG_FORCE_FULL_SPEED
			usb_highspeed_flag = TRUE;
		#endif

			dstk_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;
	#endif

	#ifdef APPLE_IAP2_STACK
		case enIRPT_IAP2:
			iap2stk_IRPprocess( irp );
			if( irp->complete != NULL )
			{
				(*irp->complete) ( irp->result, irp->actualLen );
			}
			break;
	#endif

		default:
			HALT;
			break;
		}

		//if( irp->complete != NULL )
		//{
		//	(*irp->complete) ( irp->result, irp->actualLen );
		//}

	#ifdef SYSTEM_CRASH_CHECK_ENABLE
		task_usbotg_check_cnt = 2;
	#endif
	}
}

#endif //USB_HOST_ENABLE