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

📄 dm642_cli.c

📁 dsp DM642 pci 详细的开发例程
💻 C
📖 第 1 页 / 共 3 页
字号:
                }

                if (kNoError == nStatus)
                {
                    // Print value to the screen
                    printf("0x%08x:  0x%08x\n", nLoc, nVal);
                }
            }   // inner for-loop
        }

        if (CHOICE_Q != nStatus)
        {
            printf("Memory read %s\n\n",
                   (kNoError == nStatus) ? "passed" : "FAILED!");

        }   // End CHOICE_Q if

    }       // outer while-loop

}           // End menuReadDSPMem()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: menuWriteDSPMem
////
////  Purpose: This routine writes a value to a DM642 memory location.
////           The locations address, its size, and the value to write
////           are all provided by the user.
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void menuWriteDSPMem( DM642_HANDLE hDM642 )
{
    unsigned int nVal       = 0;
    unsigned int nStartAddr = 0;
    int nStatus             = kNoError;
    int nBytesPerWord       = 0;


    while (kNoError == nStatus)
    {
        if (kNoError == nStatus)
        {
            // Get the Full memory address from the user
            nStatus = getInt("Write: Enter DSP Memory Address (or q) >> ", "%x",
                              &nStartAddr);
        }

        if (kNoError == nStatus)
        {
            // Get the value to write from the user
            nStatus = getInt("Write: Value to write (or q) >> ", "%x", &nVal);
        }

        if (kNoError == nStatus)
        {
            // Get the number of bytes per word
            nStatus = getInt("Write: Enter # bytes per word (or q) >> ", "%x",
                              &nBytesPerWord);
        }

        if (kNoError == nStatus)
        {
            nStatus = DM642WriteDSPMem(hDM642,
                                       nStartAddr,
                                       nVal,
                                       nBytesPerWord);
        }

        if (kNoError == nStatus)
        {
            nStatus = DM642ReadDSPMem(hDM642,
                                      nStartAddr,
                                      &nVal,
                                      nBytesPerWord);
        }

        if (kNoError == nStatus)
        {
            printf("Value read back Add: 0x%08x:  Value: 0x%08x\n",
                    nStartAddr,
                    nVal);
        }

        if (CHOICE_Q != nStatus)
        {
            printf("Memory write %s\n\n",
                   (kNoError == nStatus) ? "passed" : "FAILED!");

        }   // End if CHOICE_Q

    }       // End while-loop

}           // END menuWriteDSPMem()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: fillMemory
////
////  Purpose: This routine fills a block of DM642 memory with a repeating
////           data value.  The user provides the block's starting address,
////           the number of words to fill, and the value.
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void fillMemory( DM642_HANDLE hDM642 )
{
    int nStatus             = kNoError;
    unsigned int nVal       = 0;
    unsigned int nStartAddr = 0;
    unsigned int nNumWords  = 0;


    if (kNoError == nStatus)
    {
        // Get the Starting address from the user
        nStatus = getInt ("Enter the starting address (or q) >> ", "%x",
                           &nStartAddr);
    }

    if (kNoError == nStatus)
    {
        // Get the number of words to write
        nStatus = getInt ("Enter # words to fill (or q) >> ", "%x",
                           &nNumWords);
    }

    if (kNoError == nStatus)
    {
        // Get the value to write.
        // The same value will be written to each address
        nStatus = getInt ("Enter value to fill memory with (or q) >> ", "%x",
                           &nVal);
    }

    if (kNoError == nStatus)
    {
        // Write the values
        nStatus = DM642FillMem (hDM642, nStartAddr, nNumWords, nVal);
    }

    if (CHOICE_Q != nStatus)
    {
        printf ("Memory fill %s\n\n",
                (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End fillMemory()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: readMemToFile
////
////  Purpose: This routine reads a specified number of words/bytes
////           from a spcified address and writes the values to a
////           file.  The user provides the starting address, the 
////           word count, and the filename.  The file can be either ASCII
////           or BINARY.
////
////  Input Parameters:
////      hDM642  - Handle of the currently-open DM642 board/card
////      fBinary - Flag that tells us if the file is binary
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void readMemToFile( DM642_HANDLE hDM642, BOOLEAN fBinary )
{
    int          nStatus = kNoError;
    char         sFilename [80];
    unsigned int nLoc    = 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 starting address from the user
        nStatus = getInt("Enter the memory start address (or q) >> ", "%x",
                          &nLoc);
    }

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

    if (kNoError == nStatus)
    {
        if (fBinary)
        {
            // Write memory values to a Binary file
            nStatus = DM642ReadMemToBinaryFile(hDM642, sFilename,
                                                nLoc,   nNum);
        }
        else
        {
            // Write memory values to an ASCII file
            nStatus = DM642ReadMemToFile(hDM642, sFilename, nLoc, nNum);
        }
    }

    if (CHOICE_Q != nStatus)
    {
        printf("Memory read %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End readMemToFile()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: writeMemFromFile
////
////  Purpose: This routine reads words from a file and writes them to a
////           block of memory starting at a specified address.   The user
////           provides the address and the filename.  The file can be either
////           ASCII or BINARY.
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////      fBinary - Flag that tells us if the file is binary
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void writeMemFromFile (DM642_HANDLE hDM642, BOOLEAN fBinary)
{
    char         sFilename[80];
    int          nStatus        = kNoError;
    unsigned int nLoc           = 0;


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

    if (kNoError == nStatus)
    {
        // Get the Starting memory address
        nStatus = getInt ("Enter starting Memory address (or q) >> ", "%x", &nLoc);
    }

    if (kNoError == nStatus)
    {
        // Ensure location is not in flash memory
        if (isFlash (hDM642, nLoc))
        {
            printf("This function does not support writing to Flash!\n");
            printf("Use Flash-specific routines to access the Flash device!\n");

            nStatus = kErrorFileWrite;
        }
        else
        {
            if (fBinary)
            {
                // read values from a Binary file into memory
                nStatus = DM642WriteMemFromBinaryFile(hDM642, sFilename, nLoc);
            }
            else
            {
                // read values from an ASCII file into memory
                nStatus = DM642WriteMemFromFile(hDM642, sFilename, nLoc);
            }
        }
    }       // if (kNoError == nStatus)

    if (CHOICE_Q != nStatus)
    {
        printf("Memory write %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End writeMemFromFile()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: loadDotHexFile
////
////  Purpose: This routine reads words from a file and writes them to a
////           block of memory starting at a specified address.   The user
////           provides the filename.  The file MUST be in .hex-format.
////           [this format specifies the address inside the file].
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void loadDotHexFile (DM642_HANDLE hDM642)
{
    char sFilename[80];
    int  nStatus = kNoError;


    if (kNoError == nStatus)
    {
        // Get the input filename from the user
        nStatus = getString("enter the .hex filename to write to mem (or q) >> ",
                             sFilename);
    }

    if (kNoError == nStatus)
    {
        // Load the input file into memory
        nStatus = DM642WriteMemFromDotHexFile(hDM642, sFilename);
    }


    if (CHOICE_Q != nStatus)
    {
        printf(".hex memory write %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End loadDotHexFile()


//////////////////////////////////////////////////////////////////////////////
////
////  Name: resetAndLoadDotHexFile
////
////  Purpose: This routine first resets the DSP, and then reads words from
////           a file and writes them to a block of memory starting at a
////           specified address.   The user provides the filename.  The
////           file MUST be in .hex-format.  [this format specifies the
/////          address inside the file].
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void resetAndLoadDotHexFile (DM642_HANDLE hDM642)
{
    char sFilename[80];
    int  nStatus = kNoError;


    if (kNoError == nStatus)
    {
        // Get the input filename from the user
        nStatus = getString("enter the .hex filename to write to mem (or q) >> ",
                             sFilename);
    }

    if (kNoError == nStatus)
    {
        // Load the input file into memory
        nStatus = DM642ResetAndLoadDotHexFile(hDM642, sFilename);
    }


    if (CHOICE_Q != nStatus)
    {
        printf(".hex memory write %s\n\n",
               (kNoError == nStatus) ? "passed" : "FAILED!");
    }

}       // End loadDotHexFile()

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

⌨️ 快捷键说明

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