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

📄 usbtargdefaultpipe.c

📁 USB source code of Vxworks 5.6. It has device and the host stack.
💻 C
📖 第 1 页 / 共 4 页
字号:
        OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = FALSE;        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargInterfaceGet exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargInterfaceSet - processes a SET_INTERFACE request** This function is called when a SET_INTERFACE request is received from * the host. It sets the current interface with the interface value send * by host.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:*   None** \NOMANUAL*/LOCAL STATUS usbTargInterfaceSet    (    pTARG_TCD	pTcd		/* Pointer to the TCD */    )    {    STATUS	status = OK;    pUSB_SETUP	pSetup = (pUSB_SETUP) pTcd->setupBfr;	/* USB_SETUP buffer */    UINT16	interfaceIndex = FROM_LITTLEW (pSetup->index);							/* interface index */    UINT8	alternateSetting = LSB (FROM_LITTLEW (pSetup->value));						/* alternate setting to set */	    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargInterfaceSet entered ...", USB_TARG_WV_FILTER);       /*     * If the callback is not registered by the target application,     * return an ERROR     */    if (pTcd->pCallbacks->interfaceSet == NULL)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* Get the interface setting from the target application. */    if ((*pTcd->pCallbacks->interfaceSet)	(pTcd->callbackParam, pTcd->targChannel,	interfaceIndex, alternateSetting) != OK)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );    pTcd->controlErpPending = TRUE;    OSS_MUTEX_RELEASE (pTcd->tcdMutex);    /* Initialize the status erp */        initStatusErp (pTcd);    /* Submit Tcd */        if ((status = submitCntlErp ( pTcd )) != OK )        {        OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = FALSE;        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargInterfaceSet exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargStatusGet - processes a GET_STATUS setup packet** This function is called when the GET_STATUS request is issued from* host.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:*   None** \NOMANUAL*/LOCAL STATUS usbTargStatusGet    (    pTARG_TCD	pTcd		/* Pointer to TCD */    )    {    STATUS	status = OK;    pUSB_SETUP	pSetup = (pUSB_SETUP) pTcd->setupBfr;	/* USB_SETUP buffer */    UINT16	index = FROM_LITTLEW (pSetup->index);	/* index */    UINT16	length = FROM_LITTLEW (pSetup->length);	/* length */    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargStatusGet entered ...", USB_TARG_WV_FILTER);       /*     * This request isn't supported unless the target application has     * provided a statusGet handler.     */    if (pTcd->pCallbacks->statusGet == NULL)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    if ((*pTcd->pCallbacks->statusGet)	(pTcd->callbackParam, pTcd->targChannel,	pSetup->requestType, index,	min (length, sizeof (pTcd->dataBfr)), pTcd->dataBfr) != OK)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* Take Mutex */    OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = TRUE;    /* Release Mutex */    OSS_MUTEX_RELEASE (pTcd->tcdMutex);    /* initialize the erp for data transfer */    initDataErpForResponse (pTcd, 2, pTcd->dataBfr);    /* Submit Tcd */    if ((status = submitCntlErp ( pTcd )) != OK )        {        OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = FALSE;        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargStatusGet exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargAddressSet - processes a SET_ADDRESS setup packet** This function is called when a SET_ADDRESS request is receuived from* the host. <device address> to be set is received from the setup packet.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:*   None** \NOMANUAL*/LOCAL STATUS usbTargAddressSet    (    pTARG_TCD	pTcd		/* Pointer to the TCD */    )    {    STATUS	status = OK;    pUSB_SETUP	pSetup = (pUSB_SETUP) pTcd->setupBfr;	/* USB_SETUP buffer */    UINT16	deviceAddress = FROM_LITTLEW (pSetup->value);	/* address */    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargAddressSet entered ...", USB_TARG_WV_FILTER);       /*     * If the callback is not registered by the target application,     * return an ERROR     */    if (pTcd->pCallbacks->addressSet == NULL)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    if ((*pTcd->pCallbacks->addressSet)	(pTcd->callbackParam, pTcd->targChannel, deviceAddress) != OK)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* Take Mutex */    OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );    pTcd->controlErpPending = TRUE;    /* Release Mutex */    OSS_MUTEX_RELEASE (pTcd->tcdMutex);    /* Initialize the status erp */    initStatusErp (pTcd);    /* Set the address of the device */    usbHalTcdAddressSet(&pTcd->tcdNexus, deviceAddress);    /* Submit Tcd */    if ((status = submitCntlErp ( pTcd )) != OK )        {        OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = FALSE;        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargAddressSet exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargSynchFrameGet - processes a GET_SYNCH_FRAME setup packet** This function is called when a GET_SYNCH_FRAME request is received from* the host.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:*   None** \NOMANUAL*/LOCAL STATUS usbTargSynchFrameGet    (    pTARG_TCD	pTcd		/* Pointer to TCD */    )    {    STATUS	status = OK;    pUSB_SETUP	pSetup = (pUSB_SETUP) pTcd->setupBfr;	/* USB_SETUP packet */    UINT16	endpoint = FROM_LITTLEW (pSetup->index);/* endpoint no */    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargSynchFrameGet entered ...", USB_TARG_WV_FILTER);       /*     * If the callback is not registered by the target application,     * return an ERROR     */    if (pTcd->pCallbacks->synchFrameGet == NULL)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* Get the synch frame from the target application. */    if ((*pTcd->pCallbacks->synchFrameGet)	(pTcd->callbackParam, pTcd->targChannel,	endpoint, (pUINT16) pTcd->dataBfr) != OK)	    {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* Take Mutex */    OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );    pTcd->controlErpPending = TRUE;        /* Release Mutex */    OSS_MUTEX_RELEASE (pTcd->tcdMutex);    /* Initialize the data erp for response */    initDataErpForResponse (pTcd, 2, pTcd->dataBfr);    /* Submit Tcd */    if ((status = submitCntlErp ( pTcd )) != OK )        {        OSS_MUTEX_TAKE ( pTcd->tcdMutex , OSS_BLOCK );        pTcd->controlErpPending = FALSE;        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargSynchFrameGet exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargVendorSpecificRequest - processes a vendor specific setup packet** This function is called when any vendor specific request is received* from the host.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:*   None** \NOMANUAL*/LOCAL STATUS usbTargVendorSpecificRequest    (    pTARG_TCD	pTcd		/* Pointer to TCD */    )    {    pUSB_SETUP pSetup = (pUSB_SETUP) pTcd->setupBfr;	/* USB_SETUP buffer */    UINT16 value = FROM_LITTLEW (pSetup->value);	/* wValue */    UINT16 index = FROM_LITTLEW (pSetup->index);	/* wIndex */    UINT16 length = FROM_LITTLEW (pSetup->length);	/* wLength */    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargVendorSpecificRequest entered ...", USB_TARG_WV_FILTER);       /*     * If the callback is not registered by the target application,     * return an ERROR     */    if (pTcd->pCallbacks->vendorSpecific == NULL)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    if ((*pTcd->pCallbacks->vendorSpecific)	(pTcd->callbackParam, pTcd->targChannel,	pSetup->requestType, pSetup->request, value ,index , length) != OK)        {        cntlEndpointStall ( pTcd );        return ERROR;        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargVendorSpecificRequest exiting ...", USB_TARG_WV_FILTER);       return OK;    }/********************************************************************************* usbParseSetupPacket - parse/execute a control pipe request** The TARG_TCD.setupBfr should contain a setup packet.  Validate it.  If* valid, parse and execute it.** RETURNS: OK if setup packet valid, else ERROR if invalid** ERRNO:* \is* \i S_usbTargLib_TCD_FAULT* TCD fault occured.* \ie** \NOMANUAL*/LOCAL STATUS usbParseSetupPacket    (    pTARG_TCD	pTcd		/* Pointer to the TCD */    )    {    pUSB_SETUP	pSetup = NULL;	/* USB_SETUP buffer */    UINT16	state = 0;	/* state of endpoint */    /* Validate the setup packet */    if (pTcd->setupErp.bfrList [0].actLen != sizeof (USB_SETUP))	return ERROR;    /*     * Check if default control endpoints are stalled,     * if so, clear the stall conditions     */    /* Check if default control In endpoint is stalled */    if (usbHalTcdEndpointStatusGet (&pTcd->tcdNexus ,                                   pTcd->defaultControlPipeIN, (pUINT8)(&state))                                 != OK)        return ossStatus (S_usbTargLib_TCD_FAULT);    state = FROM_LITTLEW (state);    if (state == USB_ENDPOINT_STS_HALT) /* endpoint is stalled, unstall it */        if ((usbHalTcdEndpointStateSet (&pTcd->tcdNexus ,                                        pTcd->defaultControlPipeIN,                                        TCD_ENDPOINT_UNSTALL)) != OK)            return ossStatus (S_usbTargLib_TCD_FAULT);    state = 0;    /* Check if default control Out endpoint is stalled*/    if ( usbHalTcdEndpointStatusGet (&pTcd->tcdNexus ,                                  pTcd->defaultControlPipeOUT, (pUINT8)(&state))                                  != OK)        return ossStatus (S_usbTargLib_TCD_FAULT);    state = FROM_LITTLEW (state);    /* endpoint is stalled, unstall it */    if ( state == USB_ENDPOINT_STS_HALT )        if ((usbHalTcdEndpointStateSet (&pTcd->tcdNexus,                                        pTcd->defaultControlPipeOUT,                                        TCD_ENDPOINT_UNSTALL)) != OK)            return ossStatus (S_usbTargLib_TCD_FAULT);    pSetup = (pUSB_SETUP) pTcd->setupBfr;    /* Execute based on the type of request. */    if ((pSetup->requestType & USB_RT_CATEGORY_MASK) == USB_RT_STANDARD)	{	switch (pSetup->request)	    {	    case USB_REQ_CLEAR_FEATURE:		return usbTargFeatureClear (pTcd);	    case USB_REQ_SET_FEATURE:		return usbTargFeatureSet (pTcd);	    case USB_REQ_GET_CONFIGURATION:		return usbTargConfigurationGet (pTcd);	    case USB_REQ_SET_CONFIGURATION:		return usbTargConfigurationSet (pTcd);	    case USB_REQ_GET_DESCRIPTOR:		return usbTargDescriptorGet (pTcd);	    case USB_REQ_SET_DESCRIPTOR:		return usbTargDescriptorSet (pTcd);	    case USB_REQ_GET_INTERFACE:		return usbTargInterfaceGet (pTcd);	    case USB_REQ_SET_INTERFACE:		return usbTargInterfaceSet (pTcd);	    case USB_REQ_GET_STATUS:		return usbTargStatusGet (pTcd);	    case USB_REQ_SET_ADDRESS:		return usbTargAddressSet (pTcd);	    case USB_REQ_GET_SYNCH_FRAME:		return usbTargSynchFrameGet (pTcd);	    default:		return ERROR;	    }	}    else        return usbTargVendorSpecificRequest (pTcd);    }

⌨️ 快捷键说明

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