📄 kitlusbser.c
字号:
break;
}
break;
case DEVICE_QUALIFIER:
//KITLOutputDebugString("MCU >> Get Device Qualifier Descriptor \n");
g_uEp0State = EP0_STATE_GD_DEV_QUALIFIER;
break;
}
break;
case STANDARD_CLEAR_FEATURE:
//KITLOutputDebugString("MCU >> Clear Feature \n");
switch (g_oDeviceRequest.bmRequestType)
{
case DEVICE_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 1)
uRemoteWakeUp = FALSE;
break;
case ENDPOINT_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 0)
{
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
oStatusGet.Endpoint0= 0;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01) // IN Endpoint 1
oStatusGet.Endpoint1= 0;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03) // OUT Endpoint 3
oStatusGet.Endpoint3= 0;
}
break;
default:
break;
}
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_SET_FEATURE:
//KITLOutputDebugString("\n MCU >> Set Feature \n");
switch (g_oDeviceRequest.bmRequestType)
{
case DEVICE_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 1)
uRemoteWakeUp = TRUE;
break;
case ENDPOINT_RECIPIENT:
if (g_oDeviceRequest.wValue_L == 0)
{
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
oStatusGet.Endpoint0= 1;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01)
oStatusGet.Endpoint1= 1;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03)
oStatusGet.Endpoint3= 1;
}
break;
default:
break;
}
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_GET_STATUS:
switch(g_oDeviceRequest.bmRequestType)
{
case (0x80):
oStatusGet.Device=((UINT8)uRemoteWakeUp<<1)|0x1; // SelfPowered
g_uEp0State = EP0_GET_STATUS0;
break;
case (0x81):
oStatusGet.Interface=0;
g_uEp0State = EP0_GET_STATUS1;
break;
case (0x82):
if ((g_oDeviceRequest.wIndex_L & 0x7f) == 0x00)
g_uEp0State = EP0_GET_STATUS2;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x01)
g_uEp0State = EP0_GET_STATUS3;
if ((g_oDeviceRequest.wIndex_L & 0x8f) == 0x03)
g_uEp0State = EP0_GET_STATUS4;
break;
default:
break;
}
break;
case STANDARD_GET_INTERFACE:
g_uEp0State = EP0_INTERFACE_GET;
break;
case STANDARD_SET_INTERFACE:
oInterfaceGet.AlternateSetting= g_oDeviceRequest.wValue_L;
g_uEp0State = EP0_STATE_INIT;
break;
case STANDARD_SYNCH_FRAME:
g_uEp0State = EP0_STATE_INIT;
break;
default:
break;
}
}
TransferEp0();
//KITLOutputDebugString ("[-]HandleEvent_EP0\n");
}
/* S3C2450USBSER_Init
*
* Called by PQOAL KITL framework to initialize the serial port
*
* Return Value:
*/
BOOL S3C2450USBSER_Init (KITL_SERIAL_INFO *pSerInfo)
{
volatile S3C2450_IOPORT_REG *g_pIOPortReg;
UINT32 uStatus;
g_pIOPortReg = (S3C2450_IOPORT_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_IOPORT, FALSE);
memset(&g_Info, 0, sizeof(g_Info));
memset(&USBSerInfo, 0, sizeof(USBSERKITL_INFO));
// //KITLOutputDebugString ("[+]S3C2450USBSER_Init\n");
KITLOutputDebugString ("Wait for connecting\n");
KitlIoPortBase = (DWORD)pSerInfo->pAddress;
if (!KitlIoPortBase)
{
return FALSE;
}
else
{
g_pUSBDReg = (volatile S3C2450_USBD_REG *)OALPAtoVA(KitlIoPortBase, FALSE);
//KITLOutputDebugString ("KitlIoPortBase OK\n");
S3C2450_USB_INIT();
#if 1 //polling
while(USBSerInfo.dwState != KITLUSBSER_STATE_CONFIGURED)
{
Inp32(SYS_STATUS_REG, uStatus); // System status read
if (uStatus & INT_REG_RESET) // Reset interrupt
{
Outp32(SYS_STATUS_REG, INT_REG_RESET); // Interrupt Clear
SetEndpoint();
g_uEp0State = EP0_STATE_INIT;
//KITLOutputDebugString("\n [USB_Diag_Log] : Reset Mode \n");
}
g_pUSBDReg->IR = 0;
HandleEvent_EP0();
}
#endif
}
pSerInfo->bestSize = 512;
//KITLOutputDebugString ("[-]S3C2450USBSER_Init\n");
return TRUE;
}
/* S3C2450USBSER_WriteData
*
* Block until the byte is sent
*
* Return Value: TRUE on success, FALSE otherwise
*/
UINT16 S3C2450USBSER_WriteData (UINT8 *pch, UINT16 length)
{
// //KITLOutputDebugString("[+]S3C2450USBSER_WriteData , Input LEN: %d, State :%d \n",length,USBSerInfo.dwState);
if (USBSerInfo.dwState != KITLUSBSER_STATE_CONNECTED)
return length;
length = HandleEvent_BulkIn(pch, length);
//KITLOutputDebugString("[-]S3C2450USBSER_WriteData, output LEN : %d\n\n",length);
return length;
}
void S3C2450USBSER_SendComplete (UINT16 length)
{
UINT32 ep_int;
UINT16 ep1csr;
// clear EP1 interrupt
//KITLOutputDebugString ("[+]S3C2450USBSER_SendComplete\n");
Inp32(EP_INT_REG, ep_int);
// EP1 CSR register status check
Outp32(INDEX_REG, 0x01);
Inp32(EP_STATUS_REG, ep1csr);
if (ep_int & INT_REG_EP1){
Outp32(EP_INT_REG, INT_REG_EP1); // Interrupt Clear
// //KITLOutputDebugString ("[-]SendCom_ClearINT,%x, LENd : %d\n\n",ep_int,length);
if (ep1csr & EP_SENT_STALL) { // SENT STALL : protocol stall.
//KITLOutputDebugString("Sent Stall \n");
Outp32(EP_STATUS_REG, EP_SENT_STALL);
}
if (ep1csr & EP_TX_SUCCESS)
{
//KITLOutputDebugString("EP1_TX_SUCCESS\n");
Outp32(EP_STATUS_REG, EP_TX_SUCCESS); // Endpoint Status Register Clear
}
}
//KITLOutputDebugString ("[-]S3C2450USBSER_SendComplete\n");
}
/* S3C2450USBSER_ReadData
*
* Called from PQOAL KITL to read a byte from serial port
*
* Return Value: TRUE on success, FALSE otherwise
*/
UINT16 S3C2450USBSER_ReadData (UINT8 *pch, UINT16 length)
{
volatile S3C2450_INTR_REG *s2450INT = (S3C2450_INTR_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_INTR, FALSE);
UINT32 uStatus,uStatus1;
UINT16 ep_int;
UINT16 RxLength = 0;
Inp32(SYS_STATUS_REG, uStatus); // System status read
Inp32(SYS_CON_REG, uStatus1); // System status read
//KITLOutputDebugString("SYS_STATUS_REG : %x, SYS_CON_REG : %x \n", uStatus,uStatus1);
Inp32(EP_INT_REG, ep_int);
//KITLOutputDebugString("EP_INT_REG : %x \n", ep_int);
if (uStatus & INT_REG_VBUS)
{
Outp32(SYS_STATUS_REG, INT_REG_VBUS); // Interrupt Clear
//KITLOutputDebugString ("INT_REG_VBUS\n");
}
if (uStatus & 0xff80) // Error interrupt check
{
Outp32(SYS_STATUS_REG, INT_ERR); // Interrupt Clear
//KITLOutputDebugString ("Error interrupt check : %x\n",uStatus);
}
// Which USB interrupts happen
if (uStatus & INT_REG_SUSPEND)
{
Outp32(SYS_STATUS_REG, INT_REG_SUSPEND); // Interrupt Clear
//KITLOutputDebugString ("INT_REG_SUSPEND\n");
}
if (uStatus & INT_REG_RESUME)
{
Outp32(SYS_STATUS_REG, INT_REG_RESUME); // Host software send ClearPortFeature. Interrupt Clear
//KITLOutputDebugString ("INT_REG_RESUME\n");
}
if (uStatus & INT_REG_RESET) // Reset interrupt
{
Outp32(SYS_STATUS_REG, INT_REG_RESET); // Interrupt Clear
SetEndpoint();
g_uEp0State = EP0_STATE_INIT;
//KITLOutputDebugString ("INT_REG_RESET\n");
}
if (uStatus & INT_REG_SDE) // Device Speed Detection interrupt
{
Outp32(SYS_STATUS_REG, INT_REG_SDE); // Interrupt Clear
//KITLOutputDebugString("\n [USB_Diag_Log] : Speed Detection interrupt \n");
//KITLOutputDebugString (" Speed Detection interrupt\n");
if (uStatus & INT_REG_HSP) // Set if Device is High speed or Full speed
{
Outp32(SYS_STATUS_REG, INT_REG_HSP); // High Speed Device Interrupt Clear?? may be not.
//KITLOutputDebugString("\n [USB_Diag_Log] : High Speed Detection\n");
// KITLOutputDebugString ("USB_HIGH\n");
SetMaxPktSizes(USB_HIGH);
SetDescriptorTable();
}
else
{
//KITLOutputDebugString ("USB_FULL\n");
SetMaxPktSizes(USB_FULL);
SetDescriptorTable();
}
}
//}
Outp32(EP_STATUS_REG,uStatus);
// Inp32(EP_STATUS_REG, ep_int_status); // EP interrrupt status read
//KITLOutputDebugString("EP_STATUS_REG : %x \n", ep_int_status);
Inp32(EP_INT_REG, ep_int);
//KITLOutputDebugString("EP_INT_REG2 : %x \n", ep_int);
if (ep_int & INT_REG_EP0)
{
//KITLOutputDebugString((" Control Transfer Interrupt \n"));
Outp32(EP_INT_REG, INT_REG_EP0); // Interrupt Clear
HandleEvent_EP0();
}
// Endpoint3 bulkOut
else if (ep_int & INT_REG_EP3)
{
//KITLOutputDebugString(" Bulk Out Transfer Interrupt \n");
// printf("*");
RxLength = HandleEvent_BulkOut(pch, length);
Outp32(EP_INT_REG, INT_REG_EP3); // Interrupt Clear
//KITLOutputDebugString ("[-]READ_Clear INT : %x , LEN : %d\n\n",ep_int,RxLength);
}
//KITLOutputDebugString ("[-]S3C2450USBSER_ReadData\n\n");
return RxLength;
}
/* S3C2450USBSER_EnableInt
*
* Enable Recv data interrupt
*
* Return Value:
*/
VOID S3C2450USBSER_EnableInt (void)
{
#ifndef USBSER_KITL_POLL
volatile S3C2450_INTR_REG *g_pINTReg;
g_pINTReg = (volatile S3C2450_INTR_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_INTR, FALSE);
//KITLOutputDebugString ("[+]S3C2450USBSER_EnableInt\n");
g_pINTReg->INTMSK1 &= ~(1<<IRQ_USBD);
// //KITLOutputDebugString ("[-]S3C2450USBSER_EnableInt\n");
#endif
}
/* S3C2450USBSER_DisableInt
*
* Disable Recv data interrupt
*
* Return Value:
*/
VOID S3C2450USBSER_DisableInt (void)
{
#ifndef USBSER_KITL_POLL
volatile S3C2450_INTR_REG *g_pINTReg;
g_pINTReg = (volatile S3C2450_INTR_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_INTR, FALSE);
//KITLOutputDebugString ("[+]S3C2450USBSER_DisableInt\n");
g_pINTReg->INTMSK1 |= (1<<IRQ_USBD);
//KITLOutputDebugString ("[-]S3C2450USBSER_DisableInt\n");
#endif
}
VOID S3C2450USBSER_PowerOff (void)
{
//KITLOutputDebugString ("+S3C2450USBSER_PowerOff\n");
}
VOID S3C2450USBSER_PowerOn (void)
{
//KITLOutputDebugString ("+S3C2450USBSER_PowerOn\n");
}
// serial driver
OAL_KITL_SERIAL_DRIVER DrvUSBSerial = {
S3C2450USBSER_Init,
NULL,
S3C2450USBSER_WriteData,//TX
S3C2450USBSER_SendComplete,//Clear EP1 Interrupt pending
S3C2450USBSER_ReadData,//RX
S3C2450USBSER_EnableInt,
S3C2450USBSER_DisableInt,
NULL, //S3C2450USBSER_PowerOff,
NULL, //S3C2450USBSER_PowerOn,
NULL, //flow control
};
const OAL_KITL_SERIAL_DRIVER *GetKitlUSBSerialDriver (void)
{
return &DrvUSBSerial;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -