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

📄 usbtargmslib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
* value.
*
* RETURNS: USB_BULK_CBW
*
* ERRNO:
*  none.
*/

USB_BULK_CBW *usbMsCBWInit (void)
    {
    
    /* init CBW and set signature */
    
    memset(&g_cbw, 0, sizeof(USB_BULK_CBW));
    g_cbw.signature = USB_BULK_SWAP_32 (USB_CBW_SIGNATURE);

    return(&g_cbw);
    }

/******************************************************************************
*
* usbMsCSWGet - get the current CSW
*
* This routine retrieves the current CSW.
*
* RETURNS: USB_BULK_CSW
*
* ERRNO:
*  none.
*/

USB_BULK_CSW *usbMsCSWGet (void)
    {

    /* return instance of last saved CSW data structure */

    return(&g_csw);
    }

/*******************************************************************************
*
* usbMsCSWInit - initialize the CSW
*
* This routine initializes the CSW.
*
* RETURNS: USB_BULK_CSW
*
* ERRNO:
*  none
*/

USB_BULK_CSW *usbMsCSWInit (void)
    {
    memset(&g_csw, 0, sizeof(USB_BULK_CSW));
    g_csw.signature = USB_BULK_SWAP_32 (USB_CSW_SIGNATURE);

    return(&g_csw);
    }


/*******************************************************************************
*
* usbMsBulkInStall - stall the bulk-in pipe
*
* This routine stalls the bulk-in pipe.
*
* RETURNS: OK or ERROR if not able to stall the bulk IN endpoint.
*
* ERRNO: 
*  none
*/

STATUS usbMsBulkInStall (void)
    {
    STATUS	retVal = ERROR;

#ifdef USB1_1
    retVal = usbTargPipeStatusSet(g_targChannel,
                                  g_bulkInPipeHandle,
                                  TCD_ENDPOINT_STALL);
#else
    retVal = usbTargPipeStatusSet(g_bulkInPipeHandle,
                                  TCD_ENDPOINT_STALL);
#endif

    if (retVal == OK)
        g_bulkInStallStatus = TRUE;
    return(retVal);
    }


/*******************************************************************************
*
* usbMsBulkInUnStall - unstall the bulk-in pipe
*
* This routine unstalls the bulk-in pipe.
*
* RETURNS: OK or ERROR if not able to un-stall the bulk IN endpoint.
*
* ERRNO: 
*  none
*/

STATUS usbMsBulkInUnStall (void)
    {
    STATUS	retVal = ERROR;

    /* Unstall the endpoint */

#ifdef USB1_1

    retVal = usbTargPipeStatusSet(g_targChannel,
                                  g_bulkInPipeHandle,
                                  TCD_ENDPOINT_UNSTALL);
#else
    retVal = usbTargPipeStatusSet(g_bulkInPipeHandle,
                                  TCD_ENDPOINT_UNSTALL);
#endif

    if (retVal == OK)
        g_bulkInStallStatus = FALSE;

    return(retVal);
    }

/*******************************************************************************
*
* usbMsBulkOutStall - stall the bulk-out pipe
*
* This routine stalls the bulk-out pipe.
*
* RETURNS: OK or ERROR in unable to stall the bulk OUT endpoints.
*
* ERRNO:
*  none.
*/

STATUS usbMsBulkOutStall (void)
    {
    STATUS	retVal = ERROR;

    /* Stall the bulk OUT endpoint */

#ifdef USB1_1

    retVal = usbTargPipeStatusSet(g_targChannel,
                                  g_bulkOutPipeHandle,
                                  TCD_ENDPOINT_STALL);
#else
    retVal = usbTargPipeStatusSet(g_bulkOutPipeHandle,
                                  TCD_ENDPOINT_STALL);
#endif
    if (retVal == OK)
        g_bulkOutStallStatus = TRUE;

    return(retVal);
    }

