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

📄 dmacli.c

📁 dsp DM642 pci 详细的开发例程
💻 C
📖 第 1 页 / 共 2 页
字号:
            printf("DMA Physical Address => 0x%08x\n", nDmaPhysAddr);
        }

        // Gets the Host DMA Buffer physical address.
        if (0 == strcmp (sChoice, "5"))
        {
            //-------------------------------------------------------------
            // Get the Virtual address. This address is used to tell the
            // Host the location of the Host DMA buffer
            //-------------------------------------------------------------
            nDmaVirtAddr = DM642DmaGetVirtualAddr(hDma);

            printf("DMA Virtual Address => 0x%08x\n", nDmaVirtAddr);
        }

        // Move data from the Host DMA Buffer to an ASCII file
        if (0 == strcmp(sChoice, "6"))
        {
            // Move the data to a file
            copyDmaSpaceToFile(hDM642, hDma, nDmaBufType);
        }

        // Move data from an ASCII input file into the Host DMA Buffer.
        if (0 == strcmp(sChoice, "7"))
        {
            copyDmaSpaceFromFile(hDM642, hDma, nDmaBufType);
        }

        //-------------------------------------------------------------
        // Write the DM642 address space the DSP register.
        // (I.E. SDRAM address to DMA data In/Out of)
        //-------------------------------------------------------------
        if ((0 == strcmp (sChoice, "8")) || (0 == strcmp (sChoice, "12")))
        {
            int nMyStatus = kNoError;

            if (kNoError == nMyStatus)
            {
                // Get the address from the user
                printf("The following address is used to determine what\n");
                printf("memory/device space the DM642 uses for the DMA\n");

                nMyStatus = getInt ("Enter the DSP Local DMA Address >> ", "%x", &nVal1);
            }

            if (kNoError == nMyStatus)
            {
                // Set the Local DMA Address
                nMyStatus = DM642DmaIOCTLSetDspPhysAddr(hDM642, nVal1, FALSE);
            }
        }

        //--------------------------------------------------------------------
        // Write the host DMA buffer physical address into the DSP register.
        // This address tells the DSP where the target memory is located.
        // This section does not use an offset value. I.E. should be used
        // when the desired DMA target is not the HOST.
        //--------------------------------------------------------------------
        if (0 == strcmp (sChoice, "9"))
        {
            int nMyStatus = kNoError;

            if (kNoError == nMyStatus)
            {
                // Get the PCI DMA address
                nMyStatus = getInt ("Enter PCI DMA Address >> ", "%x",
                                    &nVal1);
            }

            if (kNoError == nMyStatus)
            {
                // write the address to the register
                nMyStatus = DM642DmaIOCTLSetPciPhysAddr(hDM642, nVal1);
            }
        }

        // starts the DMA transfer
        if ((0 == strcmp (sChoice, "10")) || (0 == strcmp (sChoice, "14")))
        {
            unsigned int nXferSizeB;
            unsigned int nXferType;
            int          nMyStatus = kNoError;

            if (kNoError == nMyStatus)
            {
                // Get the transfer size
                nMyStatus = getInt ("DMA Transfer Size (words) >> ", "%x",
                                    &nXferSizeB);

		// BMA added for a fix
		nXferSizeB = (nXferSizeB * 4);

            }

            if (kNoError == nMyStatus)
            {
                // get the Transfer type
                nMyStatus = getInt("DMA Transfer Type [0=None, 1=DM642->PCI, 2,3=PCI->DM642] >> ",
                                   "%x", &nXferType);
            }

            if (kNoError == nMyStatus)
            {
                // Start the transfer
                nMyStatus = DM642DmaIOCTLStartTransfer(hDM642, nXferSizeB, nXferType);
            }
        }

        // Check for transfer complete
        if ((0 == strcmp (sChoice, "11")) || (0 == strcmp (sChoice, "15")))
        {
            int fIsXferDone;

            // Check for transfer complete
            fIsXferDone = DM642DmaIOCTLIsTransferComplete(hDM642);

            printf("DMA transfer status == %s\n",
                   (fIsXferDone ? "FINISHED" : "STILL IN PROGRESS" ));
        }

        //--------------------------------------------------------------------
        // Write the host DMA buffer physical address into the DSP register.
        // This address tells the DSP where the target memory is located.
        // This function takes a memory offset value and adds it to the
        // Physical address created by the DMA open function.
        //--------------------------------------------------------------------
        if (0 == strcmp (sChoice, "13"))
        {
            int           nMyStatus = kNoError;
            unsigned int  nOffsW;

            if (kNoError == nMyStatus)
            {
                nMyStatus = getInt("Enter Host DMA buffer Offset (in 32-bit words) >> ", "%x",
                                   &nOffsW);
            }

            if (kNoError == nMyStatus)
            {
                // Set the PCI DMA address
                nMyStatus = DM642DmaSetPciAddrFromOffs(hDM642, hDma, nOffsW);
            }
        }

        // Exit
        if (0 == strcmp (sChoice, "q"))
        {
            break;
        }

    }   // End of while loop

    // Close/Release the DMA buffer space
    DM642DmaClose(hDM642, &hDma);

    if (pDmaBuf != NULL)
    {
        // Free the allocated memory
        free(pDmaBuf);
        pDmaBuf = NULL;
    }

}       // End RunDMASubMenu

