2023-07-06 12:08:22 +00:00
# ##############################################################################
# # Copyright (C) 2022-2023 Analog Devices, Inc. All rights reserved.
# ## SPDX short identifier: ADIBSD
# ##############################################################################
2022-04-28 08:19:06 +00:00
# To use this script you can source it in any tcl shell or simply
# run it e.g. tclsh ../../scripts/adi_fmc_constr_generator.tcl fmc0
proc gen_fmc_constr { { fmc_index1 fmc} { fmc_index2 { } } } {
variable col0_max 0
variable col1_max 0
variable col2_max 0
variable col3_max 0
variable io_standard_max 0
set platform [ expr [ regexp { a10gx | a10soc| s10soc} [ file tail [ pwd ] ] ] ? " { i n t e l } " : " { x i l i n x } " ]
if { [ string match $platform xilinx] } {
set constr_file [ open fmc_constr.xdc w+ ]
if { [ string length $fmc_index2 ] == 0 } {
gen_xilinx_fmc $fmc_index1 fmc $constr_file
} else {
gen_xilinx_fmc $fmc_index1 fmc1 $constr_file
gen_xilinx_fmc $fmc_index2 fmc2 $constr_file
}
close $constr_file
if { ! [ catch { [ string length [ get_property NAME [ current_project ] ] ] } errmsg] } {
add_files - fileset constrs_1 - norecurse fmc_constr.xdc
}
} else {
set constr_file [ open fmc_constr.tcl w+ ]
if { [ string length $fmc_index2 ] == 0 } {
gen_intel_fmc $fmc_index1 fmc $constr_file
} else {
gen_intel_fmc $fmc_index1 fmc1 $constr_file
gen_intel_fmc $fmc_index2 fmc2 $constr_file
}
close $constr_file
}
}
proc gen_xilinx_fmc { fmc_index fmc_file constr_file} {
set cwd [ pwd ]
set carrier [ file tail $cwd ]
set eval_board [ file tail [ file dirname $cwd ] ]
global col0_max
global col1_max
global col2_max
global col3_max
global io_standard_max
variable last_gbt_pin 0
variable gbt_exist_flag 0
variable edit_flag 0
set carrier_path [ glob ../ ../ common/ $carrier / $carrier \ _$fmc_index * .txt]
set carrier_file [ open $carrier_path r]
set carrier_data [ read $carrier_file ]
close $carrier_file
set line_c [ split $carrier_data \ n]
set carrierType [ expr [ string match * $carrier * vck190vmk180] ? 2 : [ string match * u* $carrier ] || [ string match v* $carrier ] ]
set eval_board_path [ glob ../ common/ * _$fmc_file * .txt]
set eval_board_file [ open $eval_board_path r]
set eval_board_data [ read $eval_board_file ]
close $eval_board_file
set line_e [ split $eval_board_data \ n]
for { set i 1 } { $i < [ llength $line_e ] } { incr i} {
if { [ string match [ lindex $line_e $i ] " " ] || [ string match " * " [ lindex $line_e $i ] ] } { continue }
if { [ string match # * [ lindex $line_e $i ] ] } { continue }
set col_e [ join [ lindex $line_e $i ] " " ]
if { [ string match $carrier vcu118] && [ string match $fmc_index fmcp] && [ string match * [ lindex $col_e 0 ] * D4D5B20B21] } {
set last_gbt_pin [ lindex $col_e 0 ]
set gbt_exist_flag 1
}
if { ! [ string match [ lindex $col_e 4 ] # N/ A] } {
if { ! $carrierType } {
if { [ string match [ lindex $col_e 4 ] LVDS] || [ string match [ lindex $col_e 4 ] LVDS15] } { set col_e [ lreplace $col_e 4 4 LVDS_25] }
if { [ string match [ lindex $col_e 4 ] LVCMOS18] || [ string match [ lindex $col_e 4 ] LVCMOS15] } { set col_e [ lreplace $col_e 4 4 LVCMOS25] }
}
if { $carrierType == 1 } {
if { [ string match [ lindex $col_e 4 ] LVDS_25] || [ string match [ lindex $col_e 4 ] LVDS15] } { set col_e [ lreplace $col_e 4 4 LVDS] }
if { [ string match [ lindex $col_e 4 ] LVCMOS25] || [ string match [ lindex $col_e 4 ] LVCMOS15] } { set col_e [ lreplace $col_e 4 4 LVCMOS18] }
}
if { $carrierType == 2 } {
if { [ string match [ lindex $col_e 4 ] LVDS_25] || [ string match [ lindex $col_e 4 ] LVDS] } { set col_e [ lreplace $col_e 4 4 LVDS15] }
if { [ string match [ lindex $col_e 4 ] LVCMOS25] || [ string match [ lindex $col_e 4 ] LVCMOS18] } { set col_e [ lreplace $col_e 4 4 LVCMOS15] }
}
set io_standard [ lindex $col_e 4 ]
} else { set io_standard " " }
if { ! [ string match [ lindex $col_e 5 ] # N/ A] } {
for { set k 5 } { $k < [ llength $col_e ] } { incr k} {
append io_standard " [ l i n d e x $ c o l _ e $ k ] "
}
}
if { [ string length $io_standard ] > $io_standard_max } {
set io_standard_max [ string length $io_standard ]
}
for { set j 1 } { $j < [ llength $line_c ] } { incr j} {
set col_c [ join [ lindex $line_c $j ] " " ]
if { [ string match [ lindex $col_e 0 ] [ lindex $col_c 0 ] ] } {
if { ! [ string match [ lindex $col_c 2 ] # N/ A] } {
if { [ string length [ lindex $col_c 0 ] ] > $col0_max } {
set col0_max [ string length [ lindex $col_c 0 ] ]
}
if { [ string length [ lindex $col_c 1 ] ] > $col1_max } {
set col1_max [ string length [ lindex $col_c 1 ] ]
}
if { [ string length [ lindex $col_c 2 ] ] > $col2_max } {
set col2_max [ string length [ lindex $col_c 2 ] ]
}
}
if { [ string length [ lindex $col_e 3 ] ] > $col3_max } {
set col3_max [ string length [ lindex $col_e 3 ] ]
}
}
}
}
if { [ string match $carrier vcu118] && [ string match $fmc_index fmcp] && $gbt_exist_flag } { set edit_flag 1 }
for { set i 1 } { $i < [ llength $line_e ] } { incr i} {
if { [ string match [ lindex $line_e $i ] " " ] || [ string match " * " [ lindex $line_e $i ] ] } {
puts $constr_file " "
continue
}
if { [ string match # * [ lindex $line_e $i ] ] } {
puts $constr_file [ lindex $line_e $i ]
continue
}
if { $edit_flag } {
puts $constr_file " # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - T H I S S E C T I O N N E E D S M A N U A L E D I T I N G - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "
set edit_flag 0
}
set col_e [ join [ lindex $line_e $i ] " " ]
for { set j 1 } { $j < [ llength $line_c ] } { incr j} {
set col_c [ join [ lindex $line_c $j ] " " ]
if { [ string match [ lindex $col_e 0 ] [ lindex $col_c 0 ] ] } {
if { ! [ string match [ lindex $col_c 2 ] # N/ A] } {
set spaces_0 " "
set spaces_1 " "
set spaces_2 " "
set spaces_3 " "
for { set k 0 } { $k < [ expr $col0_max - [ string length [ lindex $col_c 0 ] ] ] } { incr k} { append spaces_0 " " }
for { set k 0 } { $k < [ expr $col1_max - [ string length [ lindex $col_c 1 ] ] ] } { incr k} { append spaces_1 " " }
for { set k 0 } { $k < [ expr $col2_max - [ string length [ lindex $col_c 2 ] ] ] } { incr k} { append spaces_2 " " }
for { set k 0 } { $k < [ expr $col3_max - [ string length [ lindex $col_e 3 ] ] ] } { incr k} { append spaces_3 " " }
if { ! [ string match [ lindex $col_e 4 ] # N/ A] } {
if { ! $carrierType } {
if { [ string match [ lindex $col_e 4 ] LVDS] || [ string match [ lindex $col_e 4 ] LVDS15] } { set col_e [ lreplace $col_e 4 4 LVDS_25] }
if { [ string match [ lindex $col_e 4 ] LVCMOS18] || [ string match [ lindex $col_e 4 ] LVCMOS15] } { set col_e [ lreplace $col_e 4 4 LVCMOS25] }
}
if { $carrierType == 1 } {
if { [ string match [ lindex $col_e 4 ] LVDS_25] || [ string match [ lindex $col_e 4 ] LVDS15] } { set col_e [ lreplace $col_e 4 4 LVDS] }
if { [ string match [ lindex $col_e 4 ] LVCMOS25] || [ string match [ lindex $col_e 4 ] LVCMOS15] } { set col_e [ lreplace $col_e 4 4 LVCMOS18] }
}
if { $carrierType == 2 } {
if { [ string match [ lindex $col_e 4 ] LVDS_25] || [ string match [ lindex $col_e 4 ] LVDS] } { set col_e [ lreplace $col_e 4 4 LVDS15] }
if { [ string match [ lindex $col_e 4 ] LVCMOS25] || [ string match [ lindex $col_e 4 ] LVCMOS18] } { set col_e [ lreplace $col_e 4 4 LVCMOS15] }
}
set io_standard " $ s p a c e s _ 2 I O S T A N D A R D [ l i n d e x $ c o l _ e 4 ] "
} else {
set io_standard " "
}
if { ! [ string match [ lindex $col_e 5 ] # N/ A] } {
if { ! [ string length $io_standard ] } { set io_standard $spaces_2 }
for { set k 5 } { $k < [ llength $col_e ] } { incr k} {
append io_standard " [ l i n d e x $ c o l _ e $ k ] "
}
}
if { [ string length $io_standard ] > 0 } {
for { set k 0 } { $k < [ expr $io_standard_max + [ string length $spaces_2 ] + 12 - [ string length $io_standard ] ] } { incr k} { append spaces_3 " " }
puts $constr_file " s e t _ p r o p e r t y - d i c t \{ P A C K A G E _ P I N [ l i n d e x $ c o l _ c 2 ] $ i o _ s t a n d a r d \} \[ g e t _ p o r t s [ l i n d e x $ c o l _ e 3 ] \] $ s p a c e s _ 3 ; # # [ l i n d e x $ c o l _ c 0 ] $ s p a c e s _ 0 [ l i n d e x $ c o l _ c 1 ] $ s p a c e s _ 1 [ l i n d e x $ c o l _ c 3 ] "
} else {
for { set k 0 } { $k < [ expr $io_standard_max + 12 - [ string length $io_standard ] ] } { incr k} { append spaces_3 " " }
puts $constr_file " s e t _ p r o p e r t y - d i c t \{ P A C K A G E _ P I N [ l i n d e x $ c o l _ c 2 ] \} $ s p a c e s _ 2 \[ g e t _ p o r t s [ l i n d e x $ c o l _ e 3 ] \] $ s p a c e s _ 3 ; # # [ l i n d e x $ c o l _ c 0 ] $ s p a c e s _ 0 [ l i n d e x $ c o l _ c 1 ] $ s p a c e s _ 1 [ l i n d e x $ c o l _ c 3 ] "
}
if { [ string match $carrier vcu118] && [ string match $fmc_index fmcp] && [ string match [ lindex $col_c 0 ] $last_gbt_pin ] && ! [ string match $last_gbt_pin * [ lindex $line_c [ expr $j + 2 ] ] ] && [ string match [ lindex $col_e 0 ] $last_gbt_pin ] && ! [ string match $last_gbt_pin * [ lindex $line_e [ expr $i + 2 ] ] ] } {
puts $constr_file # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
}
}
}
}
}
}
proc gen_intel_fmc { fmc_index fmc_file constr_file} {
set cwd [ pwd ]
set carrier [ file tail $cwd ]
global col0_max
global col1_max
global col2_max
global col3_max
variable current_index 1
variable spaceFlag 0
variable serialFlag 0
variable xcvrCount 0
set xcvrType " x c v r _ \$ \{ i \} "
set carrier_path [ glob ../ ../ common/ $carrier / $carrier \ _$fmc_index * .txt]
set carrier_file [ open $carrier_path r]
set carrier_data [ read $carrier_file ]
close $carrier_file
set line_c [ split $carrier_data \ n]
set eval_board_path [ glob ../ common/ * _$fmc_file * .txt]
set eval_board_file [ open $eval_board_path r]
set eval_board_data [ read $eval_board_file ]
close $eval_board_file
set line_e [ split $eval_board_data \ n]
for { set i 1 } { $i <= [ llength $line_e ] } { incr i} {
if { [ string match [ lindex $line_e $i ] " " ] || [ string match " * " [ lindex $line_e $i ] ] || $i == [ llength $line_e ] } { continue }
if { [ string match # * [ lindex $line_e $i ] ] } { continue }
set col_e [ join [ lindex $line_e $i ] " " ]
set col_e [ constrToIntel $line_e $col_e $i ]
for { set j 1 } { $j < [ llength $line_c ] } { incr j} {
set col_c [ join [ lindex $line_c $j ] " " ]
if { [ string match [ lindex $col_e 0 ] [ lindex $col_c 0 ] ] } {
if { ! [ string match [ lindex $col_c 2 ] # N/ A] } {
if { [ string length [ lindex $col_c 0 ] ] > $col0_max } {
set col0_max [ string length [ lindex $col_c 0 ] ]
}
if { [ string length [ lindex $col_c 1 ] ] > $col1_max } {
set col1_max [ string length [ lindex $col_c 1 ] ]
}
if { [ string length [ lindex $col_c 2 ] ] > $col2_max } {
set col2_max [ string length [ lindex $col_c 2 ] ]
}
}
if { [ string length [ lindex $col_e 3 ] ] > $col3_max } {
set col3_max [ string length [ lindex $col_e 3 ] ]
}
}
}
}
for { set i 1 } { $i <= [ llength $line_e ] } { incr i} {
if { [ string match # * [ lindex $line_e $i ] ] } {
puts $constr_file [ lindex $line_e $i ]
continue
}
set col_e [ join [ lindex $line_e $i ] " " ]
set col_e [ constrToIntel $line_e $col_e $i ]
if { [ string match " * s e r i a l _ d a t a * " [ lindex $col_e 3 ] ] && ! [ string match " * _ d a t a * " [ lindex $line_e [ expr $i + 1 ] ] ] } { set serialFlag 1 }
if { [ string match [ lindex $line_e $i ] " " ] || [ string match " * " [ lindex $line_e $i ] ] || $i == [ llength $line_e ] } {
puts $constr_file " "
if { $serialFlag } {
for { set k $current_index } { $k <= $i } { incr k} {
set col_e [ join [ lindex $line_e $k ] " " ]
set col_e [ constrToIntel $line_e $col_e $k ]
2023-08-07 11:14:11 +00:00
if { [ string match " * \[ 0 \] * " [ lindex $col_e 3 ] ] && ! [ string match " * ( n ) * " [ lindex $col_e 3 ] ] } {
2022-04-28 08:19:06 +00:00
puts $constr_file " s e t _ i n s t a n c e _ a s s i g n m e n t - n a m e X C V R _ V C C R _ V C C T _ V O L T A G E 1 _ 0 V - t o [ s t r i n g m a p - n o c a s e { [ 0 ] " " } [ l i n d e x $ c o l _ e 3 ] ] "
}
}
puts $constr_file " "
for { set k $current_index } { $k <= $i } { incr k} {
set col_e [ join [ lindex $line_e $k ] " " ]
set col_e [ constrToIntel $line_e $col_e $k ]
2023-08-07 11:14:11 +00:00
if { [ string match " * \[ 0 \] * " [ lindex $col_e 3 ] ] && ! [ string match " * ( n ) * " [ lindex $col_e 3 ] ] } {
2022-04-28 08:19:06 +00:00
set xcvrCount 0
puts $constr_file " s e t _ i n s t a n c e _ a s s i g n m e n t - n a m e I O _ S T A N D A R D \" H I G H S P E E D D I F F E R E N T I A L I / O \" - t o [ s t r i n g m a p - n o c a s e { [ 0 ] " " } [ l i n d e x $ c o l _ e 3 ] ] "
} else { incr xcvrCount}
}
puts $constr_file " "
puts $constr_file " f o r \{ s e t i 0 \} \{ \$ i < [ e x p r $ x c v r C o u n t / 2 ] \} \{ i n c r i \} \{ "
for { set k $current_index } { $k <= $i } { incr k} {
set col_e [ join [ lindex $line_e $k ] " " ]
set col_e [ constrToIntel $line_e $col_e $k ]
2023-08-07 11:14:11 +00:00
if { [ string match " * \[ 0 \] * " [ lindex $col_e 3 ] ] && ! [ string match " * ( n ) * " [ lindex $col_e 3 ] ] } {
2022-04-28 08:19:06 +00:00
if { [ string match " * d a t a _ * " [ lindex $col_e 3 ] ] } { set xcvrType " x c v r _ [ s t r i n g i n d e x [ l i n d e x $ c o l _ e 3 ] [ e x p r [ s t r i n g l a s t _ [ l i n d e x $ c o l _ e 3 ] ] + 1 ] ] _ \$ \{ i \} " }
puts $constr_file " s e t _ i n s t a n c e _ a s s i g n m e n t - n a m e X C V R _ R E C O N F I G _ G R O U P $ x c v r T y p e - t o [ s t r i n g m a p - n o c a s e { [ 0 ] \[ \$ \{ i \} \] } [ l i n d e x $ c o l _ e 3 ] ] "
}
}
puts $constr_file " \} "
set serialFlag 0
set current_index $i
}
for { set k $current_index } { $k < $i } { incr k} {
set col_e [ join [ lindex $line_e $k ] " " ]
set col_e [ constrToIntel $line_e $col_e $k ]
if { ! [ string match [ lindex $col_e 4 ] # N/ A] && ! [ string match " * ( n ) * " [ lindex $col_e 3 ] ] && ! [ string match " " [ lindex $col_e 4 ] ] } {
set io_standard [ string map - nocase { LVCMOS15 " \" 1 . 8 V \" " LVCMOS18 " \" 1 . 8 V \" " LVCMOS25 " \" 1 . 8 V \" " } [ lindex $col_e 4 ] ]
puts $constr_file " s e t _ i n s t a n c e _ a s s i g n m e n t - n a m e I O _ S T A N D A R D $ i o _ s t a n d a r d - t o [ l i n d e x $ c o l _ e 3 ] "
set spaceFlag 1
}
}
for { set k $current_index } { $k < $i } { incr k} {
set col_e [ join [ lindex $line_e $k ] " " ]
set col_e [ constrToIntel $line_e $col_e $k ]
if { ! [ string match [ lindex $col_e 5 ] # N/ A] && ! [ string match " * ( n ) * " [ lindex $col_e 3 ] ] && ! [ string match " " [ lindex $col_e 5 ] ] } {
set io_standard [ string map - nocase { DIFF_TERM " I N P U T _ T E R M I N A T I O N D I F F E R E N T I A L " } [ lindex $col_e 5 ] ]
puts $constr_file " s e t _ i n s t a n c e _ a s s i g n m e n t - n a m e $ i o _ s t a n d a r d - t o [ l i n d e x $ c o l _ e 3 ] "
}
}
set current_index $i
if { $spaceFlag } { puts $constr_file " " }
continue
}
for { set j 1 } { $j < [ llength $line_c ] } { incr j} {
set col_c [ join [ lindex $line_c $j ] " " ]
if { [ string match [ lindex $col_e 0 ] [ lindex $col_c 0 ] ] } {
if { ! [ string match [ lindex $col_c 2 ] # N/ A] } {
set spaces_0 " "
set spaces_1 " "
set spaces_2 " "
set spaces_3 " "
for { set k 0 } { $k < [ expr $col0_max - [ string length [ lindex $col_c 0 ] ] ] } { incr k} { append spaces_0 " " }
for { set k 0 } { $k < [ expr $col1_max - [ string length [ lindex $col_c 1 ] ] ] } { incr k} { append spaces_1 " " }
for { set k 0 } { $k < [ expr $col2_max - [ string length [ lindex $col_c 2 ] ] ] } { incr k} { append spaces_2 " " }
for { set k 0 } { $k < [ expr $col3_max - [ string length [ lindex $col_e 3 ] ] ] } { incr k} { append spaces_3 " " }
puts $constr_file " s e t _ l o c a t i o n _ a s s i g n m e n t [ l i n d e x $ c o l _ c 2 ] $ s p a c e s _ 2 - t o [ l i n d e x $ c o l _ e 3 ] $ s p a c e s _ 3 ; # # [ l i n d e x $ c o l _ c 0 ] $ s p a c e s _ 0 [ l i n d e x $ c o l _ c 1 ] $ s p a c e s _ 1 [ l i n d e x $ c o l _ c 3 ] "
}
}
}
}
}
proc constrToIntel { line_e col_e i} {
if { [ string match " * _ p * " [ lindex $col_e 3 ] ] && [ string match " * _ n * " [ lindex $line_e [ expr $i + 1 ] ] ] } { set col_e [ lreplace $col_e 3 3 [ string map - nocase { _p " " } [ lindex $col_e 3 ] ] ] }
if { [ string match " * _ n * " [ lindex $col_e 3 ] ] && [ string match " * _ p * " [ lindex $line_e [ expr $i-1 ] ] ] } { set col_e [ lreplace $col_e 3 3 " \" [ s t r i n g m a p - n o c a s e { _ n " " } [ l i n d e x $ c o l _ e 3 ] ] ( n ) \" " ] }
if { [ string match " * _ d a t a * " [ lindex $col_e 3 ] ] && ! [ string match " * s e r i a l _ d a t a * " [ lindex $col_e 3 ] ] } {
set col_e [ lreplace $col_e 3 3 [ string map - nocase { _data _serial_data} [ lindex $col_e 3 ] ] ]
}
return $col_e
}
# Allow the script to be called or sourced
if { [ info script] eq $::argv0 } {
if { $::argv == " " } {
puts " T o c r e a t e t h e f m c _ c o n s t r . x d c , c a l l t h e a d i _ f m c _ c o n s t r _ g e n e r a t o r . t c l w i t h a r g u m e n t ( s ) < f m c _ p o r t > "
puts " e . g . t c l s h . . / . . / s c r i p t s / a d i _ f m c _ c o n s t r _ g e n e r a t o r . t c l f m c 0 "
puts " e . g . t c l s h . . / . . / s c r i p t s / a d i _ f m c _ c o n s t r _ g e n e r a t o r . t c l f m c 0 f m c 1 "
puts " N O T E : T h e f m c p o r t n a m e c a n b e d e d u c e d f r o m t h e g i t r e p o h d l / p r o j e c t s / c o m m o n / < c a r r i e r > / < c a r r i e r > _ < f m c _ p o r t > . t x t "
} else {
gen_fmc_constr $::argv
}
} else {
puts " T o c r e a t e t h e f m c _ c o n s t r . x d c c a l l t h e g e n _ f m c _ c o n s t r < f m c _ p o r t > p r o c e d u r e "
puts " e . g . g e n _ f m c _ c o n s t r f m c 0 "
puts " e . g . g e n _ f m c _ c o n s t r f m c 0 f m c 1 "
puts " N O T E : T h e f m c p o r t n a m e c a n b e d e d u c e d f r o m t h e g i t r e p o h d l / p r o j e c t s / c o m m o n / < c a r r i e r > / < c a r r i e r > _ < f m c _ p o r t > . t x t "
}