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

📄 usbhalendpoint.c

📁 USB source code of Vxworks 5.6. It has device and the host stack.
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usbHalEndpoint.c - HAL Endpoint specific functionalities *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01i,17sep04,ami  WindView Instrumentation Changes01h,02aug04,ami  erp::userPtr changed to erp::tcdPrt01g,19jul04,ami  Coding Convention Changes01f,30jun04,pdg  Bug fixes - Full speed testing of isp158201e,21jun04,ami  Changes for Endianess to Printing a File01d,15jun04,pdg  Fix for transferring data with the mass storage device.01c,14jun04,ami  Changes for sending a 0 length packet when the data to be                 sent is a multiple of max packet size.01b,03may04,pdg  Fix for receiving less data from the host than expected01a,08mar04,pdg  First.*//*DESCRIPTIONThis file defines the hardware independent endpoint specific functionalitiesof the Hardware Adaption Layer.INCLUDE FILES: drv/usb/target/usbTcd.h, usb/target/usbHal.h,               usb/target/usbHalDebug.h, usb/ossLib.h, string.h               usb/target/usbPeriphInstr.h  *//* includes */#include <string.h>                 #include "usb/target/usbTcd.h"       #include "usb/target/usbHal.h"       #include "usb/target/usbHalDebug.h"   #include "usb/ossLib.h"               #include "usb/target/usbPeriphInstr.h"/* forward declarations */LOCAL VOID usbHalEndpointRelease (pUSBHAL_TCD pUsbHal,                                   pUSBHAL_PIPE_INFO pPipeInfo);/********************************************************************************* usbHalTcdEndpointAssign - configure an endpoint on the target controller** This function is used to configure an endpoint for USB operations. * <pEndpointDesc> is the endpoint descriptor obtained from the above layer. On* successfull configuration, we get a pipe handle <ppPipeHandle> which is * used to carry out any further operations on that endpoint.** RETURNS: OK if endpoint is configured successfully, ERROR otherwise.** ERRNO:*   None.*/STATUS usbHalTcdEndpointAssign    (    pUSBHAL_TCD_NEXUS	pNexus,			/* USBHAL_TCD_NEXUS */    pUSB_ENDPOINT_DESCR pEndpointDesc,		/* USB_ENDPOINT_DESCR */    UINT16		uConfigurationValue,	/* configuration value */    UINT16		uInterface,		/* interface number */    UINT16		uAltSetting,		/* alternate setting */    pVOID		* ppPipeHandle		/* pointer to the Pipe handle */    )    {    pUSBHAL_TCD	pUsbHal = NULL;			/* USBHAL_TCD */    TRB_ENDPOINT_ASSIGN	trbEndpointAssign;	/* TRB_ENDPOINT_ASSIGN */    STATUS	status = ERROR;    pUSBHAL_PIPE_INFO	pPipeInfo = NULL;	/* USBHAL_PIPE_INFO */    UINT32	uIndex = 0;    UINT32	maskValue = 0;    /* WindView Instrumentation */     USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,    "usbHalTcdEndpointAssign entered...", USB_HAL_WV_FILTER);       USBHAL_DEBUG("usbHalTcdEndpointAssign - Entering\n",0,0,0,0,0,0);    /* Check the validity of the parameters */    if ((pNexus == NULL) || (pEndpointDesc == NULL) ||        (ppPipeHandle == NULL) || (pNexus->handle == NULL))        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Bad Parameters Received...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign: Invalid parameters\n",0,0,0,0,0,0);        return ERROR;        }    /* Retrieve the hal data structure */    pUsbHal = (pUSBHAL_TCD)pNexus->handle;    /* Check if the endpoint can be accomodated */    if ((pUsbHal->uActiveEndpoints == pUsbHal->halDeviceInfo.uNumberEndpoints))        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Endpoint cannot be accomodated...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign: Endpoint cannot be accomodated\n",                    0,0,0,0,0,0);        return ERROR;        }    /* Populate the TRB - start */    trbHeaderInit((pTRB_HEADER)(&trbEndpointAssign),                  pUsbHal->pTCDHandle,                  TCD_FNC_ENDPOINT_ASSIGN,                  sizeof(TRB_ENDPOINT_ASSIGN));    trbEndpointAssign.pEndpointDesc = pEndpointDesc;    trbEndpointAssign.uConfigurationValue = uConfigurationValue;    trbEndpointAssign.uInterface = uInterface;    trbEndpointAssign.uAltSetting = uAltSetting;    /* Populate the TRB - end */    /* Call the single entry point for the TCD */    status = (*pUsbHal->tcdExecFunc)(&trbEndpointAssign);    /* If the function returns ERROR, return an ERROR */    if (status == ERROR)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Error in single fucntion call...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign : Error in assigning an endpoint\n",                    0,0,0,0,0,0);        return ERROR;        }    /* Allocate memory for the Pipe information structure */    pPipeInfo = OSS_CALLOC(sizeof(USBHAL_PIPE_INFO));    /* Check if memory allocation is successful */    if (pPipeInfo == NULL)        {        TRB_ENDPOINT_RELEASE trbEptRelease;        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Memory allocation error...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign : Memory allocation error\n",                    0,0,0,0,0,0);        /* Populate the TRB - start */        trbHeaderInit((pTRB_HEADER)(&trbEptRelease),                pUsbHal->pTCDHandle,                TCD_FNC_ENDPOINT_RELEASE,                sizeof(TRB_ENDPOINT_RELEASE));        trbEptRelease.pipeHandle = trbEndpointAssign.pipeHandle;        /* Populate the TRB - End */        /* Call the single entry point for the TCD */        (*pUsbHal->tcdExecFunc)(&trbEptRelease);        return ERROR;        }    /* Populate the members of the structure */    pPipeInfo->pipeHandle = trbEndpointAssign.pipeHandle;    pPipeInfo->uEndpointAddress = pEndpointDesc->endpointAddress;    pPipeInfo->maxPacketSize = (TO_LITTLEW(pEndpointDesc->maxPacketSize) &                                USB_MAX_PACKET_SIZE_MASK) *                                (((TO_LITTLEW(pEndpointDesc->maxPacketSize) &                                USB_NUMBER_OF_TRANSACTIONS_MASK) >>                                USB_NUMBER_OF_TRANSACTIONS_BITPOSITION) + 1);    /* Create a mutex for synchronizing the pipe requests */    if (OSS_MUTEX_CREATE(&pPipeInfo->mutexHandle) != OK)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Error creating the mutex...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign : Mutex creation error\n",                    0,0,0,0,0,0);        /* Call the function to release the resources allocated earlier */        usbHalEndpointRelease(pUsbHal, pPipeInfo);        return ERROR;        }    /* Initialize the mask value */    maskValue = 0x01;    /* Acquire the mutex before modifying the TCD data */    OSS_MUTEX_TAKE(pUsbHal->mutex, OSS_BLOCK);    /*      * Retrieve the correct mask value based on the bitposition which is     * not occupied by any other endpoint     */    while(((pUsbHal->uActiveEndpointsBitmap & maskValue) != 0) &&          (uIndex < pUsbHal->halDeviceInfo.uNumberEndpoints))        {        maskValue <<= 1;        uIndex++;        }    /* Check if the index is valid */    if (uIndex >= pUsbHal->halDeviceInfo.uNumberEndpoints)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointAssign exiting: Invalid Endpoint index obtained...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdEndpointAssign : Invalid Index\n",0,0,0,0,0,0);        /* Release the mutex */        OSS_MUTEX_RELEASE (pUsbHal->mutex);        /* Call the function to release the resources allocated earlier */        usbHalEndpointRelease (pUsbHal, pPipeInfo);        return ERROR;        }    /* Update the bitmap */    pUsbHal->uActiveEndpointsBitmap |= maskValue;    /* Increment the number of active endpoints */    pUsbHal->uActiveEndpoints++;    /* Store the pipe pointer in the array indexed at 'uIndex' */    *((pUsbHal->pPipeInfo) + uIndex) = pPipeInfo;    /* Release the mutex */    OSS_MUTEX_RELEASE (pUsbHal->mutex);    /* Copy the pointer */    *ppPipeHandle = pPipeInfo;    /* WindView Instrumentation */     USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,    "usbHalTcdEndpointAssign exiting...", USB_HAL_WV_FILTER);       USBHAL_DEBUG ("usbHalTcdEndpointAssign - Exiting\n",0,0,0,0,0,0);    return OK;    }/********************************************************************************* usbHalTcdEndpointRelease - unconfigure endpoint on the target controller** This function is used to release an endpoint configured earlier. * <pPipeHandle> is the handle to the pipe for the endpoint to be relesed. ** RETURNS: OK if endpoint is unconfigured successfully, ERROR otherwise.** ERRNO:*   none.*/STATUS usbHalTcdEndpointRelease    (    pUSBHAL_TCD_NEXUS	pNexus,		/* USBHAL_TCD_NEXUS */    pVOID pPipeHandle			/* pipe handle */    )    {    pUSBHAL_TCD		pUsbHal = NULL;		/* USBHAL_TCD */    TRB_ENDPOINT_RELEASE trbEndpointRelease;	/* TRB_ENDPOINT_RELEASE */    STATUS		status = ERROR;    pUSBHAL_PIPE_INFO	pHalPipeHandle = NULL;	/* USBHAL_PIPE_INFO */    pUSB_ERP		pErp = NULL;		/* USB_ERP */    UINT32		uIndex = 0;    /* WindView Instrumentation */     USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,    "usbHalTcdEndpointRelease entered...", USB_HAL_WV_FILTER);       USBHAL_DEBUG ("usbHalTcdEndpointRelease - Entering\n",0,0,0,0,0,0);    /* Check the validity of the parameters */    if ((pNexus == NULL) || (pPipeHandle == NULL) ||        (pNexus->handle == NULL))        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointRelease exiting: Bad Parameters Received...",        USB_HAL_WV_FILTER);           USBHAL_ERR ("usbHalTcdEndpointRelease : Invalid parameters\n",                     0,0,0,0,0,0);        return ERROR;        }    /* Extract the pointer to the USB HAL data structure */    pUsbHal = (pUSBHAL_TCD)pNexus->handle;    /* Extract the Pipe handle */    pHalPipeHandle = (pUSBHAL_PIPE_INFO)pPipeHandle;    /* Acquire the mutex before modifying the TCD data structure */    OSS_MUTEX_TAKE (pUsbHal->mutex, OSS_BLOCK);    /* Get the index into the array which contains the Pipe info pointer */    for (uIndex = 0;        ((*((pUsbHal->pPipeInfo) + uIndex) != pHalPipeHandle) &&        (uIndex < pUsbHal->halDeviceInfo.uNumberEndpoints));        uIndex++);    /* Check if the index is valid */    if ((uIndex >= pUsbHal->halDeviceInfo.uNumberEndpoints) ||        (((0x01 << uIndex) & pUsbHal->uActiveEndpointsBitmap) == 0) ||        (*((pUsbHal->pPipeInfo) + uIndex) == NULL))        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointRelease exiting: Pipe info pointer not found...",        USB_HAL_WV_FILTER);           USBHAL_ERR ("usbHalTcdEndpointRelease : Pipe info pointer not found",                     0,0,0,0,0,0);        /* Release the mutex */        OSS_MUTEX_RELEASE (pUsbHal->mutex);        return ERROR;        }    /* Populate the TRB - start */    trbHeaderInit ((pTRB_HEADER)(&trbEndpointRelease),                    pUsbHal->pTCDHandle,                    TCD_FNC_ENDPOINT_RELEASE,                    sizeof(TRB_ENDPOINT_RELEASE));    trbEndpointRelease.pipeHandle = pHalPipeHandle->pipeHandle;    /* Populate the TRB - End */    /* Call the single entry point of the TCD */    status = (*pUsbHal->tcdExecFunc)(&trbEndpointRelease);    /* If the function returns ERROR, return an ERROR */    if (status == ERROR)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,        "usbHalTcdEndpointRelease exiting: TCD Error in releasing an endpoint...",        USB_HAL_WV_FILTER);           USBHAL_ERR ("usbHalTcdEndpointRelease:Error in releasing an endpoint\n",                    0,0,0,0,0,0);        /* Release the mutex */        OSS_MUTEX_RELEASE(pUsbHal->mutex);        return ERROR;        }    /* Acquire the mutex created for this list */    OSS_MUTEX_TAKE (pHalPipeHandle->mutexHandle, OSS_BLOCK);    /* Extract the first element of the list */    pErp = usbListFirst (&pHalPipeHandle->listHead);    /*     * This loop unlinks all the elements from the link and calls the callbacks     * for each ERP linked     */    while (pErp != NULL)        {        /* Unlink this element */        usbListUnlink (&pErp->tcdLink);        /* Update the result of the ERP */        pErp->result = S_usbTcdLib_ERP_CANCELED;        /* Call the callback function for the ERP */        if (pErp->targCallback != NULL)            (*pErp->targCallback)(pErp);        /* Extract the next element of the list */        pErp = usbListFirst (&pHalPipeHandle->listHead);        }    /* Release the mutex */    OSS_MUTEX_RELEASE (pHalPipeHandle->mutexHandle);    /* Destroy the mutex */    OSS_MUTEX_DESTROY (pHalPipeHandle->mutexHandle);    /* Free the memory allocated for the Pipe info data structure */    OSS_FREE (pHalPipeHandle);    /* Reset the array element */    *((pUsbHal->pPipeInfo) + uIndex) = NULL;    /* Update the bitmap indicating the active endpoints */    pUsbHal->uActiveEndpointsBitmap &= ~(0x01 << uIndex);    /* Update the number of active endpoints */    pUsbHal->uActiveEndpoints--;    /* Release the mutex */    OSS_MUTEX_RELEASE (pUsbHal->mutex);    /* WindView Instrumentation */     USB_HAL_LOG_EVENT(USB_HAL_ENDPOINT,    "usbHalTcdEndpointRelease exiting...", USB_HAL_WV_FILTER);       USBHAL_DEBUG("usbHalTcdEndpointRelease - Exiting\n",0,0,0,0,0,0);    return OK;

⌨️ 快捷键说明

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