//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include <windows.h>
#include <halether.h>
#include <bsp.h>
#include "loader.h"
#include "usb.h"
// start // from otg_dev.c
static void VIC_InterruptEnable(UINT32 intNum);
static void VIC_InterruptDisable(UINT32 intNum);
static void VIC_ClearVectAddr(void);
static void VIC_InitializeVectTable(void);
static void delayLoop(int count);
//=====================================================================
// setting the device qualifier descriptor and a string descriptor
const UINT8 aDeviceQualifierDescriptor[] =
{
0x0a, // 0 desc size
0x06, // 1 desc type (DEVICE)
0x00, // 2 USB release
0x02, // 3 => 2.00
0x00, // 4 class
0x00, // 5 subclass
0x00, // 6 protocol
64, // 7 max pack size
0x01, // 8 number of other-speed configuration
0x00, // 9 reserved
};
const UINT8 aDescStr0[]=
{
4, STRING_DESCRIPTOR, LANGID_US_L, LANGID_US_H, // codes representing languages
};
const UINT8 aDescStr1[]= // Manufacturer
{
(0x14+2), STRING_DESCRIPTOR,
'S', 0x0, 'y', 0x0, 's', 0x0, 't', 0x0, 'e', 0x0, 'm', 0x0, ' ', 0x0, 'M', 0x0,
'C', 0x0, 'U', 0x0,
};
const UINT8 aDescStr2[]= // Product
{
(0x2a+2), STRING_DESCRIPTOR,
'S', 0x0, 'E', 0x0, 'C', 0x0, ' ', 0x0, 'S', 0x0, '3', 0x0, 'C', 0x0, '6', 0x0,
'4', 0x0, '1', 0x0, '0', 0x0, 'X', 0x0, ' ', 0x0, 'T', 0x0, 'e', 0x0, 's', 0x0,
't', 0x0, ' ', 0x0, 'B', 0x0, '/', 0x0, 'D', 0x0
};
//=====================================================================
// global varibles used in several functions
OTGDEV oOtgDev;
USB_GET_STATUS oStatusGet;
USB_INTERFACE_GET oInterfaceGet;
UINT16 g_usConfig;
bool g_bTransferEp0 = false;
// end // from otg_dev.c
//static UINT32 g_uDownloadFileSize;
//static UINT32 g_uDownloadAddress = DMABUFFER;
volatile UINT32 readPtIndex;
volatile UINT8 *g_pDownPt;
//volatile S3C6410_USBOTG_LINK_REG *pUSBOTG_LINK;
//volatile S3C6410_USBOTG_PHY_REG *pUSBOTG_PHY;
volatile S3C6410_VIC_REG *s6410VIC0;
volatile S3C6410_VIC_REG *s6410VIC1;
void Isr_Init(void);
void C_IsrHandler(unsigned int val);
extern void ASM_IsrHandler(void);
void SetEndpoint(void);
// start // from otg_dev.c
//////////
// Function Name : OTGDEV_InitOtg
// Function Desctiption : This function initializes OTG PHY and LINK.
// Input : eSpeed, USB Speed (high or full)
// Output : NONE
// Version :
void OTGDEV_InitOtg(USB_SPEED eSpeed)
{
UINT8 ucMode;
volatile S3C6410_SYSCON_REG *pSysConReg = (S3C6410_SYSCON_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_SYSCON, FALSE);
volatile UINT32 uTemp;
uTemp = Inp32SYSC(0x900);
Outp32SYSC(0x900, uTemp|(1<<16)); // unmask usb signal // For NAND Boot
pSysConReg->HCLK_GATE |= (1<<20);
oOtgDev.m_eSpeed = eSpeed;
oOtgDev.m_uIsUsbOtgSetConfiguration = 0;
oOtgDev.m_uEp0State = EP0_STATE_INIT;
oOtgDev.m_uEp0SubState = 0;
OTGDEV_InitPhyCon();
OTGDEV_SoftResetCore();
OTGDEV_InitCore();
OTGDEV_CheckCurrentMode(&ucMode);
if (ucMode == INT_DEV_MODE)
{
delayLoop(10000);
OTGDEV_ClearSoftDisconnect();
OTGDEV_InitDevice();
}
else
{
EdbgOutputDebugString("Error : Current Mode is Host\n");
return;
}
oOtgDev.m_eSpeed = USB_HIGH;
oOtgDev.m_uControlEPMaxPktSize = HIGH_SPEED_CONTROL_PKT_SIZE;
oOtgDev.m_uBulkInEPMaxPktSize = HIGH_SPEED_BULK_PKT_SIZE;
oOtgDev.m_uBulkOutEPMaxPktSize = HIGH_SPEED_BULK_PKT_SIZE;
}
//////////
// Function Name : OTGDEV_HandleEvent
// Function Desctiption : This function handles various OTG interrupts of Device mode.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_HandleEvent(void)
{
UINT32 uGIntStatus, uDStatus;
UINT32 ep_int_status, ep_int;
UINT32 uPcgctl;
UINT32 uGrstctl;
Inp32(GINTSTS, uGIntStatus); // System status read
Outp32(GINTSTS, uGIntStatus); // Interrupt Clear
if (uGIntStatus & INT_RESET) // Reset interrupt
{
OTGDEV_SetAllOutEpNak();
oOtgDev.m_uEp0State = EP0_STATE_INIT;
Outp32(DAINTMSK,((1<<BULK_OUT_EP)|(1<<CONTROL_EP))<<16|((1<<BULK_IN_EP)|(1<<CONTROL_EP)));
Outp32(DOEPMSK, CTRL_OUT_EP_SETUP_PHASE_DONE|AHB_ERROR|TRANSFER_DONE);
Outp32(DIEPMSK, INTKN_TXFEMP|NON_ISO_IN_EP_TIMEOUT|AHB_ERROR|TRANSFER_DONE);
Outp32(GRXFSIZ, RX_FIFO_SIZE); // Rx FIFO Size
Outp32(GNPTXFSIZ, NPTX_FIFO_SIZE<<16| NPTX_FIFO_START_ADDR<<0); // Non Periodic Tx FIFO Size
Outp32(GRSTCTL, (1<<5)|(1<<4)); // TX and RX FIFO Flush
OTGDEV_SetOpMode(USB_CPU);
OTGDEV_ClearAllOutEpNak();
Inp32(PCGCCTL,uPcgctl);
Outp32(PCGCCTL, uPcgctl&~(1<<0)); //start pclk
DBGUSB("\n [USB_Diag_Log] : Reset Mode\n");
}
if (uGIntStatus & INT_ENUMDONE) // Device Speed Detection interrupt
{
DBGUSB("\n [USB_Diag_Log] : Speed Detection interrupt \n");
Inp32(DSTS, uDStatus); // System status read
if (((uDStatus&0x6) >>1) == USB_HIGH) // Set if Device is High speed or Full speed
{
DBGUSB("\n [USB_Diag_Log] : High Speed Detection\n");
OTGDEV_SetMaxPktSizes(USB_HIGH);
}
else if(((uDStatus&0x6) >>1) == USB_FULL)
{
DBGUSB("\n [USB_Diag_Log] : full Speed Detection\n");
OTGDEV_SetMaxPktSizes(USB_FULL);
}
else
{
DBGUSB("\n [USB_Diag_Log] : No specific speed option\n"); //Assert(0);
while(1);
}
OTGDEV_SetEndpoint();
OTGDEV_SetDescriptorTable();
}
if (uGIntStatus & INT_RESUME)
{
Inp32(PCGCCTL,uPcgctl);
Outp32(PCGCCTL, uPcgctl &~ (1<<0)); //start pclk
DBGUSB("\n [USB_Diag_Log] : Resume Mode \n");
}
if (uGIntStatus & INT_SUSPEND)
{
Inp32(PCGCCTL,uPcgctl);
Outp32(PCGCCTL, uPcgctl |(1<<0)); //stop pclk
DBGUSB("\n [USB_Diag_Log] : Suspend Mode\n");
}
if(uGIntStatus & INT_RX_FIFO_NOT_EMPTY)
{
UINT32 GrxStatus;
UINT32 fifoCntByte;
Outp32(GINTMSK, INT_RESUME|INT_OUT_EP|INT_IN_EP|INT_ENUMDONE|INT_RESET|INT_SUSPEND);
Inp32(GRXSTSP, GrxStatus);
if ((GrxStatus & SETUP_PKT_RECEIVED) == SETUP_PKT_RECEIVED)
{
DBGUSB("SETUP_PACKET_RECEIVED\n");
OTGDEV_HandleEvent_EP0();
Inp32(GRSTCTL,uGrstctl);
Outp32(GRSTCTL, uGrstctl &~ (0x1f<<6)|(0x1<<5)); //tx fifo flush
g_bTransferEp0 = true;
}
else if ((GrxStatus & OUT_PKT_RECEIVED) == OUT_PKT_RECEIVED)
{
fifoCntByte = (GrxStatus & 0x7ff0)>>4;
if(((GrxStatus & 0xF)==BULK_OUT_EP)&&(fifoCntByte))
{
DBGUSB("Bulk Out : OUT_PKT_RECEIVED\n");
OTGDEV_HandleEvent_BulkOut(fifoCntByte);
if( oOtgDev.m_eOpMode == USB_CPU )
Outp32(GINTMSK, INT_RESUME|INT_OUT_EP|INT_IN_EP|INT_ENUMDONE|INT_RESET|INT_SUSPEND|INT_RX_FIFO_NOT_EMPTY);
return;
}
}
Outp32(GINTM