-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_array.v
More file actions
67 lines (44 loc) · 1.52 KB
/
Copy pathmemory_array.v
File metadata and controls
67 lines (44 loc) · 1.52 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
`timescale 1ns / 1ps
`include "axi_pkg.vh"
module memory_array(
input clk,
input resetn,
input write_en,
input read_en,
input [`MEM_ADDR_WIDTH-1:0] address,
input [`DATA_WIDTH-1:0] write_data,
output reg [`DATA_WIDTH-1:0] read_data
);
//=========================================================
// Memory Declaration
//=========================================================
reg [`DATA_WIDTH-1:0] memory [0:`MEM_DEPTH-1];
integer i;
//=========================================================
// Memory Operations
//=========================================================
always @(posedge clk) begin
if(!resetn) begin
read_data <= 0;
// Optional memory initialization
for(i = 0; i < `MEM_DEPTH; i = i + 1)
memory[i] <= 0;
end
else begin
//-------------------------
// Write Operation
//-------------------------
if (write_en) begin
memory[address] <= write_data;
$display("WRITE: addr=%0d data=%h", address, write_data);
end
//-------------------------
// Read Operation
//-------------------------
if (read_en) begin
read_data <= memory[address];
$display("READ : addr=%0d data=%h", address, memory[address]);
end
end // <-- closes the else begin
end // <-- closes always block
endmodule