⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 s3c2510usbloopback.c

📁 VxWorks BSP for S3C2510A
💻 C
📖 第 1 页 / 共 4 页
字号:

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb ClearFeature, 0x%04X, 0x%02X\n", feature, index);
#endif  /* DEBUG_TRACE */

    switch (feature)
    {
    case USB_FEATURE_ENDPOINT_STALL:
#ifdef  DEBUG_TRACE
        printf("USB_FEATURE_ENDPOINT_STALL\n");
#endif  /* DEBUG_TRACE */
        switch (index & 0x7f)
        {
        case 0:
            ep0Status = 0;
            break;

        case 1:
            ep1Status = 0;
            break;

        case 2:
            ep2Status = 0;
            break;

        case 3:
            ep3Status = 0;
            break;

        case 4:
            ep4Status = 0;
            break;

        default:
            printf("s3c2510Usb Error: Unknown endpoint, 0x%02X\n", index);
            break;
        }
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    case USB_FEATURE_REMOTE_WAKEUP:
#ifdef  DEBUG_TRACE
        printf("USB_FEATURE_REMOTE_WAKEUP\n");
#endif  /* DEBUG_TRACE */
        deviceStatus = 0;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    default:
        printf("s3c2510Usb Error: Unknown feature, 0x%04X\n", feature);
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;
    }
}

/*******************************************************************************
*
* s3c2510UsbSetFeature - set feature.
*
* RETURNS : N/A
*/

void s3c2510UsbSetFeature(void)
{
    UINT16 feature = FROM_LITTLEW(usbSetup.wValue);
    UINT8 index = LSB(FROM_LITTLEW(usbSetup.wIndex));

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SetFeature, 0x%04X, 0x%02X\n", feature, index);
#endif  /* DEBUG_TRACE */

    switch (feature)
    {
    case USB_FEATURE_ENDPOINT_STALL:
#ifdef  DEBUG_TRACE
        printf("USB_FEATURE_ENDPOINT_STALL\n");
#endif  /* DEBUG_TRACE */
        switch (index & 0x7f)
        {
        case 0:
            ep0Status = USB_EP_STATUS_HALT;
            break;

        case 1:
            ep1Status = USB_EP_STATUS_HALT;
            break;

        case 2:
            ep2Status = USB_EP_STATUS_HALT;
            break;

        case 3:
            ep3Status = USB_EP_STATUS_HALT;
            break;

        case 4:
            ep4Status = USB_EP_STATUS_HALT;
            break;

        default:
            printf("s3c2510Usb Error: Unknown endpoint, 0x%02X\n", index);
            break;
        }
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    case USB_FEATURE_REMOTE_WAKEUP:
#ifdef  DEBUG_TRACE
        printf("USB_FEATURE_REMOTE_WAKEUP\n");
#endif  /* DEBUG_TRACE */
        deviceStatus = USB_DEV_STATUS_REMOTE_WAKEUP;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    default:
        printf("s3c2510Usb Error: Unknown feature, 0x%04X\n", feature);
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
        break;
    }
}

/*******************************************************************************
*
* s3c2510UsbSetAddress - set address.
*
* RETURNS : N/A
*/

void s3c2510UsbSetAddress(void)
{
    UINT8 address = LSB(FROM_LITTLEW(usbSetup.wValue));

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SetAddress, 0x%02X\n", address);
#endif  /* DEBUG_TRACE */

    *S3C2510_USBFA = S3C2510_USBFA_UP | (address & S3C2510_USBFA_MASK);
    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;

    /* Endpoint 0 state is idle. */
    ep0State = EP0_STATE_IDLE;
}

/*******************************************************************************
*
* s3c2510UsbGetDescriptor - get descriptor.
*
* RETURNS : N/A
*/

