diff --git a/tcl/package_ip.tcl b/tcl/package_ip.tcl index 31e23e6..3e86088 100644 --- a/tcl/package_ip.tcl +++ b/tcl/package_ip.tcl @@ -30,6 +30,48 @@ proc SplitSub { str startword } { } } +# Gets all the values whose key starts with 'startword.*', returns a +# dictionary with the same values, but the keys are instead '*'. +# +# EX: With the dictionary d = { param.foo one param.bar two biz three } +# +# Calling [GetSubValues $d "param"] would result in the dictionary: +# +# { foo one bar two } +proc GetSubValues {map subcat} { + set res_map [dict create] + + foreach {key val} $map { + set new_key [SplitSub $key $subcat] + + if { $new_key != "" } { + dict append res_map $new_key $val + } + } + + return $res_map +} + +proc InterfaceAddParameters {iface params} { + foreach {param_name val} $params { + puts "Setting parameter $param_name" + + ipx::add_bus_parameter $param_name $iface + set param [ipx::get_bus_parameters $param_name -of_objects $iface] + set_property value $val $param + } +} + +proc InterfaceAddPortMaps {iface port_maps} { + foreach {logical_port physical_port} $port_maps { + puts "Mapping logical port $logical_port" + + ipx::add_port_map $logical_port $iface + set port_map [ipx::get_port_maps $logical_port -of_objects $iface] + set_property physical_name $physical_port $port_map + } +} + # Parse the interface configuration and create a new interface # in the current core # @@ -93,36 +135,11 @@ proc ParseInterfaceConf { iface_name iface_conf } { set_property INTERFACE_MODE [dict get $iface_conf "MODE"] $iface } - # Create user parameters - foreach {key val} $iface_conf { - set param_name [SplitSub $key "PARAMETER"] + set params [GetSubValues $iface_conf "PARAMETER"] + set port_maps [GetSubValues $iface_conf "PORT"] - if { $param_name == "" } { - continue - } - - puts "Setting parameter $param_name" - - ipx::add_bus_parameter $param_name $iface - set param [ipx::get_bus_parameters $param_name -of_objects $iface] - set_property value $val $param - } - - # Create port mappings - foreach {key val} $iface_conf { - set logical_port [SplitSub $key "PORT"] - set physical_port $val - - if { $logical_port == "" } { - continue - } - - puts "Mapping logical port $logical_port" - - ipx::add_port_map $logical_port $iface - set port_map [ipx::get_port_maps $logical_port -of_objects $iface] - set_property physical_name $physical_port $port_map - } + InterfaceAddParameters $iface $params + InterfaceAddPortMaps $iface $port_maps } set gitroot [exec git rev-parse --show-toplevel]