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

Subversion Repositories openrisc_me

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 350 julius
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
////  Generic Double-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 double-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
////  double-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_dpram
61
  (
62 483 julius
   rst,
63 350 julius
   // Generic synchronous double-port RAM interface
64
   clk_a, ce_a, addr_a, do_a,
65
   clk_b, ce_b, we_b, addr_b, di_b
66 482 julius
`ifdef OR1200_RAM_PARITY
67
   , p_err
68
`endif
69 350 julius
   );
70
 
71
   //
72
   // Default address and data buses width
73
   //
74
   parameter aw = 5;
75
   parameter dw = 32;
76
 
77
   //
78
   // Generic synchronous double-port RAM interface
79
   //
80 483 julius
   input                        rst;    // Reset
81 350 julius
   input                        clk_a;  // Clock
82
   input                        ce_a;   // Chip enable input
83
   input [aw-1:0]                addr_a; // address bus inputs
84
   output [dw-1:0]               do_a;   // output data bus
85
   input                        clk_b;  // Clock
86
   input                        ce_b;   // Chip enable input
87
   input                        we_b;   // Write enable input
88
   input [aw-1:0]                addr_b; // address bus inputs
89
   input [dw-1:0]                di_b;   // input data bus
90 482 julius
`ifdef OR1200_RAM_PARITY
91
   output                       p_err; // parity error indicator
92
`endif
93 350 julius
 
94
   //
95
   // Internal wires and registers
96
   //
97
 
98
   //
99
   // Generic double-port synchronous RAM model
100
   //
101
 
102
   //
103
   // Generic RAM's registers and wires
104
   //
105 483 julius
`ifdef OR1200_RAM_PARITY
106
   parameter par_w = (dw/8);
107
 
108
   reg [(dw+par_w)-1:0]          mem [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;    // RAM content
109 482 julius
`else
110 350 julius
   reg [dw-1:0]          mem [(1<<aw)-1:0] /*synthesis syn_ramstyle = "no_rw_check"*/;    // RAM content
111 482 julius
`endif
112 350 julius
   reg [aw-1:0]          addr_a_reg;             // RAM address registered
113
 
114 482 julius
`ifdef OR1200_RAM_PARITY
115 483 julius
   wire [(dw+par_w)-1:0]         do_a_wire;
116
   wire [par_w-1:0]              di_p;
117
   wire [par_w-1:0]              do_p;
118
   wire [par_w-1:0]              parity_err;
119 482 julius
`else
120
   wire [dw-1:0]         do_a_wire;
121
`endif
122 350 julius
 
123
   // Function to access GPRs (for use by Verilator). No need to hide this one
124
   // from the simulator, since it has an input (as required by IEEE 1364-2001).
125
   function [31:0] get_gpr;
126
      // verilator public
127
      input [aw-1:0]             gpr_no;
128 483 julius
`ifdef OR1200_RAM_PARITY
129
      reg [(dw+par_w)-1:0]               gpr_temp;
130 482 julius
      begin
131
         gpr_temp = mem[gpr_no];
132
         get_gpr = gpr_temp[31:0];
133 483 julius
      end
134 482 julius
`else
135 483 julius
 
136 482 julius
         get_gpr = mem[gpr_no];
137
`endif
138 350 julius
   endfunction // get_gpr
139 462 julius
 
140 482 julius
   task set_gpr;
141 462 julius
      // verilator public
142
      input [aw-1:0]             gpr_no;
143
      input [dw-1:0]             value;
144
 
145 482 julius
      mem[gpr_no] =
146
`ifdef OR1200_RAM_PARITY
147
        {(^value[(8*3)+7:(8*3)]),(^value[(8*2)+7:(8*2)]),
148
         (^value[(8*1)+7:(8*1)]),(^value[(8*0)+7:(8*0)]),
149
         value}
150
`else
151
                    value
152
`endif
153
                      ;
154
   endtask // get_gpr
155
 
156
`ifdef OR1200_RAM_PARITY
157
   genvar                       i;
158
   generate
159 483 julius
      for (i=0;i<par_w;i=i+1) begin: paritygen
160 482 julius
         or1200_parity_gen pgen(.d_i(di_b[(i*8)+7:(i*8)]), .p_o(di_p[i]));
161
         or1200_parity_chk pchk(.d_i(do_a_wire[(i*8)+7:(i*8)]),
162
                                .p_i(do_p[i]), .err_o(parity_err[i]));
163
      end
164
   endgenerate
165
 
166
   // Extract parity bits of data out
167 483 julius
   assign do_p = do_a_wire[(dw+par_w)-1:dw];
168
 
169
   reg ce_a_r;
170
   always @(posedge clk_a)
171
     if (rst)
172
       ce_a_r <= 0;
173
     else
174
       ce_a_r <= ce_a;
175 350 julius
 
176 482 julius
   // Indicate error
177 483 julius
   assign p_err = (|parity_err) & ce_a_r;
178 482 julius
 
179
   // Inject a parity error. Can specify GPR number to affect,
180
   // and which parity or data bit to switch.
181
   task gen_parity_err;
182
      input [aw-1:0]             gpr_no;
183
      input [31:0]               parity_bit_no;
184
      input [31:0]               data_bit_no;
185 483 julius
      reg [(dw+par_w)-1:0]       do_temp;
186 482 julius
      begin
187
         do_temp = mem[gpr_no];
188
         // Switch parity bit
189 483 julius
         if (parity_bit_no >= 0 && parity_bit_no < par_w)
190
           do_temp[dw+parity_bit_no] = ~do_temp[dw+parity_bit_no];
191 482 julius
         // Switch data bit
192 483 julius
         if (data_bit_no >= 0 && data_bit_no < dw)
193
           do_temp[data_bit_no] = ~do_temp[data_bit_no];
194 482 julius
         // Write word back
195
         mem[gpr_no] = do_temp;
196
      end
197
   endtask // gen_parity_err
198
`endif
199
 
200 350 julius
   //
201
   // Data output drivers
202
   //
203 482 julius
   assign do_a_wire = mem[addr_a_reg];
204
   assign do_a = do_a_wire[dw-1:0];
205 350 julius
 
206
   //
207
   // RAM read
208
   //
209
   always @(posedge clk_a)
210
     if (ce_a)
211
       addr_a_reg <=  addr_a;
212
 
213
   //
214
   // RAM write
215
   //
216
   always @(posedge clk_b)
217
     if (ce_b & we_b)
218 482 julius
`ifdef OR1200_RAM_PARITY
219
       mem[addr_b] <=  {di_p,di_b};
220
`else
221 350 julius
       mem[addr_b] <=  di_b;
222 482 julius
`endif
223
 
224 350 julius
endmodule // or1200_dpram

powered by: WebSVN 2.1.0

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