📄 s3c2510usbloopback.c
字号:
/* Update the source address for DMA transfer */
*S3C2510_DSAR(GDMA_USB_OUT)=(UINT)S3C2510_USBFIFO(0);
/* update the destination address */
*S3C2510_DDAR(GDMA_USB_OUT)=(UINT)ep0RxBuffer;
/* update the transfer count for DMA */
*S3C2510_DTCR(GDMA_USB_OUT) = length;
/* enable the DMA run register */
*S3C2510_DRER(GDMA_USB_OUT) |= S3C2510_DCON_RE;
#if 0
/* update the Rx buffer */
for(i=0; i < length/4; i++)
{
ep0RxBuffer++;
ep0RxCount +=4;
}
#else
ep0RxBuffer += length/4;
ep0RxCount += length;
#endif
#else
for (i=0; i<length; i+=4)
{
*ep0RxBuffer = *S3C2510_USBFIFO(0);
ep0RxBuffer++;
ep0RxCount += 4;
}
#endif
if (ep0RxCount >= ep0RxLength)
{
/* Check this if we need to do S3C2510_USBEP0CSR_USBDEND */
*S3C2510_USBCSR(0) |= ( S3C2510_USBEP0CSR_USBSVORDY |
S3C2510_USBEP0CSR_USBDEND );
ep0State = EP0_STATE_IDLE ;
ep0RxLength = 0;
ep0RxCount = 0;
ep0RxBuffer = NULL;
#ifdef DEBUG_TRACE
printf("EP0 RX done\n");
#endif /* DEBUG_TRACE */
}
else
{
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
}
}/* if non zero length ... */
}
/*******************************************************************************
*
* s3c2510UsbDeviceRequestStandard - handle Standard Device Request.
*
* RETURNS : N/A
*/
void s3c2510UsbDeviceRequestStandard(void)
{
UINT8 recipient = usbSetup.bmRequestType & USB_RT_RECIPIENT_MASK;
#ifdef DEBUG_TRACE
printf("s3c2510Usb DeviceRequestStandard, 0x%02X\n", recipient);
#endif /* DEBUG_TRACE */
switch (recipient)
{
case USB_RT_DEVICE:
#ifdef DEBUG_TRACE
printf("USB_RT_DEVICE\n");
#endif /* DEBUG_TRACE */
switch (usbSetup.bRequest)
{
case USB_REQUEST_GET_STATUS:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_STATUS\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetStatus();
break;
case USB_REQUEST_CLEAR_FEATURE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_CLEAR_FEATURE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbClearFeature();
break;
case USB_REQUEST_SET_FEATURE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_FEATURE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetFeature();
break;
case USB_REQUEST_SET_ADDRESS:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_ADDRESS\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetAddress();
break;
case USB_REQUEST_GET_DESCRIPTOR:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_DESCRIPTOR\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetDescriptor();
break;
case USB_REQUEST_SET_DESCRIPTOR:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_DESCRIPTOR\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetDescriptor();
break;
case USB_REQUEST_GET_CONFIGURATION:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_CONFIGURATION\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetConfig();
break;
case USB_REQUEST_SET_CONFIGURATION:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_CONFIGURATION\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetConfig();
break;
default:
printf("s3c2510Usb Error: Unknown request, 0x%02X\n", usbSetup.bRequest);
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
}
break;
case USB_RT_INTERFACE:
#ifdef DEBUG_TRACE
printf("USB_RT_INTERFACE\n");
#endif /* DEBUG_TRACE */
switch (usbSetup.bRequest)
{
case USB_REQUEST_GET_INTERFACE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_INTERFACE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetInterface();
break;
case USB_REQUEST_SET_INTERFACE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_INTERFACE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetInterface();
break;
default:
printf("s3c2510Usb Error: Unknown request, 0x%02X\n", usbSetup.bRequest);
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
}
break;
case USB_RT_ENDPOINT:
#ifdef DEBUG_TRACE
printf("USB_RT_ENDPOINT\n");
#endif /* DEBUG_TRACE */
switch (usbSetup.bRequest)
{
case USB_REQUEST_GET_STATUS:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_STATUS\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetStatus();
break;
case USB_REQUEST_CLEAR_FEATURE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_CLEAR_FEATURE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbClearFeature();
break;
case USB_REQUEST_SET_FEATURE:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SET_FEATURE\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSetFeature();
break;
case USB_REQUEST_GET_DESCRIPTOR:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_GET_DESCRIPTOR\n");
#endif /* DEBUG_TRACE */
s3c2510UsbGetDescriptor();
break;
case USB_REQUEST_SYNC_FRAME:
#ifdef DEBUG_TRACE
printf("USB_REQUEST_SYNC_FRAME\n");
#endif /* DEBUG_TRACE */
s3c2510UsbSyncFrame();
break;
default:
printf("s3c2510Usb Error: Unknown request, 0x%02X\n", usbSetup.bRequest);
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
}
break;
case USB_RT_OTHER:
#ifdef DEBUG_TRACE
printf("USB_RT_OTHER\n");
#endif /* DEBUG_TRACE */
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
default:
printf("s3c2510Usb Error: Unknown recipient, 0x%02X\n", recipient);
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
}
}
/*******************************************************************************
*
* s3c2510UsbDeviceRequestClass - handle Standard Class Request.
*
* RETURNS : N/A
*/
void s3c2510UsbDeviceRequestClass(void)
{
}
/*******************************************************************************
*
* s3c2510UsbDeviceRequestVendor - handle Standard Vendor Request.
*
* RETURNS : N/A
*/
void s3c2510UsbDeviceRequestVendor(void)
{
/* Get the length of data to be transferred or recieved */
UINT16 length = FROM_LITTLEW(usbSetup.wLength);
switch (usbSetup.bRequest)
{
case USB_LOOPBACK_CONTROL_WRITE:
#ifdef DEBUG_TRACE
printf("USB_LOOPBACK_CONTROL_WRITE \n");
#endif /* DEBUG_TRACE */
/* if zero length */
if(length == 0)
{
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
/* Endpoint 0 state is idle. */
ep0State = EP0_STATE_IDLE;
break;
}
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
ep0State = EP0_STATE_RECEIVE;
memset(controlLoopbackBuffer, 0, sizeof(controlLoopbackBuffer));
ep0RxBuffer = (UINT32 *)controlLoopbackBuffer;
ep0RxLength = ((length < sizeof(controlLoopbackBuffer))?length :sizeof(controlLoopbackBuffer));
ep0RxCount = 0;
/* Receive the data in to loop back buffer */
s3c2510UsbEp0Rx();
break;
case USB_LOOPBACK_CONTROL_READ:
#ifdef DEBUG_TRACE
printf("USB_LOOPBACK_CONTROL_READ \n");
#endif /* DEBUG_TRACE */
/* if zero length */
if(length == 0)
{
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
/* Endpoint 0 state is idle. */
ep0State = EP0_STATE_IDLE;
break;
}
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
ep0State = EP0_STATE_TRANSMIT;
ep0TxBuffer = (UINT32 *)controlLoopbackBuffer;
ep0TxLength = ((length < sizeof(controlLoopbackBuffer))?length :sizeof(controlLoopbackBuffer));
ep0TxCount = 0;
/* Transmit the loop back buffer */
s3c2510UsbEp0Tx();
break;
default:
printf("s3c2510Usb Error: Unknown request, 0x%02X\n", usbSetup.bRequest);
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
break;
}
}
/*******************************************************************************
*
* s3c2510UsbInt - interrupt service routine.
*
* RETURNS : N/A
*/
void s3c2510UsbInt(void)
{
UINT32 status;
UINT32 stateInt;
UINT32 enabledInt;
/* Read and clear interrupt status. */
status = *S3C2510_USBINTR;
*S3C2510_USBINTR = status;
stateInt = status & (S3C2510_USBINTR_RESET | S3C2510_USBINTR_RESUME | S3C2510_USBINTR_SUSPEND);
/* Get enabled interrupt. */
enabledInt = *S3C2510_USBINTRE & (S3C2510_USBINTRE_EP4 |
S3C2510_USBINTRE_EP3 |
S3C2510_USBINTRE_EP2 |
S3C2510_USBINTRE_EP1 |
S3C2510_USBINTRE_EP0);
if (stateInt == S3C2510_USBINTR_SUSPEND)
{
*S3C2510_USBINTRE = (enabledInt | S3C2510_USBINTRE_RESET);
}
else if (stateInt == S3C2510_USBINTR_RESUME)
{
*S3C2510_USBINTRE = (enabledInt | S3C2510_USBINTRE_RESET | S3C2510_USBINTRE_SUSPEND);
}
else if (stateInt == (S3C2510_USBINTR_RESUME | S3C2510_USBINTR_SUSPEND))
{
*S3C2510_USBINTRE = (enabledInt | S3C2510_USBINTRE_RESET | S3C2510_USBINTRE_SUSPEND);
}
else if (stateInt == S3C2510_USBINTR_RESET)
{
s3c2510UsbReset();
}
/* Endpoint 0 Interrupt */
if (status & S3C2510_USBINTR_EP0)
{
netJobAdd(
(FUNCPTR)s3c2510UsbEP0Handler,
0,
0,
0,
0,
0
);
}
/* Endpoint 1 Interrupt */
if (status & S3C2510_USBINTR_EP1)
{
netJobAdd(
(FUNCPTR)s3c2510UsbEP1Handler,
0,
0,
0,
0,
0
);
}
/* Endpoint 2 Interrupt */
if (status & S3C2510_USBINTR_EP2)
{
netJobAdd(
(FUNCPTR)s3c2510UsbEP2Handler,
0,
0,
0,
0,
0
);
}
/* Endpoint 3 Interrupt */
if (status & S3C2510_USBINTR_EP3)
{
netJobAdd(
(FUNCPTR)s3c2510UsbEP3Handler,
0,
0,
0,
0,
0
);
}
/* Endpoint 4 Interrupt */
if (status & S3C2510_USBINTR_EP4)
{
netJobAdd(
(FUNCPTR)s3c2510UsbEP4Handler,
0,
0,
0,
0,
0
);
}
}
/*******************************************************************************
*
* s3c2510UsbEP0Handler - Endpoint 0 interrupt handler.
*
* RETURNS : N/A
*/
void s3c2510UsbEP0Handler(void)
{
UINT32 status;
/* Read Endpoint 0 Common Status Register. */
status = *S3C2510_USBCSR(0);
#ifdef DEBUG_TRACE
printf("s3c2510Usb EP0Handler, 0x%08X\n", status);
#endif /* DEBUG_TRACE */
if (status & S3C2510_USBEP0CSR_USBSTSTALL)
{
#ifdef DEBUG_TRACE
printf("S3C2510_USBEP0CSR_USBSTSTALL\n");
#endif /* DEBUG_TRACE */
/* Clear status.changed by Ajay */
*S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSTSTALL;
/* Endpoint 0 state is idle. */
ep0State = EP0_STATE_IDLE;
}
else if (status & S3C2510_USBEP0CSR_USBSETEND)
{
printf("S3C2510_USBEP0CSR_USBSETEND\n");
/* Endpoint 0 state is idle. */
ep0State = EP0_STATE_IDLE;
}
else if (!status)
{
printf("s3c2510Usb Error: Invalid status\n");
}
switch (ep0State)
{
case EP0_STATE_IDLE:
#ifdef DEBUG_TRACE
printf("EP0_STATE_IDLE\n");
#endif /* DEBUG_TRACE */
if (status & S3C2510_USBEP0CSR_USBORDY)
{
UINT32 count = (*S3C2510_USBWCEP(0) & S3C2510_USBWCEP_WRTCNT_MASK) >> S3C2510_USBWCEP_WRTCNT_SHIFT;
if (count != USB_SETUP_LEN)
{
printf("s3c2510Usb Error: Invalid length, %d\n", (int)count);
}
((UINT32 *)(&usbSetup))[0] = *S3C2510_USBFIFO(0);
((UINT32 *)(&usbSetup))[1] = *S3C2510_USBFIFO(0);
switch (usbSetup.bmRequestType & USB_RT_CATEGORY_MASK)
{
case USB_RT_STANDARD:
#ifdef DEBUG_TRACE
printf("USB_RT_STANDARD\n");
#endif /* DEBUG_TRACE */
s3c2510UsbDeviceRequestStandard();
break;
case USB_RT_CLASS:
#ifdef DEBUG_TRACE
printf("USB_RT_CLASS\n");
#endif /* DEBUG_TRACE */
s3c2510UsbDeviceRequestClass();
break;
case USB_RT_VENDOR:
#ifdef DEBUG_TRACE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -