📄 usbtcdpdiusbd12evallib.c
字号:
* RETURNS: selected packet size*/LOCAL UINT16 pickPacketSize ( UINT16 direction, UINT16 inMaxPacketSize, UINT16 outMaxPacketSize, UINT16 inOutMaxPacketSize ) { switch (direction) { case USB_DIR_IN: return inMaxPacketSize; case USB_DIR_OUT: return outMaxPacketSize; case USB_DIR_INOUT: return inOutMaxPacketSize; } return 0; } /***************************************************************************** fncEndpointAssign - Assigns an endpoint for a specific kind of transfer** This function is called when the usbTargLib or the target application* wants to create a new pipe. This function enables the endpoint to handle* the type of data transfer indicated by the caller.** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncEndpointAssign ( pTRB_ENDPOINT_ASSIGN pTrb, pTARGET pTarget ) { pUSB_TARG_ENDPOINT_INFO pEndpoint; /* NOTE: By convention, usbTargLib guarantees that the parameters in the * TRB are valid for this endpoint prior to calling this function. */ pEndpoint = &pTarget->pEndpoints [pTrb->endpointId]; pEndpoint->endpointNum = pTrb->endpointNum; pEndpoint->configuration = pTrb->configuration; pEndpoint->interface = pTrb->interface; pEndpoint->transferType = pTrb->transferType; pEndpoint->direction = pTrb->direction; /* Determine the maxPacketSize based on the selected type of transfer */ switch (pTrb->transferType) { case USB_XFRTYPE_CONTROL: pEndpoint->maxPacketSize = pEndpoint->ctlMaxPacketSize; break; case USB_XFRTYPE_BULK: pEndpoint->maxPacketSize = pickPacketSize (pTrb->direction, pEndpoint->bulkInMaxPacketSize, pEndpoint->bulkOutMaxPacketSize, pEndpoint->bulkInOutMaxPacketSize); break; case USB_XFRTYPE_INTERRUPT: pEndpoint->maxPacketSize = pickPacketSize (pTrb->direction, pEndpoint->intInMaxPacketSize, pEndpoint->intOutMaxPacketSize, pEndpoint->intInOutMaxPacketSize); break; case USB_XFRTYPE_ISOCH: pEndpoint->maxPacketSize = pickPacketSize (pTrb->direction, pEndpoint->isochInMaxPacketSize, pEndpoint->isochOutMaxPacketSize, pEndpoint->isochInOutMaxPacketSize); break; } /* Enable the endpoint as necessary. */ d12SetEndpointStatus (pTarget, pTrb->endpointId, 0); /* reset to DATA0 */ switch (pTrb->endpointId) { case D12_ENDPOINT_CONTROL_OUT: case D12_ENDPOINT_CONTROL_IN: break; /* no additional processing required */ case D12_ENDPOINT_2_OUT: case D12_ENDPOINT_2_IN: /* These comprise the D12's "main" endpoint. When these endpoints * are enabled, we need to change the endpoint configuration mode * according to the type of transfer. */ if (++pTarget->epMainCount == 1 && pTrb->transferType == USB_XFRTYPE_ISOCH) { pTarget->configByte &= ~D12_CMD_SM_CFG_MODE_MASK; switch (pTrb->direction) { case USB_DIR_OUT: pTarget->configByte |= D12_CMD_SM_CFG_MODE1_ISO_OUT; break; case USB_DIR_IN: pTarget->configByte |= D12_CMD_SM_CFG_MODE2_ISO_IN; break; case USB_DIR_INOUT: pTarget->configByte |= D12_CMD_SM_CFG_MODE3_ISO_IO; break; } d12SetMode (pTarget); } /* NOTE: Code falls through into case below intentionally. */ case D12_ENDPOINT_1_OUT: case D12_ENDPOINT_1_IN: /* Whenever the D12's endpoint #1 or #2 is enabled, we need to * issue a Set Endpoint Enable command. */ if (++pTarget->epOneAndTwoCount == 1) d12SetEndpointEnable (pTarget, ENABLE); break; } /* Mark the endpoint as "in use" */ pEndpoint->flags |= TCD_ENDPOINT_IN_USE; return OK; }/***************************************************************************** fncEndpointRelease - Releases an endpoint** This function is used to release an endpoint which was previously enabled* for data transfer by calling fncEndpointAssign().** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncEndpointRelease ( pTRB_ENDPOINT_RELEASE pTrb, pTARGET pTarget ) { pUSB_TARG_ENDPOINT_INFO pEndpoint; /* mark endpoint as no longer "in use" */ pEndpoint = &pTarget->pEndpoints [pTrb->endpointId]; pEndpoint->flags &= ~TCD_ENDPOINT_IN_USE; pEndpoint->endpointNum = 0; pEndpoint->configuration = 0; pEndpoint->interface = 0; pEndpoint->transferType = 0; pEndpoint->direction = 0; pEndpoint->maxPacketSize = 0; /* We may need to disable certain d12 functions. */ switch (pEndpoint->endpointId) { case D12_ENDPOINT_CONTROL_OUT: case D12_ENDPOINT_CONTROL_IN: break; /* no additional processing required */ case D12_ENDPOINT_2_OUT: case D12_ENDPOINT_2_IN: /* These comprise the D12's "main" endpoint. When these endpoints * are disabled, we may need to change the endpoint configuration. */ if (--pTarget->epMainCount == 0) { pTarget->configByte &= ~D12_CMD_SM_CFG_MODE_MASK; pTarget->configByte |= D12_CMD_SM_CFG_MODE0_NON_ISO; d12SetMode (pTarget); } /* NOTE: Code falls through into case below intentionally. */ case D12_ENDPOINT_1_OUT: case D12_ENDPOINT_1_IN: /* Whenever the D12's endpoint #1 or #2 is disabled, we may need to * issue a Set Endpoint Enable command. */ if (--pTarget->epOneAndTwoCount == 0) d12SetEndpointEnable (pTarget, DISABLE); break; } return OK; }/***************************************************************************** fncSignalResume - Drives RESUME signalling on USB** If the USB is in the SUSPEND state, the host may wish to drive RESUME* signalling in order to try to "wake up" the host.** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncSignalResume ( pTRB_SIGNAL_RESUME pTrb, pTARGET pTarget ) { d12SendResume (pTarget); return OK; }/***************************************************************************** fncEndpointStateSet - Sets endpoint as stalled/unstalled or resets data toggle** In response to an error condition, the usbTargLib or an application may* wish to set one or more endpoints to the "stalled" state. Using this* function, the caller can specify whether an endpoint should be "stalled"* or "unstalled".** Independently, an endpoint's data toggle may be reset to DATA0. This is * necessary when a "configuration event" is detected for the endpoint.** RETURNS: OK, or S_usbTcdLib_xxx if an error is detected.*/LOCAL int fncEndpointStateSet ( pTRB_ENDPOINT_STATE_SET pTrb, pTARGET pTarget ) { if ((pTrb->state & TCD_ENDPOINT_STALL) != 0) { stallEndpoint (pTarget, pTrb->endpointId); } if ((pTrb->state & TCD_ENDPOINT_UNSTALL) != 0 || (pTrb->state & TCD_ENDPOINT_DATA0) != 0) { d12SetEndpointStatus (pTarget, pTrb->endpointId, 0); } return OK; }/***************************************************************************** fncCurrentFrameGet - Returns current USB frame number** Certain applications, particularly those using isochronous data transfers,* need to know the current USB frame number. This function returns the* most recently decoded USB frame number (as encoded in the USB SOF packet).** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncCurrentFrameGet ( pTRB_CURRENT_FRAME_GET pTrb, pTARGET pTarget ) { pTrb->frameNo = d12ReadCurrentFrameNumber (pTarget); return OK; }/***************************************************************************** fncErpSubmit - Submits an ERP for subsequent data transfer** All data transfers across the USB are managed through ERPs (Endpoint* Request Packets). These ERPs are analogous to the IRPs used by the host* to manage data transfers.** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncErpSubmit ( pTRB_ERP_SUBMIT pTrb, pTARGET pTarget ) { pUSB_ERP pErp = pTrb->pErp; /* Enqueue the ERP for the corresponding endpoint. */ usbListLink (&pTarget->erps [pErp->endpointId], pErp, &pErp->tcdLink, LINK_TAIL); pTarget->endpointNeedsService [pErp->endpointId] = TRUE; OSS_SEM_GIVE (pTarget->intPending); return OK; }/***************************************************************************** fncErpCancel - Cancels an ERP ** This function allows the caller to cancel an ERP which was previously* submitted for execution by calling fncErpSubmit(). It may or may not* be possible to cancel the ERP (depending on whether or not the ERP has* already completed processing).** RETURNS: OK or S_usbTcdLib_xxxx if an error is detected*/LOCAL int fncErpCancel ( pTRB_ERP_CANCEL pTrb, pTARGET pTarget ) { return cancelErp (pTarget, pTrb->pErp); }/***************************************************************************** usbTcdPdiusbd12EvalExec - USB_TCD_EXEC_FUNC entry point for PDIUSBD12 TCD** This is the primary entry point for the Philips PDIUSBD12 (ISA eval version)* USB TCD (Target Controller Driver). The function qualifies the TRB passed* by the caller and fans out to the appropriate TCD function handler.** RETURNS: OK or ERROR if failed to execute TRB passed by caller** ERRNO:* S_usbTcdLib_BAD_PARAM* S_usbTcdLib_BAD_HANDLE* S_usbTcdLib_SHUTDOWN*/STATUS usbTcdPdiusbd12EvalExec ( pVOID pTrb /* TRB to be executed */ ) { pTRB_HEADER pHeader = (pTRB_HEADER) pTrb; pTARGET pTarget = NULL; int status; /* Validate parameters */ if (pHeader == NULL || pHeader->trbLength < sizeof (TRB_HEADER)) return ossStatus (S_usbTcdLib_BAD_PARAM); if (pHeader->function != TCD_FNC_ATTACH) { if ((pTarget = (pTARGET) pHeader->handle) == NULL) return ossStatus (S_usbTcdLib_BAD_HANDLE); if (pTarget->shutdown) return ossStatus (S_usbTcdLib_SHUTDOWN); } /* Guard against other tasks */ if (pHeader->function != TCD_FNC_ATTACH && pHeader->function != TCD_FNC_DETACH) { OSS_MUTEX_TAKE (pTarget->tcdMutex, OSS_BLOCK); } /* Fan-out to appropriate function processor */ switch (pHeader->function) { case TCD_FNC_ATTACH: status = fncAttach ((pTRB_ATTACH) pHeader); break; case TCD_FNC_DETACH: status = fncDetach ((pTRB_DETACH) pHeader, pTarget); break; case TCD_FNC_ENABLE: status = fncEnable ((pTRB_ENABLE_DISABLE) pHeader, pTarget); break; case TCD_FNC_DISABLE: status = fncDisable ((pTRB_ENABLE_DISABLE) pHeader, pTarget); break; case TCD_FNC_ADDRESS_SET: status = fncAddressSet ((pTRB_ADDRESS_SET) pHeader, pTarget); break; case TCD_FNC_ENDPOINT_ASSIGN: status = fncEndpointAssign ((pTRB_ENDPOINT_ASSIGN) pHeader, pTarget); break; case TCD_FNC_ENDPOINT_RELEASE: status = fncEndpointRelease ((pTRB_ENDPOINT_RELEASE) pHeader, pTarget); break; case TCD_FNC_SIGNAL_RESUME: status = fncSignalResume ((pTRB_SIGNAL_RESUME) pHeader, pTarget); break; case TCD_FNC_ENDPOINT_STATE_SET: status = fncEndpointStateSet ((pTRB_ENDPOINT_STATE_SET) pHeader, pTarget); break; case TCD_FNC_CURRENT_FRAME_GET: status = fncCurrentFrameGet ((pTRB_CURRENT_FRAME_GET) pHeader, pTarget); break; case TCD_FNC_ERP_SUBMIT: status = fncErpSubmit ((pTRB_ERP_SUBMIT) pHeader, pTarget); break; case TCD_FNC_ERP_CANCEL: status = fncErpCancel ((pTRB_ERP_CANCEL) pHeader, pTarget); break; default: status = S_usbTcdLib_BAD_PARAM; break; } /* Release guard mutex */ if (pHeader->function != TCD_FNC_ATTACH && pHeader->function != TCD_FNC_DETACH) { OSS_MUTEX_RELEASE (pTarget->tcdMutex); } /* Return status */ return ossStatus (status); }/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -