1 |
157 |
olivier.gi |
//----------------------------------------------------------------------------
|
2 |
|
|
// Copyright (C) 2009 , Olivier Girard
|
3 |
|
|
//
|
4 |
|
|
// Redistribution and use in source and binary forms, with or without
|
5 |
|
|
// modification, are permitted provided that the following conditions
|
6 |
|
|
// are met:
|
7 |
|
|
// * Redistributions of source code must retain the above copyright
|
8 |
|
|
// notice, this list of conditions and the following disclaimer.
|
9 |
|
|
// * Redistributions in binary form must reproduce the above copyright
|
10 |
|
|
// notice, this list of conditions and the following disclaimer in the
|
11 |
|
|
// documentation and/or other materials provided with the distribution.
|
12 |
|
|
// * Neither the name of the authors nor the names of its contributors
|
13 |
|
|
// may be used to endorse or promote products derived from this software
|
14 |
|
|
// without specific prior written permission.
|
15 |
|
|
//
|
16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17 |
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18 |
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
19 |
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
20 |
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
21 |
|
|
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
22 |
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
23 |
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
24 |
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
25 |
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
26 |
|
|
// THE POSSIBILITY OF SUCH DAMAGE
|
27 |
|
|
//
|
28 |
|
|
//----------------------------------------------------------------------------
|
29 |
|
|
//
|
30 |
|
|
// *File Name: omsp_register_file.v
|
31 |
202 |
olivier.gi |
//
|
32 |
157 |
olivier.gi |
// *Module Description:
|
33 |
|
|
// openMSP430 Register files
|
34 |
|
|
//
|
35 |
|
|
// *Author(s):
|
36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
37 |
|
|
//
|
38 |
|
|
//----------------------------------------------------------------------------
|
39 |
202 |
olivier.gi |
// $Rev$
|
40 |
|
|
// $LastChangedBy$
|
41 |
|
|
// $LastChangedDate$
|
42 |
157 |
olivier.gi |
//----------------------------------------------------------------------------
|
43 |
|
|
`ifdef OMSP_NO_INCLUDE
|
44 |
|
|
`else
|
45 |
|
|
`include "openMSP430_defines.v"
|
46 |
|
|
`endif
|
47 |
|
|
|
48 |
|
|
module omsp_register_file (
|
49 |
|
|
|
50 |
|
|
// OUTPUTs
|
51 |
|
|
cpuoff, // Turns off the CPU
|
52 |
|
|
gie, // General interrupt enable
|
53 |
|
|
oscoff, // Turns off LFXT1 clock input
|
54 |
|
|
pc_sw, // Program counter software value
|
55 |
|
|
pc_sw_wr, // Program counter software write
|
56 |
|
|
reg_dest, // Selected register destination content
|
57 |
|
|
reg_src, // Selected register source content
|
58 |
|
|
scg0, // System clock generator 1. Turns off the DCO
|
59 |
|
|
scg1, // System clock generator 1. Turns off the SMCLK
|
60 |
|
|
status, // R2 Status {V,N,Z,C}
|
61 |
|
|
|
62 |
|
|
// INPUTs
|
63 |
|
|
alu_stat, // ALU Status {V,N,Z,C}
|
64 |
|
|
alu_stat_wr, // ALU Status write {V,N,Z,C}
|
65 |
|
|
inst_bw, // Decoded Inst: byte width
|
66 |
|
|
inst_dest, // Register destination selection
|
67 |
|
|
inst_src, // Register source selection
|
68 |
|
|
mclk, // Main system clock
|
69 |
|
|
pc, // Program counter
|
70 |
|
|
puc_rst, // Main system reset
|
71 |
|
|
reg_dest_val, // Selected register destination value
|
72 |
|
|
reg_dest_wr, // Write selected register destination
|
73 |
|
|
reg_pc_call, // Trigger PC update for a CALL instruction
|
74 |
|
|
reg_sp_val, // Stack Pointer next value
|
75 |
|
|
reg_sp_wr, // Stack Pointer write
|
76 |
|
|
reg_sr_wr, // Status register update for RETI instruction
|
77 |
|
|
reg_sr_clr, // Status register clear for interrupts
|
78 |
|
|
reg_incr, // Increment source register
|
79 |
|
|
scan_enable // Scan enable (active during scan shifting)
|
80 |
|
|
);
|
81 |
|
|
|
82 |
|
|
// OUTPUTs
|
83 |
|
|
//=========
|
84 |
202 |
olivier.gi |
output cpuoff; // Turns off the CPU
|
85 |
|
|
output gie; // General interrupt enable
|
86 |
|
|
output oscoff; // Turns off LFXT1 clock input
|
87 |
157 |
olivier.gi |
output [15:0] pc_sw; // Program counter software value
|
88 |
|
|
output pc_sw_wr; // Program counter software write
|
89 |
|
|
output [15:0] reg_dest; // Selected register destination content
|
90 |
|
|
output [15:0] reg_src; // Selected register source content
|
91 |
|
|
output scg0; // System clock generator 1. Turns off the DCO
|
92 |
|
|
output scg1; // System clock generator 1. Turns off the SMCLK
|
93 |
|
|
output [3:0] status; // R2 Status {V,N,Z,C}
|
94 |
|
|
|
95 |
|
|
// INPUTs
|
96 |
|
|
//=========
|
97 |
|
|
input [3:0] alu_stat; // ALU Status {V,N,Z,C}
|
98 |
|
|
input [3:0] alu_stat_wr; // ALU Status write {V,N,Z,C}
|
99 |
|
|
input inst_bw; // Decoded Inst: byte width
|
100 |
|
|
input [15:0] inst_dest; // Register destination selection
|
101 |
|
|
input [15:0] inst_src; // Register source selection
|
102 |
|
|
input mclk; // Main system clock
|
103 |
|
|
input [15:0] pc; // Program counter
|
104 |
|
|
input puc_rst; // Main system reset
|
105 |
|
|
input [15:0] reg_dest_val; // Selected register destination value
|
106 |
|
|
input reg_dest_wr; // Write selected register destination
|
107 |
|
|
input reg_pc_call; // Trigger PC update for a CALL instruction
|
108 |
|
|
input [15:0] reg_sp_val; // Stack Pointer next value
|
109 |
|
|
input reg_sp_wr; // Stack Pointer write
|
110 |
|
|
input reg_sr_wr; // Status register update for RETI instruction
|
111 |
|
|
input reg_sr_clr; // Status register clear for interrupts
|
112 |
|
|
input reg_incr; // Increment source register
|
113 |
|
|
input scan_enable; // Scan enable (active during scan shifting)
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
//=============================================================================
|
117 |
|
|
// 1) AUTOINCREMENT UNIT
|
118 |
|
|
//=============================================================================
|
119 |
|
|
|
120 |
|
|
wire [15:0] inst_src_in;
|
121 |
|
|
wire [15:0] incr_op = (inst_bw & ~inst_src_in[1]) ? 16'h0001 : 16'h0002;
|
122 |
|
|
wire [15:0] reg_incr_val = reg_src+incr_op;
|
123 |
|
|
|
124 |
|
|
wire [15:0] reg_dest_val_in = inst_bw ? {8'h00,reg_dest_val[7:0]} : reg_dest_val;
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
//=============================================================================
|
128 |
|
|
// 2) SPECIAL REGISTERS (R1/R2/R3)
|
129 |
|
|
//=============================================================================
|
130 |
|
|
|
131 |
|
|
// Source input selection mask (for interrupt support)
|
132 |
|
|
//-----------------------------------------------------
|
133 |
|
|
|
134 |
|
|
assign inst_src_in = reg_sr_clr ? 16'h0004 : inst_src;
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
// R0: Program counter
|
138 |
|
|
//---------------------
|
139 |
|
|
|
140 |
|
|
wire [15:0] r0 = pc;
|
141 |
|
|
|
142 |
|
|
wire [15:0] pc_sw = reg_dest_val_in;
|
143 |
|
|
wire pc_sw_wr = (inst_dest[0] & reg_dest_wr) | reg_pc_call;
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
// R1: Stack pointer
|
147 |
|
|
//-------------------
|
148 |
|
|
reg [15:0] r1;
|
149 |
|
|
wire r1_wr = inst_dest[1] & reg_dest_wr;
|
150 |
|
|
wire r1_inc = inst_src_in[1] & reg_incr;
|
151 |
|
|
|
152 |
|
|
`ifdef CLOCK_GATING
|
153 |
|
|
wire r1_en = r1_wr | reg_sp_wr | r1_inc;
|
154 |
|
|
wire mclk_r1;
|
155 |
|
|
omsp_clock_gate clock_gate_r1 (.gclk(mclk_r1),
|
156 |
|
|
.clk (mclk), .enable(r1_en), .scan_enable(scan_enable));
|
157 |
|
|
`else
|
158 |
202 |
olivier.gi |
wire UNUSED_scan_enable = scan_enable;
|
159 |
|
|
wire mclk_r1 = mclk;
|
160 |
157 |
olivier.gi |
`endif
|
161 |
|
|
|
162 |
|
|
always @(posedge mclk_r1 or posedge puc_rst)
|
163 |
|
|
if (puc_rst) r1 <= 16'h0000;
|
164 |
|
|
else if (r1_wr) r1 <= reg_dest_val_in & 16'hfffe;
|
165 |
|
|
else if (reg_sp_wr) r1 <= reg_sp_val & 16'hfffe;
|
166 |
|
|
`ifdef CLOCK_GATING
|
167 |
|
|
else r1 <= reg_incr_val & 16'hfffe;
|
168 |
|
|
`else
|
169 |
|
|
else if (r1_inc) r1 <= reg_incr_val & 16'hfffe;
|
170 |
|
|
`endif
|
171 |
|
|
|
172 |
202 |
olivier.gi |
wire UNUSED_reg_sp_val_0 = reg_sp_val[0];
|
173 |
157 |
olivier.gi |
|
174 |
202 |
olivier.gi |
|
175 |
157 |
olivier.gi |
// R2: Status register
|
176 |
|
|
//---------------------
|
177 |
|
|
reg [15:0] r2;
|
178 |
|
|
wire r2_wr = (inst_dest[2] & reg_dest_wr) | reg_sr_wr;
|
179 |
|
|
|
180 |
|
|
`ifdef CLOCK_GATING // -- WITH CLOCK GATING --
|
181 |
|
|
wire r2_c = alu_stat_wr[0] ? alu_stat[0] : reg_dest_val_in[0]; // C
|
182 |
|
|
|
183 |
|
|
wire r2_z = alu_stat_wr[1] ? alu_stat[1] : reg_dest_val_in[1]; // Z
|
184 |
|
|
|
185 |
|
|
wire r2_n = alu_stat_wr[2] ? alu_stat[2] : reg_dest_val_in[2]; // N
|
186 |
|
|
|
187 |
|
|
wire [7:3] r2_nxt = r2_wr ? reg_dest_val_in[7:3] : r2[7:3];
|
188 |
|
|
|
189 |
|
|
wire r2_v = alu_stat_wr[3] ? alu_stat[3] : reg_dest_val_in[8]; // V
|
190 |
|
|
|
191 |
|
|
wire r2_en = |alu_stat_wr | r2_wr | reg_sr_clr;
|
192 |
|
|
wire mclk_r2;
|
193 |
|
|
omsp_clock_gate clock_gate_r2 (.gclk(mclk_r2),
|
194 |
|
|
.clk (mclk), .enable(r2_en), .scan_enable(scan_enable));
|
195 |
|
|
|
196 |
|
|
`else // -- WITHOUT CLOCK GATING --
|
197 |
|
|
wire r2_c = alu_stat_wr[0] ? alu_stat[0] :
|
198 |
|
|
r2_wr ? reg_dest_val_in[0] : r2[0]; // C
|
199 |
|
|
|
200 |
|
|
wire r2_z = alu_stat_wr[1] ? alu_stat[1] :
|
201 |
|
|
r2_wr ? reg_dest_val_in[1] : r2[1]; // Z
|
202 |
|
|
|
203 |
|
|
wire r2_n = alu_stat_wr[2] ? alu_stat[2] :
|
204 |
|
|
r2_wr ? reg_dest_val_in[2] : r2[2]; // N
|
205 |
|
|
|
206 |
|
|
wire [7:3] r2_nxt = r2_wr ? reg_dest_val_in[7:3] : r2[7:3];
|
207 |
|
|
|
208 |
|
|
wire r2_v = alu_stat_wr[3] ? alu_stat[3] :
|
209 |
|
|
r2_wr ? reg_dest_val_in[8] : r2[8]; // V
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
wire mclk_r2 = mclk;
|
213 |
|
|
`endif
|
214 |
|
|
|
215 |
181 |
olivier.gi |
`ifdef ASIC_CLOCKING
|
216 |
157 |
olivier.gi |
`ifdef CPUOFF_EN
|
217 |
|
|
wire [15:0] cpuoff_mask = 16'h0010;
|
218 |
|
|
`else
|
219 |
|
|
wire [15:0] cpuoff_mask = 16'h0000;
|
220 |
|
|
`endif
|
221 |
|
|
`ifdef OSCOFF_EN
|
222 |
|
|
wire [15:0] oscoff_mask = 16'h0020;
|
223 |
|
|
`else
|
224 |
|
|
wire [15:0] oscoff_mask = 16'h0000;
|
225 |
|
|
`endif
|
226 |
|
|
`ifdef SCG0_EN
|
227 |
|
|
wire [15:0] scg0_mask = 16'h0040;
|
228 |
|
|
`else
|
229 |
|
|
wire [15:0] scg0_mask = 16'h0000;
|
230 |
|
|
`endif
|
231 |
|
|
`ifdef SCG1_EN
|
232 |
|
|
wire [15:0] scg1_mask = 16'h0080;
|
233 |
|
|
`else
|
234 |
|
|
wire [15:0] scg1_mask = 16'h0000;
|
235 |
|
|
`endif
|
236 |
|
|
`else
|
237 |
|
|
wire [15:0] cpuoff_mask = 16'h0010; // For the FPGA version: - the CPUOFF mode is emulated
|
238 |
|
|
wire [15:0] oscoff_mask = 16'h0020; // - the SCG1 mode is emulated
|
239 |
|
|
wire [15:0] scg0_mask = 16'h0000; // - the SCG0 is not supported
|
240 |
|
|
wire [15:0] scg1_mask = 16'h0080; // - the SCG1 mode is emulated
|
241 |
|
|
`endif
|
242 |
202 |
olivier.gi |
|
243 |
157 |
olivier.gi |
wire [15:0] r2_mask = cpuoff_mask | oscoff_mask | scg0_mask | scg1_mask | 16'h010f;
|
244 |
202 |
olivier.gi |
|
245 |
157 |
olivier.gi |
always @(posedge mclk_r2 or posedge puc_rst)
|
246 |
|
|
if (puc_rst) r2 <= 16'h0000;
|
247 |
|
|
else if (reg_sr_clr) r2 <= 16'h0000;
|
248 |
|
|
else r2 <= {7'h00, r2_v, r2_nxt, r2_n, r2_z, r2_c} & r2_mask;
|
249 |
|
|
|
250 |
|
|
assign status = {r2[8], r2[2:0]};
|
251 |
|
|
assign gie = r2[3];
|
252 |
|
|
assign cpuoff = r2[4] | (r2_nxt[4] & r2_wr & cpuoff_mask[4]);
|
253 |
|
|
assign oscoff = r2[5];
|
254 |
|
|
assign scg0 = r2[6];
|
255 |
|
|
assign scg1 = r2[7];
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
// R3: Constant generator
|
259 |
|
|
//-------------------------------------------------------------
|
260 |
|
|
// Note: the auto-increment feature is not implemented for R3
|
261 |
|
|
// because the @R3+ addressing mode is used for constant
|
262 |
|
|
// generation (#-1).
|
263 |
|
|
reg [15:0] r3;
|
264 |
|
|
wire r3_wr = inst_dest[3] & reg_dest_wr;
|
265 |
|
|
|
266 |
|
|
`ifdef CLOCK_GATING
|
267 |
|
|
wire r3_en = r3_wr;
|
268 |
|
|
wire mclk_r3;
|
269 |
|
|
omsp_clock_gate clock_gate_r3 (.gclk(mclk_r3),
|
270 |
|
|
.clk (mclk), .enable(r3_en), .scan_enable(scan_enable));
|
271 |
|
|
`else
|
272 |
|
|
wire mclk_r3 = mclk;
|
273 |
|
|
`endif
|
274 |
|
|
|
275 |
|
|
always @(posedge mclk_r3 or posedge puc_rst)
|
276 |
|
|
if (puc_rst) r3 <= 16'h0000;
|
277 |
|
|
`ifdef CLOCK_GATING
|
278 |
|
|
else r3 <= reg_dest_val_in;
|
279 |
|
|
`else
|
280 |
|
|
else if (r3_wr) r3 <= reg_dest_val_in;
|
281 |
|
|
`endif
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
//=============================================================================
|
285 |
|
|
// 4) GENERAL PURPOSE REGISTERS (R4...R15)
|
286 |
|
|
//=============================================================================
|
287 |
|
|
|
288 |
|
|
// R4
|
289 |
|
|
//------------
|
290 |
|
|
reg [15:0] r4;
|
291 |
|
|
wire r4_wr = inst_dest[4] & reg_dest_wr;
|
292 |
|
|
wire r4_inc = inst_src_in[4] & reg_incr;
|
293 |
|
|
|
294 |
|
|
`ifdef CLOCK_GATING
|
295 |
|
|
wire r4_en = r4_wr | r4_inc;
|
296 |
|
|
wire mclk_r4;
|
297 |
|
|
omsp_clock_gate clock_gate_r4 (.gclk(mclk_r4),
|
298 |
|
|
.clk (mclk), .enable(r4_en), .scan_enable(scan_enable));
|
299 |
|
|
`else
|
300 |
|
|
wire mclk_r4 = mclk;
|
301 |
|
|
`endif
|
302 |
|
|
|
303 |
|
|
always @(posedge mclk_r4 or posedge puc_rst)
|
304 |
|
|
if (puc_rst) r4 <= 16'h0000;
|
305 |
|
|
else if (r4_wr) r4 <= reg_dest_val_in;
|
306 |
|
|
`ifdef CLOCK_GATING
|
307 |
|
|
else r4 <= reg_incr_val;
|
308 |
|
|
`else
|
309 |
|
|
else if (r4_inc) r4 <= reg_incr_val;
|
310 |
|
|
`endif
|
311 |
|
|
|
312 |
|
|
// R5
|
313 |
|
|
//------------
|
314 |
|
|
reg [15:0] r5;
|
315 |
|
|
wire r5_wr = inst_dest[5] & reg_dest_wr;
|
316 |
|
|
wire r5_inc = inst_src_in[5] & reg_incr;
|
317 |
|
|
|
318 |
|
|
`ifdef CLOCK_GATING
|
319 |
|
|
wire r5_en = r5_wr | r5_inc;
|
320 |
|
|
wire mclk_r5;
|
321 |
|
|
omsp_clock_gate clock_gate_r5 (.gclk(mclk_r5),
|
322 |
|
|
.clk (mclk), .enable(r5_en), .scan_enable(scan_enable));
|
323 |
|
|
`else
|
324 |
|
|
wire mclk_r5 = mclk;
|
325 |
|
|
`endif
|
326 |
|
|
|
327 |
|
|
always @(posedge mclk_r5 or posedge puc_rst)
|
328 |
|
|
if (puc_rst) r5 <= 16'h0000;
|
329 |
|
|
else if (r5_wr) r5 <= reg_dest_val_in;
|
330 |
|
|
`ifdef CLOCK_GATING
|
331 |
|
|
else r5 <= reg_incr_val;
|
332 |
|
|
`else
|
333 |
|
|
else if (r5_inc) r5 <= reg_incr_val;
|
334 |
|
|
`endif
|
335 |
|
|
|
336 |
|
|
// R6
|
337 |
|
|
//------------
|
338 |
|
|
reg [15:0] r6;
|
339 |
|
|
wire r6_wr = inst_dest[6] & reg_dest_wr;
|
340 |
|
|
wire r6_inc = inst_src_in[6] & reg_incr;
|
341 |
|
|
|
342 |
|
|
`ifdef CLOCK_GATING
|
343 |
|
|
wire r6_en = r6_wr | r6_inc;
|
344 |
|
|
wire mclk_r6;
|
345 |
|
|
omsp_clock_gate clock_gate_r6 (.gclk(mclk_r6),
|
346 |
|
|
.clk (mclk), .enable(r6_en), .scan_enable(scan_enable));
|
347 |
|
|
`else
|
348 |
|
|
wire mclk_r6 = mclk;
|
349 |
|
|
`endif
|
350 |
|
|
|
351 |
|
|
always @(posedge mclk_r6 or posedge puc_rst)
|
352 |
|
|
if (puc_rst) r6 <= 16'h0000;
|
353 |
|
|
else if (r6_wr) r6 <= reg_dest_val_in;
|
354 |
|
|
`ifdef CLOCK_GATING
|
355 |
|
|
else r6 <= reg_incr_val;
|
356 |
|
|
`else
|
357 |
|
|
else if (r6_inc) r6 <= reg_incr_val;
|
358 |
|
|
`endif
|
359 |
|
|
|
360 |
|
|
// R7
|
361 |
|
|
//------------
|
362 |
|
|
reg [15:0] r7;
|
363 |
|
|
wire r7_wr = inst_dest[7] & reg_dest_wr;
|
364 |
|
|
wire r7_inc = inst_src_in[7] & reg_incr;
|
365 |
|
|
|
366 |
|
|
`ifdef CLOCK_GATING
|
367 |
|
|
wire r7_en = r7_wr | r7_inc;
|
368 |
|
|
wire mclk_r7;
|
369 |
|
|
omsp_clock_gate clock_gate_r7 (.gclk(mclk_r7),
|
370 |
|
|
.clk (mclk), .enable(r7_en), .scan_enable(scan_enable));
|
371 |
|
|
`else
|
372 |
|
|
wire mclk_r7 = mclk;
|
373 |
|
|
`endif
|
374 |
|
|
|
375 |
|
|
always @(posedge mclk_r7 or posedge puc_rst)
|
376 |
|
|
if (puc_rst) r7 <= 16'h0000;
|
377 |
|
|
else if (r7_wr) r7 <= reg_dest_val_in;
|
378 |
|
|
`ifdef CLOCK_GATING
|
379 |
|
|
else r7 <= reg_incr_val;
|
380 |
|
|
`else
|
381 |
|
|
else if (r7_inc) r7 <= reg_incr_val;
|
382 |
|
|
`endif
|
383 |
|
|
|
384 |
|
|
// R8
|
385 |
|
|
//------------
|
386 |
|
|
reg [15:0] r8;
|
387 |
|
|
wire r8_wr = inst_dest[8] & reg_dest_wr;
|
388 |
|
|
wire r8_inc = inst_src_in[8] & reg_incr;
|
389 |
|
|
|
390 |
|
|
`ifdef CLOCK_GATING
|
391 |
|
|
wire r8_en = r8_wr | r8_inc;
|
392 |
|
|
wire mclk_r8;
|
393 |
|
|
omsp_clock_gate clock_gate_r8 (.gclk(mclk_r8),
|
394 |
|
|
.clk (mclk), .enable(r8_en), .scan_enable(scan_enable));
|
395 |
|
|
`else
|
396 |
|
|
wire mclk_r8 = mclk;
|
397 |
|
|
`endif
|
398 |
|
|
|
399 |
|
|
always @(posedge mclk_r8 or posedge puc_rst)
|
400 |
|
|
if (puc_rst) r8 <= 16'h0000;
|
401 |
|
|
else if (r8_wr) r8 <= reg_dest_val_in;
|
402 |
|
|
`ifdef CLOCK_GATING
|
403 |
|
|
else r8 <= reg_incr_val;
|
404 |
|
|
`else
|
405 |
|
|
else if (r8_inc) r8 <= reg_incr_val;
|
406 |
|
|
`endif
|
407 |
|
|
|
408 |
|
|
// R9
|
409 |
|
|
//------------
|
410 |
|
|
reg [15:0] r9;
|
411 |
|
|
wire r9_wr = inst_dest[9] & reg_dest_wr;
|
412 |
|
|
wire r9_inc = inst_src_in[9] & reg_incr;
|
413 |
|
|
|
414 |
|
|
`ifdef CLOCK_GATING
|
415 |
|
|
wire r9_en = r9_wr | r9_inc;
|
416 |
|
|
wire mclk_r9;
|
417 |
|
|
omsp_clock_gate clock_gate_r9 (.gclk(mclk_r9),
|
418 |
|
|
.clk (mclk), .enable(r9_en), .scan_enable(scan_enable));
|
419 |
|
|
`else
|
420 |
|
|
wire mclk_r9 = mclk;
|
421 |
|
|
`endif
|
422 |
|
|
|
423 |
|
|
always @(posedge mclk_r9 or posedge puc_rst)
|
424 |
|
|
if (puc_rst) r9 <= 16'h0000;
|
425 |
|
|
else if (r9_wr) r9 <= reg_dest_val_in;
|
426 |
|
|
`ifdef CLOCK_GATING
|
427 |
|
|
else r9 <= reg_incr_val;
|
428 |
|
|
`else
|
429 |
|
|
else if (r9_inc) r9 <= reg_incr_val;
|
430 |
|
|
`endif
|
431 |
|
|
|
432 |
|
|
// R10
|
433 |
|
|
//------------
|
434 |
|
|
reg [15:0] r10;
|
435 |
|
|
wire r10_wr = inst_dest[10] & reg_dest_wr;
|
436 |
|
|
wire r10_inc = inst_src_in[10] & reg_incr;
|
437 |
|
|
|
438 |
|
|
`ifdef CLOCK_GATING
|
439 |
|
|
wire r10_en = r10_wr | r10_inc;
|
440 |
|
|
wire mclk_r10;
|
441 |
|
|
omsp_clock_gate clock_gate_r10 (.gclk(mclk_r10),
|
442 |
|
|
.clk (mclk), .enable(r10_en), .scan_enable(scan_enable));
|
443 |
|
|
`else
|
444 |
|
|
wire mclk_r10 = mclk;
|
445 |
|
|
`endif
|
446 |
|
|
|
447 |
|
|
always @(posedge mclk_r10 or posedge puc_rst)
|
448 |
|
|
if (puc_rst) r10 <= 16'h0000;
|
449 |
|
|
else if (r10_wr) r10 <= reg_dest_val_in;
|
450 |
|
|
`ifdef CLOCK_GATING
|
451 |
|
|
else r10 <= reg_incr_val;
|
452 |
|
|
`else
|
453 |
|
|
else if (r10_inc) r10 <= reg_incr_val;
|
454 |
|
|
`endif
|
455 |
|
|
|
456 |
|
|
// R11
|
457 |
|
|
//------------
|
458 |
|
|
reg [15:0] r11;
|
459 |
|
|
wire r11_wr = inst_dest[11] & reg_dest_wr;
|
460 |
|
|
wire r11_inc = inst_src_in[11] & reg_incr;
|
461 |
|
|
|
462 |
|
|
`ifdef CLOCK_GATING
|
463 |
|
|
wire r11_en = r11_wr | r11_inc;
|
464 |
|
|
wire mclk_r11;
|
465 |
|
|
omsp_clock_gate clock_gate_r11 (.gclk(mclk_r11),
|
466 |
|
|
.clk (mclk), .enable(r11_en), .scan_enable(scan_enable));
|
467 |
|
|
`else
|
468 |
|
|
wire mclk_r11 = mclk;
|
469 |
|
|
`endif
|
470 |
|
|
|
471 |
|
|
always @(posedge mclk_r11 or posedge puc_rst)
|
472 |
|
|
if (puc_rst) r11 <= 16'h0000;
|
473 |
|
|
else if (r11_wr) r11 <= reg_dest_val_in;
|
474 |
|
|
`ifdef CLOCK_GATING
|
475 |
|
|
else r11 <= reg_incr_val;
|
476 |
|
|
`else
|
477 |
|
|
else if (r11_inc) r11 <= reg_incr_val;
|
478 |
|
|
`endif
|
479 |
|
|
|
480 |
|
|
// R12
|
481 |
|
|
//------------
|
482 |
|
|
reg [15:0] r12;
|
483 |
|
|
wire r12_wr = inst_dest[12] & reg_dest_wr;
|
484 |
|
|
wire r12_inc = inst_src_in[12] & reg_incr;
|
485 |
|
|
|
486 |
|
|
`ifdef CLOCK_GATING
|
487 |
|
|
wire r12_en = r12_wr | r12_inc;
|
488 |
|
|
wire mclk_r12;
|
489 |
|
|
omsp_clock_gate clock_gate_r12 (.gclk(mclk_r12),
|
490 |
|
|
.clk (mclk), .enable(r12_en), .scan_enable(scan_enable));
|
491 |
|
|
`else
|
492 |
|
|
wire mclk_r12 = mclk;
|
493 |
|
|
`endif
|
494 |
|
|
|
495 |
|
|
always @(posedge mclk_r12 or posedge puc_rst)
|
496 |
|
|
if (puc_rst) r12 <= 16'h0000;
|
497 |
|
|
else if (r12_wr) r12 <= reg_dest_val_in;
|
498 |
|
|
`ifdef CLOCK_GATING
|
499 |
|
|
else r12 <= reg_incr_val;
|
500 |
|
|
`else
|
501 |
|
|
else if (r12_inc) r12 <= reg_incr_val;
|
502 |
|
|
`endif
|
503 |
|
|
|
504 |
|
|
// R13
|
505 |
|
|
//------------
|
506 |
|
|
reg [15:0] r13;
|
507 |
|
|
wire r13_wr = inst_dest[13] & reg_dest_wr;
|
508 |
|
|
wire r13_inc = inst_src_in[13] & reg_incr;
|
509 |
|
|
|
510 |
|
|
`ifdef CLOCK_GATING
|
511 |
|
|
wire r13_en = r13_wr | r13_inc;
|
512 |
|
|
wire mclk_r13;
|
513 |
|
|
omsp_clock_gate clock_gate_r13 (.gclk(mclk_r13),
|
514 |
|
|
.clk (mclk), .enable(r13_en), .scan_enable(scan_enable));
|
515 |
|
|
`else
|
516 |
|
|
wire mclk_r13 = mclk;
|
517 |
|
|
`endif
|
518 |
|
|
|
519 |
|
|
always @(posedge mclk_r13 or posedge puc_rst)
|
520 |
|
|
if (puc_rst) r13 <= 16'h0000;
|
521 |
|
|
else if (r13_wr) r13 <= reg_dest_val_in;
|
522 |
|
|
`ifdef CLOCK_GATING
|
523 |
|
|
else r13 <= reg_incr_val;
|
524 |
|
|
`else
|
525 |
|
|
else if (r13_inc) r13 <= reg_incr_val;
|
526 |
|
|
`endif
|
527 |
|
|
|
528 |
|
|
// R14
|
529 |
|
|
//------------
|
530 |
|
|
reg [15:0] r14;
|
531 |
|
|
wire r14_wr = inst_dest[14] & reg_dest_wr;
|
532 |
|
|
wire r14_inc = inst_src_in[14] & reg_incr;
|
533 |
|
|
|
534 |
|
|
`ifdef CLOCK_GATING
|
535 |
|
|
wire r14_en = r14_wr | r14_inc;
|
536 |
|
|
wire mclk_r14;
|
537 |
|
|
omsp_clock_gate clock_gate_r14 (.gclk(mclk_r14),
|
538 |
|
|
.clk (mclk), .enable(r14_en), .scan_enable(scan_enable));
|
539 |
|
|
`else
|
540 |
|
|
wire mclk_r14 = mclk;
|
541 |
|
|
`endif
|
542 |
|
|
|
543 |
|
|
always @(posedge mclk_r14 or posedge puc_rst)
|
544 |
|
|
if (puc_rst) r14 <= 16'h0000;
|
545 |
|
|
else if (r14_wr) r14 <= reg_dest_val_in;
|
546 |
|
|
`ifdef CLOCK_GATING
|
547 |
|
|
else r14 <= reg_incr_val;
|
548 |
|
|
`else
|
549 |
|
|
else if (r14_inc) r14 <= reg_incr_val;
|
550 |
|
|
`endif
|
551 |
|
|
|
552 |
|
|
// R15
|
553 |
|
|
//------------
|
554 |
|
|
reg [15:0] r15;
|
555 |
|
|
wire r15_wr = inst_dest[15] & reg_dest_wr;
|
556 |
|
|
wire r15_inc = inst_src_in[15] & reg_incr;
|
557 |
|
|
|
558 |
|
|
`ifdef CLOCK_GATING
|
559 |
|
|
wire r15_en = r15_wr | r15_inc;
|
560 |
|
|
wire mclk_r15;
|
561 |
|
|
omsp_clock_gate clock_gate_r15 (.gclk(mclk_r15),
|
562 |
|
|
.clk (mclk), .enable(r15_en), .scan_enable(scan_enable));
|
563 |
|
|
`else
|
564 |
|
|
wire mclk_r15 = mclk;
|
565 |
|
|
`endif
|
566 |
|
|
|
567 |
|
|
always @(posedge mclk_r15 or posedge puc_rst)
|
568 |
|
|
if (puc_rst) r15 <= 16'h0000;
|
569 |
|
|
else if (r15_wr) r15 <= reg_dest_val_in;
|
570 |
|
|
`ifdef CLOCK_GATING
|
571 |
|
|
else r15 <= reg_incr_val;
|
572 |
|
|
`else
|
573 |
202 |
olivier.gi |
else if (r15_inc) r15 <= reg_incr_val;
|
574 |
157 |
olivier.gi |
`endif
|
575 |
|
|
|
576 |
|
|
|
577 |
|
|
//=============================================================================
|
578 |
|
|
// 5) READ MUX
|
579 |
|
|
//=============================================================================
|
580 |
|
|
|
581 |
202 |
olivier.gi |
assign reg_src = (r0 & {16{inst_src_in[0]}}) |
|
582 |
|
|
(r1 & {16{inst_src_in[1]}}) |
|
583 |
|
|
(r2 & {16{inst_src_in[2]}}) |
|
584 |
|
|
(r3 & {16{inst_src_in[3]}}) |
|
585 |
|
|
(r4 & {16{inst_src_in[4]}}) |
|
586 |
|
|
(r5 & {16{inst_src_in[5]}}) |
|
587 |
|
|
(r6 & {16{inst_src_in[6]}}) |
|
588 |
|
|
(r7 & {16{inst_src_in[7]}}) |
|
589 |
|
|
(r8 & {16{inst_src_in[8]}}) |
|
590 |
|
|
(r9 & {16{inst_src_in[9]}}) |
|
591 |
|
|
(r10 & {16{inst_src_in[10]}}) |
|
592 |
|
|
(r11 & {16{inst_src_in[11]}}) |
|
593 |
|
|
(r12 & {16{inst_src_in[12]}}) |
|
594 |
|
|
(r13 & {16{inst_src_in[13]}}) |
|
595 |
|
|
(r14 & {16{inst_src_in[14]}}) |
|
596 |
157 |
olivier.gi |
(r15 & {16{inst_src_in[15]}});
|
597 |
|
|
|
598 |
202 |
olivier.gi |
assign reg_dest = (r0 & {16{inst_dest[0]}}) |
|
599 |
|
|
(r1 & {16{inst_dest[1]}}) |
|
600 |
|
|
(r2 & {16{inst_dest[2]}}) |
|
601 |
|
|
(r3 & {16{inst_dest[3]}}) |
|
602 |
|
|
(r4 & {16{inst_dest[4]}}) |
|
603 |
|
|
(r5 & {16{inst_dest[5]}}) |
|
604 |
|
|
(r6 & {16{inst_dest[6]}}) |
|
605 |
|
|
(r7 & {16{inst_dest[7]}}) |
|
606 |
|
|
(r8 & {16{inst_dest[8]}}) |
|
607 |
|
|
(r9 & {16{inst_dest[9]}}) |
|
608 |
|
|
(r10 & {16{inst_dest[10]}}) |
|
609 |
|
|
(r11 & {16{inst_dest[11]}}) |
|
610 |
|
|
(r12 & {16{inst_dest[12]}}) |
|
611 |
|
|
(r13 & {16{inst_dest[13]}}) |
|
612 |
|
|
(r14 & {16{inst_dest[14]}}) |
|
613 |
157 |
olivier.gi |
(r15 & {16{inst_dest[15]}});
|
614 |
|
|
|
615 |
|
|
|
616 |
|
|
endmodule // omsp_register_file
|
617 |
|
|
|
618 |
|
|
`ifdef OMSP_NO_INCLUDE
|
619 |
|
|
`else
|
620 |
|
|
`include "openMSP430_undefines.v"
|
621 |
|
|
`endif
|