?? kitlusbser.c
字號:
//
// 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 <bsp.h>
#include <kitl_cfg.h>
#include "kitlusbser.h"
// start // from otg_dev.c
static DWORD KitlIoPortBase;
extern USBSerKitl_POLL;
/*----------------------------------------------------------------------
* Variables for EP0 resend control. Keep track of last packet sent.
*/
S3CUSB_INFO g_Info; // record keeping
SetupPKG dReq;
USBSERKITL_INFO USBSerInfo;
static char * sendPacket;
static int sendPacketLength;
static int sendTotalLength;
static char * savSendPacket;
static int savSendPacketLength;
//=====================================================================
// 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;
volatile UINT32 readPtIndex;
volatile UINT8 *g_pDownPt;
void SetEndpoint(void);
static void delayLoop(int count);
// 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 UINT32 uTemp;
uTemp = Inp32SYSC(0x900);
Outp32SYSC(0x900, uTemp|(1<<16)); // unmask usb signal
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)
{
OTGDEV_SetSoftDisconnect();
delayLoop(10);
OTGDEV_ClearSoftDisconnect();
OTGDEV_InitDevice();
}
else
{
EdbgOutputDebugString("Error : Current Mode is Host\n");
return;
}
if(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;
}
else
{
oOtgDev.m_uControlEPMaxPktSize = FULL_SPEED_CONTROL_PKT_SIZE;
oOtgDev.m_uBulkInEPMaxPktSize = FULL_SPEED_BULK_PKT_SIZE;
oOtgDev.m_uBulkOutEPMaxPktSize = FULL_SPEED_BULK_PKT_SIZE;
}
oOtgDev.m_uEp0State = EP0_STATE_INIT;
OTGDEV_SetOpMode(USB_CPU);
OTGDEV_SetDescriptorTable();
OTGDEV_SetEndpoint();
}
//////////
// Function Name : OTGDEV_HandleEvent
// Function Desctiption : This function handles various OTG interrupts of Device mode.
// Input : NONE
// Output : NONE
// Version :
UINT16 OTGDEV_HandleEvent(UINT8 *pch, UINT16 length)
{
volatile UINT32 uGIntStatus, uDStatus;
UINT32 ep_int_status, ep_int;
UINT32 uPcgctl;
UINT32 uGrstctl;
length = 0;
Inp32(GINTSTS, uGIntStatus); // System status read
Outp32(GINTSTS, uGIntStatus); // Interrupt Clear
if (uGIntStatus & INT_RESET) // Reset interrupt
{
Outp32(GINTSTS, INT_RESET); // Interrupt Clear
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
{
Outp32(GINTSTS, INT_ENUMDONE); // Interrupt Clear
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)
{
Outp32(GINTSTS, INT_RESUME); // Host software send ClearPortFeature. Interrupt Clear
Inp32(PCGCCTL,uPcgctl);
Outp32(PCGCCTL, uPcgctl &~ (1<<0)); //start pclk
DBGUSB("\n [USB_Diag_Log] : Resume Mode \n");
}
if (uGIntStatus & INT_SUSPEND)
{
Outp32(GINTSTS, INT_SUSPEND); // Interrupt Clear
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(pch, 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);
length = fifoCntByte;
}
}
Outp32(GINTMSK, INT_RESUME|INT_OUT_EP|INT_IN_EP|INT_ENUMDONE|INT_RESET|INT_SUSPEND|INT_RX_FIFO_NOT_EMPTY); //gint unmask
}
if ((uGIntStatus & INT_IN_EP) || (uGIntStatus & INT_OUT_EP))
{
Inp32(DAINT, ep_int);
if (ep_int & (1<<CONTROL_EP))
{
Inp32(DIEPINT0, ep_int_status);
if (ep_int_status & INTKN_TXFEMP)
{
if (g_bTransferEp0==true)
{
OTGDEV_TransferEp0();
g_bTransferEp0 = false;
}
}
Outp32(DIEPINT0, ep_int_status); // Interrupt Clear
}
else if (ep_int & ((1<<CONTROL_EP)<<16))
{
Inp32(DOEPINT0, ep_int_status);
OTGDEV_SetOutEpXferSize(EP_TYPE_CONTROL, 1, 8);
Outp32(DOEPCTL0, 0u<<31|1<<26); //ep0 enable, clear nak
Outp32(DOEPINT0, ep_int_status); // Interrupt Clear
}
}
return length;
}
//////////
// Function Name : OTGDEV_HandleEvent_EP0
// Function Desctiption : This function is called when Setup packet is received.
// Input : NONE
// Output : NONE
// Version :
void OTGDEV_HandleEvent_EP0(void)
{
UINT32 DeviceRequestLength;
UINT16 i;
UINT32 ReadBuf[64]={0x0000, };
UINT16 setaddress;
UINT32 uRemoteWakeUp=0;
if (oOtgDev.m_uEp0State == EP0_STATE_INIT)
{
for(i=0;i<2;i++)
{
ReadBuf[i] = Input32(EP0_FIFO);
}
oOtgDev.m_oDeviceRequest.bmRequestType=ReadBuf[0];
oOtgDev.m_oDeviceRequest.bRequest=ReadBuf[0]>>8;
oOtgDev.m_oDeviceRequest.wValue_L=ReadBuf[0]>>16;
oOtgDev.m_oDeviceRequest.wValue_H=ReadBuf[0]>>24;
oOtgDev.m_oDeviceRequest.wIndex_L=ReadBuf[1];
oOtgDev.m_oDeviceRequest.wIndex_H=ReadBuf[1]>>8;
oOtgDev.m_oDeviceRequest.wLength_L=ReadBuf[1]>>16;
oOtgDev.m_oDeviceRequest.wLength_H=ReadBuf[1]>>24;
// OTGDEV_PrintEp0Pkt((UINT8 *)&oOtgDev.m_oDeviceRequest, 8);
if (oOtgDev.m_oDeviceRequest.bmRequestType & 0x60 )
{
switch ( oOtgDev.m_oDeviceRequest.bRequest )
{
case ( SET_CONTROL_LINE_STATE ) :
{
/* Host is notifying us of control line state.
* wValue contains bitmask
* 0 - DTR
* 1 - RTS
*/
//KITLOutputDebugString("SET_CONTROL_LINE_STATE, H:%X,L:%X \r\n",g_oDeviceRequest.wValue_H, g_oDeviceRequest.wValue_L);
if ( oOtgDev.m_oDeviceRequest.wValue_L & 0x01 )
{
USBSerInfo.dwModemStatus |= (MS_DSR_ON|MS_RLSD_ON); // DTR active, set DSR/RLSD
}
else
{
USBSerInfo.dwModemStatus &= ~(MS_DSR_ON|MS_RLSD_ON); // DTR clear, clr DSR/RLSD
}
if ( oOtgDev.m_oDeviceRequest.wValue_L & 0x02 )
{
USBSerInfo.dwModemStatus |= MS_CTS_ON; // RTS active, set CTS
}
else
{
USBSerInfo.dwModemStatus &= ~MS_CTS_ON; // RTS clear, clear CTS
}
if ( USBSerInfo.dwModemStatus != 0 )
{
USBSerInfo.dwState = KITLUSBSER_STATE_CONNECTED;
KITLOutputDebugString("\n KITLUSBSER_STATE_CONNECTED \n");
}
else
{
USBSerInfo.dwState = KITLUSBSER_STATE_CONFIGURED;
KITLOutputDebugString("\n KITLUSBSER_STATE_CONFIGURED \n");
}
/* Command is complete */
// sendDone(0);
}
break;
default:
{
//KITLOutputDebugString("Unknown vendor/class request %X\r\n",g_oDeviceRequest.bRequest);
}
}
return;
}
switch (oOtgDev.m_oDeviceRequest.bRequest)
{
case STANDARD_SET_ADDRESS:
setaddress = (oOtgDev.m_oDeviceRequest.wValue_L); // Set Address Update bit
Outp32(DCFG, 1<<18|setaddress<<4|oOtgDev.m_eSpeed<<0);
oOtgDev.m_uEp0State = EP0_STATE_INIT;
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -