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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [memory_sram.v] - Diff between revs 4 and 9

Only display areas with differences | Details | Blame | View Log

Rev 4 Rev 9
//=======================================================================
//=======================================================================
// Project Monophony
// Project Monophony
//   Wire-Frame 3D Graphics Accelerator IP Core
//   Wire-Frame 3D Graphics Accelerator IP Core
//
//
// File:
// File:
//   memory_sram.v
//   memory_sram.v
//
//
// Abstract:
// Abstract:
//   sram memory for simulation
//   sram memory for simulation
//
//
// Author:
// Author:
//   Kenji Ishimaru (info.wf3d@gmail.com)
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
//
//
//======================================================================
//======================================================================
//
//
// Copyright (c) 2015, Kenji Ishimaru
// Copyright (c) 2015, Kenji Ishimaru
// All rights reserved.
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// modification, are permitted provided that the following conditions are met:
//
//
//  -Redistributions of source code must retain the above copyright notice,
//  -Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
//   this list of conditions and the following disclaimer.
//  -Redistributions in binary form must reproduce the above copyright notice,
//  -Redistributions in binary form must reproduce the above copyright notice,
//   this list of conditions and the following disclaimer in the documentation
//   this list of conditions and the following disclaimer in the documentation
//   and/or other materials provided with the distribution.
//   and/or other materials provided with the distribution.
//
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//
// Revision History
// Revision History
 
 
module memory_sram (
module memory_sram (
  clk,
  clk,
  adr,
  adr,
  din,
  din,
  be,
  be,
  dout,
  dout,
  rdb,
  rdb,
  wrb,
  wrb,
  rstb
  rstb
);
);
 
 
/////////////////////////////////////
/////////////////////////////////////
// parameter
// parameter
////////////////////////////////////
////////////////////////////////////
  parameter P_ADRS_WIDTH = 22;
  parameter P_ADRS_WIDTH = 22;
  parameter P_DATA_WIDTH = 32;
  parameter P_DATA_WIDTH = 32;
  parameter P_BE_WIDTH = P_DATA_WIDTH/8;
  parameter P_BE_WIDTH = P_DATA_WIDTH/8;
/////////////////////////////////////
/////////////////////////////////////
// Port Definition
// Port Definition
////////////////////////////////////
////////////////////////////////////
  input          clk;
  input          clk;
  input  [P_ADRS_WIDTH-1:0]
  input  [P_ADRS_WIDTH-1:0]
                 adr;
                 adr;
  input  [P_DATA_WIDTH-1:0]
  input  [P_DATA_WIDTH-1:0]
                 din;
                 din;
  input  [P_BE_WIDTH-1:0]
  input  [P_BE_WIDTH-1:0]
                 be;
                 be;
  output [P_DATA_WIDTH-1:0]
  output [P_DATA_WIDTH-1:0]
                 dout;
                 dout;
  input          rdb;
  input          rdb;
  input          wrb;
  input          wrb;
  input          rstb;
  input          rstb;
/////////////////////////////////////
/////////////////////////////////////
// reg
// reg
////////////////////////////////////
////////////////////////////////////
// memory instance
// memory instance
  reg  [31:0] mem[0:(1 << P_ADRS_WIDTH)-1];
  reg  [31:0] mem[0:(1 << P_ADRS_WIDTH)-1];
 
 
  reg  [P_DATA_WIDTH-1:0]
  reg  [P_DATA_WIDTH-1:0]
             r_dout_1z;
             r_dout_1z;
  reg  [P_DATA_WIDTH-1:0]
  reg  [P_DATA_WIDTH-1:0]
             r_dout_2z;
             r_dout_2z;
/////////////////////////////////////
/////////////////////////////////////
// wire
// wire
////////////////////////////////////
////////////////////////////////////
  wire [P_DATA_WIDTH-1:0]
  wire [P_DATA_WIDTH-1:0]
             w_dout;
             w_dout;
  wire [P_DATA_WIDTH-1:0]
  wire [P_DATA_WIDTH-1:0]
             w_din;
             w_din;
/////////////////////////////////////
/////////////////////////////////////
// assign
// assign
////////////////////////////////////
////////////////////////////////////
  assign w_dout = mem[adr];
  assign w_dout = mem[adr];
  assign w_din = f_new_data(din,be,mem[adr]);
  assign w_din = f_new_data(din,be,mem[adr]);
  assign dout = r_dout_2z;
  assign dout = r_dout_2z;
/////////////////////////////////////
/////////////////////////////////////
// always
// always
////////////////////////////////////
////////////////////////////////////
   integer i;
   integer i;
   initial begin
   initial begin
   for (i=0;i<(1 << P_ADRS_WIDTH);i=i+1)
   for (i=0;i<(1 << P_ADRS_WIDTH);i=i+1)
      mem[i] = 32'h00000000;
      mem[i] = 32'h00000000;
   end
   end
  always @(posedge clk) begin
  always @(posedge clk) begin
    if (wrb == 1'b0) begin
    if (wrb == 1'b0) begin
      mem[adr] <= w_din;
      mem[adr] <= w_din;
    end
    end
  end
  end
 
 
//`ifdef RTL_DEBUG
//`ifdef RTL_DEBUG
//  always @(posedge clk) begin
//  always @(posedge clk) begin
//    if (wrb == 1'b0) begin
//    if (wrb == 1'b0) begin
//      $display("a4 a d = %h %h",adr,adr<<2,w_din);
//      $display("a4 a d = %h %h",adr,adr<<2,w_din);
//    end
//    end
//  end
//  end
//`endif
//`endif
 
 
  always @(posedge clk) begin
  always @(posedge clk) begin
    r_dout_1z <= w_dout;
    r_dout_1z <= w_dout;
    r_dout_2z <= r_dout_1z;
    r_dout_2z <= r_dout_1z;
  end
  end
 
 
 
 
  function [P_DATA_WIDTH-1:0] f_new_data;
  function [P_DATA_WIDTH-1:0] f_new_data;
      input [P_DATA_WIDTH-1:0] new_data;
      input [P_DATA_WIDTH-1:0] new_data;
      input [P_BE_WIDTH-1:0]   be;
      input [P_BE_WIDTH-1:0]   be;
      input [P_DATA_WIDTH-1:0] cur_data;
      input [P_DATA_WIDTH-1:0] cur_data;
      reg   [P_DATA_WIDTH-1:0] result;
      reg   [P_DATA_WIDTH-1:0] result;
      begin
      begin
          result = cur_data;
          result = cur_data;
          if (be[0]) result[7:0] = new_data[7:0];
          if (be[0]) result[7:0] = new_data[7:0];
          if (be[1]) result[15:8] = new_data[15:8];
          if (be[1]) result[15:8] = new_data[15:8];
          if (be[2]) result[23:16] = new_data[23:16];
          if (be[2]) result[23:16] = new_data[23:16];
          if (be[3]) result[31:24] = new_data[31:24];
          if (be[3]) result[31:24] = new_data[31:24];
          f_new_data = result;
          f_new_data = result;
      end
      end
  endfunction
  endfunction
 
 
 
 
endmodule
endmodule
 
 
 
 

powered by: WebSVN 2.1.0

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