void s3c2510UsbGetDescriptor(void)
{
    UINT8 type = MSB(FROM_LITTLEW(usbSetup.wValue));
    UINT16 length = FROM_LITTLEW(usbSetup.wLength);

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb GetDescriptor, 0x%02X\n", type);
#endif  /* DEBUG_TRACE */

    switch (type)
    {
    case USB_DESCRIPTOR_DEVICE:
#ifdef  DEBUG_TRACE
        printf("USB_DESCRIPTOR_DEVICE\n");
#endif  /* DEBUG_TRACE */
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        ep0State    = EP0_STATE_TRANSMIT;
        ep0TxBuffer = (UINT32 *)descrDevice;
        /* Changed by Ajay...as it is a clear bug */
        /* ep0TxLength = sizeof(descrDevice);*/
        ep0TxLength = ((length < sizeof(descrDevice))?length :sizeof(descrDevice));
        ep0TxCount  = 0;
#ifdef  DEBUG_TRACE
        s3c2510UsbDump((UCHAR *)ep0TxBuffer, ep0TxLength);
#endif  /* DEBUG_TRACE */
        s3c2510UsbEp0Tx();
        break;

    case USB_DESCRIPTOR_CONFIGURATION:
#ifdef  DEBUG_TRACE
        printf("USB_DESCRIPTOR_CONFIGURATION\n");
#endif  /* DEBUG_TRACE */
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        ep0State    = EP0_STATE_TRANSMIT;
        ep0TxBuffer = (UINT32 *)(descrConfig);
        /* Changed by Ajay...as it is a clear bug */
        /* ep0TxLength = sizeof(descrConfig);*/
        ep0TxLength = ((length < sizeof(descrConfig))?length :sizeof(descrConfig));
        ep0TxCount  = 0;
#ifdef  DEBUG_TRACE
        s3c2510UsbDump((UCHAR *)ep0TxBuffer, ep0TxLength);
#endif  /* DEBUG_TRACE */
        s3c2510UsbEp0Tx();
        break;

    case USB_DESCRIPTOR_STRING:
#ifdef  DEBUG_TRACE
        printf("USB_DESCRIPTOR_STRING\n");
#endif  /* DEBUG_TRACE */
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    case USB_DESCRIPTOR_INTERFACE:
#ifdef  DEBUG_TRACE
        printf("USB_DESCRIPTOR_INTERFACE\n");
#endif  /* DEBUG_TRACE */
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    case USB_DESCRIPTOR_ENDPOINT:
#ifdef  DEBUG_TRACE
        printf("USB_DESCRIPTOR_ENDPOINT\n");
#endif  /* DEBUG_TRACE */
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
        break;

    default:
        printf("s3c2510Usb Error: Unknown descriptor type, 0x%02X\n", type);
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
        break;
    }
}

/*******************************************************************************
*
* s3c2510UsbSetDescriptor - set descriptor.
*
* RETURNS : N/A
*/

