Quartus® Verilog Register Bank 中的 II Tcl 版本編號

author-image

作者

這個範例程式會產生一個 Verilog 檔案,其六重價值儲存在一銀行的收銀機中。您可以使用此程式將少量資料 (例如修訂版編號) 自動寫入設計中的註冊銀行。

產生的 Verilog 檔案名為 version_reg.v。 請使用您想要儲存在收銀機中的六倍號碼來呼叫程式。在此頁面底部有一個如何呼叫程式的範例。

當您在 Tcl 腳本中呼叫程式時,您應該在壿取聲明中結束程式通話,因為如果建立 Verilog 檔案有問題,程式會返回錯誤。您可以揑取錯誤並顯示。

proc generate_verilog { hex_value } {

    set num_digits [string length $hex_value]
    set bit_width [expr { 4 * $num_digits } ]
    set high_index [expr { $bit_width - 1 } ]
    set reset_value [string repeat "0" $num_digits]

    if { [catch {
        set fh [open "version_reg.v" w ]
        puts $fh "module version_reg (clock, reset, data_out);"
        puts $fh "    input clock;"
        puts $fh "    input reset;"
        puts $fh "    output \[$high_index:0\] data_out;"
        puts $fh "    reg \[$high_index:0\] data_out;"
        puts $fh "    always @ (posedge clock or negedge reset) begin"
        puts $fh "        if (!reset)"
        puts $fh "            data_out <= ${bit_width}'h${reset_value};"
        puts $fh "        else"
        puts $fh "            data_out <= ${bit_width}'h${hex_value};"
        puts $fh "    end"
        puts $fh "endmodule"
        close $fh
    } res ] } {
        return -code error $res
    } else {
        return 1
    }
}

 

使用捕捉聲明

以下是如何將上述程式稱為並摽取任何錯誤的範例:

set my_hex_number "A5"
if { [catch { generate_verilog $my_hex_number } res] } {
    post_message -type error "Couldn't generate Verilog file\n$res"
}
# If the script gets here, there were no errors.

這個頁面的內容綜合了英文原始內容的人工翻譯譯文與機器翻譯譯文。本內容是基於一般資訊目的,方便您參考而提供,不應視同完整或準確的內容。如果這個頁面的英文版與譯文之間發生任何牴觸,將受英文版規範及管轄。 查看這個頁面的英文版。