Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
gasparka committed Aug 6, 2018
1 parent d0b1a2a commit ec7a24d
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 239 deletions.
43 changes: 0 additions & 43 deletions pyha/common/stream.py

This file was deleted.

61 changes: 0 additions & 61 deletions pyha/common/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,67 +103,6 @@ def np_to_py(array):
return array


def snr(pure, noisy):
sig_pow = np.mean(np.abs(pure))
error = np.array(pure) - np.array(noisy)
err_pow = np.mean(np.abs(error))

snr_db = 20 * np.log10(sig_pow / err_pow)
return snr_db


def show_plot():
import matplotlib.pyplot as plt
plt.tight_layout()
plt.grid()
if plt.gca().get_legend_handles_labels() != ([], []):
plt.legend()
plt.show()


class SignalTapParser:
def __init__(self, file: str):
import csv

self.labels = []
self.data = []
with open(file) as csvfile:
reader = csv.reader(csvfile)
for x in reader:
if len(x) and x[0] == 'Data:':
self.labels = next(reader)
self.data = [x for x in reader]

self.trans_data = np.array(self.data).T

def __getitem__(self, item: str):
i = self.labels.index(item)
return self.trans_data[i]

def to_int(self, data, bits):
r = []
for x in data:
with suppress(ValueError):
new = int(x, 16)
if new >= 2 ** (bits - 1): # conv to signed
new -= 2 ** (bits)
r.append(new)
return r

# NB! these wont work if you export sfixed signal( has negative bounds in name )
# need to invert msb or something
def to_float(self, data, bits):
""" assume 1 sign others fractional"""
ints = self.to_int(data, bits)
return np.array(ints) / 2 ** (bits - 1)

def to_bladerf(self, data):
""" assume 5 bit is for integer(1 bit is sign) and others for fractional part
This is used in bladeRF """
ints = self.to_int(data, 16)
return np.array(ints) / 2 ** (11)


def to_signed_int(number, bit_length):
# http://stackoverflow.com/questions/1375897/how-to-get-the-signed-integer-value-of-a-long-in-python
mask = (2 ** bit_length) - 1
Expand Down
41 changes: 0 additions & 41 deletions pyha/conversion/python_types_vhdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,29 +443,6 @@ def _pyha_typedef(self):
self.elems[0]._pyha_type())
return None # arrays of submodules are already defined in each submodule package!

def _pyha_init(self):
if not self.elements_compatible_typed:
return '\n'.join(x._pyha_init() for x in self.elems)

if self.not_submodules_list:
return super()._pyha_init()

inits = ['{}.pyha_init_next(self.{}({}));'.format(self.elems[0]._pyha_module_name(), self._pyha_name(), i)
for i in range(len(self.current))]
return '\n'.join(inits)

def _pyha_update_registers(self):
if not self.elements_compatible_typed:
return '\n'.join(x._pyha_update_registers() for x in self.elems)

if self.not_submodules_list:
return super()._pyha_update_registers()

inits = [
'{}.pyha_update_registers(self.{}({}));'.format(self.elems[0]._pyha_module_name(), self._pyha_name(), i)
for i in range(len(self.current))]
return '\n'.join(inits)

def _pyha_reset(self, prefix='self', filter_func=None) -> str:
if filter_func:
if not filter_func(self):
Expand Down Expand Up @@ -604,12 +581,6 @@ def _pyha_arr_type_name(self):
elem_type = elem_type.replace('(', '').replace(')', '').replace(' ', '').replace('-', '_').replace('.', '_')
return '{}_list_t{}'.format(elem_type, TypeAppendHack)

def _pyha_init(self) -> str:
return '{}.pyha_init_next(self.{});'.format(self._pyha_module_name(), self._pyha_name())

def _pyha_update_registers(self):
return '{}.pyha_update_registers(self.{});'.format(self._pyha_module_name(), self._pyha_name())

def _pyha_reset(self, prefix='self', filter_func=None):
if filter_func:
if not filter_func(self):
Expand All @@ -624,18 +595,6 @@ def _pyha_reset(self, prefix='self', filter_func=None):
ret += sub._pyha_reset(tmp_prefix, filter_func=filter_func) # recursive
return ret

def _pyha_recursive_object_assign(self, prefix='self', other_name="other"):
ret = ''
for i, sub in enumerate(self.elems):
tmp_prefix = prefix
tmp_other = other_name
if self._name != '-':
if self._name[0] != '[':
tmp_prefix += f'.{self._pyha_name()}'
tmp_other += f'.{self._pyha_name()}'
ret += sub._pyha_recursive_object_assign(tmp_prefix, tmp_other) # recursive
return ret

