# Vivado Hardware Manager ILA capture helpers.
#
# Source this file in a live Vivado Tcl session after the hardware target is
# open. The upload helper intentionally calls display_hw_ila_data so the Vivado
# Logic Analyzer waveform tab is bound to the latest hw_ila_data object instead
# of staying on an empty/no-content view.

proc upload_display_write_ila_data {ila_name csv_path} {
    set ila [get_hw_ilas -quiet $ila_name]
    if {[llength $ila] != 1} {
        error "ILA not found uniquely: $ila_name -> $ila"
    }

    set data [upload_hw_ila_data $ila]
    display_hw_ila_data $data
    write_hw_ila_data -force -csv_file $csv_path $data
    display_hw_ila_data $data

    return $data
}

proc display_existing_ila_data {data_name} {
    set data [get_hw_ila_datas -quiet $data_name]
    if {[llength $data] != 1} {
        error "ILA data not found uniquely: $data_name -> $data"
    }

    display_hw_ila_data $data
    return $data
}
