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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [or1200/] [or1200_spram_32_bw.v] - Blame information for rev 483

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 350 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Generic Single-Port Synchronous RAM 32-bit Byte-Write       ////
4
////                                                              ////
5
////  This file is part of memory library available from          ////
6
////  http://www.opencores.org/cvsweb.shtml/generic_memories/     ////
7
////                                                              ////
8
////  Description                                                 ////
9
////  This block is a wrapper with common single-port             ////
10
////  synchronous memory interface for different                  ////
11
////  types of ASIC and FPGA RAMs. Beside universal memory        ////
12
////  interface it also provides behavioral model of generic      ////
13
////  single-port synchronous RAM.                                ////
14
////  It should be used in all OPENCORES designs that want to be  ////
15
////  portable accross different target technologies and          ////
16
////  independent of target memory.                               ////
17
////                                                              ////
18
////  Author(s):                                                  ////
19
////      - Michael Unneback, unneback@opencores.org              ////
20
////      - Tadej Markovic, tadej.markovic@gmail.com              ////
21
////                                                              ////
22
//////////////////////////////////////////////////////////////////////
23
////                                                              ////
24
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
25
////                                                              ////
26
//// This source file may be used and distributed without         ////
27
//// restriction provided that this copyright statement is not    ////
28
//// removed from the file and that any derivative work contains  ////
29
//// the original copyright notice and the associated disclaimer. ////
30
////                                                              ////
31
//// This source file is free software; you can redistribute it   ////
32
//// and/or modify it under the terms of the GNU Lesser General   ////
33
//// Public License as published by the Free Software Foundation; ////
34
//// either version 2.1 of the License, or (at your option) any   ////
35
//// later version.                                               ////
36
////                                                              ////
37
//// This source is distributed in the hope that it will be       ////
38
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
39
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
40
//// PURPOSE.  See the GNU Lesser General Public License for more ////
41
//// details.                                                     ////
42
////                                                              ////
43
//// You should have received a copy of the GNU Lesser General    ////
44
//// Public License along with this source; if not, download it   ////
45
//// from http://www.opencores.org/lgpl.shtml                     ////
46
////                                                              ////
47
//////////////////////////////////////////////////////////////////////
48
//
49
// CVS Revision History
50
//
51
// $Log: or1200_dpram_32x32.v,v $
52
// Revision 2.0  2010/06/30 11:00:00  ORSoC
53
// New 
54
//
55
 
56
// synopsys translate_off
57
`include "timescale.v"
58
// synopsys translate_on
59
`include "or1200_defines.v"
60
 
61
module or1200_spram_32_bw
62
  (
63
`ifdef OR1200_BIST
64
   // RAM BIST
65
   mbist_si_i, mbist_so_o, mbist_ctrl_i,
66
`endif
67
   // Generic synchronous single-port RAM interface
68 483 julius
   clk, rst, ce, we, addr, di, doq
69 482 julius
`ifdef OR1200_RAM_PARITY
70
   , p_err
71
`endif
72 350 julius
   );
73
 
74
   //
75
   // Default address and data buses width
76
   //
77
   parameter aw = 10;
78
   parameter dw = 32;
79
 
80 482 julius
   parameter bw = 8;
81
 
82
 
83 350 julius
`ifdef OR1200_BIST
84
   //
85
   // RAM BIST
86
   //
87
   input mbist_si_i;
88
   input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
89
   output                                 mbist_so_o;
90
`endif
91 483 julius
 
92
`ifdef OR1200_RAM_PARITY
93
   output                                 p_err; // parity error indicator
94
`endif
95 350 julius
 
96
   //
97 483 julius
   // Generic synchronous single-port byte-writable RAM interface
98 350 julius
   //
99
   input                                  clk;  // Clock
100 483 julius
   input                                  rst;  // Reset
101 350 julius
   input                                  ce;   // Chip enable input
102
   input [3:0]                             we;   // Write enable input
103
   input [aw-1:0]                          addr; // address bus inputs
104
   input [dw-1:0]                          di;   // input data bus
105
   output [dw-1:0]                         doq;  // output data bus
106 483 julius
 
107 350 julius
 
108
   //
109
   // Internal wires and registers
110
   //
111
 
112
   //
113
   // Generic single-port synchronous RAM model
114
   //
115
 
116
   //
117
   // Generic RAM's registers and wires
118
   //
119 482 julius
`ifdef OR1200_RAM_PARITY
120 483 julius
   reg [bw:0]    mem0 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
121
   reg [bw:0]    mem1 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
122
   reg [bw:0]    mem2 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
123
   reg [bw:0]    mem3 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
124 350 julius
`else
125 483 julius
   reg [bw-1:0] mem0 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
126
   reg [bw-1:0] mem1 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
127
   reg [bw-1:0] mem2 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
128
   reg [bw-1:0] mem3 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
129 350 julius
`endif
130 483 julius
   reg [aw-1:0] addr_reg;                // RAM address register
131 482 julius
 
132
`ifdef OR1200_RAM_PARITY
133
   wire [(dw+(dw/8))-1:0]                  doq_wire;
134
   wire [bw:0]                             doq0_wire;
135
   wire [bw:0]                             doq1_wire;
136
   wire [bw:0]                             doq2_wire;
137
   wire [bw:0]                             doq3_wire;
138
   wire [(dw/8)-1:0]                       di_p;