def _pyha_type_is_compatible(self, other) -> bool:
if type(self.current) != type(other.current):
return False
Expand Down
83 changes: 0 additions & 83 deletions pyha/conversion/redbaron_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,89 +514,6 @@ def build_imports(self):
imports = [f'use work.{x}.all;' for x in Conversion.converted_names]
return template.format(IMPORTS=formatter(imports))

def build_deepcopy(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_deepcopy(self:inout self_t; other: in self_t) is
-- copy 'other' to 'self.next'. ':=' cannot be used as it would directly copy to 'self'
begin
{DATA}
end procedure;""")

if prototype_only:
return template.splitlines()[0][:-3] + ';'
data = [x._pyha_recursive_object_assign() for x in self.data.elems]
return template.format(DATA=formatter(data))

def build_list_deepcopy(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_list_deepcopy(self:inout {DTYPE}; other: in {DTYPE}) is
-- run deepcopy for each list element
begin
for i in self'range loop
pyha_deepcopy(self(i), other(i));
end loop;
end procedure;""")

dtype = self.data._pyha_arr_type_name()
template = template.format(DTYPE=dtype)
if prototype_only:
return template.splitlines()[0][:-3] + ';'
return template

def build_reset(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_reset(self:inout self_t) is
-- executed on reset signal. Reset values are determined from initial values of Python variables.
begin
{DATA}
pyha_update_registers(self);
end procedure;""")

if prototype_only:
return template.splitlines()[0][:-3] + ';'
data = [x._pyha_reset() for x in self.data.elems if not is_constant(x._name)]
return template.format(DATA=formatter(data))

def build_reset_constants(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_reset_constants(self:inout self_t) is
-- reset CONSTANTS, executed before 'main'. Helps synthesis tools to determine constants.
begin
{DATA}
end procedure;""")

if prototype_only:
return template.splitlines()[0][:-3] + ';'
data = [x._pyha_reset_constants() for x in self.data.elems]
return template.format(DATA=formatter(data))

def build_update_registers(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_update_registers(self:inout self_t) is
-- loads 'next' values to registers, executed on clock rising edge
begin
{DATA}
end procedure;""")

if prototype_only:
return template.splitlines()[0][:-3] + ';'
data = [x._pyha_update_registers() for x in self.data.elems]
return template.format(DATA=formatter(data))

def build_init(self, prototype_only=False):
template = textwrap.dedent("""\
procedure pyha_init_next(self:inout self_t) is
-- sets all .next's to current register values, executed before 'main'.
-- thanks to this, '.next' variables are always written before read, so they can never be registers
begin
{DATA}
end procedure;""")

if prototype_only:
return template.splitlines()[0][:-3] + ';'
data = [x._pyha_init() for x in self.data.elems]
return template.format(DATA=formatter(data))

def build_constructor(self, prototype_only=False):
template = textwrap.dedent("""\
function {NAME}{ARGS} return self_t is
Expand Down
2 changes: 1 addition & 1 deletion pyha/simulation/sim_include/cocotb_simulation_top.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cocotb.result import ReturnValue # pragma: no cover
from cocotb.triggers import RisingEdge, Timer # pragma: no cover
from tqdm import tqdm # pragma: no cover
import sys
import sys # pragma: no cover


@cocotb.coroutine # pragma: no cover
Expand Down
2 changes: 0 additions & 2 deletions pyha/simulation/simulation_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
from pyha import Hardware
from pyha.common.complex import default_complex
from pyha.common.context_managers import RegisterBehaviour, SimulationRunning, SimPath, AutoResize
from pyha.common.core import PyhaFunc
from pyha.common.fixed_point import Sfix, default_sfix
from pyha.common.stream import packetize, Stream, unpacketize
from pyha.common.util import get_iterable, np_to_py
from pyha.conversion.python_types_vhdl import init_vhdl_type
from pyha.simulation.vhdl_simulation import VHDLSimulation
Expand Down
8 changes: 0 additions & 8 deletions tests/test_python_types_vhdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,6 @@ def test_pyha_type(self):
expect = 'T_0.self_t'
assert self.dut._pyha_type() == expect

def test_pyha_init(self):
expect = 'T_0.pyha_init_next(self.name);'
assert self.dut._pyha_init() == expect

def test_pyha_update_registers(self):
expect = 'T_0.pyha_update_registers(self.name);'
assert self.dut._pyha_update_registers() == expect

def test_pyha_type_is_compatible(self):
class A(Hardware):
def __init__(self, init):
Expand Down

0 comments on commit ec7a24d

Please sign in to comment.