This repository was archived by the owner on Jun 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdm_readunit.sv
More file actions
59 lines (55 loc) · 1.39 KB
/
Copy pathdm_readunit.sv
File metadata and controls
59 lines (55 loc) · 1.39 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
`include "constants.v"
module DataMemoryReader(
input readEnable,
input extendCtrl,
output logic [31:0] readData,
input [1:0] widthCtrl,
input [31:0] address,
input [31:0] data_sram_rdata
);
logic [15:0] halfWord;
logic [7:0] readbyte;
always_comb begin
readData = 0;
if (!readEnable) begin
readData = 'bX;
end
else if (widthCtrl == `memWidth4) begin
readData = data_sram_rdata;
end
else if (widthCtrl == `memWidth2) begin
if (address[1]) begin
halfWord = data_sram_rdata[31:16];
end
else begin
halfWord = data_sram_rdata[15:0];
end
if (extendCtrl) begin
readData = $signed(halfWord);
end
else begin
readData = halfWord;
end
end
else if (widthCtrl == `memWidth1) begin
if (address[1:0] == 3) begin
readbyte = data_sram_rdata[31:24];
end
else if (address[1:0] == 2) begin
readbyte = data_sram_rdata[23:16];
end
else if (address[1:0] == 1) begin
readbyte = data_sram_rdata[15:8];
end
else if (address[1:0] == 0) begin
readbyte = data_sram_rdata[7:0];
end
if (extendCtrl) begin
readData = $signed(readbyte);
end
else begin
readData = readbyte;
end
end
end
endmodule