Skip to content

Commit b7a9971

Browse files
committed
scripts: Add xcvr automation scripts
These scripts are used to import the generated parameters from the xcvr_wizard project to the project in use. Signed-off-by: Elena-Hadarau_adi <[email protected]>
1 parent 82b5d5e commit b7a9971

File tree

3 files changed

+307
-31
lines changed

3 files changed

+307
-31
lines changed
+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
###############################################################################
2+
## Copyright (C) 2016-2023 Analog Devices, Inc. All rights reserved.
3+
### SPDX short identifier: ADIBSD
4+
###############################################################################
5+
6+
proc adi_xcvr_parameters {file_paths parameters} {
7+
8+
set default_parameters {
9+
"RX_NUM_OF_LANES" "8"
10+
"TX_NUM_OF_LANES" "8"
11+
"RX_LANE_RATE" "12.5"
12+
"TX_LANE_RATE" "12.5"
13+
"LINK_MODE" "1"
14+
"RX_LANE_INVERT" "0"
15+
"TX_LANE_INVERT" "0"
16+
"QPLL_REFCLK_DIV" "1"
17+
"QPLL_FBDIV_RATIO" "1"
18+
"POR_CFG" "16'b0000000000000110"
19+
"PPF0_CFG" "16'b0000011000000000"
20+
"PPF1_CFG" "16'b0000011000000000"
21+
"QPLL_CFG" "27'h0680181"
22+
"QPLL_FBDIV" "10'b0000110000"
23+
"QPLL_CFG0" "16'b0011001100011100"
24+
"QPLL_CFG1" "16'b1101000000111000"
25+
"QPLL_CFG1_G3" "16'b1101000000111000"
26+
"QPLL_CFG2" "16'b0000111111000000"
27+
"QPLL_CFG2_G3" "16'b0000111111000000"
28+
"QPLL_CFG3" "16'b0000000100100000"
29+
"QPLL_CFG4" "16'b0000000000000011"
30+
"QPLL_CP_G3" "10'b0000011111"
31+
"QPLL_LPF" "10'b0100110111"
32+
"QPLL_CP" "10'b0001111111"
33+
"CPLL_FBDIV" "2"
34+
"CPLL_FBDIV_4_5" "5"
35+
"CPLL_CFG0" "16'b0000000111111010"
36+
"CPLL_CFG1" "16'b0000000000100011"
37+
"CPLL_CFG2" "16'b0000000000000010"
38+
"CPLL_CFG3" "16'b0000000000000000"
39+
"CH_HSPMUX" "16'b0010010000100100"
40+
"PREIQ_FREQ_BST" "0"
41+
"RXPI_CFG0" "16'b0000000000000010"
42+
"RXPI_CFG1" "16'b0000000000010101"
43+
"RTX_BUF_CML_CTRL" "3'b011"
44+
"TX_OUT_DIV" "1"
45+
"TX_CLK25_DIV" "20"
46+
"TX_PI_BIASSET" "1"
47+
"TXPI_CFG" "16'b0000000001010100"
48+
"A_TXDIFFCTRL" "5'b10110"
49+
"RX_OUT_DIV" "1"
50+
"RX_CLK25_DIV" "20"
51+
"RX_DFE_LPM_CFG" "16'h0104"
52+
"RX_PMA_CFG" "32'h001e7080"
53+
"RX_CDR_CFG" "72'h0b000023ff10400020"
54+
"RXCDR_CFG0" "16'b0000000000000010"
55+
"RXCDR_CFG2" "16'b0000001001101001"
56+
"RXCDR_CFG2_GEN2" "10'b1001100101"
57+
"RXCDR_CFG2_GEN4" "16'b0000000010110100"
58+
"RXCDR_CFG3" "16'b0000000000010010"
59+
"RXCDR_CFG3_GEN2" "6'b011010"
60+
"RXCDR_CFG3_GEN3" "16'b0000000000010010"
61+
"RXCDR_CFG3_GEN4" "16'b0000000000100100"
62+
"RXDFE_KH_CFG2" "16'h0200"
63+
"RXDFE_KH_CFG3" "16'h4101"
64+
"RX_WIDEMODE_CDR" "2'b00"
65+
"RX_XMODE_SEL" "1'b1"
66+
"TXDRV_FREQBAND" "0"
67+
"TXFE_CFG0" "16'b0000001111000010"
68+
"TXFE_CFG1" "16'b0110110000000000"
69+
"TXFE_CFG2" "16'b0110110000000000"
70+
"TXFE_CFG3" "16'b0110110000000000"
71+
"TXPI_CFG0" "16'b0000001100000000"
72+
"TXPI_CFG1" "16'b0001000000000000"
73+
"TXSWBST_EN" "0"
74+
}
75+
76+
set correction_map {
77+
"TXOUT_DIV" "TX_OUT_DIV"
78+
"RXOUT_DIV" "RX_OUT_DIV"
79+
"CPLL_FBDIV_45" "CPLL_FBDIV_4_5"
80+
"RXCDR_CFG" "RX_CDR_CFG"
81+
}
82+
83+
set updated_params {}
84+
set param_file_path [dict get $file_paths param_file_path]
85+
set cfng_file_path [dict get $file_paths cfng_file_path]
86+
87+
if {$param_file_path ne ""} {
88+
89+
set param_file_content [read [open $param_file_path r]]
90+
91+
# Define a regex pattern for extracting the value of QPLL_FBDIV_TOP from $param_file_path
92+
set param_pattern {QPLL_FBDIV_TOP = ([0-9]+);}
93+
set match [regexp -inline $param_pattern $param_file_content]
94+
set QPLL_FBDIV_TOP [lindex $match 1]
95+
96+
switch $QPLL_FBDIV_TOP {
97+
16 {set QPLL_FBDIV_IN "10'b0000100000"}
98+
20 {set QPLL_FBDIV_IN "10'b0000110000"}
99+
32 {set QPLL_FBDIV_IN "10'b0001100000"}
100+
40 {set QPLL_FBDIV_IN "10'b0010000000"}
101+
64 {set QPLL_FBDIV_IN "10'b0011100000"}
102+
66 {set QPLL_FBDIV_IN "10'b0101000000"}
103+
80 {set QPLL_FBDIV_IN "10'b0100100000"}
104+
100 {set QPLL_FBDIV_IN "10'b0101110000"}
105+
default {set QPLL_FBDIV_IN "10'b0000000000"}
106+
}
107+
108+
switch $QPLL_FBDIV_TOP {
109+
66 {set QPLL_FBDIV_RATIO "1'b0"}
110+
default {set QPLL_FBDIV_RATIO "1'b1"}
111+
}
112+
}
113+
114+
set file_content [read [open $cfng_file_path r]]
115+
set match ""
116+
regexp {QPLL[0-9]+} $cfng_file_path match
117+
118+
# Define a regex pattern for extracting parameters and their values
119+
set pattern {'([^']+)' => '([^']+\\?'?[0-9a-hA-H]*)'}
120+
set results {}
121+
set matches [regexp -all -inline $pattern $file_content]
122+
123+
for {set i 0} {$i < [llength $matches]} {incr i 3} {
124+
125+
set param [lindex $matches $i+1]
126+
set value [lindex $matches $i+2]
127+
128+
set cleaned_value [string map {"\\" ""} $value]
129+
set corrected_param $param
130+
131+
if {[dict exists $correction_map $param]} {
132+
set corrected_param [dict get $correction_map $param]
133+
}
134+
135+
if {[string first $match $param] == 0} {
136+
137+
if {[regexp {^(QPLL)[0-9]+(.*)} $param _ prefix rest]} {
138+
set corrected_param "${prefix}${rest}"
139+
}
140+
}
141+
142+
if {[dict exists $default_parameters $corrected_param]} {
143+
144+
set default_value [dict get $default_parameters $corrected_param]
145+
146+
if {$cleaned_value != $default_value} {
147+
148+
if {[string equal $cleaned_value "QPLL_FBDIV_IN"]} {
149+
set cleaned_value $QPLL_FBDIV_IN
150+
}
151+
if {[string equal $cleaned_value "QPLL_FBDIV_RATIO"]} {
152+
set cleaned_value $QPLL_FBDIV_RATIO
153+
}
154+
if {[string equal $corrected_param "PREIQ_FREQ_BST"]} {
155+
set cleaned_value [expr {$cleaned_value}]
156+
}
157+
158+
dict set updated_params $corrected_param $cleaned_value
159+
}
160+
}
161+
lappend results [list $corrected_param $cleaned_value]
162+
}
163+
164+
if {[llength $parameters] > 0} {
165+
foreach {key value} $parameters {
166+
167+
if {[dict exists $default_parameters $key]} {
168+
set default_value [dict get $default_parameters $key]
169+
170+
if {$value != $default_value} {
171+
dict set updated_params $key $value
172+
}
173+
}
174+
if {[dict exists $updated_params $key]} {
175+
set default_value [dict get $updated_params $key]
176+
177+
if {$value != $default_value} {
178+
dict set updated_params $key $value
179+
}
180+
}
181+
}
182+
}
183+
184+
return $updated_params
185+
}

