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

📄 usbtargmslib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 5 页
字号:
    USB_TARG_CHANNEL	targChannel,	/* target channel */
    UINT8		requestType,	/* request type */
    UINT16		index,		/* wIndex */
    UINT16		length,		/* length */
    pUINT8		pBfr,		/* to hold status */
    pUINT16		pActLen		/* actual length */
    )
    {
    UINT8		data[2] = {0,0};/* To hold status information */
    UINT16		epStatus;	/* endpoint status */

    /* only one target */

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

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

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

    requestType &= ~(USB_RT_DIRECTION_MASK | USB_RT_CATEGORY_MASK);

    if (requestType == USB_RT_DEVICE)
        {

        /* self powered */

        data[1] = 0x1; 
        
        if (g_remoteDevWakeup == TRUE)
            {
            data[1] |= 0x2;
            }
        }
    else if (requestType == USB_RT_INTERFACE)
        {
        /* nothing to do */
        }
    else if (requestType == USB_RT_ENDPOINT)
        {
        if (index == MS_BULK_IN_ENDPOINT_NUM)
            {
            if (g_bulkInStallStatus == TRUE)
                epStatus = USB_ENDPOINT_STS_HALT;
            else
                epStatus = 0x0;
            }
        else if (index == MS_BULK_OUT_ENDPOINT_NUM)
            {
            if (g_bulkOutStallStatus == TRUE)
                epStatus = USB_ENDPOINT_STS_HALT;
            else
                epStatus = 0x0;
            }
        else
            return(ERROR);

        if (epStatus == USB_ENDPOINT_STS_HALT)
            data[0] = 0x1;
        }
    else
        return(ERROR);

    memcpy(pBfr,data,2);
    *pActLen = 2;

    return(OK);
    }
#else

/*******************************************************************************
*
* 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 */
    USB_TARG_CHANNEL	targChannel,	/* target channel */
    UINT16		requestType,	/* request type */
    UINT16		index,		/* wIndex */
    UINT16		length,		/* wLength */
    pUINT8		pBfr		/* to hold status */
    )
    {
    STATUS		status = ERROR;

    /* only one target */

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

    /* This is an invalid request if received in default state */

    if (g_deviceAddr == 0)
        return ERROR;

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

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

    requestType &= ~(USB_RT_DIRECTION_MASK | USB_RT_CATEGORY_MASK);

    if (requestType == USB_RT_DEVICE)
        {
        pBfr[0] = g_uDeviceStatus;
        status = OK;
        }
    else if (requestType == USB_RT_INTERFACE)
        {
        /* nothing to do */
        }
    else if (requestType == USB_RT_ENDPOINT)
        {
        if (index == g_bulkInEpDescr.endpointAddress)
            status = usbTargPipeStatusGet(g_bulkInPipeHandle, pBfr);

        else if (index == g_bulkOutEpDescr.endpointAddress)
            status = usbTargPipeStatusGet(g_bulkOutPipeHandle, pBfr);
        else
            return(ERROR);

        }
    else
        return(ERROR);

    return(status);
    }

#endif


/*******************************************************************************
*
* addressSet - set the specified address
*
* This routine implements the set address standard device request.
*
* RETURNS: ERROR or OK
*
* ERRNO: N/A
*/

LOCAL STATUS addressSet
    (
    pVOID		param,		/* TCD specific parameter */ 
    USB_TARG_CHANNEL	targChannel,	/* target channel */
    UINT16		deviceAddress	/* device channel */
    )
    {

    /* only one target */

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

    /* The device cannot accept a set address request after configuration */

    if (g_configuration != 0)
        return ERROR;

    g_deviceAddr = deviceAddress;

    return(OK);
    }


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

