| 1 |
2 |
olivier.girard |
//----------------------------------------------------------------------------
|
| 2 |
|
|
// Copyright (C) 2001 Authors
|
| 3 |
|
|
//
|
| 4 |
|
|
// This source file may be used and distributed without restriction provided
|
| 5 |
|
|
// that this copyright statement is not removed from the file and that any
|
| 6 |
|
|
// derivative work contains the original copyright notice and the associated
|
| 7 |
|
|
// disclaimer.
|
| 8 |
|
|
//
|
| 9 |
|
|
// This source file is free software; you can redistribute it and/or modify
|
| 10 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
| 11 |
|
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
| 12 |
|
|
// (at your option) any later version.
|
| 13 |
|
|
//
|
| 14 |
|
|
// This source is distributed in the hope that it will be useful, but WITHOUT
|
| 15 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 16 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
| 17 |
|
|
// License for more details.
|
| 18 |
|
|
//
|
| 19 |
|
|
// You should have received a copy of the GNU Lesser General Public License
|
| 20 |
|
|
// along with this source; if not, write to the Free Software Foundation,
|
| 21 |
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 22 |
|
|
//
|
| 23 |
|
|
//----------------------------------------------------------------------------
|
| 24 |
|
|
//
|
| 25 |
|
|
// *File Name: ram.v
|
| 26 |
|
|
//
|
| 27 |
|
|
// *Module Description:
|
| 28 |
|
|
// Scalable RAM model
|
| 29 |
|
|
//
|
| 30 |
|
|
// *Author(s):
|
| 31 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
| 32 |
|
|
//
|
| 33 |
|
|
//----------------------------------------------------------------------------
|
| 34 |
|
|
`timescale 1ns / 100ps
|
| 35 |
|
|
|
| 36 |
|
|
module ram (
|
| 37 |
|
|
|
| 38 |
|
|
// OUTPUTs
|
| 39 |
|
|
ram_dout, // RAM data output
|
| 40 |
|
|
|
| 41 |
|
|
// INPUTs
|
| 42 |
|
|
ram_addr, // RAM address
|
| 43 |
|
|
ram_cen, // RAM chip enable (low active)
|
| 44 |
|
|
ram_clk, // RAM clock
|
| 45 |
|
|
ram_din, // RAM data input
|
| 46 |
|
|
ram_wen // RAM write enable (low active)
|
| 47 |
|
|
);
|
| 48 |
|
|
|
| 49 |
|
|
// PARAMETERs
|
| 50 |
|
|
//============
|
| 51 |
|
|
parameter ADDR_MSB = 6;
|
| 52 |
|
|
|
| 53 |
|
|
// OUTPUTs
|
| 54 |
|
|
//============
|
| 55 |
|
|
output [15:0] ram_dout; // RAM data output
|
| 56 |
|
|
|
| 57 |
|
|
// INPUTs
|
| 58 |
|
|
//============
|
| 59 |
|
|
input [ADDR_MSB:0] ram_addr; // RAM address
|
| 60 |
|
|
input ram_cen; // RAM chip enable (low active)
|
| 61 |
|
|
input ram_clk; // RAM clock
|
| 62 |
|
|
input [15:0] ram_din; // RAM data input
|
| 63 |
|
|
input [1:0] ram_wen; // RAM write enable (low active)
|
| 64 |
|
|
|
| 65 |
|
|
|
| 66 |
|
|
// RAM
|
| 67 |
|
|
//============
|
| 68 |
|
|
|
| 69 |
|
|
reg [15:0] mem [(1<<(ADDR_MSB+1))-1:0];
|
| 70 |
|
|
reg [ADDR_MSB:0] ram_addr_reg;
|
| 71 |
|
|
|
| 72 |
|
|
wire [15:0] mem_val = mem[ram_addr];
|
| 73 |
|
|
|
| 74 |
|
|
always @(posedge ram_clk)
|
| 75 |
|
|
if (~ram_cen)
|
| 76 |
|
|
begin
|
| 77 |
|
|
if (ram_wen==2'b00) mem[ram_addr] <= ram_din;
|
| 78 |
|
|
else if (ram_wen==2'b01) mem[ram_addr] <= {ram_din[15:8], mem_val[7:0]};
|
| 79 |
|
|
else if (ram_wen==2'b10) mem[ram_addr] <= {mem_val[15:8], ram_din[7:0]};
|
| 80 |
|
|
ram_addr_reg <= ram_addr;
|
| 81 |
|
|
end
|
| 82 |
|
|
|
| 83 |
|
|
assign ram_dout = mem[ram_addr_reg];
|
| 84 |
|
|
|
| 85 |
|
|
|
| 86 |
|
|
endmodule // ram
|