Quartus® II Tcl 将报告数据导出到 CSV 文件

author-image

作者

许多设计者会在 FPGA 设计的某些阶段使用 Excel。可以轻松地将数据从 Quartus II 报告面板导出到 CSV 文件,并在 Excel 中打开。

这个简单的程序从指定报告面板导出数据,然后将其写入文件。调用此程序时必须打开一个项目。以下示例展示了如何在脚本中使用此程序。

proc panel_to_csv { panel_name csv_file } {

    set fh [open $csv_file w]
    load_report
    set num_rows [get_number_of_rows -name $panel_name]

    # Go through all the rows in the report file, including the
    # row with headings, and write out the comma-separated data
    for { set i 0 } { $i < $num_rows } { incr i } {
        set row_data [get_report_panel_row -name $panel_name -row $i]
        puts $fh [join $row_data ","]
    }

    unload_report
    close $fh
}

使用此程序的脚本如下所示。使用以下命令在系统命令提示符下运行此脚本。

load_package report
package require cmdline

proc panel_to_csv { panel_name csv_file } {

    set fh [open $csv_file w]
    load_report
    set num_rows [get_number_of_rows -name $panel_name]

    # Go through all the rows in the report file, including the
    # row with headings, and write out the comma-separated data
    for { set i 0 } { $i < $num_rows } { incr i } {
        set row_data [get_report_panel_row -name $panel_name -row $i]
        puts $fh [join $row_data ","]
    }

    unload_report
    close $fh
}

set options {\
    { "project.arg" "" "Project name" } \
    { "revision.arg" "" "Revision name" } \
    { "panel.arg" "" "Panel name" } \
    { "file.arg" "" "Output file name"} \
}
array set opts [::cmdline::getoptions quartus(args) $options]

project_open $opts(project) -revision $opts(revision)

panel_to_csv $opts(panel) $opts(file)

unload_report

可以使用以下命令在命令提示符下运行此脚本。

quartus_sh -t script.tcl -project <project name> -revision <revision name> -panel <panel name> -file <file name>

如果在系统命令提示符下输入面板名称参数,务必正确引用。某些字符(如竖线 (|))在命令外壳中有特殊含义。