# Source JTAG/TCL frame work
cd $env(CHIPSCOPE)/bin/nt
source $env(CHIPSCOPE)/bin/nt/tcljtag.tcl

# Open JTAG
set handle [jtag_open type=xilinx_platformusb frequency=750000]
jtag_lock $handle
set devlist [jtag_autodetect $handle]
puts $devlist

# Scan chain
set idcode_list [jtag_scanchain $handle]
puts $idcode_list

# Get number of devices in chain
set devcount [jtag_devicecount $handle] 
puts "Number of devices in the chain: $devcount"

# Get Device ID
set devtype "Virtex-4SX"
set devid 2


puts "IR Length of device $devid is [jtag_irlength $handle $devid]"
#jtag_navigate $handle TLR


# ---------------------------------------------------------------
# Shift the USER1 Instruction (b1111000010) into the Instruction Register of FPGA
# User 1
puts [jtag_shiftir      $handle -buffer "1100001111" -endstate RTI -device $devid]

# DevIDCode
#puts [jtag_shiftir      $handle -buffer "1001001111" -endstate RTI -device $devid]

# Write LED <= 0x55
puts [jtag_shiftdr      $handle -buffer "10101010" -endstate RTI -device $devid]

# ---------------------------------------------------------------

jtag_unlock $handle
jtag_close $handle
exit
