add width check function to utils
This commit is contained in:
parent
ea6b3f73b9
commit
3f724b3336
|
|
@ -187,8 +187,9 @@ class LogicAnalyzerCore(Elaboratable):
|
|||
|
||||
def get_max_addr(self):
|
||||
"""
|
||||
Return the maximum addresses in memory used by the core. The address space used
|
||||
by the core extends from `base_addr` to the number returned by this function.
|
||||
Return the maximum addresses in memory used by the core. The address
|
||||
space used by the core extends from `base_addr` to the number returned
|
||||
by this function.
|
||||
"""
|
||||
return self.sample_mem.get_max_addr()
|
||||
|
||||
|
|
|
|||
|
|
@ -52,8 +52,9 @@ class LogicAnalyzerFSM(Elaboratable):
|
|||
|
||||
def get_max_addr(self):
|
||||
"""
|
||||
Return the maximum addresses in memory used by the core. The address space used
|
||||
by the core extends from `base_addr` to the number returned by this function.
|
||||
Return the maximum addresses in memory used by the core. The address
|
||||
space used by the core extends from `base_addr` to the number returned
|
||||
by this function.
|
||||
"""
|
||||
return self.r.get_max_addr()
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ class LogicAnalyzerTriggerBlock(Elaboratable):
|
|||
|
||||
def get_max_addr(self):
|
||||
"""
|
||||
Return the maximum addresses in memory used by the core. The address space used
|
||||
by the core extends from `base_addr` to the number returned by this function.
|
||||
Return the maximum addresses in memory used by the core. The address
|
||||
space used by the core extends from `base_addr` to the number returned
|
||||
by this function.
|
||||
"""
|
||||
return self.r.get_max_addr()
|
||||
|
||||
|
|
|
|||
|
|
@ -152,8 +152,9 @@ class ReadOnlyMemoryCore(Elaboratable):
|
|||
|
||||
def get_max_addr(self):
|
||||
"""
|
||||
Return the maximum addresses in memory used by the core. The address space used
|
||||
by the core extends from `base_addr` to the number returned by this function.
|
||||
Return the maximum addresses in memory used by the core. The address
|
||||
space used by the core extends from `base_addr` to the number returned
|
||||
by this function.
|
||||
"""
|
||||
return self._max_addr
|
||||
|
||||
|
|
|
|||
|
|
@ -38,16 +38,27 @@ def words_to_value(data):
|
|||
concatenates them together in little-endian order.
|
||||
"""
|
||||
|
||||
for d in data:
|
||||
if d > 0 and d > 2**16 - 1:
|
||||
raise ValueError("Unsigned integer too large.")
|
||||
|
||||
if d < 0 and d < -(2**15):
|
||||
raise ValueError("Signed integer too large.")
|
||||
[check_value_fits_in_bits(d, 16) for d in data]
|
||||
|
||||
return int("".join([f"{i:016b}" for i in data[::-1]]), 2)
|
||||
|
||||
|
||||
def check_value_fits_in_bits(value, n_bits):
|
||||
"""
|
||||
Rasies an exception if the provided value isn't an integer that cannot
|
||||
be expressed with the provided number of bits.
|
||||
"""
|
||||
|
||||
if not isinstance(value, int):
|
||||
raise TypeError("Value must be an integer.")
|
||||
|
||||
if value > 0 and value > 2**n_bits - 1:
|
||||
raise ValueError("Unsigned integer too large.")
|
||||
|
||||
if value < 0 and value < -(2 ** (n_bits - 1)):
|
||||
raise ValueError("Signed integer too large.")
|
||||
|
||||
|
||||
def value_to_words(data, n_words):
|
||||
"""
|
||||
Takes a integer, interprets it as a set of 16-bit integers
|
||||
|
|
|
|||
Loading…
Reference in New Issue