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

📄 usbtargprnlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
*/LOCAL STATUS configurationGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    pUINT8	pConfiguration		/* data to be sent */    )    {    /* This request is not accepted when the device is in the default state */    if (uDeviceAddress == 0)        return ERROR;    *pConfiguration = curConfiguration;    return OK;    }/******************************************************************************** configurationSet - invoked by usbTargLib for SET_CONFIGURATION request** This function is used to set the current configuration to the * configuration value sent by host. <configuration> consist of the value * to set.** RETURNS: OK, or ERROR if unable to set specified configuration** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS configurationSet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT8	configuration		/* onfiguration value */    )    {    /*      * This request is invalid if received in a default state     * or the configuration value is not expected     */    if ((uDeviceAddress == 0) || (configuration > PRN_CONFIG_VALUE))        return ERROR;    /* Check if the configuration value is the expected value */    if (configuration == PRN_CONFIG_VALUE)    	{    	/* Create the bulk pipe if it is not created */    	if (bulkPipeHandle == NULL)    	    {    	    /* Create a bulk OUT pipe */    	    if (usbTargPipeCreate (targChannel,                                   &epDescr,                                   configuration,                                   PRN_INTERFACE_NUM,                                   PRN_INTERFACE_ALT_SETTING,                                   &bulkPipeHandle) != OK)        	    return ERROR;    	    /* Initialize ERP to listen for data */    	    initBulkOutErp ();    	    }    	curConfiguration = configuration;    	}    else    	{    	/* Delete the bulk pipe if created */    	if (bulkPipeHandle != NULL)    	    {    	    usbTargPipeDestroy (bulkPipeHandle);    	    bulkPipeHandle = NULL;    	    }    	curConfiguration = configuration;    	}    return OK;    }/*************************************************************************** descriptorGet - invoked by usbTargLib for GET_DESCRIPTOR request** This function is used to get the descriptor value. The type of * descriptor to get is specified in <descriptorType>.** RETURNS: OK, or ERROR if unable to return requested descriptor** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS descriptorGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT8	requestType,            /* Request Type */    UINT8	descriptorType,         /* Descriptor Type */    UINT8	descriptorIndex,        /* Index of the descriptor */    UINT16	languageId,             /* Lang. ID for string descriptors */    UINT16	length,                 /* Length of the descriptor */    pUINT8	pBfr,                   /* buffer in which data is to be sent */    pUINT16	pActLen                 /* Length of data in the buffer */    )    {    UINT8 bfr [USB_MAX_DESCR_LEN];	/* buffer to hold descriptor value */    UINT16 actLen;			/* actual length */    /* Determine type of descriptor being requested. */    if (requestType == (USB_RT_DEV_TO_HOST | USB_RT_STANDARD | USB_RT_DEVICE))    	{        switch (descriptorType)            {    	    case USB_DESCR_DEVICE:                usbDescrCopy (pBfr, &devDescr, length, pActLen);                break;    	    case USB_DESCR_DEVICE_QUALIFIER:                usbDescrCopy (pBfr, &devQualifierDescr, length, pActLen);                break;    	    case USB_DESCR_CONFIGURATION:                memcpy (bfr, &configDescr, USB_CONFIG_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN], &ifDescr,                        USB_INTERFACE_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN],                        &epDescr, USB_ENDPOINT_DESCR_LEN);                actLen = min (length, USB_CONFIG_DESCR_LEN +        		      USB_INTERFACE_DESCR_LEN + USB_ENDPOINT_DESCR_LEN);                memcpy (pBfr, bfr, actLen);                *pActLen = actLen;                break;    	    case USB_DESCR_OTHER_SPEED_CONFIGURATION:                memcpy (bfr, &otherSpeedConfigDescr, USB_CONFIG_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN], &ifDescr,        	        USB_INTERFACE_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN],                        &otherSpeedEpDescr, USB_ENDPOINT_DESCR_LEN);                actLen = min (length, USB_CONFIG_DESCR_LEN +                              USB_INTERFACE_DESCR_LEN + USB_ENDPOINT_DESCR_LEN);                 memcpy (pBfr, bfr, actLen);                 *pActLen = actLen;                 break;    	    case USB_DESCR_STRING:                switch (descriptorIndex)                    {                    case 0: /* language descriptor */                        usbDescrCopy (pBfr, &langDescr, length, pActLen);            		break;                    case ID_STR_MFG:                        usbDescrStrCopy (pBfr, pStrMfg, length, pActLen);            		break;                    case ID_STR_PROD:                        usbDescrStrCopy (pBfr, pStrProd, length, pActLen);                        break;                    default:                        return ERROR;                     }                break;    	       default:    		    return ERROR;    	    }    	}    else    	{    	return ERROR;    	}    return OK;    }/******************************************************************************** interfaceGet - invoked by usbTargLib for GET_INTERFACE request** 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** \NOMANUAL*/LOCAL STATUS interfaceGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	interfaceIndex,		/* index of the specified interface */    pUINT8	pAlternateSetting	/* value of alternate setting sent */    )    {    /*      * This is an invalid request if the device is in     * default or addressed state     */    if ((uDeviceAddress == 0) ||(curConfiguration == 0))        return ERROR;    *pAlternateSetting = PRN_INTERFACE_ALT_SETTING;    return OK;    }/******************************************************************************** interfaceSet - invoked by usbTargLib for SET_INTERFACE request** 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.** \NOMANUAL*/LOCAL STATUS interfaceSet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	interfaceIndex,		/* interface index */    UINT8	alternateSetting	/* alternate setting to be set */    )    {    /*     * This is an invalid request if the device is in default/addressed state     * or if the alternate setting value does not match     */    if ((uDeviceAddress == 0) ||        (curConfiguration == 0) ||        (alternateSetting != PRN_INTERFACE_ALT_SETTING))        return ERROR;    curAlternateSetting = alternateSetting;    return OK;    }/******************************************************************************** statusGet - invoked by usbTargLib for GET_STATUS request** This function is used to get the status of the recipient specified in* <index>. The status is sent in <pBfr> to the host.** RETURNS: OK, or ERROR if unable to get the status of the recepient.** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS statusGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	requestType,            /* type of request */    UINT16	index,                  /* recipient */    UINT16	length,                 /* wLength */    pUINT8	pBfr                    /* status of the specified recipient */    )    {    STATUS	status = ERROR;		    /* This is an invalid request if received in default state */    if (uDeviceAddress == 0)        return ERROR;    /* Switch based on the recipient value specified */    switch(requestType & USB_RT_RECIPIENT_MASK)        {        case USB_RT_DEVICE:            pBfr[0] = uDeviceStatus;            status = OK;            break;        case USB_RT_ENDPOINT:            if ((index == epDescr.endpointAddress) && (bulkPipeHandle != NULL))                status = usbTargPipeStatusGet(bulkPipeHandle, pBfr);            break;        default:            break;        }    return status;    }/******************************************************************************** addressSet - invoked by usbTargLib for SET_ADDRESS request** This function is used to set the address of the device. <deviceAddress>* consist of the address to set.** RETURNS: OK, or ERROR if unable to set the address** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS addressSet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	deviceAddress		/* device address to set */    )    {    /* The device cannot accept a set address request after configuration */    if (curConfiguration != 0)        return ERROR;    /* Copy the address to the global */    uDeviceAddress = deviceAddress;    return OK;    }/******************************************************************************** vendorSpecific - invoked by usbTargLib for VENDOR_SPECIFIC request** This fucntion is called when any vendor specific request comes from host.** RETURNS: OK, or ERROR if unable to process vendor-specific request** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS vendorSpecific    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT8	requestType,		/* characteristics of request */    UINT8	request,		/* request type */    UINT16	value,                  /* wValue */    UINT16	index,                  /* wIndex */    UINT16	length                  /* length to transfer */    )    {    UINT8	bfr [USB_MAX_DESCR_LEN]; /* Buffer to hold data */	    pUSB_PRINTER_CAPABILITIES pCaps = (pUSB_PRINTER_CAPABILITIES) bfr;    UINT16	capsLen = strlen (capsString) + 2;    if (requestType == (USB_RT_DEV_TO_HOST | USB_RT_CLASS | USB_RT_INTERFACE))    	{    	switch (request)    	    {    	    case USB_REQ_PRN_GET_DEVICE_ID:                /* Send the IEEE-1284-style "device id" string. */                pCaps->length = TO_BIGW (capsLen);                memcpy (pCaps->caps, capsString, strlen (capsString));                usbTargControlResponseSend (targChannel, capsLen,                                             (pUINT8) pCaps);                 return OK;    	    case USB_REQ_PRN_GET_PORT_STATUS:                /* Initiate the data phase for sending the port status */                 usbTargControlResponseSend (targChannel, sizeof (portStatus),                                              (pUINT8) &portStatus);                  return OK;    	    default:        	break;    	    }    	}    else if (requestType == (USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_OTHER))    	{    	switch (request)    	    {    	    case USB_REQ_PRN_SOFT_RESET:                /* We accept the SOFT_RESET and initiate the status phase*/                usbTargControlResponseSend (targChannel, 0, NULL);                return OK;    	    default:                break;    	    }    	}    return ERROR;    }   

⌨️ 快捷键说明

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