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

📄 usbtargdefaultpipe.c

📁 USB source code of Vxworks 5.6. It has device and the host stack.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usbTargDefaultPipe.c - Handles the requests to the default control pipe *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01h,17sep04,hch  merge for windview instrumentation01g,02aug04,ami  erp::userPtr changed to erp::tcdPrt01f,29jul04,pdg  Fixed coverity errors01e,29jul04,pdg  Diab compiler warnings fixed01d,19jul04,ami  Coding Convention Changes01c,19jul04,pdg  Cleaned up warning01b,30jun04,pdg  Bug fixes - isp1582 full speed testing01a,01apr04,ami  First*//*DESCRIPTIONThis module handles the standard requests to the default pipe by calling the callback functions present in the callback table. It also provides the interfaces for non-standard control data transfers on the default control pipeto the USB Target Application.INCLUDE FILES: usb/usbPlatform.h, string.h, usb/ossLib.h, usb/usb.h,                usb/usbHandleLib.h, usb/target/HalLib.h,               usb/target/usbHalCommon.h, usb/target/usbTargLib.h,               usb/target/usbTargUtil.h, usb/target/usbPeriphInstr.h*//* includes */#include "usb/usbPlatform.h"	#include "string.h"                     #include "usb/ossLib.h" 	#include "usb/usb.h"		#include "usb/usbHandleLib.h"	#include "usb/target/usbHalLib.h"      #include "usb/target/usbHalCommon.h"   #include "usb/target/usbTargLib.h"     #include "usb/target/usbTargUtil.h"  #include "usb/target/usbPeriphInstr.h"        /* forward declaration */LOCAL VOID usbTargDataOUTErpCallback (pUSB_ERP pErp);LOCAL VOID usbTargDataINErpCallback (pUSB_ERP pErp);LOCAL VOID usbTargStatusErpCallback (pUSB_ERP pErp);LOCAL STATUS usbParseSetupPacket (pTARG_TCD pTcd);/********************************************************************************* submitCntlErp - submits the control ERP** This function is used to submit the Endpoint Request Packet over the* default control pipes. If an error occurs, the control pipes are stalled.** RETURNS: OK or ERROR if not able to submit the ERP** ERRNO:* \is* \i S_usbTargLib_TCD_FAULT* Fault in TCD occured.* \ie** \NOMANUAL*/LOCAL STATUS submitCntlErp    (    pTARG_TCD		pTcd		/* Pointer to TCD */    )    {    STATUS		status = OK;    if (usbHalTcdErpSubmit (&pTcd->tcdNexus , &pTcd->defaultControlErp) != OK)        {        status = ossStatus (S_usbTargLib_TCD_FAULT);        cntlEndpointStall (pTcd);        }    return status;    }/********************************************************************************* initSetupErp - initialize setup erp** This function is uesd to initialize the Setup ERP.** RETURNS: N/A** ERRNO:*   None** \NOMANUAL*/VOID initSetupErp    (    pTARG_TCD		pTcd		/* pointer to the TCD */    )    {        /* Initialize the setup buffer */    memset (&pTcd->setupErp , 0 , sizeof(USB_ERP));    /* Initialize the setup buffer */    memset(pTcd->setupBfr, 0, sizeof(USB_SETUP));    pTcd->setupErp.targPtr = pTcd;    pTcd->setupErp.erpLen = sizeof (USB_ERP);    pTcd->setupErp.targCallback = (ERP_CALLBACK)usbTargSetupErpCallback;    pTcd->setupErp.pPipeHandle = pTcd->defaultControlPipeOUT;    pTcd->setupErp.dataToggle = USB_DATA0;    pTcd->setupErp.bfrCount = 1;    pTcd->setupErp.bfrList[0].pid = USB_PID_SETUP;    pTcd->setupErp.bfrList[0].pBfr = pTcd->setupBfr;    pTcd->setupErp.bfrList[0].bfrLen = sizeof (USB_SETUP);    }/********************************************************************************* initStatusErp - initialize status phase** This function initializes the ERP to send or receive the status phase* packet.** RETURNS: N/A** ERRNO:*   None.** \NOMANUAL*/LOCAL VOID initStatusErp    (    pTARG_TCD		pTcd		/* pointer to the TCD */    )    {    /* Reinitilize the default control erp and update */    memset ( &pTcd->defaultControlErp , 0 , sizeof (USB_ERP));    pTcd->defaultControlErp.targPtr = pTcd;    pTcd->defaultControlErp.erpLen = sizeof (USB_ERP);    pTcd->defaultControlErp.targCallback =                                     (ERP_CALLBACK)usbTargStatusErpCallback;    pTcd->defaultControlErp.pPipeHandle = pTcd->defaultControlPipeIN;    pTcd->defaultControlErp.dataToggle = USB_DATA1;    pTcd->defaultControlErp.bfrCount = 1;    pTcd->defaultControlErp.bfrList[0].pid = USB_PID_IN;    return;    }/********************************************************************************* initDataErpForResponse - initializes ERP for control In data phase** This function is used to initialize the Endpoint Request Packet for* In data phase on contol In endpoint.** RETURNS: N/A** ERRNO:*   None** \NOMANUAL*/LOCAL VOID initDataErpForResponse    (    pTARG_TCD		pTcd,			/* Pointer to the TCD */    UINT16		length,			/* length */    pUINT8		pBuf			/* Buffer for data */    )    {    /* Reinitilize the default control erp and update */    memset ( &pTcd->defaultControlErp , 0 , sizeof (USB_ERP));    pTcd->defaultControlErp.targPtr = pTcd;    pTcd->defaultControlErp.erpLen = sizeof (USB_ERP);    pTcd->defaultControlErp.targCallback =                                     (ERP_CALLBACK)usbTargDataINErpCallback;    pTcd->defaultControlErp.pPipeHandle = pTcd->defaultControlPipeIN;    pTcd->defaultControlErp.dataToggle = USB_DATA1;    pTcd->defaultControlErp.bfrCount = 1;    pTcd->defaultControlErp.bfrList[0].pBfr = pBuf;    pTcd->defaultControlErp.bfrList[0].bfrLen = length;    pTcd->defaultControlErp.bfrList[0].pid = USB_PID_IN;    return;    }/********************************************************************************* initDataErpToReceive - initializes ERP for control Out data phase** This function is initialize the Endpoint Request Packetto receive data* on Control Out Data Phase.** RETURNS: N/A** ERRNO:*   None** \NOMANUAL*/LOCAL VOID initDataErpToReceive    (    pTARG_TCD		pTcd,		/* Pointer to the TCD */    UINT16		length,		/* length of setup buffer */    pUINT8		pBuf		/* buffer for data */    )    {    /* Reinitilize the default control erp and update */    memset ( &pTcd->defaultControlErp , 0 , sizeof (USB_ERP));    pTcd->defaultControlErp.targPtr = pTcd;    pTcd->defaultControlErp.erpLen = sizeof (USB_ERP);    pTcd->defaultControlErp.targCallback =                                     (ERP_CALLBACK)usbTargDataOUTErpCallback;    pTcd->defaultControlErp.pPipeHandle = pTcd->defaultControlPipeOUT;    pTcd->defaultControlErp.dataToggle = USB_DATA1;    pTcd->defaultControlErp.bfrCount = 1;    pTcd->defaultControlErp.bfrList[0].pBfr = pBuf;    pTcd->defaultControlErp.bfrList[0].bfrLen = length;    pTcd->defaultControlErp.bfrList[0].pid = USB_PID_OUT;    return;    }/********************************************************************************* usbTargControlResponseSend - sends data to host on the control pipe** The USB Target Layer automatically creates a pipe to manage * communication on the default control endpoint (#0) defined by the USB.  * Certain application callbacks  may need to formulate a response and send * it to the host.  This function allows a caller to respond to a host * control pipe request.* This function returns as soon as the transfer is * enqueued.** RETURNS: OK, or ERROR if unable to submit response to host.** ERRNO:* \is* \i S_usbTargLib_GENERAL_FAULT* Fault occured in upper layers.** \i S_usbTargLib_BAD_PARAM* Bad Parameter is passed.* \ie*/STATUS usbTargControlResponseSend    (    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16		bfrLen,		/* length of response 0 */    pUINT8		pBfr		/* ptr to bfr  */    )    {    pTARG_TCD		pTcd = NULL;	/* TARG_TCD */    STATUS		status = ERROR;    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlResponseSend entered ...", USB_TARG_WV_FILTER);       /* Validate parameters */    if ((status = validateTarg (targChannel,&pTcd)) == OK)       {        /* Take the tcd mutex */        OSS_MUTEX_TAKE (pTcd->tcdMutex, OSS_BLOCK);        /* Check if there is some control erp pending already */        if (pTcd->controlErpPending)            {            /* WindView Instrumentation */            USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,            "usbTargControlResponseSend exiting: ERP is pending ...",            USB_TARG_WV_FILTER);               /* Release the mutex */            OSS_MUTEX_RELEASE (pTcd->tcdMutex);            return ossStatus (S_usbTargLib_GENERAL_FAULT);            }        /* Copy pBfr tp Targ_Tcd. dataBfr */        memcpy ( pTcd->dataBfr, pBfr, bfrLen);        /* Re-initialize the defaultControlErp and update it */        initDataErpForResponse (pTcd , bfrLen , pTcd->dataBfr);        pTcd->controlErpPending = TRUE ;        /* submit the erp */        if ((status = submitCntlErp (pTcd))!= OK)             pTcd->controlErpPending = FALSE;        /* Release the mutex */        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlResponseSend exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargControlStatusSend - sends control transfer status to the host** This function is used to send the status to the host. This function is* used when the control transfer does not have a data stage.** RETURNS: OK, or ERROR if unable to submit the status ERP.** ERRNO:* \is* \i S_usbTargLib_GENERAL_FAULT* Fault occured in upper layers.** \i S_usbTargLib_BAD_PARAM* Bad Parameter is passed.* \ie*/STATUS usbTargControlStatusSend    (    USB_TARG_CHANNEL	targChannel	/* target channel */    )    {    pTARG_TCD		pTcd = NULL;	/* TARG_TCD */    STATUS		status = ERROR;    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlStatusSend entered ...", USB_TARG_WV_FILTER);       /* Validate parameters */    if ((status = validateTarg (targChannel,&pTcd)) == OK)        {        /* Take the tcd mutex */        OSS_MUTEX_TAKE (pTcd->tcdMutex, OSS_BLOCK);        /* Check if there is some control erp pending already */        if (pTcd->controlErpPending)            {            /* Release the mutex */            OSS_MUTEX_RELEASE (pTcd->tcdMutex);            return ossStatus (S_usbTargLib_GENERAL_FAULT);            }        /* Re-initialize the defaultControlErp and update it */        initStatusErp (pTcd);        pTcd->controlErpPending = TRUE ;        /* submit the erp */        if ((status = submitCntlErp (pTcd))!= OK)             pTcd->controlErpPending = FALSE;        /* Release the mutex */        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlStatusSend exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargControlPayloadRcv - receives data on the default control pipe** USB Targlib Layer automatically creates a pipe to manage communication* on the default control pipe (#0) defined by the USB.  Certain * application callbacks may need to receive additional data on the control * OUT endpoint in order to complete processing of the control pipe request.* This function allows a caller to receive data on a control pipe.** RETURNS: OK, or ERROR if unable to submit ERP to receive additional data** ERRNO:* \is* \i S_usbTargLib_GENERAL_FAULT* Fault occured in upper layers.** \i S_usbTargLib_BAD_PARAM* Bad Parameter is passed.* \ie*/STATUS usbTargControlPayloadRcv    (    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16		bfrLen,		/* length of data to be received */    pUINT8		pBfr,		/* ptr to bfr  */    ERP_CALLBACK	userCallback	/* USB Target Applcaition Callback */    )    {    pTARG_TCD		pTcd = NULL;	/* TARG_TCD */    STATUS		status = ERROR;    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlPayloadRcv entered ...", USB_TARG_WV_FILTER);       /* Validate parameters */    if ((status = validateTarg (targChannel,&pTcd)) == OK)        {        /* Take the tcd mutex */        OSS_MUTEX_TAKE (pTcd->tcdMutex, OSS_BLOCK);        /* Check if there is some control erp pending already */        if (pTcd->controlErpPending)            {            /* Release the mutex */            OSS_MUTEX_RELEASE (pTcd->tcdMutex);            return ossStatus (S_usbTargLib_GENERAL_FAULT);            }        /* Re-initialize the defaultControlErp and update it */        initDataErpToReceive ( pTcd , bfrLen ,pBfr );        pTcd->defaultControlErp.userCallback = userCallback ;        pTcd->controlErpPending = TRUE ;        /* submit the erp */        if ((status = submitCntlErp (pTcd)) != OK)            pTcd->controlErpPending = FALSE;        /* Release the mutex */        OSS_MUTEX_RELEASE (pTcd->tcdMutex);        }    /* WindView Instrumentation */    USB_TARG_LOG_EVENT(USB_TARG_DEFAULT_PIPE,    "usbTargControlPayloadRcv exiting ...", USB_TARG_WV_FILTER);       return status;    }/********************************************************************************* usbTargSetupErpCallback - handles the setup packet** This function is called when a setup packet is received.** RETURNS: N/A** ERRNO:*   None**/VOID usbTargSetupErpCallback    (    pUSB_ERP		pErp		/* Pointer to ERP structure */    )    {    pTARG_TCD		pTcd = NULL;	/* TARG_TCD */

⌨️ 快捷键说明

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