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

📄 flashcli.c

📁 dsp DM642 pci 详细的开发例程
💻 C
📖 第 1 页 / 共 2 页
字号:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

static void readFlashPagesToFile( DM642_HANDLE hDM642 )
{
    int          nStatus  = kNoError;
    unsigned int nPageNum = 0;
    char         strFilename[80];


    if (kNoError == nStatus)
    {
        nStatus = getString("Enter output filename  (or q) >> ", 
                             strFilename);
    }

    if (kNoError == nStatus)
    {
        nStatus = getInt("Enter page number to read [0-7; 8 = ALL PAGES] (or q) >> ",
                         "%x",
                         &nPageNum);
    }

    if (kNoError == nStatus)
    {
        if (8 == nPageNum)
        {
            int   nCurPage;
            FILE *pfp;

            nStatus = openFile(strFilename, "w", &pfp);
            if (nStatus != kNoError)
            {
                printf("ERROR truncating flash-page file!\n");
                return;
            }

            fclose(pfp);

            for (nCurPage = 0; nCurPage < kFlash_NumPages; nCurPage++)
            {
                nStatus = DM642FlashReadPageToFile(hDM642,  strFilename,
                                                   nCurPage, TRUE,      0);
                if (nStatus != kNoError)
                {
                    printf("ERROR: Reading flash page # %d\n", nCurPage);
                    return;
                }
            }
        }
        else
        {
            nStatus = DM642FlashReadPageToFile(hDM642,   strFilename, 
                                               nPageNum, FALSE,      0);
        }
    }

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

}       // END readFlashPagesToFile()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: readFlashPagesToBinFile
////
////  Purpose: Reads a page of flash memory and writes it to a BINARY file.
////           The user is prompted for, and provides, the file name and the
////           page number.  The user can choose an ALL_PAGES option, which
////           will copy all 8 of the flash page to the file _in order_
////           (ie, it will copy page 0, then page 1, etc).
////
////           A flash page on the EVM-DM642 is 1/8 of the total flash
////           memory.  It contains 8 full sectors.  And is 512 KB.
////           [Thus, copying ALL pages creates an ~4 MB BINARY file]
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

static void readFlashPagesToBinFile( DM642_HANDLE hDM642 )
{
    int          nStatus  = kNoError;
    unsigned int nPageNum = 0;
    char         strFilename[80];


    if (kNoError == nStatus)
    {
        nStatus = getString("Enter output filename (or q) >> ", 
                            strFilename);
    }

    if (kNoError == nStatus)
    {
        nStatus = getInt("Enter page number to read [0-7; 8 = ALL PAGES] (or q) >> ",
                         "%x",
                         &nPageNum);
    }

    if (kNoError == nStatus)
    {
        if (8 == nPageNum)
        {
            int   nCurPage;
            FILE *pfp;

            nStatus = openFile(strFilename, "wb", &pfp);
            if (nStatus != kNoError)
            {
                printf("ERROR truncating flash-page file!\n");
                return;
            }

            fclose(pfp);

            for (nCurPage = 0; nCurPage < kFlash_NumPages; nCurPage++)
            {
                nStatus = DM642FlashReadPageToFile(hDM642,   strFilename,
                                                   nCurPage, TRUE,
                                                   TRUE);
                if (nStatus != kNoError)
                {
                    printf("ERROR: Reading flash page # %d\n", nCurPage);
                    return;
                }
            }
        }
        else
        {
            nStatus = DM642FlashReadPageToFile(hDM642,  strFilename,
                                               nPageNum, FALSE,     TRUE);
        }
    }

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

}       // End readFlashPagesToBinFile()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: writeFlashPagesFromFile
////
////  Purpose: Reads a full page of flash-data from a file, and writes
////           that data to a page in flash memory.
////           The user is prompted for, and provides, the file name and the
////           page number.  The user can choose an ALL_PAGES option, which
////           will copy all 8 of the flash page from the file _in order_
////           (ie, it will copy page 0, then page 1, etc).
////
////           A flash page on the EVM-DM642 is 1/8 of the total flash
////           memory.  It contains 8 full sectors.  And is 512 KB.
////
////  Input Parameters:
////      hDM642         - Handle of the currently-open DM642 board/card
////      fUseFinaryFile - Flag that tells us if the file is binary
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

static void writeFlashPagesFromFile( DM642_HANDLE hDM642, BOOL fUseBinaryFile )
{
    int          nStatus  = kNoError;
    unsigned int nPageNum = 0;
    char         strFilename[80];


    if (kNoError == nStatus)
    {
        nStatus = getString("Enter input filename (or q) >> ", 
                             strFilename);
    }

    if (kNoError == nStatus)
    {
        nStatus = getInt("Enter page number to write [0-7; 8 = ALL PAGES] (or q) >> ",
                         "%x", 
                          &nPageNum);
    }

    if (kNoError == nStatus)
    {
        if (8 == nPageNum)
        {
            nStatus = DM642FlashWriteMultiPagesFromFile(hDM642,
                                                        strFilename,
                                                        0,
                                                        kFlash_NumPages,
                                                        fUseBinaryFile);
            if (nStatus != kNoError)
            {
                printf("ERROR: Writing ALL flash pages\n");
                return;
            }
        }
        else
        {
            nStatus = DM642FlashWriteMultiPagesFromFile(hDM642,
                                                        strFilename,
                                                        nPageNum, 
                                                        1,
                                                        fUseBinaryFile);
            if (nStatus != kNoError)
            {
                printf("ERROR: Writing flash page # %d\n", nPageNum);
                return;
            }
        }
    }

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

}       // END writeFlashPagesFromFile()


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

⌨️ 快捷键说明

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