projects/scripts/adi_project_xilinx.tcl

+83
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,89 @@ proc adi_project_files {project_name project_files} {
340340
set_property top system_top [current_fileset]
341341
}
342342

343+
## Function to execute a `make` command for xcvr_wizard project within another project.
344+
#
345+
# \param[project_name] - project name for which you want to run make
346+
# \param[parameters_for_make] - parameters for the make command
347+
#
348+
proc adi_xcvr_project {parameters_for_make} {
349+
350+
global ad_hdl_dir
351+
352+
set project_name "xcvr_wizard"
353+
set current_dir [pwd]
354+
set carrier_name [file tail $current_dir]
355+
356+
switch $carrier_name {
357+
"zc706" {
358+
set xcvr_type GTXE2
359+
}
360+
"kc705" {
361+
set xcvr_type GTXE2
362+
}
363+
"zed" {
364+
set xcvr_type GTXE2
365+
}
366+
"vc707" {
367+
set xcvr_type GTXE2
368+
}
369+
"kcu105" {
370+
set xcvr_type GTHE3
371+
}
372+
"zcu102" {
373+
set xcvr_type GTHE4
374+
}
375+
"vcu118" {
376+
set xcvr_type GTYE4
377+
}
378+
"vcu128" {
379+
set xcvr_type GTYE4
380+
}
381+
default {
382+
puts "ERROR adi_project_make: Unsupported carrier (device)."
383+
return 1
384+
}
385+
}
386+
387+
set parameters_dir_name {}
388+
set make_command "make"
389+
set adi_project_dir_path [file join $ad_hdl_dir/projects $project_name $carrier_name]
390+
cd $adi_project_dir_path
391+
392+
if {[llength $parameters_for_make] > 0} {
393+
394+
set formatted_params {}
395+
396+
foreach {key value} $parameters_for_make {
397+
398+
lappend formatted_params "$key=$value"
399+
set key_parsed [string map {"LANE_" "" "_" ""} $key]
400+
set value_parrsed [string map {. _} $value]
401+
set ad_project_make_params($key) $value_parrsed
402+
lappend parameters_dir_name "${key_parsed}${value_parrsed}"
403+
}
404+
405+
append make_command " " [join $formatted_params " "]
406+
set parameters_dir_name [join $parameters_dir_name "_"]
407+
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)}"
408+
set file_local_param [string tolower $config_parser_dir_name]
409+
append file_local_param "_common.v"
410+
}
411+
412+
eval exec $make_command
413+
cd $current_dir
414+
415+
append adi_project_dir_path "/$parameters_dir_name/${project_name}_${carrier_name}.gen/sources_1/ip/${xcvr_type}_cfng.txt"
416+
set config_dir_path [file dirname $adi_project_dir_path]
417+
418+
set file_local_param_path ""
419+
if {$xcvr_type == "GTXE2"} {
420+
set file_local_param_path [file join $config_dir_path $config_parser_dir_name $file_local_param]
421+
}
422+
423+
return [dict create "cfng_file_path" $adi_project_dir_path "param_file_path" $file_local_param_path]
424+
}
425+
343426
## Run an existing project (generate bit stream).
344427
#
345428
# \param[project_name] - name of the project

