Created
January 17, 2014 21:02
-
-
Save makestuff/8481462 to your computer and use it in GitHub Desktop.
Python binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ # Fetch library code & HDL example and build it all... | |
$ cd $HOME | |
$ mkdir 20131101 | |
$ cd 20131101/ | |
$ wget -qO- http://www.swaton.ukfsn.org/bin/makestuff-lindar-20130829.tar.gz | tar zxf - | |
$ cd makestuff | |
$ scripts/msget.sh makestuff/hdlmake/20131101 | |
Fetching "makestuff/hdlmake/20131101"... | |
Uncompressing "makestuff/hdlmake/20131101" into "hdlmake" directory... | |
Fetching "makestuff/common/20131101"... | |
Uncompressing "makestuff/common/20131101" into "./common" directory... | |
$ cd hdlmake/apps/ | |
$ ../bin/hdlmake.py -g makestuff/swled | |
MakeStuff HDL Builder (C) 2012-2013 Chris McClelland | |
Fetching https://github.com/makestuff/swled/archive/20131101.tar.gz | |
Success! | |
$ cd makestuff/swled/cksum/vhdl/ | |
$ ../../../../../bin/hdlmake.py -t ../../templates/fx2all/vhdl -b nexys2-1200 -p fpga | |
: | |
$ cd ../../../../../../libs/ | |
$ ../scripts/msget.sh makestuff/libfpgalink | |
Fetching "makestuff/libfpgalink/20131101"... | |
Uncompressing "makestuff/libfpgalink/20131101" into "libfpgalink" directory... | |
$ cd libfpgalink/ | |
$ make deps | |
: | |
$ | |
$ # Get updated Python binding | |
$ cd examples/python/ | |
$ rm fpgalink2.py | |
$ wget -q https://gist.github.com/makestuff/8158151/raw/623ee45dfcf965bd0d117078e7d72abc4fae1fa0/fpgalink2.py | |
$ chmod ugo+x fpgalink2.py | |
$ | |
$ # Try interactive Python session... | |
$ LD_LIBRARY_PATH=../../lin.x64/rel python | |
Python 2.7.6 (default, Dec 30 2013, 14:37:40) | |
[GCC 4.8.2] on linux2 | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> from fpgalink2 import * | |
>>> flLoadStandardFirmware("1443:0005", "1D50:602B:0002") | |
>>> handle = flOpen("1D50:602B:0002") | |
>>> bits = flMultiBitPortAccess(handle, "D7+") | |
>>> print "{:0{}b}".format(bits, 32) | |
00000000000000000000000000000001 | |
>>> chain = jtagScanChain(handle, "D0D2D3D4") | |
>>> for id in chain: | |
... print "0x%08X" % id | |
... | |
0x21C2E093 | |
0xF5046093 | |
>>> flProgram(handle, "J:D0D2D3D4:../../../../hdlmake/apps/makestuff/swled/cksum/vhdl/fpga.xsvf") | |
>>> flSelectConduit(handle, 1) | |
>>> bytes = [0xCA, 0xFE, 0xBA, 0xBE, 0xDE, 0xAD, 0xF0, 0x0D] | |
>>> flWriteChannel(handle, 0x00, bytearray(bytes)) | |
>>> hex((flReadChannel(handle, 0x01) << 8) + flReadChannel(handle, 0x02)) | |
'0x5c8' | |
>>> readData = flReadChannel(handle, 0x02, 8) | |
>>> for byte in readData: | |
... print "0x%02X" % byte | |
... | |
0xC8 | |
0xC8 | |
0xC8 | |
0xC8 | |
0xC8 | |
0xC8 | |
0xC8 | |
0xC8 | |
>>> flClose(handle) | |
>>> quit() | |
$ | |
$ # Now try non-interactive Python session... | |
$ dd if=/dev/urandom of=random.dat bs=65536 count=1 | |
1+0 records in | |
1+0 records out | |
65536 bytes (66 kB) copied, 0.00621075 s, 10.6 MB/s | |
$ LD_LIBRARY_PATH=../../lin.x64/rel ./fpgalink2.py -i 1443:0005 -v 1d50:602b:0002 -d D7+ -p J:D0D2D3D4:../../../../hdlmake/apps/makestuff/swled/cksum/vhdl/fpga.xsvf -f random.dat | |
FPGALink Python Example Copyright (C) 2011-2013 Chris McClelland | |
Attempting to open connection to FPGALink device 1d50:602b:0002... | |
Loading firmware into 1443:0005... | |
Awaiting renumeration... | |
Attempting to open connection to FPGALink device 1d50:602b:0002 again... | |
Configuring ports... | |
Readback: 28 24 20 16 12 8 4 0 | |
0000 0000 0000 0000 0000 0000 0000 0001 | |
Programming device with config J:D0D2D3D4:../../../../hdlmake/apps/makestuff/swled/cksum/vhdl/fpga.xsvf... | |
Zeroing R1 & R2... | |
Writing random.dat to FPGALink device 1d50:602b:0002... | |
Reading channel 0... | |
Got 0x77 | |
Reading channel 1... | |
Got 0x0C | |
Reading channel 2... | |
Got 0xC0 | |
$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment