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

📄 usbtransunitinit.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 4 页
字号:
/* usbTransUnitInit.c - Translation Unit Initialization interfaces *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01k,15oct04,ami  Apigen Changes01l,07oct04,hch  Merge from Bangalore developement branch for SPR# 9648401k,16sep04,hch  Fix diab compiler error01j,06oct04,ami  Removal of warning messages related to SPR #94684 Fix01i,14sep04,gpd  memory leak fixes01h,12apr04,cfc  Apigen fixes01g,02dec03,cfc  Merge to support isochronous USB speakers01f,17nov03,sm   correcting refgen errors.01e,06nov03,cfc  Modification to support the USBD_NOTIFY_ALL from class                 drivers01d,01oct03,cfc  Merge from Bangalore fix for dual class drivers01c,21sep03,cfc  Fix compiler warnings01b,17sep03,cfc  Remove direct calls to wvEvent()01a,11sep03,cfc  Fix task creation prioritieso1d,10jul03,mat  Set Configuration Fix01c,16jun03,mat  prefixed "usb" to file name ,global variables etc01b,06jun03,mat  Wind View Instrumentation.01a,06jun03,mat  Wind River Coding Convention  API changes.*//*DESCRIPTIONImplements the Translation Unit Initialization interfaces.In order to use the USBD, it is first necessary to invoke usbdInitialize().Multiple calls to usbdInitialize() may be nested so long as a correspondingnumber of calls to usbdShutdown() are also made.  This allows multiple USBDclients to be written independently and without concern for coordinating theinitialization of the independent clients.Normal USBD clients  register with the USBD by calling usbdClientRegister().In response to this call, the Translation Unit allocates per-client datastructures and a client callback task.Callbacks for each client are invoked from this client-unique task.  Thisimproves the USBD's ability to shield clients from one-another and to helpensure the real-time response for all clients.After a client has registered, it will most often also register for dynamicattachment notification using usbdDynamicAttachRegister().  This functionallows a special client callback routine to be invoked each time a USB deviceis attached or removed from the system.  In this way, clients may discover thereal-time attachment and removal of devices.INCLUDE FILES: usbTransUnit.h*//* includes */#include "drv/usb/usbTransUnit.h" #include "usb2/usbHcdInstr.h"/* defines */#define USBTUINIT_MAX_MESSAGES   100     /* Maximum messages queued in message q *//* globals *//* Wind View Events Filter variable * value of 0 disables event capture */UINT32 usbtuInitWvFilter= 0x00;  /* list of clients registered with USBD */LIST_HEAD     usbtuClientList;   /* list of devices attached to USB */LIST_HEAD     usbtuDevList;      /* thread id of Translation Unit thread */THREAD_HANDLE usbtuThreadId;     /* message queue id of Translation Unit */MSG_Q_ID      usbtuMsgQid;       /* mutex of Translation Unit */MUTEX_HANDLE  usbtuMutex;        /* locals */LOCAL int usbtuInitCount = 0;		/* init nesting count */LOCAL BOOL usbtuInitOssInit = FALSE;	/* TRUE if ossLib is initialized  *//* forward declarations */VOID usbtuInitThreadFn( pVOID param );VOID usbtuInitClientThreadFn(pVOID driverParam);VOID usbtuInitClientIrpCompleteThreadFn(pVOID driverParam);USBHST_STATUS usbtuInitDeviceAdd(UINT32 hDevice, UINT8 interfaceNumber,                              UINT8 uSpeed, void** ppDriverData);VOID usbtuInitDeviceRemove(UINT32 hDevice, PVOID pDriverData);VOID usbtuInitDeviceSuspend(UINT32 hDevice, PVOID ppSuspendData);VOID usbtuInitDeviceResume(UINT32 hDevice, PVOID pSuspendData);/***************************************************************************** usbdInitialize - Initialize the USBD** usbdInitialize() must be called at least once prior to calling other* USBD functions.  usbdInitialize() prepares the USBD and Translation* unit to process URBs.* Calls to usbdInitialize() may be nested, allowing multiple USBD clients* to be written independently.** RETURNS: OK, or ERROR if initialization failed.** ERRNO: N/A*/STATUS usbdInitialize (void)    {            USBTU_LOG ( "usbdInitialize entered \n ");                   /* If not already initialized... */    if (++usbtuInitCount == 1)        {        /* Wind View Instrumentation */        if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE)            {            pCHAR evLog = " USBD Initialization ";            USB_HCD_LOG_EVENT(USBTU_WV_USBD_INIT, evLog, USBTU_WV_FILTER);             }         if (ossInitialize () != OK)            {            USBTU_LOG ("usbdInitialize returns ERROR:ossInitialize failed \n");            return ERROR;            }        	    usbtuInitOssInit = TRUE;               usbdInit();        /* create the Translation Unit Mutex */        if (OSS_MUTEX_CREATE (&usbtuMutex) != OK)            {            USBTU_LOG ( "usbdInitialize returns ERROR : mutex create failed \n ");            return ERROR;            }        /* create the Translation Unit Message Queue */        if (!(usbtuMsgQid = msgQCreate (USBTUINIT_MAX_MESSAGES,                                        sizeof(PVOID), MSG_Q_FIFO )))            {            OSS_MUTEX_DESTROY(usbtuMutex);            USBTU_LOG ( "usbdInitialize returns ERROR: msq q create failed\n ");                          return ERROR;            }          /* create the Translation Unit Thread */        if (OSS_THREAD_CREATE (usbtuInitThreadFn, NULL, OSS_PRIORITY_TYPICAL,                               NULL, &usbtuThreadId) !=OK)            {            OSS_MUTEX_DESTROY(usbtuMutex);            msgQDelete (usbtuMsgQid);            USBTU_LOG ( "usbdInitialize returns ERROR : thread create failed \n ");                           return ERROR;            }         }    USBTU_LOG ( "usbdInitialize  returns OK\n ");        return OK;    }/***************************************************************************** usbdShutdown - Shuts down the USBD** usbdShutdown() should be called once for every successful call to* usbdInitialize().  This function frees memory and other resources used* by the USBD and Translation Unit.** RETURNS: OK, or ERROR if shutdown failed.** ERRNO: N/A*/STATUS usbdShutdown (void)    {        STATUS s = OK;    USBTU_LOG ( "usbdShutdown entered \n ");        if (usbtuInitCount == 0)        {        /* not initialized */         USBTU_LOG ( "usbdShutdown returns OK \n");        return OK;        }    /* We've been initialized at least once. */    if (usbtuInitCount == 1)        {        /* Wind View Instrumentation */        if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE)            {            pCHAR evLog = " USBD Shutdown ";            USB_HCD_LOG_EVENT(USBTU_WV_USBD_INIT, evLog, USBTU_WV_FILTER);            }         if (usbtuInitOssInit)            {            /* Shut down osServices library */            ossShutdown ();            usbtuInitOssInit = FALSE;            }                usbdExit();        /* destroy Translation Unit Mutex */        if ( usbtuMutex )            {            if ( OSS_MUTEX_DESTROY (usbtuMutex) != OK )                {                USBTU_LOG ("usbdShutdown  ERROR:mutex destoy failed\n");                s = ERROR;                }            else                usbtuMutex = NULL;            }        /* destroy Translation Unit thread */                if ( usbtuThreadId )            {            if ( OSS_THREAD_DESTROY (usbtuThreadId) != OK )                {                USBTU_LOG ("usbdShutdown  ERROR:thread dest failed\n");                s = ERROR;                }            else                usbtuThreadId = NULL;            }        /* destroy Translation Unit message queue */        if ( usbtuMsgQid )            {            if ( msgQDelete (usbtuMsgQid) != OK )                {                USBTU_LOG ("usbdShutdown  ERROR:message q dest failed\n");                s = ERROR;                }            else                usbtuMsgQid = NULL;            }        }        --usbtuInitCount;        if ( s == OK)            {            USBTU_LOG ( "usbdShutdown returns OK \n");            }        else            {            USBTU_LOG ( "usbdShutdown returns ERROR \n");            }        return s;    }/***************************************************************************** usbdClientRegister - Registers a new client with the USBD** This routine invokes the USBD function to register a new client.* <pClientName> should point to a string of not more than USBD_NAME_LEN* characters (excluding terminating NULL) which can be used to uniquely* identify the client.	If successful, upon return the <pClientHandle>* will be filled with a newly assigned USBD_CLIENT_HANDLE.** RETURNS: OK, or ERROR if unable to register new client.*** ERRNO: N/A*/STATUS usbdClientRegister    (    pCHAR pClientName,			/* Client name */    pUSBD_CLIENT_HANDLE pClientHandle	/* Client hdl returned by USBD */    )    {    pUSBTU_DEVICE_DRIVER pDriverData;    char pIrpCompleteThreadName[USBD_NAME_LEN];    USBTU_LOG ( "usbdClientRegister entered \n");    /* Zero out the IRP thread name */    memset(pIrpCompleteThreadName,0,USBD_NAME_LEN);    /* Wind View Instrumentation */    if ((usbtuInitWvFilter & USBTU_WV_FILTER) == TRUE)        {        char evLog[USBTU_WV_LOGSIZE];        strncpy ((char*)evLog, pClientName,USBD_NAME_LEN );        strcat(evLog, " : USBD Register ");        USB_HCD_LOG_EVENT(USBTU_WV_CLIENT_INIT, evLog, USBTU_WV_FILTER);        }    if ( !usbtuInitCount)        {        /* usbdInitialize() not called */        USBTU_LOG("usbdClientRegister returns ERROR:usbdInitialize not called\n");        return ERROR;        }    /* allocate structure for client */    if ( !(pDriverData = OSS_CALLOC ( sizeof (USBTU_DEVICE_DRIVER))))        {        USBTU_LOG ( "usbdClientRegister returns ERROR : malloc failed \n");        return ERROR;        }    /* store name */    if (pClientName != NULL)        {        strncpy ((char *)(pDriverData->clientName), pClientName, USBD_NAME_LEN);        sprintf(pIrpCompleteThreadName,"%s_IRP",pClientName);        }    /* create message queue for client */    if (!(pDriverData->msgQid = msgQCreate (USBTUINIT_MAX_MESSAGES,                                            sizeof(PVOID),                                            MSG_Q_FIFO )))        {        OSS_FREE (pDriverData);        USBTU_LOG("usbdClientRegister returns ERROR:message q create failed\n");        return ERROR;        }    /* create thread for client */    if (OSS_THREAD_CREATE (usbtuInitClientThreadFn, pDriverData,                           OSS_PRIORITY_TYPICAL,                           pClientName,                           &(pDriverData->threadHandle)                          )!= OK )        {        msgQDelete(pDriverData->msgQid);        OSS_FREE (pDriverData);        USBTU_LOG("usbdClientRegister returns ERROR:thread create failed \n");        return ERROR ;        }     /* create message queue for IrpComplete */    if (!(pDriverData->msgQidIrpComplete = msgQCreate (USBTUINIT_MAX_MESSAGES,                                            sizeof(PVOID),                                            MSG_Q_FIFO )))        {        	        OSS_FREE (pDriverData);        USBTU_LOG("usbdClientRegister returns ERROR:message q create failed\n");        return ERROR;        }    /* create thread for IrpComplete */    if (OSS_THREAD_CREATE (usbtuInitClientIrpCompleteThreadFn, pDriverData,                           OSS_PRIORITY_TYPICAL,                           pIrpCompleteThreadName,                           &(pDriverData->irpThreadHandle)                          )!= OK )        {        msgQDelete(pDriverData->msgQidIrpComplete);        OSS_FREE (pDriverData);        USBTU_LOG("usbdClientRegister returns ERROR:thread create failed \n");        return ERROR ;        }    /* Link structure to global list */    OSS_MUTEX_TAKE (usbtuMutex, OSS_BLOCK);    usbListLink (&usbtuClientList, pDriverData,                    &(pDriverData->tuDriverLink), LINK_TAIL);    OSS_MUTEX_RELEASE (usbtuMutex);    /* store Return result */    if (pClientHandle != NULL)        *pClientHandle = pDriverData;    USBTU_LOG ( "usbdClientRegister returns OK \n");    return OK;

⌨️ 快捷键说明

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