LOCAL STATUS descriptorGet
    (
    pVOID		param,		/*  TCD specific parameter */		
    USB_TARG_CHANNEL	targChannel,	/* target chennel */
    UINT8		requestType,	/* request type */
    UINT8		descriptorType,	/* descriptor type */
    UINT8		descriptorIndex,/* descriptor index */
    UINT16		languageId,	/* language id */
    UINT16		length,		/* length of descriptor */
    pUINT8		pBfr,		/* buffer to hold the descriptor */
    pUINT16		pActLen		/* actual length */
    )
    {
    UINT8		bfr[USB_MAX_DESCR_LEN];	/* buffer to hold descriptor */
    UINT16		actLen;			/* actual lenght */

    /* only one target */

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

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

    if (((requestType & USB_RT_DIRECTION_MASK) != USB_RT_DEV_TO_HOST) ||
        ((requestType & USB_RT_CATEGORY_MASK) != USB_RT_STANDARD) ||
        ((requestType & USB_RT_RECIPIENT_MASK) != USB_RT_DEVICE))
        return(ERROR);

    switch(descriptorType)
    {
    case USB_DESCR_DEVICE:

        /* copy device descriptor to pBfr and set pActLen */

        usbDbgPrint("descriptorGet: USB_DESCR_DEVICE\n");
        usbDescrCopy (pBfr, &g_devDescr, length, pActLen);
        break;

    case USB_DESCR_OTHER_SPEED_CONFIGURATION:
        #if(MS_USB_HIGH_SPEED == 0)
            return(ERROR);
        #endif
    case USB_DESCR_CONFIGURATION:

        /* 
         * copy configuration, interface, and endpoint descriptors
         * to pBfr and set pActLen 
         */

        usbDbgPrint("descriptorGet: USB_DESCR_CONFIGURATION\n");

        memcpy (bfr, &g_configDescr, USB_CONFIG_DESCR_LEN);

        memcpy (&bfr[USB_CONFIG_DESCR_LEN], &g_ifDescr,
                USB_INTERFACE_DESCR_LEN);
        memcpy (&bfr[USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN],
                &g_bulkInEpDescr, USB_ENDPOINT_DESCR_LEN);

        memcpy (&bfr[USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN +
                     USB_ENDPOINT_DESCR_LEN],
                &g_bulkOutEpDescr, USB_ENDPOINT_DESCR_LEN);

        actLen = min (length, USB_CONFIG_DESCR_LEN +
                      USB_INTERFACE_DESCR_LEN + 2*USB_ENDPOINT_DESCR_LEN);

        memcpy (pBfr, bfr, actLen);
        *pActLen = actLen;

        break;

#if(0) 
    case USB_DESCR_INTERFACE:

        /* copy interface descriptor to pBfr and set pActLen */

        usbDescrCopy (pBfr, &g_ifDescr, length, pActLen);
        break;

    case USB_DESCR_ENDPOINT:

        /* copy endpoint descriptor to pBfr and set pActLen */

        usbDescrCopy (pBfr, &g_ifDescr, length, pActLen);
        break;
#endif

    case USB_DESCR_STRING:
        switch(descriptorIndex)
        {
        case 0:

            /* copy language descriptor to pBfr and set pActLen */

            usbDescrCopy (pBfr, &g_langDescr, length, pActLen);
            break;

        case ID_STR_MFG:
            usbDescrStrCopy (pBfr, g_pStrMfg, length, pActLen);
            break;

        case ID_STR_PROD:
            usbDescrStrCopy (pBfr, g_pStrProd, length, pActLen);
            break;

        /*
         * test other cases based on values set for configuration,
         * interface, and endpoint descriptors 
         */

        default:
            return(ERROR);
        }
        break;

    case USB_DESCR_DEVICE_QUALIFIER: /* DEVICE_QUALIFIER */

        /* copy device qualifier descriptor to pBfr and set pActLen */

#if(MS_USB_HIGH_SPEED == 1)
            g_usbDevQualDescr.maxPacketSize0 = g_devDescr.maxPacketSize0;
            usbDescrCopy (pBfr, &g_usbDevQualDescr, length, pActLen);
            break;
#else
            return(ERROR);
#endif

    case USB_DESCR_INTERFACE_POWER: /* INTERFACE_POWER */

        /* copy interface power descriptor to pBfr and set pActLen */

        return(ERROR);
    default:
        return(ERROR);
    }

    return(OK);
    }

