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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use crate::core::prelude::*;
#[derive(Clone, Debug, LogicBlock)]
pub struct WireOut {
pub ok1: Signal<In, Bits<31>>,
pub ok2: Signal<Out, Bits<17>>,
pub datain: Signal<In, Bits<16>>,
_n: u8,
}
impl WireOut {
pub fn new(port: u8) -> Self {
assert!(port >= 0x20 && port < 0x40);
Self {
ok1: Default::default(),
ok2: Default::default(),
datain: Default::default(),
_n: port,
}
}
}
impl Logic for WireOut {
fn update(&mut self) {}
fn connect(&mut self) {
self.ok2.connect();
}
fn hdl(&self) -> Verilog {
let name = format!("WireOut_{:x}", self._n);
Verilog::Blackbox(BlackBox {
code: format!(
r#"
module {}
(
input wire [30:0] ok1,
output wire [16:0] ok2,
input wire [15:0] datain
);
okWireOut mod_wire(.ok1(ok1),
.ok2(ok2),
.ep_addr({:x}),
.ep_datain(datain));
endmodule
(* blackbox *)
module okWireOut(
input wire [30:0] ok1,
output wire [16:0] ok2,
input wire [7:0] ep_addr,
input wire [15:0] ep_datain
);
endmodule "#,
name,
VerilogLiteral::from(self._n)
),
name,
})
}
}
#[test]
fn test_wire_out_synth() {
let mut uut = TopWrap::new(WireOut::new(0x20));
uut.uut.ok1.connect();
uut.uut.datain.connect();
uut.uut.connect_all();
yosys_validate("wire_out", &generate_verilog(&uut)).unwrap();
}
#[derive(Clone, Debug, LogicBlock)]
pub struct WireIn {
pub ok1: Signal<In, Bits<31>>,
pub dataout: Signal<Out, Bits<16>>,
_n: u8,
}
impl WireIn {
pub fn new(n: u8) -> WireIn {
assert!(n < 0x20);
WireIn {
ok1: Default::default(),
dataout: Default::default(),
_n: n,
}
}
}
impl Logic for WireIn {
fn update(&mut self) {}
fn connect(&mut self) {
self.dataout.connect();
}
fn hdl(&self) -> Verilog {
let name = format!("WireIn_{:x}", self._n);
Verilog::Blackbox(BlackBox {
code: format!(
r#"
module {}
(
input wire [30:0] ok1,
output wire [15:0] dataout
);
okWireIn mod_wire(.ok1(ok1),
.ep_addr({:x}),
.ep_dataout(dataout));
endmodule
(* blackbox *)
module okWireIn(
input wire [30:0] ok1,
input wire [7:0] ep_addr,
output wire [15:0] ep_dataout
);
endmodule "#,
name,
VerilogLiteral::from(self._n)
),
name,
})
}
}
#[test]
fn test_wire_in_synth() {
let mut uut = TopWrap::new(WireIn::new(0x02));
uut.uut.ok1.connect();
uut.connect_all();
yosys_validate("wire_in", &generate_verilog(&uut)).unwrap();
}