Altera Home Page
文档资料 许可
在线购买 下载

  主页   |   产品   |   支持   |   最终市场   |   技术中心   |   教育与活动   |   公司介绍   |   在线购买  
  mySupport   |   器件   |   软件   |   IP   |   设计范例   |   参考设计  

 产品
      MAX/MAX II
      Stratix/Stratix GX
      Nios II
  
 功能
      算法
      存储器
      总线及I/O
      逻辑
      接口与外设
      DSP
      通信
      PLL & Clocking
  
 设计输入方法
      Quartus II软件工程
      Tcl
      VHDL
      Verilog HDL
      C Code 范例
      DSP Builder
      TimeQuest
   片内调试
  
 仿真工具
      Mentor Graphics ModelSim
      Cadence NCsim
      Synopsys VCS
  
 旧范例
      图形编辑器
      AHDL
  

Quartus II Tcl Example: Get Subversion Revision Number

This sample script shows how you can access a version control software version number for your project. You can write the version number in a design file that is compiled in your FPGA design. With additional design logic, the version number can be reported by the FPGA. This information can be very useful during debugging, especially if you switch between multiple programming files. You can easily find out which version of the design is running on the FPGA, based on the version number in the FPGA.

This example uses the Subversion revision number for your project. It uses the svn info command to get information about the specified file. The svn info command prints information about items in your working copy, and it includes a line with the revision number, in the following form:

Revision: <revision number>

This example uses two procedures to run the svn info command and parse the output to get the revision number. The get_subversion_revision procedure starts the svn info command. Call the procedure with the file name to use with the svn info command. The procedure returns with an error if the command could not be run. Otherwise, the procedure returns nothing, but sets certain global variables. If the svn info command timed out, the value of the global variable done is -1. If the revision number was found, the value of the global variable done is 1 and the revision number is in the revision_number global variable. You can display the revision number in a message, as in this example, or write it into a design file.

The get_version_info procedure is a helper procedure that parses the command output a line at a time. It includes a regular expression that matches the revision number line and extracts the revision number.

proc get_subversion_revision { file_name } {

    global done

    # The maximum number of seconds to wait for the svn info
    # command to complete
    set timeout_seconds 30

    # The svn info command with filename that is run
    set cmd "svn info ${file_name}"

    # Attempt to get the version information.
    # If the command can't be run, return an error.
    # Otherwise set up a file event to process the command output.
    if { [catch {open "|$cmd"} input] } {
        return -code error $input
    } else {

        fileevent $input readable [list get_revision_info $input ]

        # Set up a timeout so that the process can't hang if the
        # repository is down.
        set timeout [after [ expr { $timeout_seconds * 1000 } ] \
            [list set done -1] ]

        # Don't continue until the revision number is found,
        # or the operation times out. Cancel the timeout anyway.
        vwait done
        after cancel $timeout
    }
}

proc get_revision_info { inp  } {

    global done revision_number

    if { [eof $inp] } {
        catch {close $inp}
        set done 1
    } elseif { $done } {
        gets $inp line
    } else {
        gets $inp line
        # Use a regular expression to match the line with the
        # revision number.
        if { [regexp {^Revision:\s+(\d+)\s*$} $line match revision_number] } {
            set done 1
        }
    }
}

set done 0
set revision_number ""

# The file name is usually your project file .qpf
set file_name [lindex $quartus(args) 0]

if { [catch { get_subversion_revision $file_name } msg] } {
    post_message -type critical_warning "Couldn't run command to get\
        revision number. $msg"
} else {

    if { -1 == $done } {
        post_message -type critical_warning "Timeout getting revision number."
    } elseif { [string equal "" $revision_number] } {
        post_message -type critical_warning \
            "Couldn't find revision number in output of svn info $file_name."
    } else {
        post_message "Revision for $file_name is $revision_number"
    }
}

You could run the script at a system command prompt with the following command (assuming the script is in a file named svn_revision.tcl):

quartus_sh -t svn_revision.tcl myproject.qpf

The script produces a message like this to show the revision:

Info: Revision for myproject.qpf is 417

You can display a message with the revision number in the global variable revision_number, as in this example, or write it into a design file.

Design Examples Disclaimer

These design examples may only be used within Altera Corporation devices and remain the property of Altera. They are being provided on an “as-is” basis and as an accommodation; therefore, all warranties, representations, or guarantees of any kind (whether express, implied, or statutory) including, without limitation, warranties of merchantability, non-infringement, or fitness for a particular purpose, are specifically disclaimed. Altera expressly does not recommend, suggest, or require that these examples be used in combination with any other product not provided by Altera.

  请填写反馈意见