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

📄 usbhalinitexit.c

📁 USB source code of Vxworks 5.6. It has device and the host stack.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* usbHalInitExit.c - HAL initialization and uninitialization functionalities *//* Copyright 2004 Wind River Systems, Inc. *//*Modification history--------------------01d,17sep04,ami  WindView Instrumentation Changes01c,29jul04,pdg  Fixed coverity error01b,19jul04,ami  Coding Convention Changes01a,08mar04,pdg  First.*//*DESCRIPTIONThis file defines the hardware independent initialization and uninitializationfunctions of the Hardware Adaption Layer.INCLUDE FILES: drv/usb/target/usbTcd.h, usb/target/usbHal.h,               usb/target/usbHalLib.h, usb/target/usbHalDebug.h,               usb/ossLib.h, usb/target/usbPeriphInstr.h*//* includes */#include "usb/target/usbTcd.h"        #include "usb/target/usbHal.h"      #include "usb/target/usbHalLib.h"    #include "usb/target/usbHalDebug.h"  #include "usb/target/usbPeriphInstr.h"     #include "usb/ossLib.h"              /* globals */UINT32		usbHalDebug = 0;	/* Debug flag for HAL *//* locals *//* forward declarations */LOCAL VOID usbHalFreeTCDResources (pUSBHAL_TCD pUsbHal);/********************************************************************************* usbHalTcdAttach - attaches a TCD** This sub-module attaches the Target Controller Driver.** RETURNS: OK if TCD is attached successfully, ERROR otherwise.** ERRNO:*   None.*/STATUS usbHalTcdAttach    (    USB_TCD_EXEC_FUNC	tcdExecFunc,	/* single entry point of TCD */    pVOID		tcdParam,	/* TCD specific paramter */    pUSBHAL_TCD_NEXUS	pNexus,		/* USBHAL_TCD */    pUSB_APPLN_DEVICE_INFO pDeviceInfo, /* USB_APPLN_DEVICE_INFO */    USB_TCD_MNGMT_CALLBACK mngmtCallback,/* management callback function */    pVOID		mngmtCallbackParam  /* management callback parameter */    )    {    pUSBHAL_TCD		pUsbHal = NULL;	/* USBHAL_TCD */    TRB_ATTACH		trbAttach;	/* TRB_ATTACH */    STATUS		status = ERROR;    /* WindView Instrumentation */    USB_HAL_LOG_EVENT(USB_HAL_INIT_EXIT,"usbHalTcdAttach entered ...",    USB_HAL_WV_FILTER);       USBHAL_DEBUG ("usbHalTcdAttach : Entering\n",0,0,0,0,0,0);    /* Check the validity of the parameters */    if ((tcdExecFunc == NULL) ||         (pNexus == NULL) ||         (pDeviceInfo == NULL) ||         (mngmtCallback == NULL))        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Bad Parameter Received...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : Invalid parameters\n",0,0,0,0,0,0);        return ERROR;        }    /* Allocate memory for the HAL data structure */    pUsbHal = OSS_CALLOC(sizeof(USBHAL_TCD));    /* Check if memory allocation is successful. If not, return an ERROR */    if (pUsbHal == NULL)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Memory Allocation Failed...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : Memory not allocated for HALTCD\n",                   0,0,0,0,0,0);        return ERROR;        }    /* Create the mutex */    if (OSS_MUTEX_CREATE(&pUsbHal->mutex) != OK)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Mutex Creation Failed...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : Mutex creation error\n",0,0,0,0,0,0);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /*     * Create the semaphore used for signalling the interrupt handler thread     * from the ISR     */    if (OSS_SEM_CREATE(1,1,&pUsbHal->intPendingSemaphore) != OK)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Semaphore Creation Failed...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : semaphore creation error\n",0,0,0,0,0,0);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /* Create the thread for handling the interrupts */    if (OSS_THREAD_CREATE((THREAD_PROTOTYPE)usbHalInterruptThread,                          pUsbHal,                          100,                          "HALThread",                          &pUsbHal->threadId) != OK)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Error Creating the thread for interrupts...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : Thread creation failed\n",0,0,0,0,0,0);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /* Check if the thread handle is valid */    if (pUsbHal->threadId == NULL)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Error Creating the thread ID ...",        USB_HAL_WV_FILTER);           USBHAL_ERR ("usbHalTcdAttach : Invalid thread ID\n",0,0,0,0,0,0);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /* Populate the TRB data structure - Start */    trbHeaderInit((pTRB_HEADER)&trbAttach,                  NULL,                  TCD_FNC_ATTACH,                  sizeof(TRB_ATTACH));    trbAttach.tcdParam = tcdParam;    trbAttach.usbHalIsr = (USB_HAL_ISR_CALLBACK)usbHalIsr;    trbAttach.usbHalIsrParam = pUsbHal;    trbAttach.pHalDeviceInfo = &pUsbHal->halDeviceInfo;    trbAttach.pDeviceInfo = pDeviceInfo;    /* Populate the TRB data structure - End */    /* Call the single entry point for the TCD */    status = (*tcdExecFunc)(&trbAttach);    /* Check if the function is executed successfully */    if (status != OK)        {        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Error in attaching TCD...",        USB_HAL_WV_FILTER);           USBHAL_ERR ("usbHalTcdAttach : Error in attaching TCD\n",0,0,0,0,0,0);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /* Store the TCD handle in HAL data structure */    pUsbHal->pTCDHandle = trbAttach.header.handle;    /* Allocate memory for the array of pointers */    pUsbHal->pPipeInfo = (pUSBHAL_PIPE_INFO *)            OSS_CALLOC(sizeof(pUSBHAL_PIPE_INFO) *            pUsbHal->halDeviceInfo.uNumberEndpoints);    /* Check if memory allocation is successful */    if (pUsbHal->pPipeInfo == NULL)        {        TRB_DETACH trbDetach;        /* WindView Instrumentation */         USB_HAL_LOG_EVENT(USB_HAL_DEVICE_CNTL,        "usbHalTcdAttach exiting: Memory Allocation for Pipes Failed...",        USB_HAL_WV_FILTER);           USBHAL_ERR("usbHalTcdAttach : Error in allocating memory for the array"                    "of pointers\n",0,0,0,0,0,0);        /* Populate the TRB - Start */        trbHeaderInit((pTRB_HEADER)&trbDetach,                      pUsbHal->pTCDHandle,                      TCD_FNC_DETACH,                      sizeof(TRB_DETACH));        /* Populate the TRB - End */        /* Call the single entry point of TCD */        (*tcdExecFunc)(&trbDetach);        /* Call the function to free the HAL TCD resources */        usbHalFreeTCDResources(pUsbHal);        return ERROR;        }    /* Store the single entry point in the TCD data structure */    pUsbHal->tcdExecFunc = tcdExecFunc;    /* Store the management callback in the TCD data structure */    pUsbHal->mngmtCallback = mngmtCallback;    /* Store the management callback parameter in the TCD data structure */    pUsbHal->mngmtCallbackParam = mngmtCallbackParam;    /* Store the HAL TCD pointer in the pNexus data structure */    pNexus->handle = pUsbHal;    /* WindView Instrumentation */    USB_HAL_LOG_EVENT(USB_HAL_INIT_EXIT,"usbHalTcdAttach exiting ...",    USB_HAL_WV_FILTER);       USBHAL_DEBUG("usbHalTcdAttach : Exiting\n",0,0,0,0,0,0);    return OK;    }/********************************************************************************* usbHalTcdDetach - detaches a TCD** This usb-routine is used to detach the TCD. All active endpoints are * deleted before the TCD is detached.** RETURNS: OK if TCD is detached successfully, ERROR otherwise.** ERRNO:*   None.*/STATUS usbHalTcdDetach    (    pUSBHAL_TCD_NEXUS	pNexus			/* USBHAL_TCD_NEXUS */    )    {    pUSBHAL_TCD		pUsbHal = NULL;		/* USBHAL_TCD */    TRB_DETACH		trbDetach;		/* TRB_DETACH */    UINT32		uIndex = 0;    STATUS		status = ERROR;    /* WindView Instrumentation */    USB_HAL_LOG_EVENT(USB_HAL_INIT_EXIT,"usbHalTcdDetach entered ...",    USB_HAL_WV_FILTER);   

⌨️ 快捷键说明

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