-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommunicator.py
More file actions
55 lines (47 loc) · 1.58 KB
/
Copy pathcommunicator.py
File metadata and controls
55 lines (47 loc) · 1.58 KB
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
import pyrtl
from fsm import FSM
valid = pyrtl.Input(bitwidth=1, name="valid")
ready = pyrtl.Input(bitwidth=1, name="ready")
m1_out = pyrtl.WireVector(bitwidth=1, name="m1_out")
m2_out = pyrtl.WireVector(bitwidth=1, name="m2_out")
transfer = pyrtl.Output(bitwidth=1, name="output")
m1_in = pyrtl.WireVector(bitwidth=2, name="m1_in")
m2_in = pyrtl.WireVector(bitwidth=2, name="m2_in")
m1_in <<= pyrtl.corecircuits.concat(valid, m2_out)
m2_in <<= pyrtl.corecircuits.concat(ready, m1_out)
m1_states = ["Inactive", "Waiting", "Active"]
m1_rules = [
"all + 0 -> Inactive, 0",
"all + 1 -> Inactive, 0",
"all + 2 -> Waiting, 0",
"all + 3 -> Active, 1",
]
m2_states = ["Inactive", "Waiting", "Active"]
m2_rules = [
"all + 0 -> Inactive, 0",
"all + 1 -> Inactive, 0",
"all + 2 -> Waiting, 1",
"all + 3 -> Active, 1"
]
machine1 = FSM(input_bitwidth=2, output_bitwidth=1, states=m1_states, rulesList=m1_rules)
machine2 = FSM(input_bitwidth=2, output_bitwidth=1, states=m2_states, rulesList=m2_rules)
machine1 <<= m1_in
machine2 <<= m2_in
m1_out <<= machine1()[0]
m2_out <<= machine2()[0]
with pyrtl.conditional_assignment:
with machine1()[1] == 2:
with machine2()[1] == 2:
transfer |= 1
with pyrtl.otherwise:
transfer |= 0
with pyrtl.otherwise:
transfer |= 0
sim_trace = pyrtl.SimulationTrace()
sim = pyrtl.Simulation(tracer=sim_trace)
sim_inputs = {
'valid' : '0010111111001111',
'ready' : '0000000111111100'
}
sim.step_multiple(sim_inputs)
sim_trace.render_trace(trace_list=['valid', 'ready', 'm1_out','m2_out', 'output'])