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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [orpsocv2/] [rtl/] [verilog/] [or1200/] [or1200_spram.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                         ////
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
////                                                              ////
21
//////////////////////////////////////////////////////////////////////
22
////                                                              ////
23
//// Copyright (C) 2000 Authors and OPENCORES.ORG                 ////
24
////                                                              ////
25
//// This source file may be used and distributed without         ////
26
//// restriction provided that this copyright statement is not    ////
27
//// removed from the file and that any derivative work contains  ////
28
//// the original copyright notice and the associated disclaimer. ////
29
////                                                              ////
30
//// This source file is free software; you can redistribute it   ////
31
//// and/or modify it under the terms of the GNU Lesser General   ////
32
//// Public License as published by the Free Software Foundation; ////
33
//// either version 2.1 of the License, or (at your option) any   ////
34
//// later version.                                               ////
35
////                                                              ////
36
//// This source is distributed in the hope that it will be       ////
37
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
38
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
39
//// PURPOSE.  See the GNU Lesser General Public License for more ////
40
//// details.                                                     ////
41
////                                                              ////
42
//// You should have received a copy of the GNU Lesser General    ////
43
//// Public License along with this source; if not, download it   ////
44
//// from http://www.opencores.org/lgpl.shtml                     ////
45
////                                                              ////
46
//////////////////////////////////////////////////////////////////////
47
//
48
// CVS Revision History
49
//
50
// $Log: or1200_dpram_32x32.v,v $
51
// Revision 2.0  2010/06/30 11:00:00  ORSoC
52
// New 
53
//
54
 
55
// synopsys translate_off
56
`include "timescale.v"
57
// synopsys translate_on
58
`include "or1200_defines.v"
59
 
60
module or1200_spram
61
  (
62
`ifdef OR1200_BIST
63
   // RAM BIST
64
   mbist_si_i, mbist_so_o, mbist_ctrl_i,
65
`endif
66
   // Generic synchronous single-port RAM interface
67 483 julius
   clk, rst, ce, we, addr, di, doq
68 482 julius
`ifdef OR1200_RAM_PARITY
69
   , p_err
70
`endif
71 350 julius
   );
72
 
73
   //
74
   // Default address and data buses width
75
   //
76
   parameter aw = 10;
77
   parameter dw = 32;
78
 
79
`ifdef OR1200_BIST
80
   //
81
   // RAM BIST
82
   //
83
   input mbist_si_i;
84
   input [`OR1200_MBIST_CTRL_WIDTH - 1:0] mbist_ctrl_i;
85 482 julius
   output                                 mbist_so_o;
86 350 julius
`endif
87
 
88
   //
89
   // Generic synchronous single-port RAM interface
90
   //
91
   input                                  clk;  // Clock
92 483 julius
   input                                  rst; // Reset
93 350 julius
   input                                  ce;   // Chip enable input
94
   input                                  we;   // Write enable input
95
   input [aw-1:0]                          addr; // address bus inputs
96
   input [dw-1:0]                          di;   // input data bus
97
   output [dw-1:0]                         doq;  // output data bus
98 482 julius
`ifdef OR1200_RAM_PARITY
99
   output                                 p_err; // parity error indicator
100
`endif
101 350 julius
 
102
   //
103
   // Internal wires and registers
104
   //
105
 
106
   //
107
   // Generic single-port synchronous RAM model
108
   //
109
 
110
   //
111
   // Generic RAM's registers and wires
112
   //
113 482 julius
`ifdef OR1200_RAM_PARITY
114 483 julius
   parameter par_w = (dw/8);
115
   reg [(dw+par_w)-1:0] mem [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
116 482 julius
`else
117 483 julius
   reg [dw-1:0] mem [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;
118 482 julius
`endif
119
 
120 483 julius
   reg [aw-1:0] addr_reg;                // RAM address register
121 482 julius
 
122
`ifdef OR1200_RAM_PARITY
123 483 julius
   wire [(dw+par_w)-1:0]         doq_wire;
124
   wire [par_w-1:0]              di_p;
125
   wire [par_w-1:0]              do_p;
126
   wire [par_w-1:0]              parity_err;
127
   reg                          ce_r;
128 350 julius
`else
129 482 julius
   wire [dw-1:0]                 doq_wire;
130 350 julius
`endif
131 482 julius
 
132
`ifdef OR1200_RAM_PARITY
133
   genvar                       i;
134
   generate
135 483 julius
      for (i=0;i<par_w;i=i+1) begin: paritygen
136 482 julius
         or1200_parity_gen pgen(.d_i(di[(i*8)+7:(i*8)]), .p_o(di_p[i]));
137
         or1200_parity_chk pchk(.d_i(doq_wire[(i*8)+7:(i*8)]),
138
                                .p_i(do_p[i]), .err_o(parity_err[i]));
139
      end
140
   endgenerate
141
 
142
   // Extract parity bits of data out
143 483 julius
   assign do_p = doq_wire[(dw+par_w)-1:dw];
144
 
145
   always @(posedge clk)
146
     if (rst)
147
       ce_r <= 0;
148
     else
149
       ce_r <= ce;
150
 
151
   // Indicate error
152
   assign p_err = (|parity_err) & ce_r;
153 350 julius
 
154 483 julius
   // Inject a parity error.
155 482 julius
   task gen_parity_err;
156 483 julius
      input [aw-1:0]             addr;
157 482 julius
      input [31:0]               parity_bit_no;
158
      input [31:0]               data_bit_no;
159 483 julius
      reg [(dw+par_w)-1:0]       do_temp;
160 482 julius
      begin
161 483 julius
         do_temp = mem[addr];
162 482 julius
         // Switch parity bit
163 483 julius
         if (parity_bit_no >= 0 && parity_bit_no < par_w)
164
           do_temp[dw+parity_bit_no] = ~do_temp[dw+parity_bit_no];
165 482 julius
         // Switch data bit
166 483 julius
         if (data_bit_no >= 0 && data_bit_no < dw)
167
           do_temp[data_bit_no] = ~do_temp[data_bit_no];
168 482 julius
         // Write word back
169 483 julius
         mem[addr] = do_temp;
170 482 julius
      end
171
   endtask // gen_parity_err
172
`endif
173
 
174
 
175 350 julius
   //
176
   // Data output drivers
177
   //
178 482 julius
   assign doq_wire = mem[addr_reg];
179
   assign doq = doq_wire[dw-1:0];
180 350 julius
 
181
   //
182
   // RAM read address register
183
   //
184
   always @(posedge clk)
185
     if (ce)
186
       addr_reg <=  addr;
187
 
188
   //
189
   // RAM write
190
   //
191
   always @(posedge clk)
192 483 julius
`ifdef OR1200_RAM_PARITY
193 350 julius
     if (we && ce)
194 482 julius
       mem[addr] <=  {di_p,di};
195 483 julius
`else
196
     if (we && ce)
197 350 julius
       mem[addr] <=  di;
198 482 julius
`endif
199 350 julius
 
200
endmodule // or1200_spram

powered by: WebSVN 2.1.0

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