共用方式為


完成 DMA 交易

[僅適用于 KMDF]

每次驅動程式的裝置 完成 DMA 傳輸時,驅動程式都必須呼叫 WdfDmaTransactionDmaCompletedWdfDmaTransactionDmaCompletedWithLengthWdfDmaTransactionDmaCompletedFinal ,然後檢查傳回值。

當傳回值為 TRUE時,DMA 交易不需要更多傳輸,而且驅動程式必須完成 DMA 交易。 一般而言,驅動程式尚未從其 EvtInterruptDpc 回呼函式傳回。 因此,此回呼函式會透過下列方式完成 DMA 交易:

  1. 呼叫WdfObjectDelete以刪除交易對象,如果驅動程式重複使用 DMA 交易對象,則呼叫WdfDmaTransactionRelease

  2. 如果交易與架構要求物件相關聯,則呼叫WdfRequestComplete 或 WdfRequestCompleteWithInformation

如果驅動程式呼叫 WdfRequestCompleteWithInformation,通常會先呼叫 WdfDmaTransactionGetBytesTransferred ,以取得所有交易傳輸 (位元組總數) 。

下列步驟說明于下列程式碼範例中,取自Isrdpc.c檔案中PLX9x5x範例的EvtInterruptDpc回呼函式:

if (readComplete) {
    BOOLEAN              transactionComplete;
    WDFDMATRANSACTION    dmaTransaction;
    size_t               bytesTransferred;

    // Get the current Read DmaTransaction.
    dmaTransaction = devExt->CurrentReadDmaTransaction;

    // Indicate that this DMA operation has completed:
    // This may start the transfer on the next packet if 
    // there is still data to be transferred.
    transactionComplete = 
          WdfDmaTransactionDmaCompleted( dmaTransaction, &status ); 
    if (transactionComplete) {
        // Complete the DmaTransaction and the request.
        devExt->CurrentReadDmaTransaction = NULL;
        bytesTransferred =  
               ((NT_SUCCESS(status)) ? 
               WdfDmaTransactionGetBytesTransferred(dmaTransaction): 0 );
        WdfDmaTransactionRelease(dmaTransaction);
        WdfRequestCompleteWithInformation(request, status, bytesTransferred);
    }
}