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

📄 usbtarglib.c

📁 This the USB source code for vxworks5.5. It has OSS library source code and also the complete targ
💻 C
📖 第 1 页 / 共 5 页
字号:
    pTARG_TCD pTcd,    UINT16 configuration,    UINT16 interface,    UINT16 endpoint    )    {    pTARG_PIPE pPipe;    pPipe = usbListFirst (&pTcd->pipes);    while (pPipe != NULL)	{	if (configuration == ANY_CONFIGURATION ||	    configuration == pPipe->configuration)	    {	    if (interface == ANY_INTERFACE ||		interface == pPipe->interface)		{		if (endpoint == ANY_ENDPOINT ||		    endpoint == pPipe->pEndpoint->endpointNum)		    {		    /* Reset our DATA0/DATA1 indicator. */		    pPipe->dataToggle = USB_DATA0;		    /* Notify the TCD to reset any TCD/hardware indicators */		    usbTcdEndpointStateSet (&pTcd->tcdNexus,			pPipe->pEndpoint->endpointId, TCD_ENDPOINT_DATA0);		    if (pPipe->pEndpoint2 != NULL)			usbTcdEndpointStateSet (&pTcd->tcdNexus,			    pPipe->pEndpoint2->endpointId, TCD_ENDPOINT_DATA0);		    }		}	    }	pPipe = usbListNext (&pPipe->pipeLink);	}    }/***************************************************************************** initErp - initializes ERP based on arguments passed by caller, then submits it** RETURNS: OK, or ERROR if unable to initialize/submit ERP*/LOCAL STATUS initErp    (    pTARG_TCD pTcd,    pBOOL erpInUse,    pUSB_ERP pErp,    ERP_CALLBACK callback,    UINT16 dataToggle,    UINT8 pid,    pUINT8 pBfr,    UINT16 bfrLen    )    {    /* Check if the ERP is already in use. */    if (*erpInUse)	return ERROR;    *erpInUse = TRUE;    /* Initialize ERP */    memset (pErp, 0, sizeof (*pErp));    pErp->userPtr = pTcd;    pErp->erpLen = sizeof (*pErp);    pErp->userCallback = callback;    pErp->dataToggle = dataToggle;    pErp->bfrCount = 1;    pErp->bfrList [0].pid = pid;    pErp->bfrList [0].pBfr = pBfr;    pErp->bfrList [0].bfrLen = bfrLen;    /* Submit the ERP. */    return usbTargTransfer (pTcd->controlPipe, pErp);    }/***************************************************************************** initSetupErp - Initialize ERP to listen for control pipe requests** RETURNS: OK, or ERROR if unable to initialize control ERP.*/LOCAL STATUS initSetupErp    (    pTARG_TCD pTcd    )    {    /* Initialize the Setup phase ERP */    return initErp (pTcd, &pTcd->setupErpPending, &pTcd->setupErp, 	setupErpCallback, USB_DATA0, USB_PID_SETUP, 	pTcd->setupBfr, sizeof (pTcd->setupBfr));    }/***************************************************************************** initDataErpForResponse - Initialize ERP to send a control pipe response** TARGET.dataBfr must already contain the data to be send to the host of* length <bfrLen>.** RETURNS: OK, or ERROR if unable to initialize/submit ERP*/LOCAL STATUS initDataErpForResponse    (    pTARG_TCD pTcd,    UINT16 bfrLen    )    {    /* Initialize the Data phase ERP */    return initErp (pTcd, &pTcd->dataErpPending, &pTcd->dataErp, 	responseErpCallback, USB_DATA1, USB_PID_IN, pTcd->dataBfr, bfrLen);    }/***************************************************************************** initStatusErp - Initialize ERP to send/rcv status phase packet** <pid> must specify the direction of the status phase packet as USB_PID_IN* (from the device to the host) or USB_PID_OUT (from host to device).** RETURNS: OK, or ERROR if unable to initialize/submit ERP*/LOCAL STATUS initStatusErp    (    pTARG_TCD pTcd,    UINT8 pid    )    {    /* Initialize the Status phase ERP */    return initErp (pTcd, &pTcd->statusErpPending, &pTcd->statusErp, 	statusErpCallback, USB_DATA1, pid, NULL, 0);    }/***************************************************************************** requestClearFeature - processes a CLEAR_FEATURE setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestClearFeature    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT16 feature = FROM_LITTLEW (pSetup->value);    UINT16 index = FROM_LITTLEW (pSetup->index);    /* A CLEAR_FEATURE request may be configuration event.  Therefore, we     * need to set the data toggle to DATA0 for any pipes which reference     * this interface.     */    if (pSetup->requestType == (USB_RT_STANDARD | USB_RT_ENDPOINT) &&	feature == USB_FSEL_DEV_ENDPOINT_HALT)	{	resetDataToggle (pTcd, ANY_CONFIGURATION, ANY_ENDPOINT, index);	}    /* The request itself isn't supported unless the target application     * has provided a featureSet handler.     */    if (pTcd->pCallbacks->featureClear == NULL)	return ERROR;    if ((*pTcd->pCallbacks->featureClear)	(pTcd->callbackParam, pTcd->targChannel, 	pSetup->requestType, feature, index) != OK)	return ERROR;    /* Request terminates with status phase. */    return initStatusErp (pTcd, USB_PID_IN);    }/***************************************************************************** requestSetFeature - processes a SET_FEATURE setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestSetFeature    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT16 feature = FROM_LITTLEW (pSetup->value);    UINT16 index = FROM_LITTLEW (pSetup->index);    /* This request isn't supported unless the target application     * has provided a featureSet handler.     */    if (pTcd->pCallbacks->featureSet == NULL)	return ERROR;    if ((*pTcd->pCallbacks->featureSet)	(pTcd->callbackParam, pTcd->targChannel, 	pSetup->requestType, feature, index) != OK)	return ERROR;    /* Request terminates with status phase. */    return initStatusErp (pTcd, USB_PID_IN);    }/***************************************************************************** requestGetConfiguration - processes a GET_CONFIGURATION setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestGetConfiguration    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    /* This request isn't supported unless the target application has     * provided a configurationGet handler.     */    if (pTcd->pCallbacks->configurationGet == NULL)	return ERROR;    /* Get the interface setting from the target application. */    if ((*pTcd->pCallbacks->configurationGet)	(pTcd->callbackParam, pTcd->targChannel, 	(pUINT8) pTcd->dataBfr) != OK)	return ERROR;    /* Transmit the interface setting back to the host */    return initDataErpForResponse (pTcd, sizeof (UINT8));    }/***************************************************************************** requestSetConfiguration - processes a SET_CONFIGURATION setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestSetConfiguration    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT8 configuration = LSB (FROM_LITTLEW (pSetup->value));    /* A SET_CONFIGURATION request is a configuration event.  Therefore, we     * need to set the data toggle to DATA0 for any pipes which reference     * this interface.     */    resetDataToggle (pTcd, configuration, ANY_INTERFACE, ANY_ENDPOINT);    /* The request itself isn't supported unless the target application     * has provided an interfaceSet handler.     */    if (pTcd->pCallbacks->configurationSet == NULL)	return ERROR;    if ((*pTcd->pCallbacks->configurationSet)	(pTcd->callbackParam, pTcd->targChannel, configuration) != OK)	return ERROR;    /* Request terminates with status phase. */    return initStatusErp (pTcd, USB_PID_IN);    }/***************************************************************************** requestGetDescriptor - processes a GET_DESCRIPTOR setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestGetDescriptor    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT8 descriptorType = MSB (FROM_LITTLEW (pSetup->value));    UINT8 descriptorIndex = LSB (FROM_LITTLEW (pSetup->value));    UINT16 languageId = FROM_LITTLEW (pSetup->index);    UINT16 length = FROM_LITTLEW (pSetup->length);    UINT16 actLen;    /* This request isn't supported unless the target application has     * provided a descriptorGet handler.     */    if (pTcd->pCallbacks->descriptorGet == NULL)	return ERROR;    /* Get the descriptor from the target application. */    if ((*pTcd->pCallbacks->descriptorGet)	(pTcd->callbackParam, pTcd->targChannel, 	pSetup->requestType, descriptorType, descriptorIndex,	languageId, min (length, sizeof (pTcd->dataBfr)), pTcd->dataBfr, 	&actLen) != OK)	{	return ERROR;	}    /* Transmit the descriptor back to the host */    return initDataErpForResponse (pTcd, actLen);    }/***************************************************************************** requestSetDescriptor - processes a SET_DESCRIPTOR setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestSetDescriptor    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT8 descriptorType = MSB (FROM_LITTLEW (pSetup->value));    UINT8 descriptorIndex = LSB (FROM_LITTLEW (pSetup->value));    UINT16 languageId = FROM_LITTLEW (pSetup->index);    UINT16 length = FROM_LITTLEW (pSetup->length);    /* This request isn't supported unless the target application has     * provided a descriptorSet handler.     */    if (pTcd->pCallbacks->descriptorSet == NULL)	return ERROR;    /* Let the target application process the SET_DESCRIPTOR request. */    return (*pTcd->pCallbacks->descriptorSet)	(pTcd->callbackParam, pTcd->targChannel, 	pSetup->requestType, descriptorType, descriptorIndex,	languageId, length);    }/***************************************************************************** requestGetInterface - processes a GET_INTERFACE setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestGetInterface    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT16 interface = FROM_LITTLEW (pSetup->index);    /* This request isn't supported unless the target application has     * provided an interfaceGet handler.     */    if (pTcd->pCallbacks->interfaceGet == NULL)	return ERROR;    /* Get the interface setting from the target application. */    if ((*pTcd->pCallbacks->interfaceGet)	(pTcd->callbackParam, pTcd->targChannel, 	interface, (pUINT8) pTcd->dataBfr) != OK)	return ERROR;    /* Transmit the interface setting back to the host */    return initDataErpForResponse (pTcd, sizeof (UINT8));    }/***************************************************************************** requestSetInterface - processes a SET_INTERFACE setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestSetInterface    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT16 interfaceIndex = FROM_LITTLEW (pSetup->index);    UINT8 alternateSetting = LSB (FROM_LITTLEW (pSetup->value));    /* A SET_INTERFACE request is a configuration event.  Therefore, we     * need to set the data toggle to DATA0 for any pipes which reference     * this interface.     */    resetDataToggle (pTcd, ANY_CONFIGURATION, interfaceIndex, ANY_ENDPOINT);    /* The request itself isn't supported unless the target application     * has provided an interfaceSet handler.     */    if (pTcd->pCallbacks->interfaceSet == NULL)	return ERROR;    if ((*pTcd->pCallbacks->interfaceSet)	(pTcd->callbackParam, pTcd->targChannel,	interfaceIndex, alternateSetting) != OK)	return ERROR;    /* Request terminates with status phase. */    return initStatusErp (pTcd, USB_PID_IN);    }/***************************************************************************** requestGetStatus - processes a GET_STATUS setup packet** RETURNS: OK if setup packet valid, else ERROR if invalid*/LOCAL STATUS requestGetStatus    (    pTARG_TCD pTcd,    pUSB_SETUP pSetup    )    {    UINT16 index = FROM_LITTLEW (pSetup->index);    UINT16 length = FROM_LITTLEW (pSetup->length);    UINT16 actLen;

⌨️ 快捷键说明

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