-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathasync_dualram_16X8.v
54 lines (43 loc) · 1.05 KB
/
async_dualram_16X8.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
`define ADDR_WIDTH 4
`define DEPTH 16
`define DATA_WIDTH 8
module async_dualram_16X8 (cs,
rst,
wr_enb,
wr_addr,
wr_data,
rd_enb,
rd_addr,
rd_data);
//port direction
input cs, rst;
//write signals
input wr_enb;
input [`ADDR_WIDTH-1:0] wr_addr;
input [`DATA_WIDTH-1:0] wr_data;
//read signals
input rd_enb;
input [`ADDR_WIDTH-1:0] rd_addr;
output reg [`DATA_WIDTH-1:0] rd_data;
//internal memory
reg [`DATA_WIDTH-1:0] ram [0:`DEPTH-1];
reg [`ADDR_WIDTH:0] i;
//implementation
always@(cs,rst,wr_addr,rd_addr,wr_data,wr_enb,rd_enb)
if (rst)
begin
rd_data <= `DATA_WIDTH'd0;
//memory initialisation
for (i=0;i<`DEPTH;i=i+1)
ram[i] <= `DATA_WIDTH'd0;
end
else
begin
//write logic
if (wr_enb && cs)
ram[wr_addr] <= wr_data;
//read logic
if (rd_enb && cs)
rd_data <= ram[rd_addr];
end
endmodule