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

Subversion Repositories wf3d

[/] [wf3d/] [trunk/] [scenario/] [3d/] [memory_sram.v] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 specular
//=======================================================================
2
// Project Monophony
3
//   Wire-Frame 3D Graphics Accelerator IP Core
4
//
5
// File:
6
//   memory_sram.v
7
//
8
// Abstract:
9
//   sram memory for simulation
10
//
11
// Author:
12 9 specular
//   Kenji Ishimaru (info.info.wf3d@gmail.com)
13 2 specular
//
14
//======================================================================
15
//
16
// Copyright (c) 2015, Kenji Ishimaru
17
// All rights reserved.
18
//
19
// Redistribution and use in source and binary forms, with or without
20
// modification, are permitted provided that the following conditions are met:
21
//
22
//  -Redistributions of source code must retain the above copyright notice,
23
//   this list of conditions and the following disclaimer.
24
//  -Redistributions in binary form must reproduce the above copyright notice,
25
//   this list of conditions and the following disclaimer in the documentation
26
//   and/or other materials provided with the distribution.
27
//
28
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
30
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
35
// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
37
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// Revision History
41
 
42
module memory_sram (
43
  clk,
44
  adr,
45
  din,
46
  be,
47
  dout,
48
  rdb,
49
  wrb,
50
  rstb
51
);
52
 
53
/////////////////////////////////////
54
// parameter
55
////////////////////////////////////
56
  parameter P_ADRS_WIDTH = 22;
57
  parameter P_DATA_WIDTH = 32;
58
  parameter P_BE_WIDTH = P_DATA_WIDTH/8;
59
/////////////////////////////////////
60
// Port Definition
61
////////////////////////////////////
62
  input          clk;
63
  input  [P_ADRS_WIDTH-1:0]
64
                 adr;
65
  input  [P_DATA_WIDTH-1:0]
66
                 din;
67
  input  [P_BE_WIDTH-1:0]
68
                 be;
69
  output [P_DATA_WIDTH-1:0]
70
                 dout;
71
  input          rdb;
72
  input          wrb;
73
  input          rstb;
74
/////////////////////////////////////
75
// reg
76
////////////////////////////////////
77
// memory instance
78
  reg  [31:0] mem[0:(1 << P_ADRS_WIDTH)-1];
79
 
80
  reg  [P_DATA_WIDTH-1:0]
81
             r_dout_1z;
82
  reg  [P_DATA_WIDTH-1:0]
83
             r_dout_2z;
84
/////////////////////////////////////
85
// wire
86
////////////////////////////////////
87
  wire [P_DATA_WIDTH-1:0]
88
             w_dout;
89
  wire [P_DATA_WIDTH-1:0]
90
             w_din;
91
/////////////////////////////////////
92
// assign
93
////////////////////////////////////
94
  assign w_dout = mem[adr];
95
  assign w_din = f_new_data(din,be,mem[adr]);
96
  assign dout = r_dout_2z;
97
/////////////////////////////////////
98
// always
99
////////////////////////////////////
100
   integer i;
101
   initial begin
102
   for (i=0;i<(1 << P_ADRS_WIDTH);i=i+1)
103
      mem[i] = 32'h00000000;
104
   end
105
  always @(posedge clk) begin
106
    if (wrb == 1'b0) begin
107
      mem[adr] <= w_din;
108
    end
109
  end
110
 
111
//`ifdef RTL_DEBUG
112
//  always @(posedge clk) begin
113
//    if (wrb == 1'b0) begin
114
//      $display("a4 a d = %h %h",adr,adr<<2,w_din);
115
//    end
116
//  end
117
//`endif
118
 
119
  always @(posedge clk) begin
120
    r_dout_1z <= w_dout;
121
    r_dout_2z <= r_dout_1z;
122
  end
123
 
124
 
125
  function [P_DATA_WIDTH-1:0] f_new_data;
126
      input [P_DATA_WIDTH-1:0] new_data;
127
      input [P_BE_WIDTH-1:0]   be;
128
      input [P_DATA_WIDTH-1:0] cur_data;
129
      reg   [P_DATA_WIDTH-1:0] result;
130
      begin
131
          result = cur_data;
132
          if (be[0]) result[7:0] = new_data[7:0];
133
          if (be[1]) result[15:8] = new_data[15:8];
134
          if (be[2]) result[23:16] = new_data[23:16];
135
          if (be[3]) result[31:24] = new_data[31:24];
136
          f_new_data = result;
137
      end
138
  endfunction
139
 
140
 
141
endmodule
142
 

powered by: WebSVN 2.1.0

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