Skip to content

Commit 9d14936

Browse files
authored
Fxp support (#15)
* Starting to lay down some work * First pass at FXP no testing yet * Fixing bugs and adding unit tests * Adding more unit tests * Have bitfile parsing cast correctly so FXP_Register contains correct values * Lots of changes Read is working correctly * Bug fixes * Pep 8 fixes * comments * merge with master * A few comment updates * Removing string based implementation Now both read and write will calculate the read and write values using the calculated delta. This as a response to the review. In doing so I was able to remove the fixedPointHelper, the only thing left in that file was the warn, which I moved to a method of session._FXPRegister I updated the tests to now work with the correct implementation my next commit will include a test clean up * Unit test clean -up * Refactor overflow bit Rather than its own seperate property overflow status is now read as a tuple and written to as a tuple for a FXP register with overflow enabled. Unit tests again all post, required some refactoring * Increase precision to not have rounding for larger integer words * Bitfile changes * Fix bug in reading 64 bit FXP with overflow automated hardware tests now all work. * Make FxpRegister inherit from Register not ArrayRegister * Did not mean to commit these * Comments * Flake 8 Fixes removing check for w503 that flake 8 seems to think foo(5 + 6 + 7 + 8) is better than foo(5 + 6 + 7 + 8) Even though Pep 8 says otherwise * Pep 8 * Fix 3.x builds * 3.x Does not support error.message Removing the custom input text. Users must look at documentation now * Responding to reviews * Small fixes for reviews * Remove new line * Spelling
1 parent c24880e commit 9d14936

File tree

6 files changed

+630
-29
lines changed

6 files changed

+630
-29
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ install:
88
- "pip install flake8"
99
- "pip install -r requirements.txt"
1010
before_script:
11-
- "flake8 nifpga --ignore=E501"
11+
- "flake8 nifpga --ignore=E501,W503 "
1212
script:
1313
- "nosetests --with-doctest"

nifpga/bitfile.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, filepath, parse_contents=False):
2828
self._base_address_on_device = int(nifpga.find("BaseAddressOnDevice").text)
2929
self._registers = {}
3030
for reg_xml in tree.find("VI").find("RegisterList"):
31-
reg = Register(reg_xml)
31+
reg = self.create_register(reg_xml)
3232
if reg.datatype is not None:
3333
assert reg.name not in self._registers, \
3434
"One or more registers have the same name '%s', this is not supported" % reg.name
@@ -71,6 +71,19 @@ def base_address_on_device(self):
7171
"""
7272
return self._base_address_on_device
7373

74+
def create_register(self, xml):
75+
if self._is_register_fxp(xml):
76+
return FxpRegister(xml)
77+
else:
78+
return Register(xml)
79+
80+
def _is_register_fxp(self, reg_xml):
81+
datatype = reg_xml.find("Datatype")
82+
for child in datatype.getchildren():
83+
if str(DataType.Fxp).lower() not in child.tag.lower():
84+
return False
85+
return True
86+
7487

7588
class Register(object):
7689
def __init__(self, reg_xml):
@@ -171,6 +184,40 @@ def __str__(self):
171184
"\tOffset: %d\n" % self._offset)
172185

173186

187+
class FxpRegister(Register):
188+
"""
189+
A fixed point control or indicator from the front panel of the top level
190+
FPGA VI.
191+
"""
192+
def __init__(self, reg_xml):
193+
super(FxpRegister, self).__init__(reg_xml)
194+
datatype = reg_xml.find("Datatype")
195+
fxp_xml = datatype.find("FXP")
196+
self._signed = True if fxp_xml.find("Signed").text.lower() == 'true' else False
197+
self._overflow = True if fxp_xml.find("IncludeOverflowStatus").text.lower() == 'true' else False
198+
self._word_length = int(fxp_xml.find("WordLength").text)
199+
self._integer_word_length = int(fxp_xml.find("IntegerWordLength").text)
200+
201+
def __len__(self):
202+
return 1
203+
204+
@property
205+
def signed(self):
206+
return self._signed
207+
208+
@property
209+
def word_length(self):
210+
return self._word_length
211+
212+
@property
213+
def integer_word_length(self):
214+
return self._integer_word_length
215+
216+
@property
217+
def overflow(self):
218+
return self._overflow
219+
220+
174221
class Fifo(object):
175222
def __init__(self, channel_xml):
176223
self._name = channel_xml.attrib["name"]

nifpga/nifpga.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class DataType(Enum):
2626
U64 = 9
2727
Sgl = 10
2828
Dbl = 11
29+
Fxp = 12
2930

3031
def __str__(self):
3132
return self.name
@@ -44,6 +45,7 @@ def _return_ctype(self):
4445
DataType.U64: ctypes.c_uint64,
4546
DataType.Sgl: ctypes.c_float,
4647
DataType.Dbl: ctypes.c_double,
48+
DataType.Fxp: ctypes.c_uint32,
4749
}
4850
return _datatype_ctype[self]
4951

@@ -369,6 +371,8 @@ def __init__(self):
369371
] # list of function_infos
370372

371373
for datatype in DataType:
374+
if datatype == DataType.Fxp:
375+
continue # Fixed point does not have read write entry points.
372376
type_ctype = datatype._return_ctype()
373377
library_function_infos.extend([
374378
LibraryFunctionInfo(
@@ -452,7 +456,6 @@ def __init__(self):
452456
NamedArgtype("elements remaining", ctypes.POINTER(ctypes.c_size_t)),
453457
]),
454458
]) # end of library_function_infos.extend() call
455-
456459
for fifoPropertyType in FifoPropertyType:
457460
type_ctype = fifoPropertyType._return_ctype()
458461
library_function_infos.extend([
@@ -475,6 +478,7 @@ def __init__(self):
475478
NamedArgtype("value", type_ctype),
476479
]),
477480
])
481+
478482
try:
479483
super(_NiFpga, self).__init__(library_name="NiFpga",
480484
library_function_infos=library_function_infos)

0 commit comments

Comments
 (0)