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 36

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 36 ultra_embe
//                            V2.1
5 34 ultra_embe
//                     Ultra-Embedded.com
6 36 ultra_embe
//                   Copyright 2011 - 2014
7 34 ultra_embe
//
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 36 ultra_embe
    output reg [31:0] reg_rs_o    /*verilator public*/,
55
    output reg [31:0] reg_rt_o    /*verilator public*/,
56 34 ultra_embe
    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 36 ultra_embe
wire            clk_delayed;
68 34 ultra_embe
wire [31:0]     data_out1;
69
wire [31:0]     data_out2;
70
reg             write_enable;
71
 
72
reg [4:0]       addr_reg;
73
reg [31:0]      data_reg;
74
 
75
wire [31:0]     q1;
76
wire [31:0]     q2;
77
 
78
//-----------------------------------------------------------------
79
// Async Read Process
80
//-----------------------------------------------------------------
81
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)
82
begin
83
    // Read Rs
84
    if (rs_i == 5'b00000)
85
        reg_rs_o <= 32'h00000000;
86
    else
87
        reg_rs_o <= data_out1;
88
 
89
    // Read Rt
90
    if (rt_i == 5'b00000)
91
        reg_rt_o <= 32'h00000000;
92
    else
93
        reg_rt_o <= data_out2;
94
 
95
    // Write enabled?
96
    if ((rd_i != 5'b00000) & (wr_i == 1'b1))
97
        write_enable <= 1'b1;
98
    else
99
        write_enable <= 1'b0;
100
end
101
 
102
//-----------------------------------------------------------------
103
// Sync addr & data
104
//-----------------------------------------------------------------
105
always @ (posedge clk_i or posedge rst_i)
106
begin
107
   if (rst_i)
108
   begin
109
        addr_reg <= 5'b00000;
110
        data_reg <= 32'h00000000;
111
 
112
   end
113
   else
114
   begin
115
        addr_reg <= rd_i;
116
        data_reg <= reg_rd_i;
117
   end
118
end
119
 
120
//-----------------------------------------------------------------
121
// Register File (using lpm_ram_dp)
122
// Unfortunatly, LPM_RAM_DP primitives have synchronous read ports.
123
// As this core requires asynchronous/non-registered read ports,
124
// we have to invert the readclock edge to get close to what we
125
// require.
126
// This will have negative timing implications!
127
//-----------------------------------------------------------------
128
lpm_ram_dp
129
#(
130
    .lpm_width(32),
131
    .lpm_widthad(5),
132
    .lpm_indata("REGISTERED"),
133
    .lpm_outdata("UNREGISTERED"),
134
    .lpm_rdaddress_control("REGISTERED"),
135
    .lpm_wraddress_control("REGISTERED"),
136
    .lpm_file("UNUSED"),
137
    .lpm_type("lpm_ram_dp"),
138
    .lpm_hint("UNUSED")
139
)
140
lpm1
141
(
142
    .rdclock(clk_delayed),
143
    .rdclken(1'b1),
144
    .rdaddress(rs_i),
145
    .rden(1'b1),
146
    .data(reg_rd_i),
147
    .wraddress(rd_i),
148
    .wren(write_enable),
149
    .wrclock(clk_i),
150
    .wrclken(1'b1),
151
    .q(q1)
152
);
153
 
154
 
155
lpm_ram_dp
156
#(
157
    .lpm_width(32),
158
    .lpm_widthad(5),
159
    .lpm_indata("REGISTERED"),
160
    .lpm_outdata("UNREGISTERED"),
161
    .lpm_rdaddress_control("REGISTERED"),
162
    .lpm_wraddress_control("REGISTERED"),
163
    .lpm_file("UNUSED"),
164
    .lpm_type("lpm_ram_dp"),
165
    .lpm_hint("UNUSED")
166
)
167
lpm2
168
(
169
    .rdclock(clk_delayed),
170
    .rdclken(1'b1),
171
    .rdaddress(rt_i),
172
    .rden(1'b1),
173
    .data(reg_rd_i),
174
    .wraddress(rd_i),
175
    .wren(write_enable),
176
    .wrclock(clk_i),
177
    .wrclken(1'b1),
178
    .q(q2)
179
);
180
 
181
//-----------------------------------------------------------------
182
// Combinatorial Assignments
183
//-----------------------------------------------------------------
184
 
185
// Delayed clock
186
assign clk_delayed  = !clk_i;
187
 
188
// Reads are bypassed during write-back
189
assign data_out1    = (rs_i != addr_reg) ? q1 : data_reg;
190
assign data_out2    = (rt_i != addr_reg) ? q2 : data_reg;
191
 
192
endmodule

powered by: WebSVN 2.1.0

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