projects/scripts/gtwizard_generator.tcl

+39-31
Original file line numberDiff line numberDiff line change
@@ -486,49 +486,57 @@ proc get_diff_params { {lane_rate_l {}} {pll_type {}} {ref_clk_l {}} {keep_ip "
486486

487487
set current_dir [pwd]
488488
set project_name [get_property NAME [current_project]]
489+
set hdl_projects_path [file normalize [file join $current_dir "../.."]]
489490

490491
## Generate configurations
491492
ad_gth_generator $lane_rate_l $pll_type $ref_clk_l
492493

493494
## Call parser script gtwiz_parser.pl
494495
cd $project_name\.gen/sources_1/ip
495496
# exec $::env(ADI_HDL_DIR)/projects/scripts/gtwiz_parser.pl $gt_type
497+
# exec ../../../../../scripts/gtwiz_parser.pl $gt_type
496498
# catch exception for the next line. If it catches something, come back to $current_dir
497-
if { [catch { exec ../../../../../scripts/gtwiz_parser.pl $gt_type } e] } {
498-
cd $current_dir
499-
puts "Some error has occured: \n$e";
500-
} else {
501-
exec ../../../../../scripts/gtwiz_parser.pl $gt_type
502-
cd $current_dir
503-
504-
## if keep_ip not true, remove from the project the generated IPs and delete them
505-
if {$keep_ip ne "true"} {
506-
foreach lane_rate $lane_rate_l {
507-
foreach ref_clk $ref_clk_l {
508-
set lane_rate_txt [string replace $lane_rate [string first . $lane_rate] [string first . $lane_rate] "_"]
509-
set ref_clk_txt [lindex [split $ref_clk "."] 0]
510-
511-
## Get the paths to generated IP so that it can be removed
512-
set src_path $current_dir/$project_name\.srcs/sources_1/ip
513-
set gen_path $current_dir/$project_name\.gen/sources_1/ip
514-
set ip_name [eval exec ls $src_path | grep $gt_type\_$pll_type\_$lane_rate_txt\_$ref_clk_txt]
515-
set ip_path_src $src_path\/$ip_name
516-
set ip_path_gen $gen_path\/$ip_name
517-
set xci_file $ip_path_src/$ip_name\.xci
518-
519-
## Remove the generated IP after the differences were written
520-
export_ip_user_files -of_objects [get_files $xci_file] -no_script -reset -force -quiet
521-
remove_files -fileset $ip_name $xci_file
522-
file delete -force $ip_path_src
523-
file delete -force $ip_path_gen
499+
set dst_path [pwd]
500+
if {[file tail $dst_path] eq "ip"} {
501+
if { [catch { exec $hdl_projects_path/scripts/gtwiz_parser.pl $gt_type } e] } {
502+
cd $current_dir
503+
puts "Some error has occured: \n$e";
504+
} else {
505+
exec $hdl_projects_path/scripts/gtwiz_parser.pl $gt_type
506+
cd $current_dir
507+
508+
## if keep_ip not true, remove from the project the generated IPs and delete them
509+
if {$keep_ip ne "true"} {
510+
foreach lane_rate $lane_rate_l {
511+
foreach ref_clk $ref_clk_l {
512+
set lane_rate_txt [string replace $lane_rate [string first . $lane_rate] [string first . $lane_rate] "_"]
513+
set ref_clk_txt [lindex [split $ref_clk "."] 0]
514+
515+
## Get the paths to generated IP so that it can be removed
516+
set src_path $current_dir/$project_name\.srcs/sources_1/ip
517+
set gen_path $current_dir/$project_name\.gen/sources_1/ip
518+
set ip_name [eval exec ls $src_path | grep $gt_type\_$pll_type\_$lane_rate_txt\_$ref_clk_txt]
519+
set ip_path_src $src_path\/$ip_name
520+
set ip_path_gen $gen_path\/$ip_name
521+
set xci_file $ip_path_src/$ip_name\.xci
522+
523+
## Remove the generated IP after the differences were written
524+
export_ip_user_files -of_objects [get_files $xci_file] -no_script -reset -force -quiet
525+
remove_files -fileset $ip_name $xci_file
526+
file delete -force $ip_path_src
527+
file delete -force $ip_path_gen
528+
}
524529
}
530+
} else {
531+
puts "\ngenerated files can be find at $project_name\.gen/sources_1/ip"
525532
}
526-
} else {
527-
puts "\ngenerated files can be find at $project_name\.gen/sources_1/ip"
528-
}
529533

530534

531-
puts "\nconfiguration file for the tranciever is $project_name\.gen/sources_1/ip/$gt_type\_cfng.txt"
535+
puts "\nconfiguration file for the tranciever is $project_name\.gen/sources_1/ip/$gt_type\_cfng.txt"
536+
}
537+
} else {
538+
puts "For running the parser script you should be in ip directory"
532539
}
533540

541+
534542
}

0 commit comments

Comments
 (0)