//////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
////
////  Name: copyDmaSpaceToFile
////
////  Purpose:  This routine reads a number of words from the Host's DMA
////            buffer and writes those words out to an ASCII file.  The user
////            is prompted for, and provides, the filename, the offset in
////            the Host's DMA buffer to start at, and the number of 32-bit
////            words to copy.
////
////  Input  Parameters:
////      hDM642   - Handle of the currently-open DM642 board/card
////      hDma     - Handle to an open/locked DMA region (space) on the Host
////      nBufType - Buffering type of the open DMA region
////                 [Contiguous or Scatter-Gather]
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

static void copyDmaSpaceToFile( DM642_HANDLE hDM642,
                                DMA_HANDLE   hDma,
                                int          nBufType )
{
    char         sFilename[80];
    int          nStatus        = kNoError;
    unsigned int nOffs          = 0;
    unsigned int nNum           = 0;


    if (kNoError == nStatus)
    {
        // Get the output filename
        nStatus = getString("Enter the output filename (or q) >> ",
                             sFilename);
    }

    if (kNoError == nStatus)
    {
        // Get the Host DMA Buffer memory offset
        nStatus = getInt("Enter the Host DMA buffer address offset (or q) >> ", "%x",
                          &nOffs);
    }

    if (kNoError == nStatus)
    {
        // Get the number of words to copy to the file
        nStatus = getInt("Enter the number of 32-bit Words to copy to the file (or q) >> ", "%x",
                         &nNum);
    }

    if (kNoError == nStatus)
    {
        // Copy the values to the output file
        nStatus = DM642DmaCopyDmaSpaceToFile( hDM642,  sFilename, hDma,
                                              nBufType, nOffs,    nNum );
    }

    if (CHOICE_Q != nStatus)
    {
        printf("DMA copy-to-file %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End copyDmaSpaceToFile()

////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////////////
////
////  Name: copyDmaSpaceFromFile
////
////
////  Purpose:  This routine reads a number of words from an ASCII file and
////            writes those words to the Host's DMA buffer.  The user
////            is prompted for, and provides, the filename, and the offset
////            in the Host's DMA buffer to start at.
////
////  Input  Parameters:
////      hDM642   - Handle of the currently-open DM642 board/card
////      hDma     - Handle to an open/locked DMA region (space) on the Host
////      nBufType - Buffering type of the open DMA region
////                 [Contiguous or Scatter-Gather]
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

static void copyDmaSpaceFromFile( DM642_HANDLE hDM642,
                                  DMA_HANDLE   hDma,
                                  int          nBufType )
{
    char         sFilename[80];
    int          nStatus = kNoError;
    unsigned int nOffs   = 0;


    if (kNoError == nStatus)
    {
        // Get the input file name
        nStatus = getString("Enter the input Filename (or q) >> ",
                             sFilename);
    }

    if (kNoError == nStatus)
    {
        // Get the Host DMA Buffer address offset
        nStatus = getInt ("Enter the Host DMA buffer address offset (or q) >> ", "%x",
                           &nOffs);
    }

    if (kNoError == nStatus)
    {
        // Copy the values from the input file to the Host DMA Buffer
        nStatus = DM642DmaCopyDmaSpaceFromFile( hDM642,  sFilename,
                                                hDma,    nBufType,
                                                nOffs );
    }

    if (CHOICE_Q != nStatus)
    {
        printf("DMA copy-from-file %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End copyDmaSpaceFromFile


//############################################################################
//                             End of Functions
//############################################################################

⌨️ 快捷键说明

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