-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphysical_memory.sv
executable file
·77 lines (61 loc) · 1.35 KB
/
physical_memory.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
module physical_memory
(
input clk,
input read,
input write,
input [15:0] address,
input [127:0] wdata,
output logic resp,
output logic [127:0] rdata
);
timeunit 1ns;
timeprecision 1ns;
parameter DELAY_MEM = 200;
logic [127:0] mem [0:2**($bits(address)-4)-1];
logic [11:0] internal_address;
logic ready;
/* Initialize memory contents from memory.lst file */
initial
begin
$readmemh("memory.lst", mem);
end
assign internal_address = address[15:4];
enum int unsigned {
idle,
busy,
respond
} state, next_state;
always @(posedge clk)
begin
/* Default */
resp = 1'b0;
next_state = state;
case(state)
idle: begin
if (read | write) begin
next_state = busy;
ready <= #DELAY_MEM 1;
end
end
busy: begin
if (ready == 1) begin
if (write) begin
mem[internal_address] = wdata;
end
rdata = mem[internal_address];
resp = 1;
next_state = respond;
end
end
respond: begin
ready <= 0;
next_state = idle;
end
default: next_state = idle;
endcase
end
always_ff @(posedge clk)
begin : next_state_assignment
state <= next_state;
end
endmodule : physical_memory