Skip to content

Commit

Permalink
Merge pull request #13 from rheineke/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
xesscorp committed Feb 6, 2017
2 parents 73ea73a + da782bb commit 44139ad
Show file tree
Hide file tree
Showing 39 changed files with 1,994 additions and 1,723 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ output/*/index.html

# Sphinx
docs/_build

# Intellij PyCharm
.idea/
ipsh.py
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ python:
# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -r requirements.txt

# command to run tests, e.g. python setup.py test
# command to run test, e.g. python setup.py test
script: python setup.py test
1 change: 1 addition & 0 deletions .travis/brew.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libusb
44 changes: 44 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,47 @@ Features
* Command-line tools for configuring the FPGA, uploading/downloading the
serial flash and SDRAM, and running diagnostics on the board.
* GUI tool that performs the same functions as the command-line tools.

Installation
--------------------------------

XSTOOLs utilities use [PyUSB](https://walac.github.io/pyusb/). PyUSB relies on a
native system library for USB access. Instructions below will cover tested
libraries.

Install for a single user with the following commands:

* Windows:
```
pip install --user -r requirements.txt
python setup.py install --home=$HOME
```

* MacOS: [HomeBrew](http://brew.sh/) is a great choice for installing system
libraries.
```
<.travis/brew.txt xargs brew install
pip install --user -r requirements.txt
python setup.py install --home=$HOME
```

* Linux: You must install [wxPython Phoenix](https://github.com/wxWidgets/Phoenix/blob/master/README.rst)
from source.
```
sudo apt-get install freeglut3-dev libgtk2.0-dev libgstreamer-plugins-base0.10-dev libwebkitgtk-dev libnotify-dev libsdl1.2-dev
wget http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2076+9cbca77.tar.gz
tar -zxvf wxPython_Phoenix-3.0.3.dev2076+9cbca77.tar.gz
python build.py dox etg --nodoc sip build

sudo apt-get install libusb-1.0.0-dev
pip install --user -r requirements.txt
python setup.py install --home=$HOME
```

Running Graphical User Interface
--------------------------------

* MacOS:
```
PYTHONPATH=$PYTHONPATH:. pythonw xstools/gxstools.py
```
14 changes: 13 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
wheel==0.23.0
# pip install --user --trusted-host wxpython.org -r requirements.txt
###### Requirements without Version Specifiers ######
# TODO: replicate pip command
# pip install --user --trusted-host wxpython.org --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2562+33fadd8-cp27-cp27m-macosx_10_6_intel.whl; sys_platform == 'darwin' and python_version == '2.7.0'
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev2562+33fadd8-cp35-cp35m-macosx_10_6_intel.whl; sys_platform == 'darwin' and python_version == '3.5'
###### Requirements with Version Specifiers ######
bitstring==3.1.5
future==0.15.2; python_version < '3.0.0'
intelhex==2.1
pypubsub==3.3.0
pyserial==2.7
pyusb==1.0.0
58 changes: 36 additions & 22 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import setuptools

import xstools

import sys
import os
import shutil
import subprocess
import sys

import xstools

if sys.version_info < (2, 6) or (3, 0) <= sys.version_info < (3, 4):
raise RuntimeError("Python version 2.6, 2.7 or >= 3.4 required.")

# Prefer setuptools over distutils
try:
import setuptools
from setuptools import setup
except ImportError:
from distutils.core import setup
Expand All @@ -19,13 +22,16 @@
history = history_file.read().replace('.. :changelog:', '')

requirements = [
'pypubsub >= 3.1.2',
'pyusb >= 1.0.0a3',
'bitstring >= 3.1.1',
'intelhex >= 1.4',
'pyserial >= 2.7',
'pypubsub >= 3.1.2',
'pyusb >= 1.0.0',
# 'wheel >= 0.23.0',
]

test_requirements = [ # TODO: put package test requirements here
''
]


Expand All @@ -37,10 +43,9 @@
author=xstools.__author__,
author_email=xstools.__email__,
url='https://github.com/xesscorp/XSTOOLs',
# packages=['xstools'],
packages=setuptools.find_packages(),
entry_points={
'console_scripts':[
'console_scripts': [
'usb2serial = xstools.usb2serial:usb2serial',
'xsflags = xstools.xsflags:xsflags',
'xsload = xstools.xsload:xsload',
Expand All @@ -51,21 +56,30 @@
'gxstools = xstools.gxstools:gxstools',
],
},
package_dir={'xstools': 'xstools'},
# Don't set include_package_data to True! Then it only includes data files under version control.
# include_package_data=True,
package_data={'xstools': ['xula*/*.bit', 'xula*/*.hex', '*.rules', 'icons/*.png']},
# package_dir={'': 'xstools'},
# Don't set include_package_data to True! Then it only includes data files under version
# control.
# include_package_data=True,
package_data={
'xstools': ['xula*/*.bit', 'xula*/*.hex', '*.rules', 'icons/*.png']
},
install_requires=requirements,
license="GPLv2+",
license='GPLv2+',
zip_safe=False,
keywords='xstools',
classifiers=['Development Status :: 2 - Pre-Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Natural Language :: English',
"Programming Language :: Python :: 2",
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7', ],
keywords='xstools FPGA',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
'Natural Language :: English',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Operating System :: Microsoft :: Windows :: Windows NT/2000',
'Operating System :: MacOS :: MacOS X',
],
test_suite='tests',
tests_require=test_requirements,
)
Expand Down
35 changes: 35 additions & 0 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest

from intelhex import IntelHex

from xstools.xilbitstr import XilinxBitstream
from xstools.xsboard import Xula2lx25, Xula2lx9, Xula50, Xula200, Xula2, Xula


class ExampleTest(unittest.TestCase):
def test_bitstreams(self):
# Why does each board bitstream have a characteristic length?
board_bit_lengths = [
(Xula2lx25, 6411696),
(Xula2lx9, 2724832),
(Xula50, 437312),
(Xula200, 1196128)
]
bitstreams = ['cfg_flash', 'sdram', 'test']
for b, exp_bit_len in board_bit_lengths:
for bs in bitstreams:
xbs = XilinxBitstream()
fp = getattr(b, bs + '_bitstream')
xbs.from_file(fp)
self.assertEqual(len(xbs.bits), exp_bit_len)
ih = xbs.to_intel_hex()
self.assertEqual(ih.minaddr(), 0)
self.assertEqual(ih.maxaddr(), (exp_bit_len + 120) // 8)

def test_intel_hex(self):
boards = [Xula2, Xula]
for b in boards:
hex_fp = b.firmware
ih = IntelHex(hex_fp)
self.assertEqual(ih.minaddr(), 2048)
self.assertEqual(ih.maxaddr(), 3145741)
27 changes: 27 additions & 0 deletions tests/test_sdram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest
from intelhex import IntelHex

from xstools.xsboard import XsBoard
from xstools.xsusb import XsUsb


class Sdramtest(unittest.TestCase):
def setUp(self):
self.board = XsBoard.get_xsboard()

@unittest.skipUnless(XsUsb.get_xsusb_ports(), 'No Xula board found')
def test_readwrite(self):
"""
test read and write sdram
writes 14 values to sdram, hereafter reads 14 values
from sdram and checks equality
"""
for v in [0, 255]:
keys = range(0, 14)
values = 14 * [v]
data = IntelHex()
data.fromdict(dict(zip(keys, values)))
self.board.write_sdram(data, 0, len(keys)-1)
result = self.board.read_sdram(0, len(keys)-1)
self.assertEqual(data.todict(), result.todict())
40 changes: 40 additions & 0 deletions tests/test_xsbitarray.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import unittest

from xstools.xsbitarray import XsBitArray


class TestXSBitArray(unittest.TestCase):
def test_head(self):
arr = XsBitArray('0b01')
self.assertEqual(arr.head(), XsBitArray('0b1'))
self.assertNotEqual(arr.head(), XsBitArray('0b0'))

def test_tail(self):
arr = XsBitArray('0b01')
self.assertEqual(arr.tail(), XsBitArray('0b0'))
self.assertNotEqual(arr.tail(), XsBitArray('0b1'))

def test_to_usb(self):
a_arr = XsBitArray('0b00010')
b_arr = XsBitArray('0b1111001')
c_arr = a_arr + b_arr
self.assertEqual(c_arr, XsBitArray('0xf22'))
self.assertEqual(c_arr.to_usb(), b'"\x0f')

def test_to_intel_hex(self):
arr = XsBitArray('0b01')
hex_arr = arr.to_intel_hex()
binstr = hex_arr.tobinstr()
# Getting an error here in IntelHex 2.1 on Python 2
# Traceback (most recent call last):
# File "/Users/xilinx/code/XSTOOLs/tests/test_xsbitarray.py", line 27, in test_to_intel_hex
# binstr = hex_arr.tobinstr()
# File "/Users/xilinx/.local/lib/python2.7/site-packages/intelhex/__init__.py", line 375, in tobinstr
# return self._tobinstr_really(start, end, pad, size)
# File "/Users/xilinx/.local/lib/python2.7/site-packages/intelhex/__init__.py", line 378, in _tobinstr_really
# return asbytes(self._tobinarray_really(start, end, pad, size).tostring())
# File "/Users/xilinx/.local/lib/python2.7/site-packages/intelhex/__init__.py", line 352, in _tobinarray_really
# bin.append(self._buf.get(i, pad))
# TypeError: an integer is required
# TODO: What should this output?
self.assertEqual(binstr, b'@')
35 changes: 35 additions & 0 deletions tests/test_xsboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import unittest

from xstools.xsboard import XsBoard, XulaNoJtag, all_xsboards
from xstools.xsusb import XsUsb


@unittest.skipUnless(XsUsb.get_xsusb_ports(), 'No Xula board found')
class XsBoardTest(unittest.TestCase):
def setUp(self):
self.board = XsBoard.get_xsboard()

def test_get_xsboard(self):
# TODO(rheineke): What is the point of None? Not used in project
board = XsBoard.get_xsboard(xsusb_id=None)
self.assertIsNone(board)

# If an explicit board name is provided, then this is chosen first
# Ensure all boards are accessible by name
boards = all_xsboards()
for b in boards:
board = XsBoard.get_xsboard(xsboard_name=b.name)
# Will fail on XulaNoJtag
if b is not XulaNoJtag:
self.assertEqual(board.__class__, b)

# If the provided board name is not found, the return the board indexed
# by xsusb_id
with self.assertRaises(IndexError):
XsBoard.get_xsboard(xsusb_id=-2)
board = XsBoard.get_xsboard(xsusb_id=0)
self.assertIsNotNone(board)

def test_blink(self):
info = self.board.get_board_info()
self.assertIsNotNone(info)
3 changes: 0 additions & 3 deletions tests/test_xsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

import unittest

from xstools import xstools


class TestXstools(unittest.TestCase):

def setUp(self):
pass

Expand Down
1 change: 0 additions & 1 deletion xstools/Erase_Flash.XES

This file was deleted.

3 changes: 0 additions & 3 deletions xstools/XstoolsApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@

"""
"""

from xsdutio import *
from xsmemio import *
5 changes: 3 additions & 2 deletions xstools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os

# Make a global variable for finding resources the programs need like icon and bitstream files.
# Make a global variable for finding resources the programs need like icon and
# bitstream files.
install_dir = os.path.dirname(__file__)

__author__ = 'XESS Corporation'
__email__ = 'info@xess.com'
__version__ = '0.1.31'
__version__ = '0.1.31-python3-dev'

0 comments on commit 44139ad

Please sign in to comment.