UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Visitor namnninh
Visitor
8,075 Views
Registered: ‎01-05-2010

ChipScope Engine Tcl interface

Hi;

 

   I am using Chipscope Engine TCL interface to write (csevio_write_value) to FPGA and to receive (csevio_read_values) hex values from FPGA through VIO.

 

   I found Zero values are padded  (ex: 00002A3B) to returned value from TCL routine inputTclArray ().

 

  My question is how to remove all padded values from hex number (ex. 0x2A3B).

 

 

 Any helps are apprecicated.

 

NN

 

 

0 Kudos
6 Replies
Xilinx Employee
Xilinx Employee
8,065 Views
Registered: ‎11-28-2007

Re: ChipScope Engine Tcl interface

It depends on what you want to do with the hex number. If you want to use it for further numeric calculation, you can simply pre-pend string "0x" to it. e.g

 

set hex_str "00002A3B"

set hex_num "0x"

append hex_num $hex_str

set hex_num_plus_1 [expr {$hex_num + 1}]

Cheers,
Jim
0 Kudos
Visitor namnninh
Visitor
8,049 Views
Registered: ‎01-05-2010

Re: ChipScope Engine Tcl interface

Hi;

 

  Thank you for your quick response to my question.

 

   Sorry, my question is not clear. I don't want to append 0x in the hex string.  Instead, I want to remove all 00 from a number (ex. 00002A3B ). So,  I only have a value(2A3B). This can help me to compare input file and output file since input values in the input file don't contain padded zero.

 

Thanks,

 

NN

0 Kudos
Xilinx Employee
Xilinx Employee
8,040 Views
Registered: ‎11-28-2007

Re: ChipScope Engine Tcl interface

set padded_hex_str "00002A3B"

regsub {^(0+)} $padded_hex_str "" hex_str

 

The hex_str will have padded "0" removed.

 

Cheers,

Jim

 

Cheers,
Jim
0 Kudos
Visitor namnninh
Visitor
8,010 Views
Registered: ‎01-05-2010

Re: ChipScope Engine Tcl interface

Hi Jim;

 

 

 I tried on the command shell. It works.

 

 I applied your method to my program. I found value:ff or oo are padded again in a couple places,

 

 

 Below is the program which  read  numbers (2 or 3 bytes) from image file and sen to FPGA and loop back. Returned values are captured and written in binary number to output file.

 

 Hopefully, you can help me to identify this problem in my program.

 

Thank you very much.

 

Regards,

 

Nam

 

Ex: input file (read 2 bytes at a time)

        13 30 45 3f 3d 3a 95 f3 ec e3 ce bb a6 98 72 57
        51 53 5e 5b 4b 4a 4c 46 46 44 4f 4f 4b 49 49

      output file:

         13 30 45 3f 3d 3a ff ff 95 f3 ff ff ec e3 ff ff
         ce bb ff ff a6 98 72 57 51 53 5e 5b 4b 4a 4c 46
        46 44 4f 4f 4b 49 49

 

 

program:

 

    set infile [open "inputData.dat" r]
    set outfile [open "dataOut.dat" w]

    fconfigure $infile -translation binary
    fconfigure $outfile -translation binary  

   .......

while {![eof $infile]} {


#read 2 bytes from a file

     set line [read  $infile 2]   
     binary scan $line H* value 

# write a v value

     set outputTclArray(AsynOut) $value

     csevio_write_values $handle $coreRef outputTclArray

#read back

    csevio_read_values $handle $coreRef inputTclArray

 

    regsub {^(0+)} $inputTclArray(AsynIn) "" hex_str

# convert to binary number

    set bin [binary format H* $hex_str]

# write to a file

    puts -nonewline $outfile $bin

}

 

 

0 Kudos
Xilinx Employee
Xilinx Employee
8,005 Views
Registered: ‎11-28-2007

Re: ChipScope Engine Tcl interface

Looks like your data are always 16 bits and sign-extended to 32 bits (prepend 0's for positive number and 1's for negative number). If that's the case, a simpler solution would be just get the last 4 characters from the return values.

 

 

set hex_str [string range $padded_hex_str 4 7]

Cheers,
Jim
0 Kudos
Visitor namnninh
Visitor
7,985 Views
Registered: ‎01-05-2010

Re: ChipScope Engine Tcl interface

Hi;

 

  I change different string range to allow different input data feed into the FPGA and collect them at the output port.

 

 It works perfectly. The output data file is identical to the input image data file.

 

 

Thank you for your help.

 

Regards,

 

Nam

 

  

0 Kudos