void s3c2510UsbSetDescriptor(void)
{
#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SetDescriptor\n");
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbGetConfig - get coniguration.
*
* RETURNS : N/A
*/

void s3c2510UsbGetConfig(void)
{
#ifdef  DEBUG_TRACE
    printf("s3c2510Usb GetConfig\n");
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
    *S3C2510_USBWCEP(0) = 2 << S3C2510_USBWCEP_CPUWRTCNT_SHIFT;
    *S3C2510_USBFIFO(0) = TO_LITTLEL(deviceConfig);
    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbSetConfig - set configuration.
*
* RETURNS : N/A
*/

void s3c2510UsbSetConfig(void)
{
    deviceConfig = FROM_LITTLEW(usbSetup.wValue);

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SetConfig, 0x%08X\n", deviceConfig);
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbGetInterface - get interface.
*
* RETURNS : N/A
*/

void s3c2510UsbGetInterface(void)
{
#ifdef  DEBUG_TRACE
    printf("s3c2510Usb GetInterface\n");
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY;
    *S3C2510_USBWCEP(0) = 2 << S3C2510_USBWCEP_CPUWRTCNT_SHIFT;
    *S3C2510_USBFIFO(0) = TO_LITTLEL(deviceInterface);
    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbSetInterface - set interface.
*
* RETURNS : N/A
*/

void s3c2510UsbSetInterface(void)
{
    deviceInterface = FROM_LITTLEW(usbSetup.wValue);

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SetInterface, 0x%08X\n", deviceInterface);
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbSyncFrame - synchronize frame.
*
* RETURNS : N/A
*/

void s3c2510UsbSyncFrame(void)
{
#ifdef  DEBUG_TRACE
    printf("s3c2510Usb SyncFrame\n");
#endif  /* DEBUG_TRACE */

    *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBSVORDY | S3C2510_USBEP0CSR_USBDEND;
}

/*******************************************************************************
*
* s3c2510UsbEp0Tx - output to Endpoint 0.
*
* RETURNS : N/A
*/

void s3c2510UsbEp0Tx()
{
    UINT32 length;
#if ! GDMA_Transfer_Mode
    UINT32 i;
#endif

#ifdef  DEBUG_TRACE
    printf("s3c2510Usb Ep0Out\n");
#endif  /* DEBUG_TRACE */
 
/* AN ERROR >>>> CHANGED BY AJAY */
#if 0
   *S3C2510_USBWCEP(0) = /* Ajay ep0TxCount */ep0TxLength << S3C2510_USBWCEP_CPUWRTCNT_SHIFT;
#endif

    if ((!ep0TxBuffer) || (!ep0TxLength))
    {
        *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
       
        printf("s3c2510Usb Error: no data, %08X, %d\n", (UINT32)ep0TxBuffer, (int)ep0TxLength);

        return;
    }

    if (!(*S3C2510_USBCSR(0) & S3C2510_USBEP0CSR_USBINRDY))
    {
        length = ep0TxLength - ep0TxCount;

        if (length > USB_EP0_MAXP_SIZE)
        {
            length = USB_EP0_MAXP_SIZE;
        }
#if 1 /* AN ERROR >>>> CHANGED BY AJAY */
        *S3C2510_USBWCEP(0) = length << S3C2510_USBWCEP_CPUWRTCNT_SHIFT;
#endif /* AN ERROR >>>> CHANGED BY AJAY */

        if (*S3C2510_USBINTR & S3C2510_USBINTR_RESET)
        {
            *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;

            ep0State    = EP0_STATE_IDLE;
            ep0TxLength = 0;
            ep0TxCount  = 0;
            ep0TxBuffer = NULL;

            printf("s3c2510Usb Error: Reset\n");

            return;
        }

        if (length > 0)
        {
#ifdef  DEBUG_TRACE
            printf("write %d bytes\n", (int)length);
#endif  /* DEBUG_TRACE */

#if GDMA_Transfer_Mode /* If to use DMA */

            /* Update the source address for DMA transfer */
            *S3C2510_DSAR(GDMA_USB_IN)=(UINT)ep0TxBuffer;

            /* update the destination address */
            *S3C2510_DDAR(GDMA_USB_IN)=(UINT)S3C2510_USBFIFO(0);

            /* update the transfer count for DMA */
      	    *S3C2510_DTCR(GDMA_USB_IN) =length;

            /* enable the DMA run register */
      	    *S3C2510_DRER(GDMA_USB_IN) |= S3C2510_DCON_RE;
#if 0
      	    /* update the length and tx buffer */
      	    for (i=0; i<length; i+=4)
            {
               *ep0TxBuffer++;
               ep0TxCount += 4;
            }
#else

            ep0TxBuffer += length/4;
            ep0TxCount += length;
#endif

#else

            for (i=0; i<length; i+=4)
            {
               *S3C2510_USBFIFO(0) = *ep0TxBuffer++;
               ep0TxCount += 4;
               
            }
#endif            
        }

        if (*S3C2510_USBINTR & S3C2510_USBINTR_RESET)
        {
            *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;

            ep0State    = EP0_STATE_IDLE;
            ep0TxLength = 0;
            ep0TxCount  = 0;
            ep0TxBuffer = NULL;

            printf("s3c2510Usb Error: Reset\n");

            return;
        }

        if (ep0TxCount >= ep0TxLength)
        {
            *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY | S3C2510_USBEP0CSR_USBDEND;
            ep0State    = EP0_STATE_IDLE ;
            ep0TxLength = 0;
            ep0TxCount  = 0;
            ep0TxBuffer = NULL;

#ifdef  DEBUG_TRACE
            printf("EP0 TX done\n");
#endif  /* DEBUG_TRACE */
        }
        else
        {
            *S3C2510_USBCSR(0) |= S3C2510_USBEP0CSR_USBINRDY;
        }
    }
}

/*******************************************************************************
*
* s3c2510UsbEp0Rx - input from Endpoint 0.
*
* RETURNS : N/A
*/

void s3c2510UsbEp0Rx()
{
	UINT32 length;
#if ! GDMA_Transfer_Mode
  UINT32 i;
#endif
#ifdef  DEBUG_TRACE
  printf("s3c2510Usb Ep0In\n");
#endif  /* DEBUG_TRACE */

 /* Check if data is available in EP0 FIFO */
  if(((*S3C2510_USBCSR(0)) & S3C2510_USBEP0CSR_USBORDY) != S3C2510_USBEP0CSR_USBORDY)
  {
    /* log the meassage no data available on EP0 */
#ifdef  DEBUG_TRACE
    printf("No data available in Ep0 \n");
#endif  /* DEBUG_TRACE */
    return;
  }
  /* Update the transfer length by shifting the write count by */
  length = *S3C2510_USBWCEP(0);
  length = length >> S3C2510_USBWCEP_WRTCNT_SHIFT;
  
  /* if non zero length tarnsfer the data from EP0 FIFO into the loopback buffer */
  if(length > 0 )
  {
  	/* if to use DMA for tarnsfers */
#if GDMA_Transfer_Mode

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -