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 482

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