/*
============================================================================
   /
  / /
 / / /\
 \\\/ /// CLabSys
  \\ ///  Cyber Lab System
   \\//   www.clabsys.com
    \/

----------------------------------------------------------------------------
Description

----------------------------------------------------------------------------
============================================================================
*/

#include <windows.h>
#include <halether.h>
#include <bsp.h>
#include "loader.h"
#include "usb.h"

// 070514 by mkkim@nsusemi.com 
#include "usbintr.h"

extern volatile UINT32 g_dwDownIndex;
extern volatile UINT8  *g_pDownPt;

extern BOOL OTGDEV_IsCableAttahced(void);

void USBSetReadBuffer(PBYTE ptr)
{
	g_pDownPt = ptr;
	g_dwDownIndex = 0;
}

DWORD USBGetReadSize(void)
{
   return g_dwDownIndex;
}


BOOL USBIsCableAttached(void)
{
	return OTGDEV_IsCableAttahced();
	//return TRUE;
}


void USBSelect(int Select)
{
/*
    volatile BSP_EGPIO_T *pEGPIOReg;
	pEGPIOReg =(volatile BSP_EGPIO_T *)OALPAtoVA(BASE_REG_PA_CPLD, FALSE);

	switch(Select)
	{
        case USB_PATH_NONE:
                EGPIO_USB_ACTIVE_MODEM_SET(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_PDA_SET(pEGPIOReg);
                msWait(1);
                break;

		case USB_PATH_PDA:
                EGPIO_USB_ACTIVE_MODEM_SET(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_PDA_CLR(pEGPIOReg);
                msWait(1);
				break;

		case USB_PATH_PHONE:
				EGPIO_USB_SEL_C_CLR(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_PDA_SET(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_MODEM_CLR(pEGPIOReg);
                msWait(1);
				break;

		case USB_PATH_WIBRO:
				EGPIO_USB_SEL_C_SET(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_PDA_SET(pEGPIOReg);
                msWait(1);
				EGPIO_USB_ACTIVE_MODEM_CLR(pEGPIOReg);
                msWait(1);
				break;

		default:
				OALMSG(OAL_WARN,(L"EOTG: Unsupported Path \r\n"));
				break;
	}
*/
}

void USBConnect(BOOL bConnect)
{
	if(bConnect)
	{
		OTGDEV_ClearSoftDisconnect();
	}
    else
	{
		OTGDEV_SetSoftDisconnect();
	}
}
