📄 usbtarginitexit.c
字号:
OSS_FREE (pTcd); return ossStatus (S_usbTargLib_OUT_OF_RESOURCES); } /* Create the handle */ if (usbHandleCreate (TARG_TCD_SIG, pTcd, &pTcd->targChannel) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdAttach exiting: Error creating the handle...", USB_TARG_WV_FILTER); /* Release memory allocated for TCD */ OSS_FREE (pTcd); return ossStatus (S_usbTargLib_OUT_OF_RESOURCES); } /* Call the HAL interface to attach the TCD to usbTargLib */ if (usbHalTcdAttach (tcdExecFunc, tcdParam, &pTcd->tcdNexus, &deviceInfo, (USB_TCD_MNGMT_CALLBACK) usbTargMgmtCallback, pTcd) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdAttach exiting: Could not attach...", USB_TARG_WV_FILTER); /* Destroy the handle */ usbHandleDestroy (pTcd->targChannel); /* Free memory for TCD */ OSS_FREE ( pTcd ); return ossStatus (S_usbTargLib_TCD_FAULT); } /* * Invoke the target application's mngmtFunc to notify it that * the attach is complete. */ if (mngmtFunc (pTcd, TARG_MNGMT_ATTACH ,&deviceInfo) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdAttach exiting: Management function returned error...", USB_TARG_WV_FILTER); /* Detach the TCD */ if (usbHalTcdDetach (&pTcd->tcdNexus) != OK ) return ossStatus (S_usbTargLib_TCD_FAULT ); /* Destroy the handle */ usbHandleDestroy (pTcd->targChannel); /* Free memory for TCD */ OSS_FREE ( pTcd ); return ossStatus(S_usbTargLib_APP_FAULT); } /* Take the mutex */ OSS_MUTEX_TAKE ( targMutex , OSS_BLOCK ); /* Add the TARG_TCD to tcdList */ usbListLink (&tcdList, pTcd, &pTcd->tcdLink, LINK_TAIL); /* Release the mutex */ OSS_MUTEX_RELEASE ( targMutex ); /* Copy the target channel handle to the parameter passed */ *pTargChannel = pTcd->targChannel; /* Store the single entry point in the nexus data structure */ pTcd->tcdNexus.tcdExecFunc = tcdExecFunc; /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdAttach exiting ...", USB_TARG_WV_FILTER); return OK; }/********************************************************************************* usbTargTcdDetach - detaches a USB target controller driver** This function detaches a USB TCD which was previously attached to the* usb Target Library by calling usbTargTcdAttach(). <targChannel> is the * handle of the target channel originally returned by usbTargTcdAttach().** RETURNS: OK, or ERROR if unable to detach TCD.** ERRNO:* \is* \i S_usbTargLib_TCD_FAULT* Fault occured in TCD.** \i S_usbTargLib_BAD_PARAM* Bad parameter is passed.** \i S_usbTargLib_APP_FAULT* Application Specific Fault occured.* \ie*/STATUS usbTargTcdDetach ( USB_TARG_CHANNEL targChannel /* handle to target channel */ ) { pTARG_TCD pTcd = NULL; /* TARG_TCD */ UINT32 status = OK; /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdDetach entered ...", USB_TARG_WV_FILTER); /* Take the mutex */ OSS_MUTEX_TAKE (targMutex, OSS_BLOCK); /* Validate the channel */ if (validateTarg(targChannel, &pTcd) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdDetach exiting: Wrong Target Channel...", USB_TARG_WV_FILTER); return ossStatus (S_usbTargLib_BAD_PARAM); } /* * Invoke the target application's mngmtFunc to notify it that * the attach is complete. */ if (mngmtFunc (pTcd, TARG_MNGMT_DETACH, NULL) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdDetach exiting: Management function returned error...", USB_TARG_WV_FILTER); return ossStatus (S_usbTargLib_APP_FAULT); } /* Release the default control In endpoint */ if(pTcd->defaultControlPipeIN != NULL) if (usbHalTcdEndpointRelease(&pTcd->tcdNexus,pTcd->defaultControlPipeIN) != OK) return ossStatus (S_usbTargLib_TCD_FAULT); /* Release the default control Out endpoint */ if(pTcd->defaultControlPipeOUT != NULL) if (usbHalTcdEndpointRelease(&pTcd->tcdNexus,pTcd->defaultControlPipeOUT) != OK) return ossStatus (S_usbTargLib_TCD_FAULT); /* Detach TCD */ if (usbHalTcdDetach (&pTcd->tcdNexus)!= OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdDetach exiting: Error detaching the TCD...", USB_TARG_WV_FILTER); return ossStatus (S_usbTargLib_TCD_FAULT); } /* Unlink the TCD */ usbListUnlink (&pTcd->tcdLink); /* Release Mutex */ OSS_MUTEX_RELEASE (targMutex); /* Destroy the handle */ if (usbHandleDestroy (pTcd->targChannel) != OK) status = ossStatus (S_usbTargLib_BAD_HANDLE); /* Release the memory */ OSS_FREE ( pTcd ); /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargTcdDetach exiting ...", USB_TARG_WV_FILTER); return status; }/********************************************************************************* usbTargEnable - enables target channel onto USB** After attaching a TCD to usbTargLib and performing any other application-* specific initialization that might be necessary, this function should be* called to enable a target channel. The USB target controlled by the TCD* will not appear as a device on the USB until this function has been called.** RETURNS: OK, or ERROR if unable to enable target channel.** ERRNO:* \is* \i S_usbTargLib_TCD_FAULT* Fault occured in TCD.** \i S_usbTargLib_BAD_PARAM* Bad parameter is passed.* \ie*/STATUS usbTargEnable ( USB_TARG_CHANNEL targChannel /* target to enable */ ) { pTARG_TCD pTcd = NULL; /* TARG_TCD */ UINT32 status = OK; /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargEnable entered ...", USB_TARG_WV_FILTER); /* Validate the channel */ if (validateTarg(targChannel, &pTcd) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargEnable exiting: Wrong Target Channel...", USB_TARG_WV_FILTER); return ossStatus (S_usbTargLib_BAD_PARAM); } OSS_MUTEX_TAKE (pTcd->tcdMutex, OSS_BLOCK); /* Enable target channel */ if (usbHalTcdEnable (&pTcd->tcdNexus) != OK) status = ossStatus (S_usbTargLib_TCD_FAULT); OSS_MUTEX_RELEASE (pTcd->tcdMutex); /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargEnable exiting ...", USB_TARG_WV_FILTER); return status; }/********************************************************************************* usbTargDisable - disables a target channel** This function is the counterpart to the usbTargEnable() function. This* function disables the indicated target channel.** RETURNS: OK, or ERROR if unable to disable the target channel.** ERRNO:* \is* \i S_usbTargLib_TCD_FAULT* Fault occured in TCD.** \i S_usbTargLib_BAD_PARAM* Bad parameter is passed.* \ie*/STATUS usbTargDisable ( USB_TARG_CHANNEL targChannel /* target to disable */ ) { pTARG_TCD pTcd = NULL; /* TARG_TCD */ UINT32 status = OK; /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargDisable entered ...", USB_TARG_WV_FILTER); /* Validate the channel */ if (validateTarg(targChannel, &pTcd) != OK) { /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargDisable exiting: Wrong Target Channel...", USB_TARG_WV_FILTER); return ossStatus (S_usbTargLib_BAD_PARAM); } /* Acquire the mutex */ OSS_MUTEX_TAKE (pTcd->tcdMutex, OSS_BLOCK); /* Disable target channel */ if (usbHalTcdDisable (&pTcd->tcdNexus) != OK) status = ossStatus (S_usbTargLib_TCD_FAULT); /* Release the mutex */ OSS_MUTEX_RELEASE (pTcd->tcdMutex); /* WindView Instrumentation */ USB_TARG_LOG_EVENT(USB_TARG_INIT_EXIT, "usbTargDisable exiting ...", USB_TARG_WV_FILTER); return status; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -