[6] | 1 | ////////////////////////////////////////////////////////////////////// |
---|
| 2 | //// //// |
---|
| 3 | //// eth_spram_256x32.v //// |
---|
| 4 | //// //// |
---|
| 5 | //// This file is part of the Ethernet IP core project //// |
---|
| 6 | //// http://www.opencores.org/projects/ethmac/ //// |
---|
| 7 | //// //// |
---|
| 8 | //// Author(s): //// |
---|
| 9 | //// - Igor Mohor ([email protected]) //// |
---|
| 10 | //// //// |
---|
| 11 | //// All additional information is available in the Readme.txt //// |
---|
| 12 | //// file. //// |
---|
| 13 | //// //// |
---|
| 14 | ////////////////////////////////////////////////////////////////////// |
---|
| 15 | //// //// |
---|
| 16 | //// Copyright (C) 2001, 2002 Authors //// |
---|
| 17 | //// //// |
---|
| 18 | //// This source file may be used and distributed without //// |
---|
| 19 | //// restriction provided that this copyright statement is not //// |
---|
| 20 | //// removed from the file and that any derivative work contains //// |
---|
| 21 | //// the original copyright notice and the associated disclaimer. //// |
---|
| 22 | //// //// |
---|
| 23 | //// This source file is free software; you can redistribute it //// |
---|
| 24 | //// and/or modify it under the terms of the GNU Lesser General //// |
---|
| 25 | //// Public License as published by the Free Software Foundation; //// |
---|
| 26 | //// either version 2.1 of the License, or (at your option) any //// |
---|
| 27 | //// later version. //// |
---|
| 28 | //// //// |
---|
| 29 | //// This source is distributed in the hope that it will be //// |
---|
| 30 | //// useful, but WITHOUT ANY WARRANTY; without even the implied //// |
---|
| 31 | //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //// |
---|
| 32 | //// PURPOSE. See the GNU Lesser General Public License for more //// |
---|
| 33 | //// details. //// |
---|
| 34 | //// //// |
---|
| 35 | //// You should have received a copy of the GNU Lesser General //// |
---|
| 36 | //// Public License along with this source; if not, download it //// |
---|
| 37 | //// from http://www.opencores.org/lgpl.shtml //// |
---|
| 38 | //// //// |
---|
| 39 | ////////////////////////////////////////////////////////////////////// |
---|
| 40 | // |
---|
| 41 | // CVS Revision History |
---|
| 42 | // |
---|
| 43 | // $Log: not supported by cvs2svn $ |
---|
| 44 | // Revision 1.9 2003/12/05 12:43:06 tadejm |
---|
| 45 | // Corrected address mismatch for xilinx RAMB4_S8 model which has wider address than RAMB4_S16. |
---|
| 46 | // |
---|
| 47 | // Revision 1.8 2003/12/04 14:59:13 simons |
---|
| 48 | // Lapsus fixed (!we -> ~we). |
---|
| 49 | // |
---|
| 50 | // Revision 1.7 2003/11/12 18:24:59 tadejm |
---|
| 51 | // WISHBONE slave changed and tested from only 32-bit accesss to byte access. |
---|
| 52 | // |
---|
| 53 | // Revision 1.6 2003/10/17 07:46:15 markom |
---|
| 54 | // mbist signals updated according to newest convention |
---|
| 55 | // |
---|
| 56 | // Revision 1.5 2003/08/14 16:42:58 simons |
---|
| 57 | // Artisan ram instance added. |
---|
| 58 | // |
---|
| 59 | // Revision 1.4 2002/10/18 17:04:20 tadejm |
---|
| 60 | // Changed BIST scan signals. |
---|
| 61 | // |
---|
| 62 | // Revision 1.3 2002/10/10 16:29:30 mohor |
---|
| 63 | // BIST added. |
---|
| 64 | // |
---|
| 65 | // Revision 1.2 2002/09/23 18:24:31 mohor |
---|
| 66 | // ETH_VIRTUAL_SILICON_RAM supported (for ASIC implementation). |
---|
| 67 | // |
---|
| 68 | // Revision 1.1 2002/07/23 16:36:09 mohor |
---|
| 69 | // ethernet spram added. So far a generic ram and xilinx RAMB4 are used. |
---|
| 70 | // |
---|
| 71 | // |
---|
| 72 | // |
---|
| 73 | |
---|
| 74 | `include "eth_defines.v" |
---|
| 75 | `include "timescale.v" |
---|
| 76 | |
---|
| 77 | module eth_spram_256x32( |
---|
| 78 | // Generic synchronous single-port RAM interface |
---|
| 79 | clk, rst, ce, we, oe, addr, di, do |
---|
| 80 | |
---|
| 81 | `ifdef ETH_BIST |
---|
| 82 | , |
---|
| 83 | // debug chain signals |
---|
| 84 | mbist_si_i, // bist scan serial in |
---|
| 85 | mbist_so_o, // bist scan serial out |
---|
| 86 | mbist_ctrl_i // bist chain shift control |
---|
| 87 | `endif |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | ); |
---|
| 92 | |
---|
| 93 | // |
---|
| 94 | // Generic synchronous single-port RAM interface |
---|
| 95 | // |
---|
| 96 | input clk; // Clock, rising edge |
---|
| 97 | input rst; // Reset, active high |
---|
| 98 | input ce; // Chip enable input, active high |
---|
| 99 | input [3:0] we; // Write enable input, active high |
---|
| 100 | input oe; // Output enable input, active high |
---|
| 101 | input [7:0] addr; // address bus inputs |
---|
| 102 | input [31:0] di; // input data bus |
---|
| 103 | output [31:0] do; // output data bus |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | `ifdef ETH_BIST |
---|
| 107 | input mbist_si_i; // bist scan serial in |
---|
| 108 | output mbist_so_o; // bist scan serial out |
---|
| 109 | input [`ETH_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i; // bist chain shift control |
---|
| 110 | `endif |
---|
| 111 | |
---|
| 112 | `ifdef ETH_XILINX_RAMB4 |
---|
| 113 | |
---|
| 114 | /*RAMB4_S16 ram0 |
---|
| 115 | ( |
---|
| 116 | .DO (do[15:0]), |
---|
| 117 | .ADDR (addr), |
---|
| 118 | .DI (di[15:0]), |
---|
| 119 | .EN (ce), |
---|
| 120 | .CLK (clk), |
---|
| 121 | .WE (we), |
---|
| 122 | .RST (rst) |
---|
| 123 | ); |
---|
| 124 | |
---|
| 125 | RAMB4_S16 ram1 |
---|
| 126 | ( |
---|
| 127 | .DO (do[31:16]), |
---|
| 128 | .ADDR (addr), |
---|
| 129 | .DI (di[31:16]), |
---|
| 130 | .EN (ce), |
---|
| 131 | .CLK (clk), |
---|
| 132 | .WE (we), |
---|
| 133 | .RST (rst) |
---|
| 134 | );*/ |
---|
| 135 | |
---|
| 136 | RAMB4_S8 ram0 |
---|
| 137 | ( |
---|
| 138 | .DO (do[7:0]), |
---|
| 139 | .ADDR ({1'b0, addr}), |
---|
| 140 | .DI (di[7:0]), |
---|
| 141 | .EN (ce), |
---|
| 142 | .CLK (clk), |
---|
| 143 | .WE (we[0]), |
---|
| 144 | .RST (rst) |
---|
| 145 | ); |
---|
| 146 | |
---|
| 147 | RAMB4_S8 ram1 |
---|
| 148 | ( |
---|
| 149 | .DO (do[15:8]), |
---|
| 150 | .ADDR ({1'b0, addr}), |
---|
| 151 | .DI (di[15:8]), |
---|
| 152 | .EN (ce), |
---|
| 153 | .CLK (clk), |
---|
| 154 | .WE (we[1]), |
---|
| 155 | .RST (rst) |
---|
| 156 | ); |
---|
| 157 | |
---|
| 158 | RAMB4_S8 ram2 |
---|
| 159 | ( |
---|
| 160 | .DO (do[23:16]), |
---|
| 161 | .ADDR ({1'b0, addr}), |
---|
| 162 | .DI (di[23:16]), |
---|
| 163 | .EN (ce), |
---|
| 164 | .CLK (clk), |
---|
| 165 | .WE (we[2]), |
---|
| 166 | .RST (rst) |
---|
| 167 | ); |
---|
| 168 | |
---|
| 169 | RAMB4_S8 ram3 |
---|
| 170 | ( |
---|
| 171 | .DO (do[31:24]), |
---|
| 172 | .ADDR ({1'b0, addr}), |
---|
| 173 | .DI (di[31:24]), |
---|
| 174 | .EN (ce), |
---|
| 175 | .CLK (clk), |
---|
| 176 | .WE (we[3]), |
---|
| 177 | .RST (rst) |
---|
| 178 | ); |
---|
| 179 | |
---|
| 180 | `else // !ETH_XILINX_RAMB4 |
---|
| 181 | `ifdef ETH_VIRTUAL_SILICON_RAM |
---|
| 182 | `ifdef ETH_BIST |
---|
| 183 | //vs_hdsp_256x32_bist ram0_bist |
---|
| 184 | vs_hdsp_256x32_bw_bist ram0_bist |
---|
| 185 | `else |
---|
| 186 | //vs_hdsp_256x32 ram0 |
---|
| 187 | vs_hdsp_256x32_bw ram0 |
---|
| 188 | `endif |
---|
| 189 | ( |
---|
| 190 | .CK (clk), |
---|
| 191 | .CEN (!ce), |
---|
| 192 | .WEN (~we), |
---|
| 193 | .OEN (!oe), |
---|
| 194 | .ADR (addr), |
---|
| 195 | .DI (di), |
---|
| 196 | .DOUT (do) |
---|
| 197 | |
---|
| 198 | `ifdef ETH_BIST |
---|
| 199 | , |
---|
| 200 | // debug chain signals |
---|
| 201 | .mbist_si_i (mbist_si_i), |
---|
| 202 | .mbist_so_o (mbist_so_o), |
---|
| 203 | .mbist_ctrl_i (mbist_ctrl_i) |
---|
| 204 | `endif |
---|
| 205 | ); |
---|
| 206 | |
---|
| 207 | `else // !ETH_VIRTUAL_SILICON_RAM |
---|
| 208 | |
---|
| 209 | `ifdef ETH_ARTISAN_RAM |
---|
| 210 | `ifdef ETH_BIST |
---|
| 211 | //art_hssp_256x32_bist ram0_bist |
---|
| 212 | art_hssp_256x32_bw_bist ram0_bist |
---|
| 213 | `else |
---|
| 214 | //art_hssp_256x32 ram0 |
---|
| 215 | art_hssp_256x32_bw ram0 |
---|
| 216 | `endif |
---|
| 217 | ( |
---|
| 218 | .CLK (clk), |
---|
| 219 | .CEN (!ce), |
---|
| 220 | .WEN (~we), |
---|
| 221 | .OEN (!oe), |
---|
| 222 | .A (addr), |
---|
| 223 | .D (di), |
---|
| 224 | .Q (do) |
---|
| 225 | |
---|
| 226 | `ifdef ETH_BIST |
---|
| 227 | , |
---|
| 228 | // debug chain signals |
---|
| 229 | .mbist_si_i (mbist_si_i), |
---|
| 230 | .mbist_so_o (mbist_so_o), |
---|
| 231 | .mbist_ctrl_i (mbist_ctrl_i) |
---|
| 232 | `endif |
---|
| 233 | ); |
---|
| 234 | |
---|
| 235 | `else // !ETH_ARTISAN_RAM |
---|
| 236 | `ifdef ETH_ALTERA_ALTSYNCRAM |
---|
| 237 | |
---|
| 238 | altera_spram_256x32 altera_spram_256x32_inst |
---|
| 239 | ( |
---|
| 240 | .address (addr), |
---|
| 241 | .wren (ce & we), |
---|
| 242 | .clock (clk), |
---|
| 243 | .data (di), |
---|
| 244 | .q (do) |
---|
| 245 | ); //exemplar attribute altera_spram_256x32_inst NOOPT TRUE |
---|
| 246 | |
---|
| 247 | `else // !ETH_ALTERA_ALTSYNCRAM |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | // |
---|
| 251 | // Generic single-port synchronous RAM model |
---|
| 252 | // |
---|
| 253 | |
---|
| 254 | // |
---|
| 255 | // Generic RAM's registers and wires |
---|
| 256 | // |
---|
| 257 | reg [ 7: 0] mem0 [255:0]; // RAM content |
---|
| 258 | reg [15: 8] mem1 [255:0]; // RAM content |
---|
| 259 | reg [23:16] mem2 [255:0]; // RAM content |
---|
| 260 | reg [31:24] mem3 [255:0]; // RAM content |
---|
| 261 | wire [31:0] q; // RAM output |
---|
| 262 | reg [7:0] raddr; // RAM read address |
---|
| 263 | // |
---|
| 264 | // Data output drivers |
---|
| 265 | // |
---|
| 266 | assign do = (oe & ce) ? q : {32{1'bz}}; |
---|
| 267 | |
---|
| 268 | // |
---|
| 269 | // RAM read and write |
---|
| 270 | // |
---|
| 271 | |
---|
| 272 | // read operation |
---|
| 273 | always@(posedge clk) |
---|
| 274 | if (ce) // && !we) |
---|
| 275 | raddr <= #1 addr; // read address needs to be registered to read clock |
---|
| 276 | |
---|
| 277 | assign #1 q = rst ? {32{1'b0}} : {mem3[raddr], mem2[raddr], mem1[raddr], mem0[raddr]}; |
---|
| 278 | |
---|
| 279 | // write operation |
---|
| 280 | always@(posedge clk) |
---|
| 281 | begin |
---|
| 282 | if (ce && we[3]) |
---|
| 283 | mem3[addr] <= #1 di[31:24]; |
---|
| 284 | if (ce && we[2]) |
---|
| 285 | mem2[addr] <= #1 di[23:16]; |
---|
| 286 | if (ce && we[1]) |
---|
| 287 | mem1[addr] <= #1 di[15: 8]; |
---|
| 288 | if (ce && we[0]) |
---|
| 289 | mem0[addr] <= #1 di[ 7: 0]; |
---|
| 290 | end |
---|
| 291 | |
---|
| 292 | // Task prints range of memory |
---|
| 293 | // *** Remember that tasks are non reentrant, don't call this task in parallel for multiple instantiations. |
---|
| 294 | task print_ram; |
---|
| 295 | input [7:0] start; |
---|
| 296 | input [7:0] finish; |
---|
| 297 | integer rnum; |
---|
| 298 | begin |
---|
| 299 | for (rnum=start;rnum<=finish;rnum=rnum+1) |
---|
| 300 | $display("Addr %h = %0h %0h %0h %0h",rnum,mem3[rnum],mem2[rnum],mem1[rnum],mem0[rnum]); |
---|
| 301 | end |
---|
| 302 | endtask |
---|
| 303 | |
---|
| 304 | `endif // !ETH_ALTERA_ALTSYNCRAM |
---|
| 305 | `endif // !ETH_ARTISAN_RAM |
---|
| 306 | `endif // !ETH_VIRTUAL_SILICON_RAM |
---|
| 307 | `endif // !ETH_XILINX_RAMB4 |
---|
| 308 | |
---|
| 309 | endmodule |
---|