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

📄 pcieepromcli.c

📁 dsp DM642 pci 详细的开发例程
💻 C
字号:
// PciEEPROMCLI.c
//////////////////////////////////////////////////////////////////////////////
////
////  Copyright (c) 2003, Valley Technologies, Inc.
////  All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
////  $Header $
////
////  $ReleaseClass: src $
////
////  Original Author                 : ebersole
////  Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
////  This file contains the CLI routines needed for the Pci-EEPROM submenu.
////  These routines read the contents of the PCI-EEPROM and do various things
////  to it (display, save to file, calculate checksum).
////  The low-level dirty work is done by the LED part of the DM642 Library.
////
//////////////////////////////////////////////////////////////////////////////


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


// Includes
#include <stdio.h>
#include "dm642_lib.h"
#include "Dm642Cli.h"


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


static void dumpPciEEPROMToScreen    (DM642_HANDLE hDM642);
static void savePciEEPROMToFile      (DM642_HANDLE hDM642);
static void validatePciEEPROMChecksum(DM642_HANDLE hDM642);
static void validateFileChecksum   (DM642_HANDLE hDM642);


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


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

void PrintPciEEPROMSubMenu(DM642_HANDLE hDM642)
{
    printf ("\n");
    printf ("******************* PCI-EEPROM Menu *******************\n");
    printf ("\n");
    printf ("Using board #%d (EVM-DM642)\n", g_dwBoardNum);
    printf ("\n");
    printf ("1:  Save PCI EEPROM to file         \n");
    printf ("2:  Dump PCI EEPROM to screen       \n");
    printf ("                                    \n");
    printf ("3:  Validate PCI EEPROM Checksum    \n");
    printf ("4:  Validate FILE       Checksum    \n");
    printf ("                                    \n");
    printf ("q:  Quit                            \n");
    printf ("                                    \n");
    printf (">> ");

}       // END PrintPciEEPROMSubMenu()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: RunPciEEPROMSubMenu
////
////  Purpose:  Displays the PCI-EEPROM 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 RunPciEEPROMSubMenu(DM642_HANDLE hDM642)
{
    
    char    sChoice[80];
    int     nStatus = 0;


    while (TRUE)
    {
        PrintPciEEPROMSubMenu(hDM642);

        scanf ("%s", sChoice);
        printf ("\n");

        if (0 == strcmp(sChoice, "1"))
        {
            savePciEEPROMToFile(hDM642);
            continue;
        }

        if (0 == strcmp(sChoice, "2"))
        {
            dumpPciEEPROMToScreen(hDM642);
            continue;
        }

        if (0 == strcmp(sChoice, "3"))
        {
            validatePciEEPROMChecksum(hDM642);
            continue;
        }

        if (0 == strcmp(sChoice, "4"))
        {
            validateFileChecksum(hDM642);
            continue;
        }

        //----------------------------
        // 'q' is the QUIT choice
        //----------------------------
        if (0 == strcmp (sChoice, "q"))
        {
            break;
        }

    }   // End infinite while-loop

}       // END RunPciEEPROMSubMenu()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: dumpPciEEPROMToScreen
////
////  Purpose: This routine reads the entire PCI EEPROM and then displays
////           those values to the screen.  The actual EEPROM reading is
////           handled by the DM642 library.
////
////  Input Parameters::
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void dumpPciEEPROMToScreen(DM642_HANDLE hDM642)
{
    int  i;
    WORD oEEPROMContents[kPciEEPROMAddr_TotalNum];


    //------------------------------------
    // Clear out our input 'buffer' ...
    //------------------------------------
    memset(oEEPROMContents, 0 , sizeof(oEEPROMContents));

    //------------------------------------------------
    // Read the entire EEPROM into our buffer
    //------------------------------------------------
    DM642PciEEPROMReadMulti(hDM642, &oEEPROMContents[0],
                                    kPciEEPROMAddr_1stAddr,
                                    kPciEEPROMAddr_TotalNum);

    //-------------------------------------------------
    // Dump the contents of our buffer to the screen
    //-------------------------------------------------
    printf("\n");
    for (i = 0; i < kPciEEPROMAddr_TotalNum; i++)
    {
        printf("Address %d: 0x%04x\n", i, oEEPROMContents[i]);
    }

    printf("\n");

    //----------------------------------------------------------------
    // Give the user a chance to actually read what's on the screen
    //----------------------------------------------------------------
    printf("Press the ENTER key to continue ...\n");
    getchar();

}       // END dumpPciEEPROM()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: savePciEEPROMToFile
////
////  Purpose: This routine reads the entire PCI EEPROM and then saves
////           those values to a file.  The routine prompts the user for the
////           name of the file.  The actual EEPROM reading is handled
////           by the  DM642 library.
////
////  Input Parameters::
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void savePciEEPROMToFile(DM642_HANDLE hDM642)
{

    WORD  oEEPROMContents[kPciEEPROMAddr_TotalNum];
    char  strFilename[32];
    FILE *fp;
    int   nStatus = kNoError;


    //-------------------------------------------------
    // Get the filename to save the EEPROM to.
    // If we get invalid input, or a QUIT, then bail.
    //-------------------------------------------------
    nStatus = getString("Enter output filename  (or q) >> ", 
                         strFilename);
    if (nStatus != kNoError)
    {
        return;
    }

    //------------------------------------
    // Clear out our input 'buffer' ...
    //------------------------------------
    memset(oEEPROMContents, 0 , sizeof(oEEPROMContents));

    //------------------------------------------------
    // Read the entire EEPROM into our buffer
    //------------------------------------------------
    DM642PciEEPROMReadMulti(hDM642, &oEEPROMContents[0],
                                   kPciEEPROMAddr_1stAddr,
                                   kPciEEPROMAddr_TotalNum);

    //-------------------------------------------------
    // Write our buffer out to the indicated file ...
    //-------------------------------------------------
    nStatus = openFile(strFilename, "w", &fp);
    if (kNoError == nStatus)
    {
        int  i;

        for (i = 0; i < kPciEEPROMAddr_TotalNum; i++)
        {
            fprintf(fp, "0x%04x\n", oEEPROMContents[i]);
        }
    }

    //-----------------
    // Clean up ...
    //-----------------
    if (fp != NULL)
    {
        fflush(fp);
        fclose(fp);
    }

}       // END savePciEEPROMToFile()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: validatePciEEPROMChecksum
////
////  Purpose:  This routine validates the checksum stored in the PCI
////            EEPROM against a checksum calculated for the
////            data currently stored in the EERPM.
////            Both the reading and checksum calculation are handled
////            by the DM642 library.
////
////  Input Parameters::
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void validatePciEEPROMChecksum(DM642_HANDLE hDM642)
{
    WORD oEEPROMContents[kPciEEPROMAddr_TotalNum];
    WORD nCalcCsum;
    int  nStatus = kNoError;


    //-------------------------------
    // Clear out our 'buffer' ...
    //-------------------------------
    memset(oEEPROMContents, 0 , sizeof(oEEPROMContents));

    //------------------------------------------------
    // Read the entire EEPROM into our buffer
    //------------------------------------------------
    DM642PciEEPROMReadMulti(hDM642, &oEEPROMContents[0],
                                   kPciEEPROMAddr_1stAddr,
                                   kPciEEPROMAddr_TotalNum);

    //--------------------------------------------------
    // Validate the checksum vs. what is in our buffer
    //--------------------------------------------------
    nStatus = DM642PciEEPROMValidateChecksum(hDM642,
                                           &oEEPROMContents[0],
                                           &nCalcCsum);

    printf("Calcuated Csum == 0x%04x, Actual Csum == 0x%04x\n",
            nCalcCsum,
            oEEPROMContents[kPciEEPROMAddr_CheckSum]);

    if(nStatus != kNoError)
    {
        printf("ERROR: checksum does not validate!\n");
    }
    else
    {
        printf("EEPROM checksum is GOOD.\n");
    }

}       // END validatePciEEPROMChecksum()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: validateFileChecksum
////
////  Purpose:  This routine validates the checksum of PCI EEPROM data
////            that is stored in a file.  The routine prompts the user for
////            the file name.  The actual checksum calculation/comparison is
////            handled by the DM642 library.
////
////  Input Parameters::
////      hDM642 - Handle of the currently-open DM642 board/card
////
////  Output Parameters: none
////
////  Return Value(s)  : none
////
//////////////////////////////////////////////////////////////////////////////

