-
Notifications
You must be signed in to change notification settings - Fork 0
/
MEM.v
74 lines (58 loc) · 1.22 KB
/
MEM.v
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
module MEM (
input clk,
input reset_b,
input [31:0] MemWriteData,
input [31:0] ALU_S,
input [4:0] WriteReg,
input MemRead,
input MemWrite,
input RegWrite,
input [1:0] MemToReg,
input [31:0] PC_Plus4,
input LUOp,
input [31:0] LUData,
output reg [37:0] MEM_WB,
// Peripheral
input [7:0] switch,
output [7:0] led,
output [11:0] digi,
output irqout,
// UART
input clk_50m,
input uart_rxd,
output uart_txd);
wire [31:0] MemReadData;
DataMem DataMem(
.clk(clk),
.reset(reset_b),
.rd(MemRead), // Read
.wr(MemWrite), // Write
.addr(ALU_S),
.wdata(MemWriteData),
.rdata(MemReadData),
// Peripheral
.switch(switch),
.led(led),
.digi(digi),
.irqout(irqout),
// UART
.clk_50m(clk_50m),
.uart_rxd(uart_rxd),
.uart_txd(uart_txd),
.uart_wait(uart_wait));
wire [31:0] RegWriteData;
assign RegWriteData = LUOp ? LUData:
MemToReg == 2'b00 ? ALU_S :
MemToReg == 2'b01 ? MemReadData :
PC_Plus4; // jal/jalr or exception
always @(posedge clk or negedge reset_b) begin
if (~reset_b) begin
MEM_WB <= 0;
end
else begin
MEM_WB[31:0] <= RegWriteData[31:0];
MEM_WB[36:32] <= WriteReg[4:0];
MEM_WB[37] <= RegWrite;
end
end
endmodule