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

📄 usbtargmslib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
        if (g_bulkOutPipeHandle != NULL)
            {
            usbTargPipeDestroy (g_bulkOutPipeHandle);
            g_bulkOutPipeHandle = NULL;
            }
        }
    else
        return(ERROR);


    return(OK);
    }

/*******************************************************************************
*
* interfaceGet - get the specified interface
*
* This function is used to get the selected alternate setting of the
* specified interface.
*
* RETURNS: OK, or ERROR if unable to return interface setting
*
* ERRNO:
*  none
*/

LOCAL STATUS interfaceGet
    (
    pVOID		param,			/* TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,		/* target channel */
    UINT16		interfaceIndex,		/* interface index */
    pUINT8		pAlternateSetting	/* alternate setting */
    )
    {

    /* only one target */

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

    if ((g_deviceAddr == 0) ||(g_configuration == 0))
        return ERROR;

    *pAlternateSetting = g_ifAltSetting;

    return(OK);
    }


/*******************************************************************************
*
* interfaceSet - set the specified interface
*
* This function is used to select the alternate setting of he specified
* interface.
*
* RETURNS: OK, or ERROR if unable to set specified interface
*
* ERRNO:
*  none.
*/

LOCAL STATUS interfaceSet
    (
    pVOID		param,			/* TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,		/* target channel */
    UINT16		interfaceIndex,		/* interface index */
    UINT8		alternateSetting	/* alternate setting */
    )
    {

    /* only one target */

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

    /*
     * This is an invalid request if the device is in default/addressed state
     * or if the alternate setting value does not match
     */

    if ((g_deviceAddr == 0) || (g_configuration == 0))
        return ERROR;

    if (alternateSetting == MS_INTERFACE_ALT_SETTING)
        {
        g_ifAltSetting = alternateSetting;
        return OK;
        }
    else
        return(ERROR);
    }


/*******************************************************************************
*
* vendorSpecific - invoke the VENDOR_SPECIFIC request
*
* This routine implements the vendor specific standard device request
*
* RETURNS: OK, or ERROR if unable to process vendor-specific request
*
* ERRNO:
*  none
*/

LOCAL STATUS vendorSpecific
    (
    pVOID		param,			/* TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,		/* target channel */
    UINT8		requestType,		/* request type */
    UINT8		request,		/* request name */
    UINT16		value,			/* wValue */	
    UINT16		index,			/* wIndex */
    UINT16		length			/* wLength */
    )
    {
    STATUS		retVal = ERROR;
    LOCAL UINT8		maxLun = 0x0;		/* device has no LUNs */
    USB_BULK_CBW	* pCbw;			/* CBW */
    UINT8		* pData;
    UINT32		size;

    /* only one target */

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

    if (requestType == (USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_INTERFACE))
        {

        /* mass storage reset */

        if (request == USB_BULK_RESET)  
            {
            usbDbgPrint("vendorSpecific: Mass Storage reset request\n");

            /* if the bulk in pipe is in use, try to clear it */

            if (g_bulkInInUse == TRUE)
                if(usbTargTransferAbort(g_bulkInPipeHandle, &g_bulkInErp) != OK)
                    return(ERROR);

            /* if the bulk out pipe is in use, try to clear it */

            if (g_bulkOutInUse == TRUE)
               if(usbTargTransferAbort(g_bulkOutPipeHandle, &g_bulkOutErp) != OK)
                   return(ERROR);

            /* setup to receive a new CBW */

            pCbw    = usbMsCBWInit();
            pData   = (UINT8 *)pCbw;
            size    = sizeof(USB_BULK_CBW);

        if (usbMsBulkOutErpInit(pData, size, bulkOutErpCallbackCBW, NULL) == OK)
            {
            retVal = usbTargControlStatusSend (targChannel);    
            }
        else
            return(ERROR);
        }
    else
        return(ERROR);
    }
    else if (requestType == (USB_RT_DEV_TO_HOST | USB_RT_CLASS |
                             USB_RT_INTERFACE))
        {

        /* getMaxLUN */ 

        if (request == USB_BULK_GET_MAX_LUN) 
            {
            usbDbgPrint("vendorSpecific: Get Max LUN request\n");
            retVal = usbTargControlResponseSend(targChannel, 1, &maxLun);       
            }
        else
            return(ERROR);
        }

#ifdef USE_MS_TEST_DATA
    else if (requestType == (USB_RT_DEV_TO_HOST | USB_RT_VENDOR |
                             USB_RT_INTERFACE))
        {
        if (request == MS_BULK_IN_TX_TEST)
            {
            usbDbgPrint("vendorSpecific: sending test data to host\n");

            {
            int i;
            for (i = 0; i < MS_TEST_DATA_SIZE; i++)
                g_usbMsTestData[i] = i;
            }

            if (usbMsBulkInErpInit(g_usbMsTestData, MS_TEST_DATA_SIZE,
                                   usbMsTestTxCallback,NULL) == OK)
                {
                retVal = usbTargControlResponseSend(targChannel, 0, NULL);
                }
            else
                return(ERROR);
            }
        else
            return(ERROR);
        }
    else if (requestType == (USB_RT_VENDOR | USB_RT_INTERFACE))
        {
        if (request == MS_BULK_OUT_RX_TEST)
            {

            usbDbgPrint("vendorSpecific: receiving test data from host\n");

            memset (&g_usbMsTestData, 0, MS_TEST_DATA_SIZE);

            if (usbMsBulkOutErpInit(g_usbMsTestData, MS_TEST_DATA_SIZE,
                                    usbMsTestRxCallback,NULL) == OK)
                {
                retVal = usbTargControlResponseSend(targChannel, 0, NULL);          
                }
            else
                return(ERROR);
            }
        else
            return(ERROR);
        }
#endif
    else
        return(ERROR);

    return(retVal);
    }

