?? kitlusbser.c
字號(hào):
oOtgDev.m_oDesc.oDescDevice.bcdUSBH=0x02; // Ver 2.0
}
// Standard configuration descriptor
oOtgDev.m_oDesc.oDescConfig.bLength=CONFIG_DESC_SIZE; // 0x9 bytes
oOtgDev.m_oDesc.oDescConfig.bDescriptorType=CONFIGURATION_DESCRIPTOR;
oOtgDev.m_oDesc.oDescConfig.wTotalLengthL=CONFIG_DESC_TOTAL_SIZE;
oOtgDev.m_oDesc.oDescConfig.wTotalLengthH=0;
oOtgDev.m_oDesc.oDescConfig.bNumInterfaces=1;
// dbg descConf.bConfigurationValue=2; // why 2? There's no reason.
oOtgDev.m_oDesc.oDescConfig.bConfigurationValue=1;
oOtgDev.m_oDesc.oDescConfig.iConfiguration=0;
oOtgDev.m_oDesc.oDescConfig.bmAttributes=CONF_ATTR_DEFAULT|CONF_ATTR_SELFPOWERED; // bus powered only.
oOtgDev.m_oDesc.oDescConfig.maxPower=25; // draws 50mA current from the USB bus.
// Standard interface descriptor
oOtgDev.m_oDesc.oDescInterface.bLength=INTERFACE_DESC_SIZE; // 9
oOtgDev.m_oDesc.oDescInterface.bDescriptorType=INTERFACE_DESCRIPTOR;
oOtgDev.m_oDesc.oDescInterface.bInterfaceNumber=0x0;
oOtgDev.m_oDesc.oDescInterface.bAlternateSetting=0x0; // ?
oOtgDev.m_oDesc.oDescInterface.bNumEndpoints = 2; // # of endpoints except EP0
oOtgDev.m_oDesc.oDescInterface.bInterfaceClass=0xff; // 0x0 ?
oOtgDev.m_oDesc.oDescInterface.bInterfaceSubClass=0xFF;
oOtgDev.m_oDesc.oDescInterface.bInterfaceProtocol=0xFF;
oOtgDev.m_oDesc.oDescInterface.iInterface=0x0;
// Standard endpoint0 descriptor
oOtgDev.m_oDesc.oDescEndpt1.bLength=ENDPOINT_DESC_SIZE;
oOtgDev.m_oDesc.oDescEndpt1.bDescriptorType=ENDPOINT_DESCRIPTOR;
oOtgDev.m_oDesc.oDescEndpt1.bEndpointAddress=BULK_IN_EP|EP_ADDR_IN; // 2400Xendpoint 1 is IN endpoint.
oOtgDev.m_oDesc.oDescEndpt1.bmAttributes=EP_ATTR_BULK;
oOtgDev.m_oDesc.oDescEndpt1.wMaxPacketSizeL=(UINT8)oOtgDev.m_uBulkInEPMaxPktSize; // 64
oOtgDev.m_oDesc.oDescEndpt1.wMaxPacketSizeH=(UINT8)(oOtgDev.m_uBulkInEPMaxPktSize>>8);
oOtgDev.m_oDesc.oDescEndpt1.bInterval=0x0; // not used
// Standard endpoint1 descriptor
oOtgDev.m_oDesc.oDescEndpt2.bLength=ENDPOINT_DESC_SIZE;
oOtgDev.m_oDesc.oDescEndpt2.bDescriptorType=ENDPOINT_DESCRIPTOR;
oOtgDev.m_oDesc.oDescEndpt2.bEndpointAddress=BULK_OUT_EP|EP_ADDR_OUT; // 2400X endpoint 3 is OUT endpoint.
oOtgDev.m_oDesc.oDescEndpt2.bmAttributes=EP_ATTR_BULK;
oOtgDev.m_oDesc.oDescEndpt2.wMaxPacketSizeL=(UINT8)oOtgDev.m_uBulkOutEPMaxPktSize; // 64
oOtgDev.m_oDesc.oDescEndpt2.wMaxPacketSizeH=(UINT8)(oOtgDev.m_uBulkOutEPMaxPktSize>>8);
oOtgDev.m_oDesc.oDescEndpt2.bInterval=0x0; // not used
}
//////////
// Function Name : OTGDEV_CheckEnumeratedSpeed
// Function Desctiption : This function checks the current usb speed.
// Input : eSpeed, usb speed(high or full)
// Output : NONE
// Version :
void OTGDEV_CheckEnumeratedSpeed(USB_SPEED *eSpeed)
{
volatile UINT32 uDStatus;
Inp32(DSTS, uDStatus); // System status read
*eSpeed = (USB_SPEED)((uDStatus&0x6) >>1);
/// 0 : High Speed (phy 30mhz or 60mhz
/// 1 : Full Speed (phy 30mhz or 60mhz)
/// 2 : low Speed (phy 6Mhz
/// 3 : Full Speed (phy 48Mhz)
}
//////////
// Function Name : OTGDEV_SetInEpXferSize
// Function Desctiption : This function sets DIEPTSIZn CSR according to input parameters.
// Input : eType, transfer type
// uPktCnt, packet count to transfer
// uXferSize, transfer size
// Output : NONE
// Version :
void OTGDEV_SetInEpXferSize(EP_TYPE eType, UINT32 uPktCnt, UINT32 uXferSize)
{
if(eType == EP_TYPE_CONTROL)
{
Outp32(DIEPTSIZ0, (uPktCnt<<19)|(uXferSize<<0));
}
else if(eType == EP_TYPE_BULK)
{
Outp32(bulkIn_DIEPTSIZ, (1<<29)|(uPktCnt<<19)|(uXferSize<<0));
}
}
//////////
// Function Name : OTGDEV_SetOutEpXferSize
// Function Desctiption : This function sets DOEPTSIZn CSR according to input parameters.
// Input : eType, transfer type
// uPktCnt, packet count to transfer
// uXferSize, transfer size
// Output : NONE
// Version :
void OTGDEV_SetOutEpXferSize(EP_TYPE eType, UINT32 uPktCnt, UINT32 uXferSize)
{
if(eType == EP_TYPE_CONTROL)
{
Outp32(DOEPTSIZ0, (1<<29)|(uPktCnt<<19)|(uXferSize<<0));
}
else if(eType == EP_TYPE_BULK)
{
Outp32(bulkOut_DOEPTSIZ, (uPktCnt<<19)|(uXferSize<<0));
}
}
//////////
// Function Name : OTGDEV_WrPktEp0
// Function Desctiption : This function reads data from the buffer and writes the data on EP0 FIFO.
// Input : buf, address of the data buffer to write on Control EP FIFO
// num, size of the data to write on Control EP FIFO(byte count)
// Output : NONE
// Version :
void OTGDEV_WrPktEp0(UINT8 *buf, int num)
{
int i;
volatile UINT32 Wr_Data=0;
for(i=0;i<num;i+=4)
{
Wr_Data = ((*(buf+3))<<24)|((*(buf+2))<<16)|((*(buf+1))<<8)|*buf;
Outp32(control_EP_FIFO, Wr_Data);
buf += 4;
}
}
//////////
// Function Name : OTGDEV_PrintEp0Pkt
// Function Desctiption : This function reads data from the buffer and displays the data.
// Input : pt, address of the data buffer to read
// count, size of the data to read(byte count)
// Output : NONE
// Version :
void OTGDEV_PrintEp0Pkt(UINT8 *pt, UINT8 count)
{
int i;
EdbgOutputDebugString("[DBG:");
for(i=0;i<count;i++)
EdbgOutputDebugString("%x,", pt[i]);
EdbgOutputDebugString("]\n");
}
//////////
// Function Name : OTGDEV_WrPktBulkInEp
// Function Desctiption : This function reads data from the buffer and writes the data on Bulk In EP FIFO.
// Input : buf, address of the data buffer to write on Bulk In EP FIFO
// num, size of the data to write on Bulk In EP FIFO(byte count)
// Output : NONE
// Version :
void OTGDEV_WrPktBulkInEp(UINT8 *buf, int num)
{
int i;
volatile UINT32 Wr_Data=0;
for(i=0;i<num;i+=4)
{
Wr_Data=((*(buf+3))<<24)|((*(buf+2))<<16)|((*(buf+1))<<8)|*buf;
Outp32(bulkIn_EP_FIFO, Wr_Data);
buf += 4;
}
}
//////////
// Function Name : OTGDEV_RdPktBulkOutEp
// Function Desctiption : This function reads data from Bulk Out EP FIFO and writes the data on the buffer.
// Input : buf, address of the data buffer to write
// num, size of the data to read from Bulk Out EP FIFO(byte count)
// Output : NONE
// Version :
void OTGDEV_RdPktBulkOutEp(UINT8 *buf, int num)
{
int i;
volatile UINT32 Rdata;
for (i=0;i<num;i+=4)
{
//Rdata = Inp32(bulkOut_EP_FIFO);
Inp32(bulkOut_EP_FIFO, Rdata);
buf[i] = (UINT8)Rdata;
buf[i+1] = (UINT8)(Rdata>>8);
buf[i+2] = (UINT8)(Rdata>>16);
buf[i+3] = (UINT8)(Rdata>>24);
}
// increase global down pointer for usb download function
g_pDownPt += num;
}
//////////
// Function Name : OTGDEV_IsUsbOtgSetConfiguration
// Function Desctiption : This function checks if Set Configuration is received from the USB Host.
// Input : NONE
// Output : configuration result
// Version :
BOOL OTGDEV_IsUsbOtgSetConfiguration(void)
{
if (oOtgDev.m_uIsUsbOtgSetConfiguration == 0)
return false;
else
return true;
}
//////////
// Function Name : OTGDEV_SetOpMode
// Function Desctiption : This function sets CSRs related to the operation mode.
// Input : eMode, operation mode(cpu or dma)
// Output : NONE
// Version :
void OTGDEV_SetOpMode(USB_OPMODE eMode)
{
oOtgDev.m_eOpMode = eMode;
Outp32(GINTMSK, INT_RESUME|INT_OUT_EP|INT_IN_EP|INT_ENUMDONE|INT_RESET|INT_SUSPEND|INT_RX_FIFO_NOT_EMPTY); //gint unmask
Outp32(GAHBCFG, MODE_SLAVE|BURST_SINGLE|GBL_INT_UNMASK);
OTGDEV_SetOutEpXferSize(EP_TYPE_BULK, 1, oOtgDev.m_uBulkOutEPMaxPktSize);
OTGDEV_SetInEpXferSize(EP_TYPE_BULK, 1, 0);
Outp32(bulkOut_DOEPCTL, 1<<31|1<<26|2<<18|1<<15|oOtgDev.m_uBulkOutEPMaxPktSize<<0); //bulk out ep enable, clear nak, bulk, usb active, next ep3, max pkt
Outp32(bulkIn_DIEPCTL, 0<<31|1<<26|2<<18|1<<15|oOtgDev.m_uBulkInEPMaxPktSize<<0); //bulk in ep enable, clear nak, bulk, usb active, next ep1, max pkt
}
/* S3C6410USBSER_Init
*
* Called by PQOAL KITL framework to initialize the serial port
*
* Return Value:
*/
BOOL S3C6410USBSER_Init (KITL_SERIAL_INFO *pSerInfo)
{
volatile S3C6410_SYSCON_REG *g_pSysConReg;
g_pSysConReg = (S3C6410_SYSCON_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_SYSCON, FALSE);
// Enable Clock Source
g_pSysConReg->HCLK_GATE |= (1<<20); // HCLK_USB
memset(&g_Info, 0, sizeof(g_Info));
memset(&USBSerInfo, 0, sizeof(USBSERKITL_INFO));
KITLOutputDebugString ("Wait for connecting\n");
KitlIoPortBase = (DWORD)pSerInfo->pAddress;
// delayLoop(100);
if (!KitlIoPortBase)
{
return FALSE;
}
else
{
OTGDEV_InitOtg(USB_HIGH);
// OTGDEV_InitOtg(USB_FULL);
}
pSerInfo->bestSize = 512;
// pSerInfo->bestSize = 64;
return TRUE;
}
/* S3C6410USBSER_WriteData
*
* Block until the byte is sent
*
* Return Value: TRUE on success, FALSE otherwise
*/
#define NPTxFEmpty (0x1<<5)
UINT16 S3C6410USBSER_WriteData (UINT8 *pch, UINT16 length)
{
volatile UINT32 uGIntStatus;
if (USBSerInfo.dwState != KITLUSBSER_STATE_CONNECTED)
{
return length;
}
while(1)
{
Inp32(GINTSTS, uGIntStatus); // Wait Until TX FIFO is availabled.
if (uGIntStatus & NPTxFEmpty)
{
break;
}
}
length = OTGDEV_HandleEvent_BulkIn(pch, length);
return length;
}
void S3C6410USBSER_SendComplete (UINT16 length)
{
volatile UINT32 dwDiepint;
Inp32(bulkIn_DIEPINT, dwDiepint);
Outp32(bulkIn_DIEPINT, dwDiepint);
}
/* S3C6410USBSER_ReadData
*
* Called from PQOAL KITL to read a byte from serial port
*
* Return Value: TRUE on success, FALSE otherwise
*/
UINT16 S3C6410USBSER_ReadData (UINT8 *pch, UINT16 length)
{
length = OTGDEV_HandleEvent(pch, length);
return length;
}
/* S3C6410USBSER_EnableInt
*
* Enable Recv data interrupt
*
* Return Value:
*/
VOID S3C6410USBSER_EnableInt (void)
{
volatile S3C6410_VIC_REG *g_pVIC1Reg;
g_pVIC1Reg = (volatile S3C6410_VIC_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_VIC1, FALSE);
if (!USBSerKitl_POLL)
{
g_pVIC1Reg->VICINTENABLE = (1<<(PHYIRQ_OTG-32));
}
}
/* S3C6410USBSER_DisableInt
*
* Disable Recv data interrupt
*
* Return Value:
*/
VOID S3C6410USBSER_DisableInt (void)
{
volatile S3C6410_VIC_REG *g_pVIC1Reg;
g_pVIC1Reg = (volatile S3C6410_VIC_REG *)OALPAtoVA(S3C6410_BASE_REG_PA_VIC1, FALSE);
if (!USBSerKitl_POLL)
{
g_pVIC1Reg->VICINTENCLEAR = (1<<(PHYIRQ_OTG-32));
}
}
VOID S3C6410USBSER_PowerOff (void)
{
//KITLOutputDebugString ("+S3C6410USBSER_PowerOff\n");
}
VOID S3C6410USBSER_PowerOn (void)
{
//KITLOutputDebugString ("+S3C6410USBSER_PowerOn\n");
}
// serial driver
OAL_KITL_SERIAL_DRIVER DrvUSBSerial = {
S3C6410USBSER_Init,
NULL,
S3C6410USBSER_WriteData,//TX
S3C6410USBSER_SendComplete,//Clear EP1 Interrupt pending
S3C6410USBSER_ReadData,//RX
S3C6410USBSER_EnableInt,
S3C6410USBSER_DisableInt,
NULL, //S3C6410USBSER_PowerOff,
NULL, //S3C6410USBSER_PowerOn,
NULL, //flow control
};
const OAL_KITL_SERIAL_DRIVER *GetKitlUSBSerialDriver (void)
{
return &DrvUSBSerial;
}
static void delayLoop(int count)
{
volatile int j,k;
for(j = 0; j < count; j++)
{
for(k=0;k<100000;k++);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -