-
Notifications
You must be signed in to change notification settings - Fork 0
/
ram_dual.v
34 lines (29 loc) · 853 Bytes
/
ram_dual.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
/*
Zero delay, dual channel RAM.
Dual channel is simpler to design as it does not have to deal with Z.
You will need RAM's for all non-trivial designs.
*/
module ram_dual #(
parameter ADDRESS_BITS = 1,
parameter DATA_BITS = 1
) (
input wire clock,
input wire reset,
input wire write,
input wire [ADDRESS_BITS-1:0] address_in,
input wire [ADDRESS_BITS-1:0] address_out,
input wire [DATA_BITS-1:0] data_in,
output wire [DATA_BITS-1:0] data_out
);
localparam MEMORY_BITS = DATA_BITS * (1 << ADDRESS_BITS);
reg [MEMORY_BITS-1:0] memory;
assign data_out = memory[address_out];
always @ (posedge clock) begin
if (reset == 1) begin
memory <= {MEMORY_BITS{1'b0}};
end
else if (write == 1) begin
memory[address_in] <= data_in;
end
end
endmodule