#ifdef USB1_1
/****************************************************************************
*
* mngmtFunc - invoke the connection management function
*
* This function handles various management related events. <mngmtCode>
* consist of the management event function code that is reported by the
* TargLib layer. <pContext> is the argument sent for the management event to
* be handled.
*
* RETURNS: OK if able to handle event, or ERROR if unable to handle event
*
* ERRNO:
*  none.
*/

LOCAL STATUS mngmtFunc
    (
    pVOID		param,			/* TCD Specic parameter */
    USB_TARG_CHANNEL	targChannel,		/* target channel */
    UINT16		mngmtCode		/* management code */
    )

    {
    switch (mngmtCode)
	{
	case TCD_MNGMT_ATTACH:

            /* Initialize local static data */

            g_targChannel = targChannel;
            usbTargEndpointInfoGet(targChannel, &g_numEndpoints, &g_pEndpoints);

            g_configuration     = 0;
            g_ifAltSetting      = 0;
            g_bulkOutPipeHandle = NULL;
            g_bulkInPipeHandle  = NULL;

            /* Initialize control pipe maxPacketSize. */

            g_devDescr.maxPacketSize0 = g_pEndpoints[0].maxPacketSize;

            /* Initialize bulk endpoint max packet size. */

            g_bulkOutEpDescr.maxPacketSize =
            g_pEndpoints [MS_BULK_OUT_ENDPOINT_ID].bulkOutMaxPacketSize;

            g_bulkInEpDescr.maxPacketSize =
            g_pEndpoints [MS_BULK_IN_ENDPOINT_ID].bulkInMaxPacketSize;

            break;

        case TCD_MNGMT_DETACH:

            break;

        case TCD_MNGMT_BUS_RESET:

            usbDbgPrint("mngmtFunc: Bus Reset\n");

        case TCD_MNGMT_VBUS_LOST:

            /* revert to power-ON configuration */

            configurationSet (param, targChannel, 0);
            break;

        default:
            break;
        }

    return OK;
    }
#else
/*******************************************************************************
*
* mngmtFunc - invoke the connection management function
*
* This function handles various management related events. <mngmtCode>
* consist of the management event function code that is reported by the
* TargLib layer. <pContext> is the argument sent for the management event to
* be handled.
*
* RETURNS: OK if able to handle event, or ERROR if unable to handle event
*
* ERRNO:
*  none.
*/

