OpenCores
URL https://opencores.org/ocsvn/xge_mac/xge_mac/trunk

Subversion Repositories xge_mac

[/] [xge_mac/] [trunk/] [rtl/] [verilog/] [generic_mem_small.v] - Diff between revs 7 and 20

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 7 Rev 20
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
////  File name "generic_mem_small.v"                             ////
////  File name "generic_mem_small.v"                             ////
////                                                              ////
////                                                              ////
////  This file is part of the "10GE MAC" project                 ////
////  This file is part of the "10GE MAC" project                 ////
////  http://www.opencores.org/cores/xge_mac/                     ////
////  http://www.opencores.org/cores/xge_mac/                     ////
////                                                              ////
////                                                              ////
////  Author(s):                                                  ////
////  Author(s):                                                  ////
////      - A. Tanguay (antanguay@opencores.org)                  ////
////      - A. Tanguay (antanguay@opencores.org)                  ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
////                                                              ////
////                                                              ////
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
//// Copyright (C) 2008 AUTHORS. All rights reserved.             ////
////                                                              ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
//// later version.                                               ////
////                                                              ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
//// details.                                                     ////
////                                                              ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
 
 
/* synthesis ramstyle = "M512" */
/* synthesis ramstyle = "M512" */
 
 
module generic_mem_small(
module generic_mem_small(
 
 
    wclk,
    wclk,
    wrst_n,
    wrst_n,
    wen,
    wen,
    waddr,
    waddr,
    wdata,
    wdata,
 
 
    rclk,
    rclk,
    rrst_n,
    rrst_n,
    ren,
    ren,
    roen,
    roen,
    raddr,
    raddr,
    rdata
    rdata
);
);
 
 
//---
//---
// Parameters
// Parameters
 
 
parameter DWIDTH = 32;
parameter DWIDTH = 32;
parameter AWIDTH = 3;
parameter AWIDTH = 3;
parameter RAM_DEPTH = (1 << AWIDTH);
parameter RAM_DEPTH = (1 << AWIDTH);
parameter SYNC_WRITE = 1;
 
parameter SYNC_READ = 1;
 
parameter REGISTER_READ = 0;
parameter REGISTER_READ = 0;
 
 
//---
//---
// Ports
// Ports
 
 
input               wclk;
input               wclk;
input               wrst_n;
input               wrst_n;
input               wen;
input               wen;
input  [AWIDTH:0]   waddr;
input  [AWIDTH-1:0] waddr;
input  [DWIDTH-1:0] wdata;
input  [DWIDTH-1:0] wdata;
 
 
input               rclk;
input               rclk;
input               rrst_n;
input               rrst_n;
input               ren;
input               ren;
input               roen;
input               roen;
input  [AWIDTH:0]   raddr;
input  [AWIDTH-1:0] raddr;
output [DWIDTH-1:0] rdata;
output [DWIDTH-1:0] rdata;
 
 
// Registered outputs
// Registered outputs
reg    [DWIDTH-1:0] rdata;
reg    [DWIDTH-1:0] rdata;
 
 
 
 
//---
//---
// Local declarations
// Local declarations
 
 
// Registers
// Registers
 
 
reg  [DWIDTH-1:0] mem_rdata;
reg  [DWIDTH-1:0] mem_rdata;
 
 
 
 
// Memory
// Memory
 
 
reg  [DWIDTH-1:0] mem [0:RAM_DEPTH-1];
reg  [DWIDTH-1:0] mem [0:RAM_DEPTH-1];
 
 
// Variables
// Variables
 
 
integer         i;
integer         i;
 
 
 
 
//---
//---
// Memory Write
// Memory Write
 
 
generate
 
    if (SYNC_WRITE) begin
 
 
 
        // Generate synchronous write
        // Generate synchronous write
        always @(posedge wclk)
always @(posedge wclk)
        begin
begin
            if (wen) begin
    if (wen) begin
                mem[waddr[AWIDTH-1:0]] <= wdata;
        mem[waddr[AWIDTH-1:0]] <= wdata;
            end
    end
        end
        end
    end
 
    else begin
 
 
 
        // Generate asynchronous write
 
        always @(wen, waddr, wdata)
 
        begin
 
            if (wen) begin
 
                mem[waddr[AWIDTH-1:0]] = wdata;
 
            end
 
        end
 
    end
 
endgenerate
 
 
 
//---
//---
// Memory Read
// Memory Read
 
 
generate
 
    if (SYNC_READ) begin
 
 
 
        // Generate registered memory read
        // Generate registered memory read
        always @(posedge rclk or negedge rrst_n)
always @(posedge rclk or negedge rrst_n)
        begin
begin
            if (!rrst_n) begin
    if (!rrst_n) begin
                mem_rdata <= {(DWIDTH){1'b0}};
        mem_rdata <= {(DWIDTH){1'b0}};
            end else if (ren) begin
    end else if (ren) begin
                mem_rdata <= mem[raddr[AWIDTH-1:0]];
        mem_rdata <= mem[raddr[AWIDTH-1:0]];
            end
    end
        end
        end
    end
 
    else begin
 
 
 
        // Generate unregisters memory read
 
        always @(raddr, rclk)
 
        begin
 
            mem_rdata = mem[raddr[AWIDTH-1:0]];
 
        end
 
    end
 
endgenerate
 
 
 
generate
generate
    if (REGISTER_READ) begin
    if (REGISTER_READ) begin
 
 
        // Generate registered output
        // Generate registered output
        always @(posedge rclk or negedge rrst_n)
        always @(posedge rclk or negedge rrst_n)
        begin
        begin
            if (!rrst_n) begin
            if (!rrst_n) begin
                rdata <= {(DWIDTH){1'b0}};
                rdata <= {(DWIDTH){1'b0}};
            end else if (roen) begin
            end else if (roen) begin
                rdata <= mem_rdata;
                rdata <= mem_rdata;
            end
            end
        end
        end
 
 
    end
    end
    else begin
    else begin
 
 
        // Generate unregisters output
        // Generate unregisters output
        always @(mem_rdata)
        always @(mem_rdata)
        begin
        begin
            rdata = mem_rdata;
            rdata = mem_rdata;
        end
        end
 
 
    end
    end
endgenerate
endgenerate
 
 
endmodule
endmodule
 
 
 
 
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.