cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cocopa
Visitor
Visitor
1,025 Views
Registered: ‎11-21-2019

Use tcl script to change constants in a package file

Jump to solution

Hello,

In my project all parameters are configured through constants in a package file. I would like to be able to change these values through tcl script, is that possible?

I know it is possible with generics, but since generics are not supported in package files (at least in Vivado 2017.4 I'm using), I would like to know if there is an alternative.

Thank you in advance.

0 Kudos
1 Solution

Accepted Solutions
cocopa
Visitor
Visitor
932 Views
Registered: ‎11-21-2019

Hi @romisaas 

Thank you for your reply,  I have found another way, I open the .vhd file and search for the line which includes my constant and then I replace it with desired parameter. Perhaps there is a more efficient or clever clever way, but at the moment it works for me!
Here is an example of the tcl script,  in case someone else is facing something similar.

EDIT: I slightly modified the script to make the constant detection more efficient.

proc  cngf_package {  NEW_CONSTANT_VALUE }
# Set the reference directory for source file relative paths 
    set origin_dir [file dirname [file normalize [info script]]]
    # Open the file to be modified (FILE1) and the temporary file (FILE2).
    set FILE1 [ open  $origin_dir/package_basic.vhd r]
    set FILE2 [ open $origin_dir/package_basic_temp.vhd w]

    while { [ gets $FILE1 LINE ] >= 0 } {
        # Search for the constant declarations
        set INDEX [ string match -nocase *constant*CONSTANT_NAME* $LINE ]
      
        # Replace Configuration parameters with the desired values
        if { $INDEX == 1 } {
            puts $FILE2 "constant CONSTANT_NAME      : Constant_type := $NEW_CONSTANT_VALUE;"
        } else {
        # Write this line, unchanged, to the temporary file if not found.
            puts $FILE2 $LINE
        }
    }
    # Close both files
    close $FILE1
    close $FILE2
    # Rename temporary file
    file rename -force $origin_dir/package_basic_temp.vhd   $origin_dir/package_basic.vhd
}

 

View solution in original post

Tags (1)
3 Replies
romisaas
Xilinx Employee
Xilinx Employee
950 Views
Registered: ‎02-12-2020

Hi @cocopa,

Are you using VHDL in your project?


I'd found a workaround in the following link

"By using std.textio to write out a text file from the VHDL model. You can generate this file during a simulation run  (or, Vivado might let you write files during synthesis). The generated text file can then be parsed into TCL to create constraints, or it could be written directly in TCL/SDC syntax and then sourced downs".

 

Also, will Packaging current project as IP, with generic parameters be applicable for your design?

You can modify and edit the Xilinx IP. Check this Answer record:

https://www.xilinx.com/support/answers/57546.html

For parameters refer to the below link: 

https://www.xilinx.com/support/documentation/sw_manuals/xilinx2017_4/ug1118-vivado-creating-packaging-custom-ip.pdf#page=54

 

Thanks,

-RomisaaS

cocopa
Visitor
Visitor
933 Views
Registered: ‎11-21-2019

Hi @romisaas 

Thank you for your reply,  I have found another way, I open the .vhd file and search for the line which includes my constant and then I replace it with desired parameter. Perhaps there is a more efficient or clever clever way, but at the moment it works for me!
Here is an example of the tcl script,  in case someone else is facing something similar.

EDIT: I slightly modified the script to make the constant detection more efficient.

proc  cngf_package {  NEW_CONSTANT_VALUE }
# Set the reference directory for source file relative paths 
    set origin_dir [file dirname [file normalize [info script]]]
    # Open the file to be modified (FILE1) and the temporary file (FILE2).
    set FILE1 [ open  $origin_dir/package_basic.vhd r]
    set FILE2 [ open $origin_dir/package_basic_temp.vhd w]

    while { [ gets $FILE1 LINE ] >= 0 } {
        # Search for the constant declarations
        set INDEX [ string match -nocase *constant*CONSTANT_NAME* $LINE ]
      
        # Replace Configuration parameters with the desired values
        if { $INDEX == 1 } {
            puts $FILE2 "constant CONSTANT_NAME      : Constant_type := $NEW_CONSTANT_VALUE;"
        } else {
        # Write this line, unchanged, to the temporary file if not found.
            puts $FILE2 $LINE
        }
    }
    # Close both files
    close $FILE1
    close $FILE2
    # Rename temporary file
    file rename -force $origin_dir/package_basic_temp.vhd   $origin_dir/package_basic.vhd
}

 

View solution in original post

Tags (1)
romisaas
Xilinx Employee
Xilinx Employee
597 Views
Registered: ‎02-12-2020
Hello @cocopa,
 
Is there any further assistance required in relation to this matter? If so, please let us know and we will be glad to help you further then.
However, if your query is answered now, please mark a response as 'Accepted Solution' (more info on this can be found here: https://forums.xilinx.com/t5/help/faqpage/faq-category-id/solutions#solutions), so that the topic can be completed then.
We appreciate your help.
 
Kind Regards,
Romisaa Samhoud
-------------------------------------------------------------------------
Don’t forget to reply, give Kudo, and accept as a solution.
-------------------------------------------------------------------------
0 Kudos