LOCAL STATUS mngmtFunc
    (
    pVOID		param,			/* TCD specific paramter */
    USB_TARG_CHANNEL	targChannel,		/* target channel */
    UINT16		mngmtCode,		/* management code */
    pVOID		pContext		/* Context value */
    )
    {
    pUSB_APPLN_DEVICE_INFO	pDeviceInfo = NULL;/* USB_APPLN_DEVICE INFO */
    switch (mngmtCode)
    	{
    	case TARG_MNGMT_ATTACH:
            if (pContext == NULL)
                return ERROR;

            g_targChannel       = targChannel;
            g_configuration     = 0;
            g_ifAltSetting      = 0;
            g_bulkOutPipeHandle = NULL;
            g_bulkInPipeHandle  = NULL;

            /* Retrieve the pointer to the device info data structure */

            pDeviceInfo = (pUSB_APPLN_DEVICE_INFO)pContext;

    	    /* Initialize global data */

            g_uDeviceFeature = pDeviceInfo->uDeviceFeature;
            g_uEndpointNumberBitmap = pDeviceInfo->uEndpointNumberBitmap;

            /*
             * If the device is USB 2.0, initialize the bcdUSB field of
             * the device descriptor and the device qualifier descriptor.
             */

            if ((g_uDeviceFeature & USB_FEATURE_USB20) != 0)
                {
                g_devDescr.bcdUsb = TO_LITTLEW(MS_USB_HIGH_SPEED_VERSION);
                g_usbDevQualDescr.bcdUsb = TO_LITTLEW(MS_USB_HIGH_SPEED_VERSION);
                }
            else
                {
                g_devDescr.bcdUsb = TO_LITTLEW(MS_USB_FULL_SPEED_VERSION);
                g_usbDevQualDescr.bcdUsb = TO_LITTLEW(MS_USB_FULL_SPEED_VERSION);
                }

            /*
             * If the device supports remote wakeup, modify the configuration
             * descriptor accordingly.
             */

            if ((g_uDeviceFeature & USB_FEATURE_DEVICE_REMOTE_WAKEUP) != 0)
                g_configDescr.attributes |= USB_ATTR_REMOTE_WAKEUP;

            /*
             * Check if the endpoint number is supported.
             * The shift value is directly taken as the endpoint address
             * as the application is specifically written for keyboard and it
             * supports only the interrupt IN endpoint.
             */

            if ((g_uEndpointNumberBitmap >>
                (16 + (USB_ENDPOINT_MASK & g_bulkInEpDescr.endpointAddress))) == 0)
                {

                /* Search through the bitmap and arrive at an endpoint address */

                UINT32 uIndex = 1;

                for (uIndex = 16; uIndex < 32; uIndex++)
                    {
                    if ((g_uEndpointNumberBitmap >> uIndex) != 0)
                        {
                        g_bulkInEpDescr.endpointAddress = USB_ENDPOINT_IN | (uIndex - 16);
                        break;
                        }
                    }
                if (uIndex == 32)
                    return ERROR;
                }

            if ((g_uEndpointNumberBitmap >> g_bulkOutEpDescr.endpointAddress) == 0)
                {

                /* Search through the bitmap and arrive at an endpoint address */

                UINT32 uIndex = 1;

                for (uIndex = 1; uIndex < 16; uIndex++)
                    {
                    if ((g_uEndpointNumberBitmap >> uIndex) != 0)
                        {
                        g_bulkOutEpDescr.endpointAddress  = uIndex;
                        break;
                        }
                    }
                if (uIndex == 16)
                    return ERROR;
                }

    	    break;

    	case TARG_MNGMT_DETACH:

            /* Reset the globals */

            g_targChannel = 0;
            g_uDeviceFeature = 0;
            g_uEndpointNumberBitmap = 0;

            /* Reset the device and device qualifier descriptors' bcusb field */

            g_devDescr.bcdUsb = TO_LITTLEW(MS_USB_VERSION);
            g_usbDevQualDescr.bcdUsb = TO_LITTLEW(MS_USB_VERSION);

            g_bulkInEpDescr.endpointAddress = MS_BULK_IN_ENDPOINT_NUM;
            g_bulkOutEpDescr.endpointAddress = MS_BULK_OUT_ENDPOINT_NUM;

    	    break;

    	case TARG_MNGMT_BUS_RESET:

            /* Copy the operating speed of the device */

    	    g_uSpeed = (UINT32)pContext;
    	    g_deviceAddr = 0;

#if 1
            g_configuration     = 0;
            g_ifAltSetting      = 0;
#endif
    	    if (g_bulkInPipeHandle != NULL)
                {
                usbTargPipeDestroy (g_bulkInPipeHandle);
                g_bulkInPipeHandle = NULL;
                }

            if (g_bulkOutPipeHandle != NULL)
                {
                usbTargPipeDestroy (g_bulkOutPipeHandle);
                g_bulkOutPipeHandle = NULL;
                }

            /* Reset the device status to indicate that it is self powered */

            g_uDeviceStatus = 0x01;

            if (g_uSpeed == USB_TCD_HIGH_SPEED)
                {
                g_devDescr.maxPacketSize0 = 
                                      MS_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE;

⌨️ 快捷键说明

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