Skip to content

Commit 73f3764

Browse files
committed
Refactoring
1 parent f6a9802 commit 73f3764

18 files changed

Lines changed: 1072 additions & 1042 deletions

examples/vhdl/embedded_python/run.py

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,85 @@
66

77
from pathlib import Path
88
from vunit import VUnit
9-
from vunit.python_fli_compile import compile_vhpi_application, compile_fli_application
9+
from vunit.python_pkg import compile_vhpi_application, compile_fli_application
10+
1011

1112
def hello_world():
1213
print("Hello World")
1314

15+
1416
class Plot():
1517

16-
def __init__(self, x_points, y_limits, title, x_label, y_label):
17-
from matplotlib import pyplot as plt
18-
19-
# Create plot with a line based on x and y vectors before they have been calculated
20-
# Starting with an uncalculated line and updating it as we calculate more points
21-
# is a trick to make the rendering of the plot quicker. This is not a bottleneck
22-
# created by the VHDL package but inherent to the Python matplotlib package.
23-
fig = plt.figure()
24-
plt.xlabel(x_label)
25-
plt.ylabel(y_label)
26-
plt.title(title)
27-
plt.xlim(x_points[0], x_points[-1])
28-
plt.ylim(*y_limits)
29-
x_vector = [x_points[0]] * len(x_points)
30-
y_vector = [(y_limits[0] + y_limits[1]) / 2] * len(x_points)
31-
line, = plt.plot(x_vector, y_vector, 'r-')
32-
fig.canvas.draw()
33-
fig.canvas.flush_events()
34-
plt.show(block=False)
35-
36-
self.plt = plt
37-
self.fig = fig
38-
self.x_vector = x_vector
39-
self.y_vector = y_vector
40-
self.line = line
41-
42-
def update(self, x, y):
43-
self.x_vector[x] = x
44-
self.y_vector[x] = y
45-
self.line.set_xdata(self.x_vector)
46-
self.line.set_ydata(self.y_vector)
47-
self.fig.canvas.draw()
48-
self.fig.canvas.flush_events()
49-
50-
def close(self):
51-
# Some extra code to allow showing the plot without blocking
52-
# the test indefinitely if window isn't closed.
53-
timer = self.fig.canvas.new_timer(interval=5000)
54-
timer.add_callback(self.plt.close)
55-
timer.start()
56-
self.plt.show()
18+
def __init__(self, x_points, y_limits, title, x_label, y_label):
19+
from matplotlib import pyplot as plt
20+
21+
# Create plot with a line based on x and y vectors before they have been calculated
22+
# Starting with an uncalculated line and updating it as we calculate more points
23+
# is a trick to make the rendering of the plot quicker. This is not a bottleneck
24+
# created by the VHDL package but inherent to the Python matplotlib package.
25+
fig = plt.figure()
26+
plt.xlabel(x_label)
27+
plt.ylabel(y_label)
28+
plt.title(title)
29+
plt.xlim(x_points[0], x_points[-1])
30+
plt.ylim(*y_limits)
31+
x_vector = [x_points[0]] * len(x_points)
32+
y_vector = [(y_limits[0] + y_limits[1]) / 2] * len(x_points)
33+
line, = plt.plot(x_vector, y_vector, 'r-')
34+
fig.canvas.draw()
35+
fig.canvas.flush_events()
36+
plt.show(block=False)
37+
38+
self.plt = plt
39+
self.fig = fig
40+
self.x_vector = x_vector
41+
self.y_vector = y_vector
42+
self.line = line
43+
44+
def update(self, x, y):
45+
self.x_vector[x] = x
46+
self.y_vector[x] = y
47+
self.line.set_xdata(self.x_vector)
48+
self.line.set_ydata(self.y_vector)
49+
self.fig.canvas.draw()
50+
self.fig.canvas.flush_events()
51+
52+
def close(self):
53+
# Some extra code to allow showing the plot without blocking
54+
# the test indefinitely if window isn't closed.
55+
timer = self.fig.canvas.new_timer(interval=5000)
56+
timer.add_callback(self.plt.close)
57+
timer.start()
58+
self.plt.show()
5759

5860

5961
def main():
60-
root = Path(__file__).parent
61-
62-
vu = VUnit.from_argv()
63-
vu.add_vhdl_builtins()
64-
vu.add_python()
65-
vu.add_random()
66-
vu.enable_location_preprocessing()
67-
simulator_name = vu.get_simulator_name()
68-
69-
if simulator_name in ["rivierapro", "activehdl"]:
70-
# TODO: Include VHPI application compilation in VUnit
71-
# NOTE: A clean build will delete the output after it was created so another no clean build has to be performed.
72-
compile_vhpi_application(root, simulator_name)
73-
elif simulator_name == "modelsim":
74-
compile_fli_application(root, vu)
75-
76-
lib = vu.add_library("lib")
77-
lib.add_source_files(root / "*.vhd")
78-
79-
vu.set_compile_option("rivierapro.vcom_flags" , ["-dbg"])
80-
vu.set_sim_option("rivierapro.vsim_flags" , ["-interceptcoutput"])
81-
# Crashes RPRO for some reason. TODO: Fix when the C code is properly
82-
# integrated into the project. Must be able to debug the C code.
83-
# vu.set_sim_option("rivierapro.vsim_flags" , ["-cdebug"])
84-
85-
vu.main()
62+
root = Path(__file__).parent
63+
64+
vu = VUnit.from_argv()
65+
vu.add_vhdl_builtins()
66+
vu.add_python()
67+
vu.add_random()
68+
vu.enable_location_preprocessing()
69+
simulator_name = vu.get_simulator_name()
70+
71+
if simulator_name in ["rivierapro", "activehdl"]:
72+
# TODO: Include VHPI application compilation in VUnit
73+
# NOTE: A clean build will delete the output after it was created so another no clean build has to be performed.
74+
compile_vhpi_application(root, vu)
75+
elif simulator_name == "modelsim":
76+
compile_fli_application(root, vu)
77+
78+
lib = vu.add_library("lib")
79+
lib.add_source_files(root / "*.vhd")
80+
81+
vu.set_compile_option("rivierapro.vcom_flags" , ["-dbg"])
82+
vu.set_sim_option("rivierapro.vsim_flags" , ["-interceptcoutput"])
83+
# Crashes RPRO for some reason. TODO: Fix when the C code is properly
84+
# integrated into the project. Must be able to debug the C code.
85+
# vu.set_sim_option("rivierapro.vsim_flags" , ["-cdebug"])
86+
87+
vu.main()
8688

8789

8890
if __name__ == "__main__":

0 commit comments

Comments
 (0)