/* Process bulk transfer out come for Rx */ STATIC EFI_STATUS ProcessBulkXfrCompleteRx(IN USB_DEVICE_TRANSFER_OUTCOME *Uto) { EFI_STATUS Status = EFI_SUCCESS;
// switch on the transfer status switch (Uto->Status) { case UsbDeviceTransferStatusCompleteOK: if (FastbootCurrentState () == ExpectDataState) DataReady (Uto->BytesCompleted, FastbootDloadBuffer ()); else DataReady (Uto->BytesCompleted, Fbd.gRxBuffer); break;
注意这里有个usb_read。为什么会放这里? Think about the last USB operation.
EFI_STATUS HandleUsbEvents(VOID) { ... if (USB_ENDPOINT_DIRECTION_OUT == USB_INDEX_TO_EPDIR (Payload.TransferOutcome.EndpointIndex)) {
Status = ProcessBulkXfrCompleteRx (&Payload.TransferOutcome); if (EFI_ERROR (Status)) { /* Should not happen, even if it happens we keep waiting for USB to be * connected */ DEBUG ((EFI_D_ERROR, "Error, should not happen! Check your USB connection")); } } else { /* Else the direction is from device to host, process TX */ Status = ProcessBulkXfrCompleteTx (&Payload.TransferOutcome);
HandleUsbEvents()会处理Rx/Tx完成event,记住是完成时才handle。
/* Wait for USB events in tight loop */ while (1) { Status = HandleUsbEvents (); if (EFI_ERROR (Status) && (Status != EFI_ABORTED)) { DEBUG ((EFI_D_ERROR, "Error, failed to handle USB event\n")); break; }