aboutsummaryrefslogtreecommitdiffstats
path: root/phy_fpga/block_ram_mod.v
blob: 11da24b947ad5fcac9da6564f9d2c16e25921b03 (plain)
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
// vim: ts=4 sw=4 noexpandtab
/*
 *   Block RAM
 *
 *   Copyright (c) 2019 Michael Buesch <m@bues.ch>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License along
 *   with this program; if not, write to the Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

`ifndef BLOCK_RAM_MOD_V_
`define BLOCK_RAM_MOD_V_


module block_ram #(
	parameter ADDR_WIDTH	= 16,
	parameter DATA_WIDTH	= 8,
	parameter MEM_BYTES		= 1024,
) (
	input							clk,
	/* Port 0 */
	input	   [ADDR_WIDTH - 1 : 0]	addr0,
	output reg [DATA_WIDTH - 1 : 0]	rd_data0,
	input	   [DATA_WIDTH - 1 : 0]	wr_data0,
	input							wr0,
	/* Port 1 */
	input	   [ADDR_WIDTH - 1 : 0]	addr1,
	output reg [DATA_WIDTH - 1 : 0]	rd_data1,
);
	reg [DATA_WIDTH - 1 : 0] mem [MEM_BYTES - 1 : 0];
	integer i;

	initial begin
		for (i = 0; i < MEM_BYTES; i++) begin
			mem[i] <= 0;
		end
	end

	always @(posedge clk) begin
		if (wr0) begin
			mem[addr0] <= wr_data0;
		end
		rd_data0 <= mem[addr0];
		rd_data1 <= mem[addr1];
	end
endmodule


`endif /* BLOCK_RAM_MOD_V_ */
bues.ch cgit interface