Search code examples
for-loophextclxilinx

How to write a TCL 'for' loop to get Hex values


I am working on a tcl script which interacts with the built-in tclsh of a EDA tool. There is a tool specific command that I need to use. This is :

set_property <property_of_object> <value_of_property> <object> 

so a typical example is

set_property OUTPUT_VALUE 43 debug_probe

Now, my idea was to do this several times using a 'for' loop. This is how I set it up :

 for {set t 0} {$t < 2} {incr t} {

 set i [format %x $t]
 set vio_output $i

 # setting VIO output to the design

 set_property OUTPUT_VALUE $vio_output [get_hw_probes probe_debug_read_select -of_objects [get_hw_vios hw_vio_2]]
 }

I cannot interpret the error well enough. But I think its saying that I should send a Hex value in the value_of_property field.

Here is the error log

ERROR: [Designutils 20-1474] The hw_probe VIO value [0] has [1] value characters. The required number of value characters for radix [HEX], is [2].

while executing
"rdi::set_property OUTPUT_VALUE 0 probe_debug_read_select"
invoked from within
"set_property OUTPUT_VALUE $vio_output [get_hw_probes probe_debug_read_select -of_objects [get_hw_vios hw_vio_2]]"

I think one of the two might be happening

(a) I am misinterpreting the error OR (b) I am not generating HEX values as requested by the tool.

I hope someone can shed some light on this.


Solution

  • Disclaimer: I don't know anything about the EDA tool you're using.

    I wonder whether whatever is handling the set_property command expects a string like 0xabcd for its hex number. Try changing your format command to

    set i [format 0x%x $t]
    

    to get the leading 0x.

    Another thought is that the error messages suggests that maybe set_property requires a two-digit hex number, if so you'd need a format statement like

    set i [format %02x $t]
    

    to force format to produce two-digit numbers - the command will produce only as many digits as it needs, which since you're passing 0 and 1 will always be only 1 digit.

    Does the tclsh in your EDA tool provide a command prompt? If so, I'd try typing in a few set_property commands to make sure that I properly understood the syntax. The chances are that while doing that, I'd get quite a lot of practice interpretting the error messages too :-)

    Good luck!

    Edit: I think I've worked out how to interpret the error message:

    ERROR: [Designutils 20-1474] The hw_probe VIO value [0] has [1] value characters.
           The required number of value characters for radix [HEX], is [2].
    

    I think this is saying that your command is passing 0 as the hw_probe VIO value, and this value has 1 character. Your current radix is HEX and that requires 2 characters to be valid. (I'm sorry if this sounds completely obvious; it took me ages to puzzle it out.) This would tend to point towards the [format %02x $t] solution.