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
use std::fmt::Debug;
#[repr(transparent)]
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)]
pub struct Clock {
pub clk: bool,
}
pub const NANOS_PER_FEMTO: f64 = 1_000_000.0;
pub fn freq_hz_to_period_femto(freq: f64) -> f64 {
(1.0e15 / freq).round()
}
#[test]
fn test_freq_to_period_mapping() {
assert_eq!(freq_hz_to_period_femto(1.0), 1.0e15)
}
impl std::ops::Not for Clock {
type Output = Clock;
fn not(self) -> Self::Output {
Clock { clk: !self.clk }
}
}
impl From<bool> for Clock {
fn from(x: bool) -> Clock {
Clock { clk: x }
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)]
pub struct Reset {
pub rst: bool,
}
pub const NO_RESET: Reset = Reset { rst: false };
pub const RESET: Reset = Reset { rst: true };
impl Into<bool> for Reset {
fn into(self) -> bool {
self.rst
}
}
impl std::ops::Not for Reset {
type Output = bool;
fn not(self) -> Self::Output {
!self.rst
}
}
#[macro_export]
macro_rules! clock_reset {
($self: ident, $clock: ident, $reset: ident, $($subs: ident), +) => {
$($self.$subs.clock.next = $self.$clock.val());+;
$($self.$subs.reset.next = $self.$reset.val());+;
}
}