diff --git a/projects/daq3/zc706/system_project.tcl b/projects/daq3/zc706/system_project.tcl index 81b06f90ef6..c768a474f43 100644 --- a/projects/daq3/zc706/system_project.tcl +++ b/projects/daq3/zc706/system_project.tcl @@ -46,7 +46,7 @@ global xcvr_config_paths # REF_CLK: Value of the reference clock [MHz] (usually LANE_RATE/20 or LANE_RATE/40) # PLL_TYPE: The PLL used for driving the link [CPLL/QPLL] -set xcvr_config_paths [adi_xcvr_projec [list \ +set xcvr_config_paths [adi_xcvr_project [list \ LANE_RATE [get_env_param LANE_RATE 10] \ REF_CLK [get_env_param REF_CLK 500] \ PLL_TYPE [get_env_param PLL_TYPE QPLL] \ diff --git a/projects/scripts/adi_project_xilinx.tcl b/projects/scripts/adi_project_xilinx.tcl index db7f3b09308..6bbc6ce150f 100644 --- a/projects/scripts/adi_project_xilinx.tcl +++ b/projects/scripts/adi_project_xilinx.tcl @@ -48,6 +48,9 @@ set p_prcfg_init "" set p_prcfg_list "" set p_prcfg_status "" +# Importing XCVR related functions +source $ad_hdl_dir/projects/xcvr_wizard/scripts/adi_xcvr_xilinx.tcl + ## Creates a Xilinx project for a given board # # \param[project_name] - name of the project @@ -346,107 +349,6 @@ proc adi_project_files {project_name project_files} { set_property top system_top [current_fileset] } - -## Function to execute a `make` command for xcvr_wizard project within another project. -# -# \param[project_name] - project name for which you want to run make -# \param[parameters_for_make] - parameters for the make command -# -proc adi_xcvr_project {parameters_for_make} { - - global ad_hdl_dir - - set project_name "xcvr_wizard" - set current_dir [pwd] - set carrier_name [file tail $current_dir] - - switch $carrier_name { - "zc706" { - set xcvr_type GTXE2 - } - "kc705" { - set xcvr_type GTXE2 - } - "zed" { - set xcvr_type GTXE2 - } - "vc707" { - set xcvr_type GTXE2 - } - "kcu105" { - set xcvr_type GTHE3 - } - "zcu102" { - set xcvr_type GTHE4 - } - "vcu118" { - set xcvr_type GTYE4 - } - "vcu128" { - set xcvr_type GTYE4 - } - default { - puts "ERROR adi_project_make: Unsupported carrier (device)." - return 1 - } - } - - set make_command "make" - set adi_project_dir_path [file join $ad_hdl_dir/projects $project_name $carrier_name] - cd $adi_project_dir_path - - set adi_dir_env "" - if {[info exists ::env(ADI_PROJECT_DIR)] && $::env(ADI_PROJECT_DIR) ne ""} { - set adi_dir_env [file tail [string trimright $::env(ADI_PROJECT_DIR) "/"]] - } - - if {[llength $parameters_for_make] > 0} { - - set formatted_params {} - set gt_xcvr_file {} - - foreach {key value} $parameters_for_make { - lappend formatted_params "$key=$value" - set key_parsed [string map {"LANE_" "" "_" ""} $key] - set value_parrsed [string map {. _} $value] - set ad_project_make_params($key) $value_parrsed - set tok "${key_parsed}${value_parrsed}" - - if {$adi_dir_env eq "" || ![regexp "(^|_)${tok}(_|$)" $adi_dir_env]} { - set gt_xcvr_file [linsert $gt_xcvr_file 0 "$tok"] - } - } - - append make_command " " [join $formatted_params " "] - set gt_xcvr_file [join $gt_xcvr_file "_"] - set config_parser_dir_name "${xcvr_type}_${ad_project_make_params(PLL_TYPE)}_${ad_project_make_params(LANE_RATE)}_${ad_project_make_params(REF_CLK)}" - set file_local_param [string tolower $config_parser_dir_name] - append file_local_param "_common.v" - } - - eval exec $make_command - cd $current_dir - - if {$adi_dir_env ne ""} { - if {$gt_xcvr_file eq ""} { - append adi_project_dir_path "/${::env(ADI_PROJECT_DIR)}${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" - } else { - append adi_project_dir_path "/$gt_xcvr_file\_$::env(ADI_PROJECT_DIR)${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" - } - } else { - append adi_project_dir_path "/$gt_xcvr_file/${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" - } - - set config_dir_path [file dirname $adi_project_dir_path] - set file_local_param_path "" - - if {$xcvr_type == "GTXE2"} { - set file_local_param_path [file join $config_dir_path $config_parser_dir_name $file_local_param] - } - - return [dict create "cfng_file_path" $adi_project_dir_path "param_file_path" $file_local_param_path] -} - ## Run an existing project (generate bit stream). # # \param[project_name] - name of the project diff --git a/projects/scripts/gtwiz_parser.pl b/projects/scripts/gtwiz_parser.pl index b6eb237ef7b..16dd729de1f 100755 --- a/projects/scripts/gtwiz_parser.pl +++ b/projects/scripts/gtwiz_parser.pl @@ -200,6 +200,7 @@ sub xcvr_diff { while (my $fline = ) { push(@File, $fline); } + close(READFILE) or die print "@[$myname] Can not close file called $pfile.\n"; # Find the GT's attributes location in the file my $gt_paramblock_start = 0; @@ -212,9 +213,24 @@ sub xcvr_diff { $gt_paramblock_end = $i; } } - close(READFILE) or die print "@[$myname] Can not close file called $pfile.\n"; - ## Update the attributes with the generated values + ## Extract base file name for the diff output + my $file_name = $pfile; + $file_name =~ s/^.*\///; + $file_name =~ s/\.v$//; + + my $git_exit_code = system("git rev-parse --is-inside-work-tree >/dev/null 2>&1"); + if ($git_exit_code != 0) { + print "WARNING: ADI's util_xcvr's can not be updated, because the current directory is NOT an HDL repository!\n"; + return 0; + } + + ## Create a copy of the original file and stage it + my $pfile_copy = $pfile . ".new"; + system "cp $pfile $pfile_copy"; + system "git add $pfile_copy"; + + ## Update the attributes with the generated values on the copy for my $i ($gt_paramblock_start..$gt_paramblock_end) { if ($File[$i] =~ m/\.\w*/) { ## it match a word which starts with a dot my $param = $File[$i]; @@ -229,26 +245,19 @@ sub xcvr_diff { } } - # Try to open file for write - open(WRITEFILE, ">$pfile") or die print "@[$myname] Can not open file called $pfile for writing.\n"; - + # Write the modified content to the copy + open(WRITEFILE, ">$pfile_copy") or die print "@[$myname] Can not open file called $pfile_copy for writing.\n"; foreach my $line (@File){ print WRITEFILE $line; } - close(WRITEFILE) or die print "@[$myname] Can not close file called $pfile.\n"; + close(WRITEFILE) or die print "@[$myname] Can not close file called $pfile_copy.\n"; - ## save the diff between the current and updated XCVR files - my $file_name = $pfile; - $file_name =~ s/^.*\///; - $file_name =~ s/\.v$//; + ## Generate diff between the staged (original) copy and the modified copy + system "git diff $pfile_copy > $file_name.diff"; - my $check_git = `git status`; - if ($check_git =~ m/On branch/i) { - system "git diff $pfile > $file_name.diff"; - system "git checkout -- $pfile"; - } else { - print "WARNING: ADI's util_xcvr's can not be updated, because the current direcotry is NOT an HDL repository!\n"; - } + ## Unstage and remove the copy to keep the repo clean + system "git rm --cached -f $pfile_copy >/dev/null 2>&1"; + unlink $pfile_copy; } diff --git a/projects/xcvr_wizard/scripts/adi_xcvr_xilinx.tcl b/projects/xcvr_wizard/scripts/adi_xcvr_xilinx.tcl new file mode 100644 index 00000000000..744e4373601 --- /dev/null +++ b/projects/xcvr_wizard/scripts/adi_xcvr_xilinx.tcl @@ -0,0 +1,112 @@ +############################################################################### +## Copyright (C) 2026 Analog Devices, Inc. All rights reserved. +### SPDX short identifier: ADIBSD +############################################################################### + +## Function to execute a `make` command for xcvr_wizard project within another project. +# +# \param[parameters_for_make] - parameters for the make command +# \param[carrier_name] - (optional) carrier name, if not provided it will be auto-detected from current directory +# +# Usage: +# adi_xcvr_project {LANE_RATE 10 REF_CLK 100} +# adi_xcvr_project {LANE_RATE 10 REF_CLK 100} kcu105 +# +proc adi_xcvr_project {parameters_for_make {carrier_name ""}} { + + global ad_hdl_dir + + set project_name "xcvr_wizard" + set current_dir [pwd] + + if {$carrier_name eq ""} { + set carrier_name [file tail $current_dir] + } + + switch $carrier_name { + "zc706" { + set xcvr_type GTXE2 + } + "kc705" { + set xcvr_type GTXE2 + } + "zed" { + set xcvr_type GTXE2 + } + "vc707" { + set xcvr_type GTXE2 + } + "kcu105" { + set xcvr_type GTHE3 + } + "zcu102" { + set xcvr_type GTHE4 + } + "vcu118" { + set xcvr_type GTYE4 + } + "vcu128" { + set xcvr_type GTYE4 + } + default { + puts "ERROR adi_project_make: Unsupported carrier (device)." + return 1 + } + } + + set make_command "make" + set adi_project_dir_path [file join $ad_hdl_dir/projects $project_name $carrier_name] + puts $adi_project_dir_path + cd $adi_project_dir_path + + set adi_dir_env "" + if {[info exists ::env(ADI_PROJECT_DIR)] && $::env(ADI_PROJECT_DIR) ne ""} { + set adi_dir_env [file tail [string trimright $::env(ADI_PROJECT_DIR) "/"]] + } + + if {[llength $parameters_for_make] > 0} { + + set formatted_params {} + set gt_xcvr_file {} + + foreach {key value} $parameters_for_make { + lappend formatted_params "$key=$value" + set key_parsed [string map {"LANE_" "" "_" ""} $key] + set value_parrsed [string map {. _} $value] + set ad_project_make_params($key) $value_parrsed + set tok "${key_parsed}${value_parrsed}" + + if {$adi_dir_env eq "" || ![regexp "(^|_)${tok}(_|$)" $adi_dir_env]} { + set gt_xcvr_file [linsert $gt_xcvr_file 0 "$tok"] + } + } + + append make_command " " [join $formatted_params " "] + set gt_xcvr_file [join $gt_xcvr_file "_"] + set config_parser_dir_name "${xcvr_type}_${ad_project_make_params(PLL_TYPE)}_${ad_project_make_params(LANE_RATE)}_${ad_project_make_params(REF_CLK)}" + set file_local_param [string tolower $config_parser_dir_name] + append file_local_param "_common.v" + } + + eval exec $make_command + cd $current_dir + + if {$adi_dir_env ne ""} { + if {$gt_xcvr_file eq ""} { + append adi_project_dir_path "/${::env(ADI_PROJECT_DIR)}${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" + } else { + append adi_project_dir_path "/$gt_xcvr_file\_$::env(ADI_PROJECT_DIR)${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" + } + } else { + append adi_project_dir_path "/$gt_xcvr_file/${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt" + } + + set config_dir_path [file dirname $adi_project_dir_path] + set file_local_param_path "" + + if {$xcvr_type == "GTXE2"} { + set file_local_param_path [file join $config_dir_path $config_parser_dir_name $file_local_param] + } + + return [dict create "cfng_file_path" $adi_project_dir_path "param_file_path" $file_local_param_path] +}