-
Notifications
You must be signed in to change notification settings - Fork 1
/
RS5_FPGA_Platform.sv
209 lines (192 loc) · 7.45 KB
/
RS5_FPGA_Platform.sv
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
`include "../rtl/RS5_pkg.sv"
module RS5_FPGA_Platform
import RS5_pkg::*;
#(
parameter int i_cnt = 2,
parameter environment_e Environment = FPGA,
parameter rv32_e RV32 = RV32M,
parameter bit COMPRESSED = 1'b1,
parameter bit XOSVMEnable = 1'b0,
parameter bit ZIHPMEnable = 1'b0,
parameter bit ZKNEEnable = 1'b0,
parameter bit VEnable = 1'b0,
parameter int VLEN = 64,
parameter int CLKS_PER_BIT_UART = 868
)
(
input logic clk,
input logic reset_n,
input logic BTND,
input logic UART_RX,
output logic UART_TX
);
logic [31:0] cpu_instruction_address, cpu_instruction;
logic [31:0] cpu_data_address, cpu_data_in, cpu_data_out;
logic cpu_operation_enable, enable_ram, enable_peripherals, enable_rtc, enable_plic;
logic enable_rtc_r, enable_plic_r, enable_peripherals_r;
logic [63:0] mtime;
logic [31:0] data_bram, data_plic, data_peripherals;
logic [63:0] data_rtc;
logic [3:0] cpu_write_enable;
logic stall;
logic mei, mti;
logic interrupt_ack;
logic [31:0] irq;
logic [i_cnt:1] irq_peripherals, iack_peripherals;
assign irq = {20'h0, mei, 3'h0, mti, 7'h0};
//////////////////////////////////////////////////////////////////////////////
// Control
//////////////////////////////////////////////////////////////////////////////
always_comb begin
if (cpu_operation_enable) begin
if (cpu_data_address[31:28] < 4'h2) begin
enable_ram = 1'b1;
enable_rtc = 1'b0;
enable_plic = 1'b0;
enable_peripherals = 1'b0;
end
else if (cpu_data_address[31:28] < 4'h3) begin
enable_ram = 1'b0;
enable_rtc = 1'b1;
enable_plic = 1'b0;
enable_peripherals = 1'b0;
end
else if (cpu_data_address[31:28] < 4'h8) begin
enable_ram = 1'b0;
enable_rtc = 1'b0;
enable_plic = 1'b1;
enable_peripherals = 1'b0;
end
else begin
enable_ram = 1'b0;
enable_rtc = 1'b0;
enable_plic = 1'b0;
enable_peripherals = 1'b1;
end
end
else begin
enable_ram = 1'b0;
enable_rtc = 1'b0;
enable_plic = 1'b0;
enable_peripherals = 1'b0;
end
end
always_ff @(posedge clk) begin
enable_rtc_r <= enable_rtc;
enable_plic_r <= enable_plic;
enable_peripherals_r <= enable_peripherals;
end
always_comb begin
if (enable_rtc_r) begin
cpu_data_in = data_rtc[31:0];
end
else if (enable_plic_r) begin
cpu_data_in = data_plic;
end
else if (enable_peripherals_r) begin
cpu_data_in = data_peripherals;
end
else begin
cpu_data_in = data_bram;
end
end
//////////////////////////////////////////////////////////////////////////////
// CPU INSTANTIATION
//////////////////////////////////////////////////////////////////////////////
RS5 #(
.Environment (Environment),
.RV32 (RV32),
.XOSVMEnable (XOSVMEnable),
.ZIHPMEnable (ZIHPMEnable),
.ZKNEEnable (ZKNEEnable),
.COMPRESSED (COMPRESSED),
.VEnable (VEnable),
.VLEN (VLEN)
) dut (
.clk (clk),
.reset_n (reset_n),
.sys_reset_i (1'b0),
.stall (stall),
.instruction_i (cpu_instruction),
.mem_data_i (cpu_data_in),
.mtime_i (mtime),
.irq_i (irq),
.instruction_address_o (cpu_instruction_address),
.mem_operation_enable_o (cpu_operation_enable),
.mem_write_enable_o (cpu_write_enable),
.mem_address_o (cpu_data_address),
.mem_data_o (cpu_data_out),
.interrupt_ack_o (interrupt_ack)
);
//////////////////////////////////////////////////////////////////////////////
// BRAM INSTANTIATION
//////////////////////////////////////////////////////////////////////////////
BRAM RAM (
.clka (clk), // input wire clka
.ena (!stall), // input wire ena
.wea (4'h0), // input wire [3 : 0] wea
.addra (cpu_instruction_address), // input wire [31 : 0] addra
.dina (0), // input wire [31 : 0] dina
.douta (cpu_instruction), // output wire [31 : 0] douta
//////////////////////////////////////////////////////
.clkb (clk), // input wire clkb
.enb (enable_ram), // input wire enb
.web (cpu_write_enable), // input wire [3 : 0] web
.addrb (cpu_data_address), // input wire [31 : 0] addrb
.dinb (cpu_data_out), // input wire [31 : 0] dinb
.doutb (data_bram) // output wire [31 : 0] doutb
);
//////////////////////////////////////////////////////////////////////////////
// RTC INSTANTIATION
//////////////////////////////////////////////////////////////////////////////
rtc rtc(
.clk (clk),
.reset_n (reset_n),
.en_i (enable_rtc),
.addr_i (cpu_data_address[3:0]),
.we_i ({4'h0, cpu_write_enable}),
.data_i ({32'h0, cpu_data_out}),
.data_o (data_rtc),
.mti_o (mti),
.mtime_o (mtime)
);
//////////////////////////////////////////////////////////////////////////////
// PLIC
//////////////////////////////////////////////////////////////////////////////
plic #(
.i_cnt(i_cnt)
) plic1 (
.clk (clk),
.reset_n (reset_n),
.en_i (enable_plic),
.we_i (cpu_write_enable),
.addr_i (cpu_data_address[23:0]),
.data_i (cpu_data_out),
.data_o (data_plic),
.irq_i (irq_peripherals),
.iack_i (interrupt_ack),
.irq_o (mei),
.iack_o (iack_peripherals)
);
//////////////////////////////////////////////////////////////////////////////
// PERIPHERALS
//////////////////////////////////////////////////////////////////////////////
Peripherals #(
.i_cnt(i_cnt),
.CLKS_PER_BIT_UART(CLKS_PER_BIT_UART)
) Peripherals1 (
.clk (clk),
.reset_n (reset_n),
.stall_o (stall),
.enable_i (enable_peripherals),
.write_enable_i (cpu_write_enable),
.data_address_i (cpu_data_address),
.data_i (cpu_data_out),
.data_o (data_peripherals),
.BTND (BTND),
.UART_TX (UART_TX),
.UART_RX (UART_RX),
.interrupt_req_o(irq_peripherals),
.interrupt_ack_i(iack_peripherals)
);
endmodule