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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [rtl/] [cpu_lite/] [altor32_regfile_alt.v] - Blame information for rev 34

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

Line No. Rev Author Line
1 34 ultra_embe
//-----------------------------------------------------------------
2
//                           AltOR32 
3
//                Alternative Lightweight OpenRisc 
4
//                            V2.0
5
//                     Ultra-Embedded.com
6
//                   Copyright 2011 - 2013
7
//
8
//               Email: admin@ultra-embedded.com
9
//
10
//                       License: LGPL
11
//-----------------------------------------------------------------
12
//
13
// Copyright (C) 2011 - 2013 Ultra-Embedded.com
14
//
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
    input           clk_i       /*verilator public*/,
49
    input           rst_i       /*verilator public*/,
50
    input           wr_i        /*verilator public*/,
51
    input [4:0]     rs_i        /*verilator public*/,
52
    input [4:0]     rt_i        /*verilator public*/,
53
    input [4:0]     rd_i        /*verilator public*/,
54
    output [31:0]   reg_rs_o    /*verilator public*/,
55
    output [31:0]   reg_rt_o    /*verilator public*/,
56
    input [31:0]    reg_rd_i    /*verilator public*/
57
);
58
 
59
//-----------------------------------------------------------------
60
// Params
61
//-----------------------------------------------------------------
62
parameter       SUPPORT_32REGS = "ENABLED";
63
 
64
//-----------------------------------------------------------------
65
// Registers
66
//-----------------------------------------------------------------
67
reg             clk_delayed;
68
wire [31:0]     data_out1;
69
wire [31:0]     data_out2;
70
reg             write_enable;
71
 
72
reg [31:0]      reg_rs_o;
73
reg [31:0]      reg_rt_o;
74
 
75
reg [4:0]       addr_reg;
76
reg [31:0]      data_reg;
77
 
78
wire [31:0]     q1;
79
wire [31:0]     q2;
80
 
81
//-----------------------------------------------------------------
82
// Async Read Process
83
//-----------------------------------------------------------------
84
always @ (clk_i or rs_i or rt_i or rd_i or reg_rd_i or data_out1 or data_out2 or rst_i or wr_i)
85
begin
86
    // Read Rs
87
    if (rs_i == 5'b00000)
88
        reg_rs_o <= 32'h00000000;
89
    else
90
        reg_rs_o <= data_out1;
91
 
92
    // Read Rt
93
    if (rt_i == 5'b00000)
94
        reg_rt_o <= 32'h00000000;
95
    else
96
        reg_rt_o <= data_out2;
97
 
98
    // Write enabled?
99
    if ((rd_i != 5'b00000) & (wr_i == 1'b1))
100
        write_enable <= 1'b1;
101
    else
102
        write_enable <= 1'b0;
103
end
104
 
105
//-----------------------------------------------------------------
106
// Sync addr & data
107
//-----------------------------------------------------------------
108
always @ (posedge clk_i or posedge rst_i)
109
begin
110
   if (rst_i)
111
   begin
112
        addr_reg <= 5'b00000;
113
        data_reg <= 32'h00000000;
114
 
115
   end
116
   else
117
   begin
118
        addr_reg <= rd_i;
119
        data_reg <= reg_rd_i;
120
   end
121
end
122
 
123
//-----------------------------------------------------------------
124
// Register File (using lpm_ram_dp)
125
// Unfortunatly, LPM_RAM_DP primitives have synchronous read ports.
126
// As this core requires asynchronous/non-registered read ports,
127
// we have to invert the readclock edge to get close to what we
128
// require.
129
// This will have negative timing implications!
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
lpm1
144
(
145
    .rdclock(clk_delayed),
146
    .rdclken(1'b1),
147
    .rdaddress(rs_i),
148
    .rden(1'b1),
149
    .data(reg_rd_i),
150
    .wraddress(rd_i),
151
    .wren(write_enable),
152
    .wrclock(clk_i),
153
    .wrclken(1'b1),
154
    .q(q1)
155
);
156
 
157
 
158
lpm_ram_dp
159
#(
160
    .lpm_width(32),
161
    .lpm_widthad(5),
162
    .lpm_indata("REGISTERED"),
163
    .lpm_outdata("UNREGISTERED"),
164
    .lpm_rdaddress_control("REGISTERED"),
165
    .lpm_wraddress_control("REGISTERED"),
166
    .lpm_file("UNUSED"),
167
    .lpm_type("lpm_ram_dp"),
168
    .lpm_hint("UNUSED")
169
)
170
lpm2
171
(
172
    .rdclock(clk_delayed),
173
    .rdclken(1'b1),
174
    .rdaddress(rt_i),
175
    .rden(1'b1),
176
    .data(reg_rd_i),
177
    .wraddress(rd_i),
178
    .wren(write_enable),
179
    .wrclock(clk_i),
180
    .wrclken(1'b1),
181
    .q(q2)
182
);
183
 
184
//-----------------------------------------------------------------
185
// Combinatorial Assignments
186
//-----------------------------------------------------------------
187
 
188
// Delayed clock
189
assign clk_delayed  = !clk_i;
190
 
191
// Reads are bypassed during write-back
192
assign data_out1    = (rs_i != addr_reg) ? q1 : data_reg;
193
assign data_out2    = (rt_i != addr_reg) ? q2 : data_reg;
194
 
195
endmodule

powered by: WebSVN 2.1.0

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