/*******************************************************************************
*
* usbMsBulkOutUnStall - unstall the bulk-out pipe
*
* This routine unstalls the bulk-out pipe.
*
* RETURNS: OK or ERROR if not able to unstall the bulk out endpoints
*
* ERRNO: 
*  none
*/

STATUS usbMsBulkOutUnStall (void)
    {
    STATUS	retVal = ERROR;

    /* un-stall the bulk-out endpoint */ 

#ifdef USB1_1
    retVal = usbTargPipeStatusSet(g_targChannel,
                                  g_bulkOutPipeHandle,
                                  TCD_ENDPOINT_UNSTALL);
#else
    retVal = usbTargPipeStatusSet(g_bulkOutPipeHandle,
                                  TCD_ENDPOINT_UNSTALL);
#endif

    if (retVal == OK)
        g_bulkOutStallStatus = FALSE;

    return(retVal);
    }


/******************************************************************************
*
* featureClear - clear the specified feature
*
* This routine implements the clear feature standard device request.
*
* RETURNS: OK or ERROR if not able to clear the feature 
*
* ERRNO:
*  none. 
*/

LOCAL STATUS featureClear
    (
    pVOID		param,		/* TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,	/* target channel */
    UINT8		requestType,	/* request type */
    UINT16		feature,	/* feature to clear */
    UINT16		index		/* index */
    )
    {
    STATUS		status = ERROR;	/* status value */
    UINT8		* pData;	/* to hold CSW */
    UINT32		dSize;		/* size of USB_BULK_CSW */
    struct usbBulkCsw	* pCsw;		/* Command Status Wrapper */
    BOOL		CSWsend = FALSE;

    /* only one target */

    if (targChannel != g_targChannel) 
        return(ERROR);

    /* This request is not accepted when the device is in the default state */

    if (g_deviceAddr == 0)
        return ERROR;

    /* this request must be standard request from the host */

    if (((requestType & USB_RT_DIRECTION_MASK) != USB_RT_HOST_TO_DEV) ||
        ((requestType & USB_RT_CATEGORY_MASK) != USB_RT_STANDARD))
        return(ERROR);

    requestType &= ~(USB_RT_DIRECTION_MASK | USB_RT_CATEGORY_MASK);

    if (requestType == USB_RT_ENDPOINT)
        {
        if (feature == USB_FSEL_DEV_ENDPOINT_HALT)
            {
            if (index == MS_BULK_IN_ENDPOINT_NUM)
                {
                status = usbMsBulkInUnStall();

                if ((status == OK) && (g_bulkInStallFlag == TRUE))
                    {
                    g_bulkInStallFlag = FALSE;
                    CSWsend = TRUE;
                    }
                }
            else if (index == MS_BULK_OUT_ENDPOINT_NUM)
                {
                status = usbMsBulkOutUnStall();

                if ((status == OK) && (g_bulkOutStallFlag == TRUE))
                    {
                    g_bulkOutStallFlag = FALSE;
                    CSWsend = TRUE;
                    }
                }
            else
                status = ERROR;

            if (CSWsend == TRUE)
                {
                pCsw = usbMsCSWGet();
                pData = (UINT8 *)pCsw;
                dSize = sizeof(USB_BULK_CSW);
                if (usbMsBulkInErpInit(pData, dSize,
                                   bulkInErpCallbackCSW, NULL) != OK)
                    return(ERROR);                                   
                }

            return(status);
            }
        else
            return(ERROR);
        }
    else if (requestType == USB_RT_DEVICE)
        {
        if (feature == USB_FSEL_DEV_REMOTE_WAKEUP)
            {

#ifdef USB1_1

            /* set remote device wakeup flag to TRUE */

            g_remoteDevWakeup = TRUE;

            return(OK);

#else

            /* 
             * If the device supports remote wakeup, call the function
             * to clear the remote wakeup feature
             */

            if ((g_uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)
                {
                status = usbTargDeviceFeatureClear(targChannel, feature);

                /* Clear the global status */

                if (status == OK)
                    g_uDeviceStatus &= ~0x02;
                }
            else
                status = ERROR;

            return(status);
#endif
            }
        else
            return(ERROR);
        }
    else if (requestType == USB_RT_INTERFACE)
        return(ERROR);
    else
        return(ERROR);
    }


/*******************************************************************************
*
* featureSet - set the specified feature
*
* This routine implements the set feature standard device request.
*
* RETURNS: OK or ERORR if not able to set the feature.
*
* ERRNO:
*  none.
*/
LOCAL STATUS featureSet
    (
    pVOID		param,		/* TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,	/* target channel */	
    UINT8		requestType,	/* request type */
    UINT16		feature,	/* feature to set */
    UINT16		index		/* wIndex */
    )
    {
    STATUS		status = ERROR;

    /* only one target */
	
    if (targChannel != g_targChannel) 
        return(ERROR);

    /*
     * This request is not accepted when the the device is in the default state
     * and the feature to be set is not TEST_MODE
     */

    if ((g_deviceAddr == 0) && (feature != USB_FSEL_DEV_TEST_MODE))
        return ERROR;

    /* this request must be standard request from the host */

    if (((requestType & USB_RT_DIRECTION_MASK) != USB_RT_HOST_TO_DEV) ||
        ((requestType & USB_RT_CATEGORY_MASK) != USB_RT_STANDARD))
        return(ERROR);

    requestType &= ~(USB_RT_DIRECTION_MASK | USB_RT_CATEGORY_MASK);

    if (requestType == USB_RT_ENDPOINT)
        {
        if (feature == USB_FSEL_DEV_ENDPOINT_HALT)
            {
            if (index == g_bulkInEpDescr.endpointAddress)
                status = usbMsBulkInStall();
            else if (index == g_bulkOutEpDescr.endpointAddress)
                status = usbMsBulkOutStall();
            else
                status = ERROR;

            return(status);
            }
        else
            return(ERROR);
        }
    else if (requestType == USB_RT_DEVICE)
        {
        if (feature == USB_FSEL_DEV_REMOTE_WAKEUP)
            {
#ifdef USB1_1

            /* set remote device wakeup flag to TRUE */

            g_remoteDevWakeup = TRUE;
            return(OK);
#else
            /*
             * If the device supports remote wakeup, call the function
             * to set the remote wakeup feature
             */

            if ((g_uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)
                {
                status = usbTargDeviceFeatureSet(targChannel, feature, index);

                /* Set the global status */

                if (status == OK)
                    g_uDeviceStatus |= 0x02;
                }
            else
                status = ERROR;

            return(status);
#endif
            }
        else if (feature == USB_FSEL_DEV_TEST_MODE) /* TEST_MODE */
            {
#ifdef USB1_1

#if(MS_USB_HIGH_SPEED == 1)

            /*
             * NOTE: device can only go into test mode until after this
             * request is acknowledged in the status phase
             */

             return(ERROR);
#else
             return(ERROR);
#endif
#else

            /*
             * If the device supports remote wakeup, call the function
             * to set the test mode feature
             */

            if ((g_uDeviceFeature & USB_FEATURE_TEST_MODE) != 0)
                {
                status = usbTargDeviceFeatureSet(targChannel,
                                                 feature,
                                                 ((index & 0xFF00) << 8));
                }

            return(status);
#endif
            }
        else
            return(ERROR);
        }
    else if (requestType == USB_RT_INTERFACE)
        return(ERROR);
    else
        return(ERROR);
    }

#ifdef USB1_1

/*******************************************************************************
*
* statusGet - get the specified status
*
* This routine implements the get status standard device request.
*
* RETURNS: OK or ERROR if not able to set the status
*
* ERRNO:
*  none
*/

LOCAL STATUS statusGet
    (
    pVOID		param,		/* TCD specific parameter */

⌨️ 快捷键说明

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