void validateFileChecksum(DM642_HANDLE hDM642)
{
    int openFile(char *sFilename, char *sOption, FILE **pfp);

    WORD  oEEPROMContents[kPciEEPROMAddr_TotalNum];
    char  strFilename[32];
    int   nStatus = kNoError;


    //-------------------------------------------------
    // Get the filename to load the EEPROM from.
    // If we get invalid input, or a QUIT, then bail.
    //-------------------------------------------------
    nStatus = getString("Enter input filename (or q) >> ", 
                         strFilename);

    if (kNoError == nStatus)
    {
        FILE *pMyFile = NULL;

        //-------------------------------
        // Clear out our 'buffer' ...
        //-------------------------------
        memset(oEEPROMContents, 0 , sizeof(oEEPROMContents));

        //---------------------------------
        // Open the indicated file ...
        //---------------------------------
        nStatus = openFile(strFilename, "r+", &pMyFile);

        if (kNoError == nStatus)
        {
            int i;

            //-------------------------------------------------
            // Read our buffer in from the indicated file ...
            //-------------------------------------------------
            for (i = 0; i < kPciEEPROMAddr_TotalNum; i++)
            {
                fscanf(pMyFile, "0x%04x\n", &oEEPROMContents[i]);
            }
        }

        //-------------------------------------------------
        // Close the file, since we are finished with it
        //-------------------------------------------------
        if (NULL != pMyFile)
        {
            fflush(pMyFile);
            fclose(pMyFile);
        }
    }

    if (kNoError == nStatus)
    {
        WORD nCalcCsum;

        //--------------------------------------------------
        // Validate the checksum vs. what is in our buffer
        // Then print the results.
        //--------------------------------------------------

        nStatus = DM642PciEEPROMValidateChecksum(hDM642,
                                               &oEEPROMContents[0],
                                               &nCalcCsum);

        printf("Calcuated Csum == 0x%04x, Actual Csum == 0x%04x\n",
                nCalcCsum,
                oEEPROMContents[kPciEEPROMAddr_CheckSum]);

        if(nStatus != kNoError)
        {
            printf("ERROR: checksum does not validate!\n");
        }
        else
        {
            printf("File checksum is GOOD.\n");
        }
    }

}       // END validateFileChecksum()


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

⌨️ 快捷键说明

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