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 482

Go to most recent revision | 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
   clk, 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
 
92
   //
93
   // Generic synchronous single-port RAM interface
94
   //
95
   input                                  clk;  // Clock
96
   input                                  ce;   // Chip enable input
97
   input [3:0]                             we;   // Write enable input
98
   input [aw-1:0]                          addr; // address bus inputs
99
   input [dw-1:0]                          di;   // input data bus
100
   output [dw-1:0]                         doq;  // output data bus
101 482 julius
`ifdef OR1200_RAM_PARITY
102
   output                                 p_err; // parity error indicator
103
`endif
104 350 julius
 
105
   //
106
   // Internal wires and registers
107
   //
108
 
109
   //
110
   // Generic single-port synchronous RAM model
111
   //
112
 
113
   //
114
   // Generic RAM's registers and wires
115
   //
116 482 julius
`ifdef OR1200_RAM_PARITY
117
   reg [bw:0]                              mem0 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
118
   reg [bw:0]                              mem1 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
119
   reg [bw:0]                              mem2 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
120
   reg [bw:0]                              mem3 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
121 350 julius
`else
122 482 julius
   reg [bw-1:0]                    mem0 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
123
   reg [bw-1:0]                    mem1 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
124
   reg [bw-1:0]                    mem2 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
125
   reg [bw-1:0]                    mem3 [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
126 350 julius
`endif
127
   reg [aw-1:0]                    addr_reg;             // RAM address register
128 482 julius
 
129
`ifdef OR1200_RAM_PARITY
130
   wire [(dw+(dw/8))-1:0]                  doq_wire;
131
   wire [bw:0]                             doq0_wire;
132
   wire [bw:0]                             doq1_wire;
133
   wire [bw:0]                             doq2_wire;
134
   wire [bw:0]                             doq3_wire;
135
   wire [(dw/8)-1:0]                       di_p;
136
   wire [(dw/8)-1:0]                       do_p;
137
   wire [(dw/8)-1:0]                       parity_err;
138
`else
139
   wire [dw-1:0]                           doq_wire;
140
`endif
141
 
142
`ifdef OR1200_RAM_PARITY
143
   genvar                       i;
144
   generate
145
      for (i=0;i<(dw/8);i=i+1) begin: paritygen
146
         or1200_parity_gen pgen(.d_i(di[(i*8)+7:(i*8)]), .p_o(di_p[i]));
147
         or1200_parity_chk pchk(.d_i(doq_wire[(i*8)+7:(i*8)]),
148
                                .p_i(do_p[i]), .err_o(parity_err[i]));
149
      end
150
   endgenerate
151
 
152
   // Extract parity bits of data out
153
   assign do_p = doq_wire[(dw+(dw/8))-1:dw];
154 350 julius
 
155 482 julius
   // Indicate error
156
   assign p_err = (|parity_err);
157
 
158
   // Inject a parity error. Can specify GPR number to affect,
159
   // and which parity or data bit to switch.
160
   task gen_parity_err;
161
      input [aw-1:0]             gpr_no;
162
      input [31:0]               parity_bit_no;
163
      input [31:0]               data_bit_no;
164
      reg [(dw+(dw/8))-1:0]      do_temp;
165
      begin
166
         // TODO
167
         /*
168
         do_temp = mem[gpr_no];
169
         // Switch parity bit
170
         if (parity_bit_no > 0 && parity_bit_no <= (dw/8))
171
           do_temp[dw+(parity_bit_no-1)] = ~do_temp[dw+(parity_bit_no-1)];
172
         // Switch data bit
173
         if (data_bit_no > 0 && data_bit_no <= dw)
174
           do_temp[data_bit_no-1] = ~do_temp[data_bit_no-1];
175
         // Write word back
176
         mem[gpr_no] = do_temp;
177
          */
178
      end
179
   endtask // gen_parity_err
180
`endif
181
 
182 350 julius
   //
183
   // Data output drivers
184
   //
185 482 julius
`ifdef OR1200_RAM_PARITY
186
   assign doq0_wire = mem0[addr_reg];
187
   assign doq1_wire = mem1[addr_reg];
188
   assign doq2_wire = mem2[addr_reg];
189
   assign doq3_wire = mem3[addr_reg];
190 350 julius
 
191 482 julius
   assign doq_wire = {// Parity bits
192
                      doq0_wire[bw],doq1_wire[bw],doq2_wire[bw],doq3_wire[bw],
193
                      // Data bytes
194
                      doq0_wire[bw-1:0],doq1_wire[bw-1:0],
195
                      doq2_wire[bw-1:0],doq3_wire[bw-1:0]};
196
`else
197
   assign doq_wire = {mem0[addr_reg], mem1[addr_reg], mem2[addr_reg], mem3[addr_reg]};
198
`endif
199
   assign doq = doq_wire[dw-1:0];
200
 
201
 
202 350 julius
   //
203
   // RAM read address register
204
   //
205
   always @(posedge clk)
206
     if (ce)
207
       addr_reg <=  addr;
208
 
209
   //
210
   // RAM write - big endian selection
211
   //
212
   always @(posedge clk)
213
     if (ce) begin
214 482 julius
`ifdef OR1200_RAM_PARITY
215
        if (we[3])
216
          mem0[addr] <=  {di_p[3],di[(bw*3)+(bw-1):(bw*3)]};
217
        if (we[2])
218
          mem1[addr] <=  {di_p[2],di[(bw*2)+(bw-1):(bw*2)]};
219
        if (we[1])
220
          mem2[addr] <=  {di_p[1],di[(bw*1)+(bw-1):(bw*1)]};
221
        if (we[0])
222
          mem3[addr] <=  {di_p[0],di[(bw*0)+(bw-1):(bw*0)]};
223
`else
224
        if (we[3])
225
          mem0[addr] <=  di[(bw*3)+(bw-1):(bw*3)];
226
        if (we[2])
227
          mem1[addr] <=  di[(bw*2)+(bw-1):(bw*2)];
228
        if (we[1])
229
          mem2[addr] <=  di[(bw*1)+(bw-1):(bw*1)];
230
        if (we[0])
231
          mem3[addr] <=  di[(bw*0)+(bw-1):(bw*0)];
232
`endif
233 350 julius
     end
234
 
235
endmodule // or1200_spram

powered by: WebSVN 2.1.0

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