139
   wire [(dw/8)-1:0]                       do_p;
140
   wire [(dw/8)-1:0]                       parity_err;
141 483 julius
   reg                                    ce_r;
142 482 julius
`else
143
   wire [dw-1:0]                           doq_wire;
144
`endif
145
 
146
`ifdef OR1200_RAM_PARITY
147
   genvar                       i;
148
   generate
149
      for (i=0;i<(dw/8);i=i+1) begin: paritygen
150
         or1200_parity_gen pgen(.d_i(di[(i*8)+7:(i*8)]), .p_o(di_p[i]));
151
         or1200_parity_chk pchk(.d_i(doq_wire[(i*8)+7:(i*8)]),
152
                                .p_i(do_p[i]), .err_o(parity_err[i]));
153
      end
154
   endgenerate
155
 
156
   // Extract parity bits of data out
157
   assign do_p = doq_wire[(dw+(dw/8))-1:dw];
158 483 julius
 
159
   always @(posedge clk)
160
     if (rst)
161
       ce_r <= 0;
162
     else
163
       ce_r <= ce;
164 350 julius
 
165 482 julius
   // Indicate error
166 483 julius
   assign p_err = (|parity_err) & ce_r;
167 482 julius
 
168
   // Inject a parity error. Can specify GPR number to affect,
169
   // and which parity or data bit to switch.
170
   task gen_parity_err;
171 483 julius
      input [aw-1:0]             word_no;
172 482 julius
      input [31:0]               data_bit_no;
173 483 julius
      reg [bw:0]                 do_temp;
174 482 julius
      begin
175 483 julius
         // Fish word out
176
         if (data_bit_no < 8) begin
177
            do_temp = mem0[word_no];
178
         end
179
         else if (data_bit_no < 16) begin
180
            do_temp = mem1[word_no];
181
            data_bit_no = data_bit_no - 8;
182
         end
183
         else if (data_bit_no < 24) begin
184
            do_temp = mem2[word_no];
185
            data_bit_no = data_bit_no - 16;
186
         end
187
         else if (data_bit_no < 32) begin
188
            do_temp = mem3[word_no];
189
            data_bit_no = data_bit_no - 24;
190
         end
191
         else begin
192
            do_temp = mem3[word_no];
193
            data_bit_no = 8;
194
         end
195
 
196
         // Switch bit
197
         do_temp[data_bit_no] = ~do_temp[data_bit_no] ;
198
 
199
         // Replace word
200
         if (data_bit_no < 8)
201
            mem0[word_no] = do_temp;
202
         else if (data_bit_no < 16)
203
            mem1[word_no] = do_temp;
204
         else if (data_bit_no < 24)
205
           mem2[word_no] = do_temp;
206
         else
207
            mem3[word_no] = do_temp;
208 482 julius
      end
209
   endtask // gen_parity_err
210
`endif
211
 
212 350 julius
   //
213
   // Data output drivers
214
   //
215 482 julius
`ifdef OR1200_RAM_PARITY
216
   assign doq0_wire = mem0[addr_reg];
217
   assign doq1_wire = mem1[addr_reg];
218
   assign doq2_wire = mem2[addr_reg];
219
   assign doq3_wire = mem3[addr_reg];
220 350 julius
 
221 482 julius
   assign doq_wire = {// Parity bits
222
                      doq0_wire[bw],doq1_wire[bw],doq2_wire[bw],doq3_wire[bw],
223
                      // Data bytes
224
                      doq0_wire[bw-1:0],doq1_wire[bw-1:0],
225
                      doq2_wire[bw-1:0],doq3_wire[bw-1:0]};
226
`else
227
   assign doq_wire = {mem0[addr_reg], mem1[addr_reg], mem2[addr_reg], mem3[addr_reg]};
228
`endif
229
   assign doq = doq_wire[dw-1:0];
230
 
231
 
232 350 julius
   //
233
   // RAM read address register
234
   //
235
   always @(posedge clk)
236
     if (ce)
237
       addr_reg <=  addr;
238
 
239
   //
240
   // RAM write - big endian selection
241
   //
242
   always @(posedge clk)
243
     if (ce) begin
244 482 julius
`ifdef OR1200_RAM_PARITY
245
        if (we[3])
246
          mem0[addr] <=  {di_p[3],di[(bw*3)+(bw-1):(bw*3)]};
247
        if (we[2])
248
          mem1[addr] <=  {di_p[2],di[(bw*2)+(bw-1):(bw*2)]};
249
        if (we[1])
250
          mem2[addr] <=  {di_p[1],di[(bw*1)+(bw-1):(bw*1)]};
251
        if (we[0])
252
          mem3[addr] <=  {di_p[0],di[(bw*0)+(bw-1):(bw*0)]};
253
`else
254
        if (we[3])
255
          mem0[addr] <=  di[(bw*3)+(bw-1):(bw*3)];
256
        if (we[2])
257
          mem1[addr] <=  di[(bw*2)+(bw-1):(bw*2)];
258
        if (we[1])
259
          mem2[addr] <=  di[(bw*1)+(bw-1):(bw*1)];
260
        if (we[0])
261
          mem3[addr] <=  di[(bw*0)+(bw-1):(bw*0)];
262
`endif
263 350 julius
     end
264
 
265 483 julius
endmodule // or1200_spram_32_bw
266
 

powered by: WebSVN 2.1.0

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