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
use crate::core::prelude::*;
#[derive(Clone, Debug, LogicBlock)]
pub struct DFF<T: Synth> {
pub d: Signal<In, T>,
pub q: Signal<Out, T>,
pub clk: Signal<In, Clock>,
}
impl<T: Synth> Default for DFF<T> {
fn default() -> DFF<T> {
Self::new(T::default())
}
}
impl<T: Synth> DFF<T> {
pub fn new(init: T) -> DFF<T> {
Self {
d: Signal::default(),
q: Signal::new_with_default(init),
clk: Signal::default(),
}
}
}
impl<T: Synth> Logic for DFF<T> {
fn update(&mut self) {
if self.clk.pos_edge() {
self.q.next = self.d.val()
}
}
fn connect(&mut self) {
self.q.connect();
}
fn hdl(&self) -> Verilog {
Verilog::Custom(format!(
"\
initial begin
q = {:x};
end
always @(posedge clk) q <= d;",
self.q.verilog()
))
}
}