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

📄 dmacli.c

📁 dsp DM642 pci 详细的开发例程
💻 C
📖 第 1 页 / 共 2 页
字号:
// dm642_cli.c
//////////////////////////////////////////////////////////////////////////////
////
////  Copyright (c) 2003, Valley Technologies, Inc.
////  All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
////  $Header $
////
////  $ReleaseClass: src $
////
////  Original Author                 : ebersole
////  Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
////  This file contains 
////
//////////////////////////////////////////////////////////////////////////////

//############################################################################


#include <stdio.h>

#include <dm642_lib.h>
#include "Dm642Cli.h"


//############################################################################
//                           Function Prototypes
//############################################################################


static void copyDmaSpaceToFile( DM642_HANDLE hDM642,
                                DMA_HANDLE   hDma,
                                int          nBufType );

static void copyDmaSpaceFromFile( DM642_HANDLE hDM642,
                                  DMA_HANDLE   hDma,
                                  int          nBufType );


//############################################################################
//                            Start of Functions
//############################################################################


//////////////////////////////////////////////////////////////////////////////
////
////  Name: PrintDMASubMenu
////
////  Purpose: Displays the DMA Sub-Menu to the screen.
////
////  Input  Parameters:
////      hDM642 -- Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void PrintDMASubMenu(DM642_HANDLE hDM642)
{
    extern DWORD g_dwBoardNum;

    printf ("\n");
    printf ("********************** DMA Menu **********************\n");
    printf ("\n");
    printf ("Using board #%d (EVM-DM642)\n", g_dwBoardNum);
    printf ("\n");
    printf (" Host Buffer Functions                             \n");
    printf ("-----------------------------                      \n");
    printf ("1:  Fill Host Buffer with Address values           \n");
    printf ("2:  Fill Host Buffer with repeating data           \n");
    printf ("3:  Display Host Buffer values                     \n");
    printf ("4:  Get Host's Physical DMA Address                \n");
    printf ("5:  Get Host's Virtual  DMA Address                \n");
    printf ("6:  Copy Host Buffer to File                       \n");
    printf ("7:  Copy File to Host Buffer                       \n");
    printf ("                                                   \n");
    printf (" DSP<-->PCI_Device Functions                       \n");
    printf ("-----------------------------                      \n");
    printf ("8:   Set DSP R/W Address (absolute address)        \n");
    printf ("9:   Set PCI R/W Address (absolute address)        \n");
    printf ("10:  Start DMA Transfer                            \n");
    printf ("11:  Check Transfer Status                         \n");
    printf ("                                                   \n");
    printf (" DSP<-->Host_Buffer Functions                      \n");
    printf ("------------------------------------               \n");
    printf ("12:  Set DSP  R/W Address (absolute address)       \n");
    printf ("13:  Set Host R/W Address (via offset)             \n");
    printf ("14:  Start DMA Xfer                                \n");
    printf ("15:  Check Transfer Status                         \n");
    printf ("                                                   \n");
    printf ("q:  Quit                                           \n");
    printf ("                                                   \n");
    printf (">>");

}       // End PrintDMASubMenu()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: RunDMASubMenu
////
////  Purpose:  Displays the DMA SubMenu.  Gets the user's choice
////            from said menu.  Processes that choice.
////
////  Input  Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void RunDMASubMenu(DM642_HANDLE hDM642)
{
    char         sChoice [80];
    int          nStatus      = 0;
    int          nOffset      = 0;
    int          nSize        = 0;
    int          nValue       = 0;
    int          nTest        = 0;
    unsigned int nVal1        = 0;
    DMA_HANDLE   hDma         = NULL;
    unsigned     nDmaBufType;
    unsigned     nDmaSizeW    = 0;
    unsigned    *pDmaBuf      = NULL;
    DWORD        nDmaPhysAddr = 0;
    DWORD        nDmaVirtAddr = 0;


    if (kNoError == nStatus)
    {
        // Get the desired DMA buffer size from the user
        nStatus = getInt("Enter the desired Host DMA Buffer size (in 32-bit Words) >>", 
                         "%x",
                         &nDmaSizeW);
    }

    if (kNoError == nStatus)
    {
         // Get the DMA buffering strategy from the user
         nStatus = getInt("Enter the desired buffering strategy [1 = Contig, 2 = Scat-Gath] >>",
                          "%x",
                          &nDmaBufType);
    }

    if (kNoError == nStatus)
    {
        //-------------------------------------------------------------
        // If the buffering strategy is Scatter-Gather we need to
        // allocate the memory
        //-------------------------------------------------------------
        if (kDmaBufType_ScatGath == nDmaBufType)
        {
            // Allocate the buffer memory
            nStatus = allocateMem(nDmaSizeW, kBytesPerWord, &pDmaBuf);
            if (nStatus != kNoError)
            {
                printf("ERROR: Could not allocate Scat-Gath buffer!\n");
            }
        }
    }

    if (kNoError == nStatus)
    {
        //--------------------------------------------------------------------
        // Create/Lock the Host DMA buffer space
        // When pDmaBuf is a NULL pointer the DM642DmaOpen funtion allocates
        // the Host DMA buffer memory and uses the contiguous buffer strategy
        //--------------------------------------------------------------------
        nStatus = DM642DmaOpen(hDM642,
                              &hDma,
                               nDmaBufType,
                               pDmaBuf,
                               nDmaSizeW * kBytesPerWord,
                               kDmaChan_0);
        if (nStatus != kNoError)
        {
            printf("ERROR: Could not open/initialize DMA!\n");
        }
    }

    if (kNoError == nStatus)
    {
        //-------------------------------------------------------------
        // Get the Physical address. This address is used to tell the
        // DM642 DSP the location of the Host DMA buffer
        //-------------------------------------------------------------
        nDmaPhysAddr = DM642DmaGetPhysicalAddr(hDma);

        //-------------------------------------------------------------
        // Get the Virtual address. This address is used to tell the
        // Host the location of the Host DMA buffer
        //-------------------------------------------------------------
        nDmaVirtAddr = DM642DmaGetVirtualAddr(hDma);

        // Print the address values
        printf("Obtained DMA buffer: %u bytes @ Virtual: 0x%08x => Phys: 0x%08x\n\n",
                nDmaSizeW * kBytesPerWord,
                nDmaVirtAddr,
                nDmaPhysAddr);
    }

    // Perform the main DMA sub-menu processing ....

    while (kNoError == nStatus)
    {
        // Print the menu
        PrintDMASubMenu(hDM642);

        // Get the users choice
        scanf ("%s", sChoice);
        printf ("\n");

        // Fill Host DMA Space with address values
        if (0 == strcmp (sChoice, "1"))
        {
            //-------------------------------------------------------------
            // hDma is the DMA structure that contains the address values
            // returned by the DMA Open function
            //-------------------------------------------------------------
            DM642DmaFillDmaSpaceWithAddrs (hDma);
        }

        // Fills Host DMA memory with a repeating, unchanging value
        if (0 == strcmp (sChoice, "2"))
        {
            unsigned int nValue;
            int          nNumWords;
            int          nMyStatus = kNoError;

            if (kNoError == nMyStatus)
            {
                // Get the starting memory address offset from the user
                nMyStatus = getInt ("Enter the memory address offset (HEX) >>", "%x",
                                    &nOffset);
            }

            if (kNoError == nMyStatus)
            {
                // Get the value to write into the Host DMA buffer
                nMyStatus = getInt ("Enter the Hex value to write >> ", "%x",
                                    &nValue);
            }

            if (kNoError == nMyStatus)
            {
                // Get the number of words to write
                nMyStatus = getInt ("Enter the number of 32-bit Words to write >> ", "%x",
                                    &nNumWords);
            }

            if (kNoError == nMyStatus)
            {
                // Fill the Host DMA buffer space
                DM642DmaFillDmaSpace (hDma, nOffset, nValue, nNumWords);
            }
        }

        // Display values from the Host DMA Buffer space
        if (0 == strcmp (sChoice, "3"))
        {
            int nMyStatus = kNoError;

            if (kNoError == nMyStatus)
            {
                // Get the starting memory address offset from the user
                nMyStatus = getInt ("Enter the memory address offset (HEX) ", "%x",
                                    &nOffset);
            }

            if (kNoError == nMyStatus)
            {
                // Get the number of words to write
                nMyStatus = getInt ("Enter the number of 32-bit words to read (HEX) ", "%x",
                                    &nSize);
            }

            printf("\n");

            if (kNoError == nMyStatus)
            {
                // Read the Host DMA buffer space
                DM642DmaDumpDmaSpace(hDma, nOffset, nSize);
            }
        }

        // Gets the Host DMA Buffer physical address.
        if (0 == strcmp (sChoice, "4"))
        {
            //-------------------------------------------------------------
            // Get the Physical address. This address is used to tell the
            // DM642 DSP the location of the Host DMA buffer
            //-------------------------------------------------------------
            nDmaPhysAddr = DM642DmaGetPhysicalAddr(hDma);

⌨️ 快捷键说明

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