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

📄 usbtargprnlib.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (pActLen != NULL)	*pActLen = bulkErp.bfrList [0].actLen;    return OK;    }/***************************************************************************** usbTargPrnDataRestart - restarts listening ERP** RETURNS: OK, or ERROR if unable to re-initiate ERP*/STATUS usbTargPrnDataRestart (void)    {    return initBulkOutErp ();    }/***************************************************************************** mngmtFunc - invoked by usbTargLib for connection management events** RETURNS: OK if able to handle event, or ERROR if unable to handle event*/LOCAL STATUS mngmtFunc    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT16 mngmtCode			    /* management code */    )    {    switch (mngmtCode)	{	case TCD_MNGMT_ATTACH:	    /* Initialize global data */	    channel = targChannel;	    usbTargEndpointInfoGet (targChannel, &numEndpoints, &pEndpoints);	    curConfiguration = 0;	    curAlternateSetting = 0;	    bulkPipeHandle = NULL;	    /* Initialize control pipe maxPacketSize. */	    devDescr.maxPacketSize0 = pEndpoints [0].maxPacketSize;	    /* Initialize bulk endpoint max packet size. */	    epDescr.maxPacketSize = 		pEndpoints [PRN_BULK_OUT_ENDPOINT_ID].bulkOutMaxPacketSize;	    /* Allocate buffer */	    if ((bulkBfr = OSS_MALLOC (BULK_BFR_LEN)) == NULL)		return ERROR;	    break;	case TCD_MNGMT_DETACH:	    /* De-allocate buffer */	    if (bulkBfr != NULL)		{		OSS_FREE (bulkBfr);		bulkBfr = NULL;		}	    break;	case TCD_MNGMT_BUS_RESET:	case TCD_MNGMT_VBUS_LOST:	    /* revert to power-ON configuration */	    configurationSet (param, targChannel, 0);	    break;	    	default:	    break;	}    return OK;    }/***************************************************************************** configurationGet - invoked by usbTargLib for GET_CONFIGURATION request** RETURNS: OK, or ERROR if unable to return configuration setting*/LOCAL STATUS configurationGet    (    pVOID param,    USB_TARG_CHANNEL targChannel,    pUINT8 pConfiguration    )    {    *pConfiguration = curConfiguration;    return OK;    }/***************************************************************************** configurationSet - invoked by usbTargLib for SET_CONFIGURATION request** RETURNS: OK, or ERROR if unable to set specified configuration*/LOCAL STATUS configurationSet    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT8 configuration    )    {    if (configuration > PRN_CONFIG_VALUE)	return ERROR;    if ((curConfiguration = configuration) == PRN_CONFIG_VALUE)	{	/* Enable the interrupt status pipe if not already enabled. */	if (bulkPipeHandle == NULL)	    {	    /* Create a pipe */	    if (usbTargPipeCreate (targChannel, PRN_BULK_OUT_ENDPOINT_ID, 0,		PRN_BULK_OUT_ENDPOINT_NUM, configuration, PRN_INTERFACE_NUM, 		USB_XFRTYPE_BULK, USB_DIR_OUT, &bulkPipeHandle) != OK)		return ERROR;	    /* Initialize ERP to listen for data */	    initBulkOutErp ();	    }	}    else	{	/* Disable the interrupt status pipe if it's enabled */	if (bulkPipeHandle != NULL)	    {	    usbTargPipeDestroy (bulkPipeHandle);	    bulkPipeHandle = NULL;	    }	}    return OK;    }/***************************************************************************** descriptorGet - invoked by usbTargLib for GET_DESCRIPTOR request** RETURNS: OK, or ERROR if unable to return requested descriptor*/LOCAL STATUS descriptorGet    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT8 requestType,    UINT8 descriptorType,    UINT8 descriptorIndex,    UINT16 languageId,    UINT16 length,    pUINT8 pBfr,    pUINT16 pActLen    )    {    UINT8 bfr [USB_MAX_DESCR_LEN];    UINT16 actLen;    /* 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_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_INTERFACE:		usbDescrCopy (pBfr, &ifDescr, length, pActLen);		break;	    case USB_DESCR_ENDPOINT:		usbDescrCopy (pBfr, &epDescr, length, pActLen);		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** RETURNS: OK, or ERROR if unable to return interface setting*/LOCAL STATUS interfaceGet    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT16 interfaceIndex,    pUINT8 pAlternateSetting    )    {    *pAlternateSetting = curAlternateSetting;    return OK;    }/***************************************************************************** interfaceSet - invoked by usbTargLib for SET_INTERFACE request** RETURNS: OK, or ERROR if unable to set specified interface*/LOCAL STATUS interfaceSet    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT16 interfaceIndex,    UINT8 alternateSetting    )    {    curAlternateSetting = alternateSetting;    return OK;    }/***************************************************************************** vendorSpecific - invoked by usbTargLib for VENDOR_SPECIFIC request** RETURNS: OK, or ERROR if unable to process vendor-specific request*/LOCAL STATUS vendorSpecific    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT8 requestType,    UINT8 request,    UINT16 value,    UINT16 index,    UINT16 length    )    {    UINT8 bfr [USB_MAX_DESCR_LEN];    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:		/* This emulator simply acknowledges these HID requests...no		 * processing is required. 		 */		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 return OK. */		return OK;	    default:		break;	    }	}    return ERROR;    }/* End of file. */

⌨️ 快捷键说明

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