1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
###############################################################################
# Copyright (c) 2011-2024 by Altair Engineering, Inc.
# All rights reserved.
#
# Altair Engineering, Inc. makes this software available as part of the Vision
# tool platform.  As long as you are a licensee of the Vision tool platform
# you may make copies of the software and modify it to be used within the
# Vision tool platform, but you must include all of this notice on any copy.
# Redistribution without written permission to any third party, with or
# without modification, is not permitted.
# Altair Engineering, Inc. does not warrant that this software is error free
# or fit for any purpose.  Altair Engineering, Inc. disclaims any liability for
# all claims, expenses, losses, damages and costs any user may incur as a
# result of using, copying or modifying the software.
# =============================================================================
#   @userware
#       TimeQuest Export Tool
#   @section
#       Link to Other Tools
#   @description
#       Get STA timing report from TimeQuest.
#
#       IMPORTANT: This script is NOT a RTLvision PRO Userware.
#
#       It is a Tcl script that can be executed in Altera's
#       TimeQuest tool to generate an Userware to visualize timing paths.
#
#       Run this script as:
#       ```
#       quartus_sta -report=sta_report.tcl <Project>
#       ```
#       It will generate the file `<Project>.rtlvision.tcl` that can be loaded
#       as a Userware in conjunction with the PathVision Userware.
#   @files
#       quartus/sta_report.tcl
#   @tag
#       rtl verilog fpga
###############################################################################


##
# Load the file that contain the procedures to access the Quartus DB as well
# as some utility procedures.
#
source [file join [file dirname [info script]] accessDB.tcl]
source [file join [file dirname [info script]] qutils.tcl]


# =============================================================================
# AddTimingPath - Call 'get_timing_paths -npaths $numPath' and add code to
#                 show the results in RTLvision.
# =============================================================================
#
proc Quartus_sta_report:AddTimingPath {fileid procName {numPath 10}} {
    puts $fileid "proc $procName {} \{"
    puts $fileid "global PathVision"
    puts $fileid "set db \$PathVision(db)"
    puts $fileid "PathVision:Clear"
    puts $fileid "\$db foreach top top break"

    ##
    # Call 'get_timing_paths -setup'
    #
    set timingPaths [get_timing_paths -npaths $numPath -setup]
    set count [get_collection_size $timingPaths]
    set n 0
    foreach_in_collection path $timingPaths {
        ##
        # Add progress update calls.
        #
        puts $fileid "if \{\[zprogress update \"\" $n $count\]\} return"

        QuUtils:WriteLine $fileid "set oidList \{\}"
        set paths [get_path_info $path -arrival_points]
        set cnt [get_collection_size $paths]
        set i 0
        foreach_in_collection point $paths {
            set total   [get_point_info $point -total_delay]
            set incr    [get_point_info $point -incremental_delay]
            set node_id [get_point_info $point -node]
            set type    [get_point_info $point -type]
            set rf      [get_point_info $point -rise_fall]

            ##
            # Skip this point if there is no corresponding node.
            #
            if {$node_id == ""} {
                continue
            }

            ##
            # Get the node name and skip nodes with a ':' in the name.
            #
            set nodeName [get_node_info $node_id -name]
            if {[string match "*:*" $nodeName]} {
                continue
            }

            ##
            # Write command to create a pin OID based on the node name.
            #
            puts $fileid "if \{\[catch \{"
            puts -nonewline $fileid "set oid \[\$db oid createFromString "
            puts -nonewline $fileid "\"pin\" \$top "
            puts -nonewline $fileid "[QuUtils:TclString $nodeName] "
            puts $fileid "\"/\" -delim \"|\"\]"
            puts $fileid "\} msg\]\} \{"
            puts $fileid "    zmessage print ERR err \$msg"
            puts $fileid "\} else \{"

            ##
            # Add the OID and the timing values to the oidList.
            #
            puts $fileid "lappend oidList \[list \$oid $incr $total $type $rf\]"
            puts $fileid "\}"

            ##
            # Here we assume that the first and last entry refer to a
            # flip-flop pin. In these cases write out code to align the
            # start and end flip-flops in the same column.
            #
            incr i
            if {$i == 1 || $i == $cnt} {
                puts $fileid "set inst \[\$db oid convertTo inst \$oid\]"
                if {$i ==    1} {set col SRC}
                if {$i == $cnt} {set col TRG}
                puts $fileid "\$db flatattr \$inst set @colgroup=$col"
            }
        }

        ##
        # Write a command to add this path to the PathVision Userware.
        #
        puts $fileid "PathVision:AddPath \$db \$oidList"
    }
    puts $fileid "\}"
}


# =============================================================================
# Main - The main procedure.
# =============================================================================
#
proc Quartus_sta_report:Main {fname copyNetlist} {
    ##
    # Open the output file.
    #
    set fileid [open $fname w]

    ##
    # Write a header to the generated script.
    #
    puts $fileid "# Script generated by quartus_sta with sta_rtlvision.tcl\n"

    ##
    # Enable the progress bar.
    #
    puts $fileid "zprogress begin"

    ##
    # Start the PathVision Userware.
    #
    puts $fileid "PathVision:Show"

    ##
    # Call the procedure that transfers the netlist from Quartus to RTLvision.
    #
    if {$copyNetlist} {
        puts $fileid "zprogress push \"Transfer Netlist\" 0.4"
        set topName [AccessDB:Copy2zdb $fileid 0]
        puts $fileid "if \{\[zprogress pop\]\} \{return\}"
    }

    ##
    # Add an Userware menu and set the new DB in the PathVision widget.
    #
    puts $fileid "zprogress push \"Annotate Timing Paths\" 0.8"
    puts $fileid "PathVision:DataBaseChanged"

    set procName "showTimingPath"
    if {$copyNetlist} {
        ##
        # Add the result of 'get_timing_paths' to the output file.
        #
        puts -nonewline $fileid "gui menu command \\"
        puts -nonewline $fileid "\t\{\"Userware\" \"Show Timing Paths\"\} \\"
        puts            $fileid "\t\{$procName\}"
    }
    Quartus_sta_report:AddTimingPath $fileid $procName
    puts $fileid "if \{\[zprogress pop\]\} \{return\}"

    ##
    # Write code to the output file to inform the GUI about the new database.
    #
    if {$copyNetlist} {
        puts $fileid "gui database changed \$db"
    } else {
        puts $fileid "zprogress push \"Exec STA file\" 1.0"
        puts $fileid $procName
        puts $fileid "if \{\[zprogress pop\]\} \{return\}"
    }

    puts $fileid "zprogress end"

    ##
    # Close the output file.
    #
    close $fileid
}


##
# Only call the main procedure if either the variable
# Quartus_sta_report_autostart does not exist or is set to true.
# Currently the Quartus_sta_report_autostart is set in quartusLink.tcl if
# sourced from the Userware menu entry 'Get STA Report'.
#checker -scope local exclude warnUndefinedVar
#
if {(![info exists Quartus_sta_report_autostart]) || \
                   $Quartus_sta_report_autostart} {
    Quartus_sta_report:Main "$quartus(settings).sta_report.tcl" true
}