-
Notifications
You must be signed in to change notification settings - Fork 1
/
ppm_testbench.py
99 lines (75 loc) · 2.8 KB
/
ppm_testbench.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from migen import *
from migen.genlib.resetsync import AsyncResetSynchronizer
import ppm
import ppm_input_testbench
import ppm_output_testbench
class PPMRoundTrip(Module):
def __init__(self,
channels=8,
timeout=4000e3,
frequency=50,
default_clk_period=1e9/16e6,
resolution=1e3,
pulse_width=300e3,
max_width=2000e3,
min_width=500e3,
):
self.submodules.ppm_tx = ppm.PPMoutput(
channels=channels,
frequency=frequency,
default_clk_period=default_clk_period,
resolution=resolution,
pulse_width=pulse_width,
max_width=max_width,
min_width=min_width
)
self.submodules.ppm_rx = ppm.PPMinput(
channels=channels,
timeout=timeout,
default_clk_period=default_clk_period,
resolution=resolution
)
self.comb += self.ppm_rx.ppm.eq(self.ppm_tx.ppm)
def print_state(dut):
yield from ppm_input_testbench.print_state(dut.ppm_rx)
yield from ppm_output_testbench.print_state(dut.ppm_tx)
def test_0(dut, channel_vals):
for chan in range(len(channel_vals)):
yield dut.ppm_tx.widths[chan].eq(channel_vals[chan])
yield
yield from print_state(dut)
yield from ppm_input_testbench.skip_us(dut.ppm_rx, 20000)
yield from print_state(dut)
for chan in range(len(channel_vals)):
assert (yield dut.ppm_tx.widths[chan]) == (yield dut.ppm_rx.widths[chan])
def testbench(dut):
yield from test_0(dut, [
1500,
500,
1500,
2000,
700,
1600,
1500,
1400,
])
if __name__ == "__main__":
channels=8
timeout=5e6
frequency=50
default_clk_period=1e9/16e6
resolution=1e3
pulse_width=300e3
max_width=2000e3
min_width=500e3
ppm_round_trip = PPMRoundTrip(
channels=channels,
timeout=timeout,
frequency=frequency,
default_clk_period=default_clk_period,
resolution=resolution,
pulse_width=pulse_width,
max_width=max_width,
min_width=min_width
)
run_simulation(ppm_round_trip, testbench(ppm_round_trip))