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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu/] [altor32_regfile_alt.v] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4 36 ultra_embe
//                            V2.1
5 27 ultra_embe
//                     Ultra-Embedded.com
6 36 ultra_embe
//                   Copyright 2011 - 2014
7 27 ultra_embe
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13 37 ultra_embe
// Copyright (C) 2011 - 2014 Ultra-Embedded.com
14 27 ultra_embe
//
15
// This source file may be used and distributed without         
16
// restriction provided that this copyright statement is not    
17
// removed from the file and that any derivative work contains  
18
// the original copyright notice and the associated disclaimer. 
19
//
20
// This source file is free software; you can redistribute it   
21
// and/or modify it under the terms of the GNU Lesser General   
22
// Public License as published by the Free Software Foundation; 
23
// either version 2.1 of the License, or (at your option) any   
24
// later version.
25
//
26
// This source is distributed in the hope that it will be       
27
// useful, but WITHOUT ANY WARRANTY; without even the implied   
28
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      
29
// PURPOSE.  See the GNU Lesser General Public License for more 
30
// details.
31
//
32
// You should have received a copy of the GNU Lesser General    
33
// Public License along with this source; if not, write to the 
34
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
35
// Boston, MA  02111-1307  USA
36
//-----------------------------------------------------------------
37
 
38
//-----------------------------------------------------------------
39
// Includes
40
//-----------------------------------------------------------------
41
`include "altor32_defs.v"
42
 
43
//-----------------------------------------------------------------
44
// Module - Altera LPM register file
45
//-----------------------------------------------------------------
46
module altor32_regfile_alt
47
(
48 37 ultra_embe
    input               clk_i       /*verilator public*/,
49
    input               rst_i       /*verilator public*/,
50
    input               wr_i        /*verilator public*/,
51
    input [4:0]         ra_i        /*verilator public*/,
52
    input [4:0]         rb_i        /*verilator public*/,
53
    input [4:0]         rd_i        /*verilator public*/,
54
    output reg [31:0]   reg_ra_o    /*verilator public*/,
55
    output reg [31:0]   reg_rb_o    /*verilator public*/,
56
    input [31:0]        reg_rd_i    /*verilator public*/
57 27 ultra_embe
);
58
 
59
//-----------------------------------------------------------------
60
// Params
61
//-----------------------------------------------------------------
62
parameter       SUPPORT_32REGS = "ENABLED";
63
 
64
//-----------------------------------------------------------------
65
// Registers
66
//-----------------------------------------------------------------
67 37 ultra_embe
wire            clk_delayed_w;
68
wire [31:0]     reg_ra_w;
69
wire [31:0]     reg_rb_w;
70
wire            write_enable_w;
71 27 ultra_embe
 
72 37 ultra_embe
reg [4:0]       addr_q;
73
reg [31:0]      data_q;
74 27 ultra_embe
 
75 37 ultra_embe
wire [31:0]     ra_w;
76
wire [31:0]     rb_w;
77 27 ultra_embe
 
78
//-----------------------------------------------------------------
79
// Sync addr & data
80
//-----------------------------------------------------------------
81
always @ (posedge clk_i or posedge rst_i)
82
begin
83
   if (rst_i)
84
   begin
85 37 ultra_embe
        addr_q <= 5'b00000;
86
        data_q <= 32'h00000000;
87 27 ultra_embe
 
88
   end
89
   else
90
   begin
91 37 ultra_embe
        addr_q <= rd_i;
92
        data_q <= reg_rd_i;
93 27 ultra_embe
   end
94
end
95
 
96
//-----------------------------------------------------------------
97
// Register File (using lpm_ram_dp)
98
// Unfortunatly, LPM_RAM_DP primitives have synchronous read ports.
99
// As this core requires asynchronous/non-registered read ports,
100
// we have to invert the readclock edge to get close to what we
101
// require.
102
// This will have negative timing implications!
103
//-----------------------------------------------------------------
104
lpm_ram_dp
105
#(
106
    .lpm_width(32),
107
    .lpm_widthad(5),
108
    .lpm_indata("REGISTERED"),
109
    .lpm_outdata("UNREGISTERED"),
110
    .lpm_rdaddress_control("REGISTERED"),
111
    .lpm_wraddress_control("REGISTERED"),
112
    .lpm_file("UNUSED"),
113
    .lpm_type("lpm_ram_dp"),
114
    .lpm_hint("UNUSED")
115
)
116
lpm1
117
(
118 37 ultra_embe
    .rdclock(clk_delayed_w),
119 27 ultra_embe
    .rdclken(1'b1),
120 37 ultra_embe
    .rdaddress(ra_i),
121 27 ultra_embe
    .rden(1'b1),
122
    .data(reg_rd_i),
123
    .wraddress(rd_i),
124 37 ultra_embe
    .wren(write_enable_w),
125 27 ultra_embe
    .wrclock(clk_i),
126
    .wrclken(1'b1),
127 37 ultra_embe
    .q(ra_w)
128 27 ultra_embe
);
129
 
130
 
131
lpm_ram_dp
132
#(
133
    .lpm_width(32),
134
    .lpm_widthad(5),
135
    .lpm_indata("REGISTERED"),
136
    .lpm_outdata("UNREGISTERED"),
137
    .lpm_rdaddress_control("REGISTERED"),
138
    .lpm_wraddress_control("REGISTERED"),
139
    .lpm_file("UNUSED"),
140
    .lpm_type("lpm_ram_dp"),
141
    .lpm_hint("UNUSED")
142
)
143
lpm2
144
(
145 37 ultra_embe
    .rdclock(clk_delayed_w),
146 27 ultra_embe
    .rdclken(1'b1),
147 37 ultra_embe
    .rdaddress(rb_i),
148 27 ultra_embe
    .rden(1'b1),
149
    .data(reg_rd_i),
150
    .wraddress(rd_i),
151 37 ultra_embe
    .wren(write_enable_w),
152 27 ultra_embe
    .wrclock(clk_i),
153
    .wrclken(1'b1),
154 37 ultra_embe
    .q(rb_w)
155 27 ultra_embe
);
156
 
157
//-----------------------------------------------------------------
158
// Combinatorial Assignments
159
//-----------------------------------------------------------------
160
 
161
// Delayed clock
162 37 ultra_embe
assign clk_delayed_w  = !clk_i;
163 27 ultra_embe
 
164 37 ultra_embe
// Register read ports
165
always @ *
166
begin
167
    if (ra_i == 5'b00000)
168
        reg_ra_o = 32'h00000000;
169
    else
170
        reg_ra_o = reg_ra_w;
171
 
172
    if (rb_i == 5'b00000)
173
        reg_rb_o = 32'h00000000;
174
    else
175
        reg_rb_o = reg_rb_w;
176
end
177
 
178
assign write_enable_w = (rd_i != 5'b00000) & wr_i;
179
 
180 27 ultra_embe
// Reads are bypassed during write-back
181 37 ultra_embe
assign reg_ra_w    = (ra_i != addr_q) ? ra_w : data_q;
182
assign reg_rb_w    = (rb_i != addr_q) ? rb_w : data_q;
183 27 ultra_embe
 
184
endmodule

powered by: WebSVN 2.1.0

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