/*******************************************************************************
*
* configurationGet - get the specified configuration
*
* This function is used to get the current configuration of the device.
* <pConfiguration> is set with the current configuration and sent to the
* host.
*
* RETURNS: OK, or ERROR if unable to return configuration setting
*
* ERRNO:
*  none
*/

LOCAL STATUS configurationGet
    (
    pVOID		param,		/*  TCD specific parameter */		
    USB_TARG_CHANNEL	targChannel,	/* target channel */
    pUINT8		pConfiguration	/* configuration value */
    )
    {
    if (targChannel != g_targChannel) /* only one target */
        return(ERROR);

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

    if (g_deviceAddr == 0)
        return ERROR;

   *pConfiguration = g_configuration;

    return(OK);
    }

/*******************************************************************************
*
* configurationSet - set the specified configuration
*
* This function is used to set the current configuration to the configuration
* value sent by host. <configuration> consists of the value to set.
*
* RETURNS: OK, or ERROR if unable to set specified configuration
*
* ERRNO:
*  none.
*/

LOCAL STATUS configurationSet
    (
    pVOID		param,		/*  TCD specific parameter */
    USB_TARG_CHANNEL	targChannel,	/* target channel */	
    UINT8		configuration	/* configuration value to set */
    )
    {
    USB_BULK_CBW	* pCbw;		/* Command Block Wrapper */
    UINT8		* pData;	
    UINT32		size;

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

    /*
     * This request is invalid if received in a default state
     * or the configuration value is not expected
     */

    if ((g_deviceAddr == 0) || (configuration > MS_CONFIG_VALUE))
        return ERROR;

    /* set current configuration global static variable */

    if (configuration == MS_CONFIG_VALUE)
        {
        usbDbgPrint("configurationSet: configuration = MS_CONFIG_VALUE\n"); 
        g_configuration = configuration;

        if (g_bulkInPipeHandle == NULL)
            {

#ifdef USB1_1

            /* Create bulk-in pipe */

            if (usbTargPipeCreate (targChannel, MS_BULK_IN_ENDPOINT_ID, 0,
		                   MS_BULK_IN_ENDPOINT_NUM, configuration,
                                   MS_INTERFACE_NUM, USB_XFRTYPE_BULK,
                                   USB_DIR_IN, &g_bulkInPipeHandle) != OK)
#else
            if (usbTargPipeCreate (targChannel, &g_bulkInEpDescr, configuration,
                                   MS_INTERFACE_NUM, g_ifAltSetting,
                                   &g_bulkInPipeHandle) != OK)
#endif
                return ERROR;
            }

        if (g_bulkOutPipeHandle == NULL)
            {
#ifdef USB1_1

            /* Create bulk-out pipe */

            if (usbTargPipeCreate (targChannel, MS_BULK_OUT_ENDPOINT_ID, 0,
                                   MS_BULK_OUT_ENDPOINT_NUM, configuration,
                                   MS_INTERFACE_NUM, USB_XFRTYPE_BULK,
                                   USB_DIR_OUT, &g_bulkOutPipeHandle) != OK)
#else
            if (usbTargPipeCreate (targChannel, &g_bulkOutEpDescr, configuration,
                                   MS_INTERFACE_NUM, g_ifAltSetting,
                                   &g_bulkOutPipeHandle) != OK)
#endif

                return ERROR;

#ifndef USE_MS_TEST_DATA

            /* Initialize ERP to listen for data */
            /* on reset setup to receive a new CBW */

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

            if (usbMsDevInit() != OK)
                return(ERROR);

            if (usbMsBulkOutErpInit(pData, size,
                                    bulkOutErpCallbackCBW, NULL) != OK)
                return(ERROR);
#endif
	        }
        usbDbgPrint("configurationSet: Exiting...\n"); 
        }
    else if (configuration == 0)
        {
        usbDbgPrint("configurationSet: configuration = 0\n"); 

        g_configuration = configuration;

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

⌨️ 快捷键说明

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