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
use rust_hdl_core::prelude::*;
#[derive(Copy, Clone, PartialEq, Debug, LogicState)]
pub enum SDRAMCommand {
LoadModeRegister, AutoRefresh, Precharge, BurstTerminate, Write, Read, Active, NOP, }
#[derive(LogicBlock, Default)]
pub struct SDRAMCommandEncoder {
pub ras_not: Signal<Out, Bit>,
pub cas_not: Signal<Out, Bit>,
pub we_not: Signal<Out, Bit>,
pub cs_not: Signal<Out, Bit>,
pub cmd: Signal<In, SDRAMCommand>,
}
impl Logic for SDRAMCommandEncoder {
#[hdl_gen]
fn update(&mut self) {
self.cs_not.next = false;
match self.cmd.val() {
SDRAMCommand::LoadModeRegister => {
self.ras_not.next = false;
self.cas_not.next = false;
self.we_not.next = false;
}
SDRAMCommand::AutoRefresh => {
self.ras_not.next = false;
self.cas_not.next = false;
self.we_not.next = true;
}
SDRAMCommand::Precharge => {
self.ras_not.next = false;
self.cas_not.next = true;
self.we_not.next = false;
}
SDRAMCommand::BurstTerminate => {
self.ras_not.next = true;
self.cas_not.next = true;
self.we_not.next = false;
}
SDRAMCommand::Write => {
self.ras_not.next = true;
self.cas_not.next = false;
self.we_not.next = false;
}
SDRAMCommand::Read => {
self.ras_not.next = true;
self.cas_not.next = false;
self.we_not.next = true;
}
SDRAMCommand::Active => {
self.ras_not.next = false;
self.cas_not.next = true;
self.we_not.next = true;
}
SDRAMCommand::NOP => {
self.ras_not.next = true;
self.cas_not.next = true;
self.we_not.next = true;
}
_ => {}
}
}
}
#[derive(LogicBlock, Default)]
pub struct SDRAMCommandDecoder {
pub ras_not: Signal<In, Bit>,
pub cas_not: Signal<In, Bit>,
pub we_not: Signal<In, Bit>,
pub cs_not: Signal<In, Bit>,
pub cmd: Signal<Out, SDRAMCommand>,
}
impl Logic for SDRAMCommandDecoder {
#[hdl_gen]
fn update(&mut self) {
self.cmd.next = SDRAMCommand::NOP;
if !self.cs_not.val() {
if self.ras_not.val() & self.cas_not.val() & self.we_not.val() {
self.cmd.next = SDRAMCommand::NOP;
} else if self.ras_not.val() & self.cas_not.val() & !self.we_not.val() {
self.cmd.next = SDRAMCommand::BurstTerminate;
} else if self.ras_not.val() & !self.cas_not.val() & self.we_not.val() {
self.cmd.next = SDRAMCommand::Read;
} else if self.ras_not.val() & !self.cas_not.val() & !self.we_not.val() {
self.cmd.next = SDRAMCommand::Write;
} else if !self.ras_not.val() & self.cas_not.val() & self.we_not.val() {
self.cmd.next = SDRAMCommand::Active;
} else if !self.ras_not.val() & self.cas_not.val() & !self.we_not.val() {
self.cmd.next = SDRAMCommand::Precharge;
} else if !self.ras_not.val() & !self.cas_not.val() & self.we_not.val() {
self.cmd.next = SDRAMCommand::AutoRefresh;
} else if !self.ras_not.val() & !self.cas_not.val() & !self.we_not.val() {
self.cmd.next = SDRAMCommand::LoadModeRegister;
}
}
}
}