-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaturn_bus.v
More file actions
253 lines (212 loc) · 7.13 KB
/
saturn_bus.v
File metadata and controls
253 lines (212 loc) · 7.13 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
(c) Raphaël Jacquot 2019
This file is part of hp_saturn.
hp_saturn is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
hp_saturn is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <https://www.gnu.org/licenses/>.
*/
`default_nettype none
module saturn_bus (
i_clk,
i_clk_en,
i_reset,
o_halt,
o_phase,
o_cycle_ctr,
o_instr_decoded,
o_debug_cycle,
o_char_to_send,
o_char_counter,
o_char_valid,
o_char_send,
i_serial_busy
);
input wire [0:0] i_clk;
input wire [0:0] i_clk_en;
input wire [0:0] i_reset;
output wire [0:0] o_halt;
output wire [1:0] o_phase;
output wire [31:0] o_cycle_ctr;
output wire [0:0] o_instr_decoded;
output wire [0:0] o_debug_cycle;
assign o_debug_cycle = dbg_debug_cycle;
output wire [7:0] o_char_to_send;
output wire [9:0] o_char_counter;
output wire [0:0] o_char_valid;
output wire [0:0] o_char_send;
input wire [0:0] i_serial_busy;
assign o_phase = phase;
assign o_cycle_ctr = cycle_ctr;
/**************************************************************************************************
*
* this is the main firmware rom module
* this module is always active, there is no configuration.
*
*************************************************************************************************/
saturn_hp48gx_rom hp48gx_rom (
.i_clk (i_clk),
.i_clk_en (i_clk_en),
.i_reset (i_reset),
`ifdef SIM
.i_phase (phase),
.i_cycle_ctr (cycle_ctr),
`endif
.i_phase_0 (phases[0]),
.i_debug_cycle (dbg_debug_cycle),
.i_bus_clk_en (bus_clk_en),
.i_bus_is_data (ctrl_bus_is_data),
.o_bus_nibble_out (rom_bus_nibble_out),
.i_bus_nibble_in (ctrl_bus_nibble_out)
);
wire [3:0] rom_bus_nibble_out;
/**************************************************************************************************
*
* this is the sysram module
*
*************************************************************************************************/
saturn_hp48gx_sysram hp48gx_sysram (
.i_clk (i_clk),
.i_clk_en (i_clk_en),
.i_reset (i_reset),
`ifdef SIM
.i_phase (phase),
// .i_phases (phases),
.i_cycle_ctr (cycle_ctr),
`endif
.i_phase_0 (phases[0]),
.i_debug_cycle (dbg_debug_cycle),
.i_bus_clk_en (bus_clk_en),
.i_bus_is_data (ctrl_bus_is_data),
.o_bus_nibble_out (sysram_bus_nibble_out),
.i_bus_nibble_in (ctrl_bus_nibble_out),
.i_bus_daisy (mmio_daisy_out),
.o_bus_daisy (sysram_daisy_out),
.o_bus_active (sysram_active)
);
wire [3:0] sysram_bus_nibble_out;
// Verilator lint_off UNUSED
wire [0:0] sysram_daisy_out;
// Verilator lint_on UNUSED
wire [0:0] sysram_active;
/**************************************************************************************************
*
* this is the io-ram module
* this module only takes one configuration parameter, size is fixed
*
*************************************************************************************************/
saturn_hp48gx_mmio hp48gx_mmio (
.i_clk (i_clk),
.i_clk_en (i_clk_en),
.i_reset (i_reset),
`ifdef SIM
.i_phase (phase),
.i_cycle_ctr (cycle_ctr),
`endif
.i_phase_0 (phases[0]),
.i_debug_cycle (dbg_debug_cycle),
.i_bus_clk_en (bus_clk_en),
.i_bus_is_data (ctrl_bus_is_data),
.o_bus_nibble_out (mmio_bus_nibble_out),
.i_bus_nibble_in (ctrl_bus_nibble_out),
.i_bus_daisy (1'b1),
.o_bus_daisy (mmio_daisy_out),
.o_bus_active (mmio_active)
);
wire [3:0] mmio_bus_nibble_out;
wire [0:0] mmio_daisy_out;
wire [0:0] mmio_active;
/**************************************************************************************************
*
* the main processor is hidden behind this bus controller device
*
*
*************************************************************************************************/
saturn_bus_controller bus_controller (
.i_clk (i_clk),
.i_clk_en (i_clk_en),
.i_reset (i_reset),
.i_phases (phases),
.i_phase (phase),
.i_cycle_ctr (cycle_ctr),
.o_bus_clk_en (ctrl_bus_clk_en),
.o_bus_is_data (ctrl_bus_is_data),
.o_bus_nibble_out (ctrl_bus_nibble_out),
.i_bus_nibble_in (ctrl_bus_nibble_in),
// more ports should show up to allow for output to the serial port of debug information
.o_debug_cycle (dbg_debug_cycle),
.o_instr_decoded (o_instr_decoded),
.o_char_to_send (o_char_to_send),
.o_char_counter (o_char_counter),
.o_char_valid (o_char_valid),
.o_char_send (o_char_send),
.i_serial_busy (i_serial_busy),
.o_halt (ctrl_halt)
);
wire [0:0] ctrl_bus_clk_en;
wire [0:0] ctrl_bus_is_data;
wire [3:0] ctrl_bus_nibble_out;
reg [3:0] ctrl_bus_nibble_in;
wire [0:0] dbg_debug_cycle;
wire [0:0] ctrl_halt;
/**************************************************************************************************
*
* priority logic for the bus
*
*
*************************************************************************************************/
reg [0:0] bus_halt;
reg [3:0] phases;
reg [1:0] phase;
reg [31:0] cycle_ctr;
wire [0:0] bus_clk_en = i_clk_en && ctrl_bus_clk_en;
initial begin
bus_halt = 1'b0;
phases = 4'b1;
cycle_ctr = 32'd0;
end
assign o_halt = bus_halt || ctrl_halt;
/* handles modules priority
* goes through all modules
* if the module is active, this is the one giving out it's data
* the last active module wins
*/
always @(*) begin
ctrl_bus_nibble_in = rom_bus_nibble_out;
if (sysram_active) ctrl_bus_nibble_in = sysram_bus_nibble_out;
if (mmio_active) ctrl_bus_nibble_in = mmio_bus_nibble_out;
end
always @(*) begin
phase = 2'd0;
if (phases[1]) phase = 2'd1;
if (phases[2]) phase = 2'd2;
if (phases[3]) phase = 2'd3;
end
always @(posedge i_clk) begin
/* if we're not debugging, advance phase on each clock */
if (!dbg_debug_cycle && i_clk_en) begin
phases <= {phases[2:0], phases[3]};
/* using phases[3] here becase it will be phase_0 on the next step,
* so we get to a new cycle on the first phase...
*/
cycle_ctr <= cycle_ctr + {31'b0, phases[3]};
end
`ifdef SIM
if (cycle_ctr == 379) begin
bus_halt <= 1'b1;
$display("BUS %0d: [%d] enough cycles for now", phase, cycle_ctr);
end
`endif
if (i_reset) begin
bus_halt <= 1'b0;
phases <= 4'b1;
cycle_ctr <= 32'd0;
end
end
endmodule