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

📄 myutils.c

📁 dsp DM642 pci 详细的开发例程
💻 C
字号:
// MyUtils.c
//////////////////////////////////////////////////////////////////////////////
////
////  Copyright (c) 2003, Valley Technologies, Inc.
////  All rights reserved.
////
//////////////////////////////////////////////////////////////////////////////
////
////  $Header $
////
////  $ReleaseClass: src $
////
////  Original Author                 : ebersole
////  Most Recent Contributing $Author: ebersole $
////
//////////////////////////////////////////////////////////////////////////////
////
////  This file is a collection of various utility routines that are used
////  throughout the CLI.
////
//////////////////////////////////////////////////////////////////////////////


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

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


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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: getInt
////
////  Purpose:  This routine prompts the user to enter some input, gets
////            this input (as a string), and then converts the input
////            into an integer value, as specified by the input format
////            string.
////
////  Input Parameters:
////      sPrompt - The string to display to the user to prompt him/her
////                  for input
////      sFormat - The format to feed to sscanf() to read and parse the
////                  user's input into an integer value (e.g.: "%x")
////
////  Output Parameters:
////      nReturn - The actual integer value to return
////
////  Return Value(s):
////      CHOICE_Q -          - iff the user typed in a 'q'
////                              this typically quits the current operation
////      CHOICE_QUESTIONMARK - iff the user typed in a questionmark
////      kNoError            - for SUCCESSFULLY getting a valid input string
////                              (and parsing the integer out of it)
////      
//////////////////////////////////////////////////////////////////////////////

int getInt (char *sPrompt, char *sFormat, int *nReturn)
{
    char sChoice[80];
    int  nStatus = kNoError;


    if (kNoError == nStatus)
    {
        //----------------------------------------------------------------
        // Use the getString() routine to do the dirty work of prompting
        //   the user and getting his/her input.  Note that 'q' and '?'
        //   cause a non-0 status value to be returned.
        //----------------------------------------------------------------
        nStatus = getString (sPrompt, sChoice);
    }

    //-------------------------------------------------------------
    // If no error occurred in getString() OR  if the user did
    //   not enter one of the 'special' characters ('q', '?').
    //-------------------------------------------------------------
    if (kNoError == nStatus)
    {
        // Convert the input to an integer value
        sscanf (sChoice, sFormat, nReturn);
    }

    return nStatus;

}       // END getInt()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: getString
////
////  Purpose:  This routine prompts the user to enter some input, then
////            gets that input in the form of a string.  This string is
////            returned to the caller.
////            This routine also checks to see if the input is one of the
////            two 'special' characters - 'q' or '?'.  If the input is
////            one of these characters, then a non-zero status code is
////            returned to the caller.
////
////  Input Parameters:
////      sPrompt - The string to display to the user to prompt him/her
////                  for input
////
////  Output Parameters:
////      nReturn - The actual value (string) to return
////
////  Return Value(s):
////      CHOICE_Q -          - iff the user typed in a 'q'
////                              this typically quits the current operation
////      CHOICE_QUESTIONMARK - iff the user typed in a questionmark
////      kNoError            - fof SUCCESSFULLY getting a valid input string
////
//////////////////////////////////////////////////////////////////////////////

int getString (char *sPrompt, char *sReturn)
{
    printf("%s", sPrompt);
    scanf ("%s", sReturn);

    if (0 == strcmp(sReturn, "q"))
    {
        printf ("\n");
        return CHOICE_Q;
    }

    if (0 == strcmp (sReturn, "?"))
    {
        printf ("\n");
        return CHOICE_QUESTIONMARK;
    }

    return kNoError;

}       // END getString()

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


//////////////////////////////////////////////////////////////////////////////
////
////  Name: isFlash
////
////  Purpose: This routine checks to see if the given address is in the
////           address range reserved for the main Flash device.
////           The flash address range is the range for a single Flash
////           _Page_ (512 KB), starting at the Base Address of the Flash.
////
////  Input Parameters:
////      hDM642 - Handle of the currently-open DM642 board/card
////      nAddr  - Full memory address to check
////
////  Output Parameters: none
////
////  Return Value(s):
////      TRUE  - iff the input memory address is in the Flash address range
////      FALSE - iff the address is NOT in the Flash address range.
////
//////////////////////////////////////////////////////////////////////////////

BOOLEAN isFlash( DM642_HANDLE hDM642, unsigned int nAddr )
{
    //---------------------------------------------------
    // We can only see one page of the Flash at a time
    //---------------------------------------------------
    return (nAddr >= kFlashBaseAddress) && 
            (nAddr < (kFlashBaseAddress + kFlashPageSize_Bytes));

}       // END isFlash()


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

⌨️ 快捷键说明

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