Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Python code accessing the BSCAN_SPARTAN3 via purely open source JTAG drivers

108 views
Skip to first unread message

wzab

unread,
May 17, 2009, 2:16:56 PM5/17/09
to
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.6.3).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh13213
# Made on 2009-05-17 20:12 CEST by <wzab@wzab>.
# Source directory was `/tmp/rrr'.
#
# Existing files will *not* be overwritten, unless `-c' is specified.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2925 -rw-r--r-- urjtag.py
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
echo 'Note: not verifying md5sums. Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
if test "$gettext_dir" = FAILED && test -f $dir/gettext \
&& ($dir/gettext --version >/dev/null 2>&1)
then
case `$dir/gettext --version 2>&1 | sed 1q` in
*GNU*) gettext_dir=$dir ;;
esac
fi
if test "$locale_dir" = FAILED && test -f $dir/shar \
&& ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
then
locale_dir=`$dir/shar --print-text-domain-dir`
fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
echo=echo
else
TEXTDOMAINDIR=$locale_dir
export TEXTDOMAINDIR
TEXTDOMAIN=sharutils
export TEXTDOMAIN
echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
then shar_n= shar_c='
'
else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
test ! -f ${st1} && test -f ${f}; then
shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
test ! -f ${st3} && test -f ${f}; then
shar_touch='touch -am $3$4$5$6$2 "$8"'

else
shar_touch=:
echo
${echo} 'WARNING: not restoring timestamps. Consider getting and'
${echo} 'installing GNU `touch'\'', distributed in GNU coreutils...'
echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir}
then : ; else ${echo} 'lock directory '${lock_dir}' exists'
exit 1
fi
if mkdir ${lock_dir}
then ${echo} 'x - created lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to create lock directory `'${lock_dir}\''.'
exit 1
fi
# ============= urjtag.py ==============
if test -f 'urjtag.py' && test "$first_param" != -c; then
${echo} 'x -SKIPPING urjtag.py (file already exists)'
else
${echo} 'x - extracting urjtag.py (text)'
sed 's/^X//' << 'SHAR_EOF' > 'urjtag.py' &&
#!/usr/bin/python
# This is PUBLIC DOMAIN code written by
# Wojciech M. Zabolotny ( wzab<at>ise.pw.edu.pl )
# It uses the libusb-driver http://rmdir.de/~michael/xilinx/
# and urJTAG http://urjtag.org/
# To change the state of the register accessible via
# the boundary scan component (BSCAN_SPARTAN3)
# with 3-bit data register.
#
# All values are now set for xpc_ext cable
# and Xilinx SPARTAN-3E Starter Kit
# The "urjtag" should be the shell script like this:
# : #!/bin/bash
# : PATH="/home/user/urjtag/bin":$PATH \
# : LD_PRELOAD="/home/user/xilinx-usb-driver/libusb-driver.so" \
# : jtag
# The test register is instantiated as follows:
#[...]
# BSS3_1 : BSCAN_SPARTAN3
# port map (CAPTURE => jt_capture,
# DRCK1 => jt_tck,
# DRCK2 => jt_tck2,
# RESET => jt_rst,
# SEL1 => jt_sel1,
# SEL2 => jt_sel2,
# SHIFT => jt_shift,
# TDI => jt_tdi,
# UPDATE => jt_update,
# TDO1 => jt_tdo,
# TDO2 => jt_tdi);
# process (jt_tck)
# begin -- process
# if jt_tck'event and jt_tck = '1' then
# jt1 <= jt_tdi;
# jt2 <= jt1;
# jt3 <= jt2;
# jt_tdo <= jt3;
# end if;
# end process;
#
# process (jt_update)
# begin -- process
# if jt_update'event and jt_update = '1' then
# led(3) <= jt3;
# led(2) <= jt2;
# led(1) <= jt1;
# end if;
# end process;
#[...]
X
import pexpect
import re
import time
class urjtag:
X def __init__(self):
X self.p=pexpect.spawn("urjtag")
X self.p.expect("jtag>")
X def cmd(self,line):
X self.p.sendline(line)
X self.p.expect("jtag>")
X if self.p.before.find("Error:")>=0:
X #res=-1
X raise("error")
X elif self.p.before.find("Unknown")>=0 or \
X self.p.before.find("unknown")>=0:
X #res=-2
X raise ("unknown command or syntax error")
X return self.p.before
u=urjtag()
u.cmd("cable xpc_ext")
s=u.cmd("detect")
#Here we parse the output of the "detect" command,
#Building the list of the parts
parts=[]
finder=re.compile(r'.*Part\((?P<num>.*?)\):\s*(?P<name>\S*)', re.M)
start=0
while True:
X rs=finder.search(s,start)
X if not rs:
X break
X # We have found a new part, add it to the list of parts
X parts.append((rs.group('num'),rs.group('name')))
X start=rs.span()[1]
# OK, so we set all the parts except the xc3s500e_fg320 in the BYPASS
# mode
for p in parts:
X if p[1]=="xc3s500e_fg320":
X u.cmd("part "+p[0])
X u.cmd("register UR 3")
X u.cmd("instruction USER1 000010 UR")
X u.cmd("instruction USER1")
X u.cmd("shift ir")
X else:
X u.cmd("part "+p[0])
X u.cmd("instruction BYPASS")
X u.cmd("shift ir")
# OK, so now we can change the value of our LEDs
# we get the "walking light" pattern
while True:
X for led in ["001","010","100"]:
X u.cmd("dr "+led)
X u.cmd("shift dr")
X time.sleep(0.1)
X
SHAR_EOF
(set 20 09 05 17 20 10 44 'urjtag.py'; eval "$shar_touch") &&
chmod 0644 'urjtag.py'
if test $? -ne 0
then ${echo} 'restore of urjtag.py failed'
fi
if ${md5check}
then (
${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'urjtag.py: MD5 check failed'
) << SHAR_EOF
2a9be846fa6ffaebb976944831059cf1 urjtag.py
SHAR_EOF
else
test `LC_ALL=C wc -c < 'urjtag.py'` -ne 2925 && \
${echo} 'restoration warning: size of urjtag.py is not 2925'
fi
fi
if rm -fr ${lock_dir}
then ${echo} 'x - removed lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to remove lock directory `'${lock_dir}\''.'
exit 1
fi
exit 0

0 new messages