1 |
167 |
olivier.gi |
//----------------------------------------------------------------------------
|
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 Dual-Port RAM model
|
29 |
|
|
//
|
30 |
|
|
// *Author(s):
|
31 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
32 |
|
|
//
|
33 |
|
|
//----------------------------------------------------------------------------
|
34 |
|
|
// $Rev: 103 $
|
35 |
|
|
// $LastChangedBy: olivier.girard $
|
36 |
|
|
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
|
37 |
|
|
//----------------------------------------------------------------------------
|
38 |
|
|
|
39 |
|
|
module ram_dp (
|
40 |
|
|
|
41 |
|
|
// OUTPUTs
|
42 |
|
|
ram_douta, // RAM data output (Port A)
|
43 |
|
|
ram_doutb, // RAM data output (Port B)
|
44 |
|
|
|
45 |
|
|
// INPUTs
|
46 |
|
|
ram_addra, // RAM address (Port A)
|
47 |
|
|
ram_cena, // RAM chip enable (low active) (Port A)
|
48 |
|
|
ram_clka, // RAM clock (Port A)
|
49 |
|
|
ram_dina, // RAM data input (Port A)
|
50 |
|
|
ram_wena, // RAM write enable (low active) (Port A)
|
51 |
|
|
ram_addrb, // RAM address (Port B)
|
52 |
|
|
ram_cenb, // RAM chip enable (low active) (Port B)
|
53 |
|
|
ram_clkb, // RAM clock (Port B)
|
54 |
|
|
ram_dinb, // RAM data input (Port B)
|
55 |
|
|
ram_wenb // RAM write enable (low active) (Port B)
|
56 |
|
|
);
|
57 |
|
|
|
58 |
|
|
// PARAMETERs
|
59 |
|
|
//============
|
60 |
|
|
parameter ADDR_MSB = 6; // MSB of the address bus
|
61 |
|
|
parameter MEM_SIZE = 256; // Memory size in bytes
|
62 |
|
|
|
63 |
|
|
// OUTPUTs
|
64 |
|
|
//============
|
65 |
|
|
output [15:0] ram_douta; // RAM data output (Port A)
|
66 |
|
|
output [15:0] ram_doutb; // RAM data output (Port B)
|
67 |
|
|
|
68 |
|
|
// INPUTs
|
69 |
|
|
//============
|
70 |
|
|
input [ADDR_MSB:0] ram_addra; // RAM address (Port A)
|
71 |
|
|
input ram_cena; // RAM chip enable (low active) (Port A)
|
72 |
|
|
input ram_clka; // RAM clock (Port A)
|
73 |
|
|
input [15:0] ram_dina; // RAM data input (Port A)
|
74 |
|
|
input [1:0] ram_wena; // RAM write enable (low active) (Port A)
|
75 |
|
|
input [ADDR_MSB:0] ram_addrb; // RAM address (Port B)
|
76 |
|
|
input ram_cenb; // RAM chip enable (low active) (Port B)
|
77 |
|
|
input ram_clkb; // RAM clock (Port B)
|
78 |
|
|
input [15:0] ram_dinb; // RAM data input (Port B)
|
79 |
|
|
input [1:0] ram_wenb; // RAM write enable (low active) (Port B)
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
// RAM
|
83 |
|
|
//============
|
84 |
|
|
|
85 |
|
|
reg [15:0] mem [0:(MEM_SIZE/2)-1];
|
86 |
|
|
reg [ADDR_MSB:0] ram_addra_reg;
|
87 |
|
|
reg [ADDR_MSB:0] ram_addrb_reg;
|
88 |
|
|
|
89 |
|
|
wire [15:0] mem_vala = mem[ram_addra];
|
90 |
|
|
wire [15:0] mem_valb = mem[ram_addrb];
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
always @(posedge ram_clka)
|
94 |
|
|
if (~ram_cena && (ram_addra<(MEM_SIZE/2)))
|
95 |
|
|
begin
|
96 |
|
|
if (ram_wena==2'b00) mem[ram_addra] <= ram_dina;
|
97 |
|
|
else if (ram_wena==2'b01) mem[ram_addra] <= {ram_dina[15:8], mem_vala[7:0]};
|
98 |
|
|
else if (ram_wena==2'b10) mem[ram_addra] <= {mem_vala[15:8], ram_dina[7:0]};
|
99 |
|
|
ram_addra_reg <= ram_addra;
|
100 |
|
|
end
|
101 |
|
|
|
102 |
|
|
assign ram_douta = mem[ram_addra_reg];
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
always @(posedge ram_clkb)
|
106 |
|
|
if (~ram_cenb && (ram_addrb<(MEM_SIZE/2)))
|
107 |
|
|
begin
|
108 |
|
|
if (ram_wenb==2'b00) mem[ram_addrb] <= ram_dinb;
|
109 |
|
|
else if (ram_wenb==2'b01) mem[ram_addrb] <= {ram_dinb[15:8], mem_valb[7:0]};
|
110 |
|
|
else if (ram_wenb==2'b10) mem[ram_addrb] <= {mem_valb[15:8], ram_dinb[7:0]};
|
111 |
|
|
ram_addrb_reg <= ram_addrb;
|
112 |
|
|
end
|
113 |
|
|
|
114 |
|
|
assign ram_doutb = mem[ram_addrb_reg];
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
endmodule // ram_dp
|