| 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 |
|
|
//
|
| 32 |
|
|
// *Module Description:
|
| 33 |
|
|
// openMSP430 Register files
|
| 34 |
|
|
//
|
| 35 |
|
|
// *Author(s):
|
| 36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
| 37 |
|
|
//
|
| 38 |
|
|
//----------------------------------------------------------------------------
|
| 39 |
|
|
// $Rev: 103 $
|
| 40 |
|
|
// $LastChangedBy: olivier.girard $
|
| 41 |
|
|
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
|
| 42 |
|
|
//----------------------------------------------------------------------------
|
| 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 |
|
|
output cpuoff; // Turns off the CPU
|
| 85 |
|
|
output gie; // General interrupt enable
|
| 86 |
|
|
output oscoff; // Turns off LFXT1 clock input
|
| 87 |
|
|
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 |
|
|
wire mclk_r1 = mclk;
|
| 159 |
|
|
`endif
|
| 160 |
|
|
|
| 161 |
|
|
always @(posedge mclk_r1 or posedge puc_rst)
|
| 162 |
|
|
if (puc_rst) r1 <= 16'h0000;
|
| 163 |
|
|
else if (r1_wr) r1 <= reg_dest_val_in & 16'hfffe;
|
| 164 |
|
|
else if (reg_sp_wr) r1 <= reg_sp_val & 16'hfffe;
|
| 165 |
|
|
`ifdef CLOCK_GATING
|
| 166 |
|
|
else r1 <= reg_incr_val & 16'hfffe;
|
| 167 |
|
|
`else
|
| 168 |
|
|
else if (r1_inc) r1 <= reg_incr_val & 16'hfffe;
|
| 169 |
|
|
`endif
|
| 170 |
|
|
|
| 171 |
|
|
|
| 172 |
|
|
// R2: Status register
|
| 173 |
|
|
//---------------------
|
| 174 |
|
|
reg [15:0] r2;
|
| 175 |
|
|
wire r2_wr = (inst_dest[2] & reg_dest_wr) | reg_sr_wr;
|
| 176 |
|
|
|
| 177 |
|
|
`ifdef CLOCK_GATING // -- WITH CLOCK GATING --
|
| 178 |
|
|
wire r2_c = alu_stat_wr[0] ? alu_stat[0] : reg_dest_val_in[0]; // C
|
| 179 |
|
|
|
| 180 |
|
|
wire r2_z = alu_stat_wr[1] ? alu_stat[1] : reg_dest_val_in[1]; // Z
|
| 181 |
|
|
|
| 182 |
|
|
wire r2_n = alu_stat_wr[2] ? alu_stat[2] : reg_dest_val_in[2]; // N
|
| 183 |
|
|
|
| 184 |
|
|
wire [7:3] r2_nxt = r2_wr ? reg_dest_val_in[7:3] : r2[7:3];
|
| 185 |
|
|
|
| 186 |
|
|
wire r2_v = alu_stat_wr[3] ? alu_stat[3] : reg_dest_val_in[8]; // V
|
| 187 |
|
|
|
| 188 |
|
|
wire r2_en = |alu_stat_wr | r2_wr | reg_sr_clr;
|
| 189 |
|
|
wire mclk_r2;
|
| 190 |
|
|
omsp_clock_gate clock_gate_r2 (.gclk(mclk_r2),
|
| 191 |
|
|
.clk (mclk), .enable(r2_en), .scan_enable(scan_enable));
|
| 192 |
|
|
|
| 193 |
|
|
`else // -- WITHOUT CLOCK GATING --
|
| 194 |
|
|
wire r2_c = alu_stat_wr[0] ? alu_stat[0] :
|
| 195 |
|
|
r2_wr ? reg_dest_val_in[0] : r2[0]; // C
|
| 196 |
|
|
|
| 197 |
|
|
wire r2_z = alu_stat_wr[1] ? alu_stat[1] :
|
| 198 |
|
|
r2_wr ? reg_dest_val_in[1] : r2[1]; // Z
|
| 199 |
|
|
|
| 200 |
|
|
wire r2_n = alu_stat_wr[2] ? alu_stat[2] :
|
| 201 |
|
|
r2_wr ? reg_dest_val_in[2] : r2[2]; // N
|
| 202 |
|
|
|
| 203 |
|
|
wire [7:3] r2_nxt = r2_wr ? reg_dest_val_in[7:3] : r2[7:3];
|
| 204 |
|
|
|
| 205 |
|
|
wire r2_v = alu_stat_wr[3] ? alu_stat[3] :
|
| 206 |
|
|
r2_wr ? reg_dest_val_in[8] : r2[8]; // V
|
| 207 |
|
|
|
| 208 |
|
|
|
| 209 |
|
|
wire mclk_r2 = mclk;
|
| 210 |
|
|
`endif
|
| 211 |
|
|
|
| 212 |
|
|
`ifdef ASIC
|
| 213 |
|
|
`ifdef CPUOFF_EN
|
| 214 |
|
|
wire [15:0] cpuoff_mask = 16'h0010;
|
| 215 |
|
|
`else
|
| 216 |
|
|
wire [15:0] cpuoff_mask = 16'h0000;
|
| 217 |
|
|
`endif
|
| 218 |
|
|
`ifdef OSCOFF_EN
|
| 219 |
|
|
wire [15:0] oscoff_mask = 16'h0020;
|
| 220 |
|
|
`else
|
| 221 |
|
|
wire [15:0] oscoff_mask = 16'h0000;
|
| 222 |
|
|
`endif
|
| 223 |
|
|
`ifdef SCG0_EN
|
| 224 |
|
|
wire [15:0] scg0_mask = 16'h0040;
|
| 225 |
|
|
`else
|
| 226 |
|
|
wire [15:0] scg0_mask = 16'h0000;
|
| 227 |
|
|
`endif
|
| 228 |
|
|
`ifdef SCG1_EN
|
| 229 |
|
|
wire [15:0] scg1_mask = 16'h0080;
|
| 230 |
|
|
`else
|
| 231 |
|
|
wire [15:0] scg1_mask = 16'h0000;
|
| 232 |
|
|
`endif
|
| 233 |
|
|
`else
|
| 234 |
|
|
wire [15:0] cpuoff_mask = 16'h0010; // For the FPGA version: - the CPUOFF mode is emulated
|
| 235 |
|
|
wire [15:0] oscoff_mask = 16'h0020; // - the SCG1 mode is emulated
|
| 236 |
|
|
wire [15:0] scg0_mask = 16'h0000; // - the SCG0 is not supported
|
| 237 |
|
|
wire [15:0] scg1_mask = 16'h0080; // - the SCG1 mode is emulated
|
| 238 |
|
|
`endif
|
| 239 |
|
|
|
| 240 |
|
|
wire [15:0] r2_mask = cpuoff_mask | oscoff_mask | scg0_mask | scg1_mask | 16'h010f;
|
| 241 |
|
|
|
| 242 |
|
|
always @(posedge mclk_r2 or posedge puc_rst)
|
| 243 |
|
|
if (puc_rst) r2 <= 16'h0000;
|
| 244 |
|
|
else if (reg_sr_clr) r2 <= 16'h0000;
|
| 245 |
|
|
else r2 <= {7'h00, r2_v, r2_nxt, r2_n, r2_z, r2_c} & r2_mask;
|
| 246 |
|
|
|
| 247 |
|
|
assign status = {r2[8], r2[2:0]};
|
| 248 |
|
|
assign gie = r2[3];
|
| 249 |
|
|
assign cpuoff = r2[4] | (r2_nxt[4] & r2_wr & cpuoff_mask[4]);
|
| 250 |
|
|
assign oscoff = r2[5];
|
| 251 |
|
|
assign scg0 = r2[6];
|
| 252 |
|
|
assign scg1 = r2[7];
|
| 253 |
|
|
|
| 254 |
|
|
|
| 255 |
|
|
// R3: Constant generator
|
| 256 |
|
|
//-------------------------------------------------------------
|
| 257 |
|
|
// Note: the auto-increment feature is not implemented for R3
|
| 258 |
|
|
// because the @R3+ addressing mode is used for constant
|
| 259 |
|
|
// generation (#-1).
|
| 260 |
|
|
reg [15:0] r3;
|
| 261 |
|
|
wire r3_wr = inst_dest[3] & reg_dest_wr;
|
| 262 |
|
|
|
| 263 |
|
|
`ifdef CLOCK_GATING
|
| 264 |
|
|
wire r3_en = r3_wr;
|
| 265 |
|
|
wire mclk_r3;
|
| 266 |
|
|
omsp_clock_gate clock_gate_r3 (.gclk(mclk_r3),
|
| 267 |
|
|
.clk (mclk), .enable(r3_en), .scan_enable(scan_enable));
|
| 268 |
|
|
`else
|
| 269 |
|
|
wire mclk_r3 = mclk;
|
| 270 |
|
|
`endif
|
| 271 |
|
|
|
| 272 |
|
|
always @(posedge mclk_r3 or posedge puc_rst)
|
| 273 |
|
|
if (puc_rst) r3 <= 16'h0000;
|
| 274 |
|
|
`ifdef CLOCK_GATING
|
| 275 |
|
|
else r3 <= reg_dest_val_in;
|
| 276 |
|
|
`else
|
| 277 |
|
|
else if (r3_wr) r3 <= reg_dest_val_in;
|
| 278 |
|
|
`endif
|
| 279 |
|
|
|
| 280 |
|
|
|
| 281 |
|
|
//=============================================================================
|
| 282 |
|
|
// 4) GENERAL PURPOSE REGISTERS (R4...R15)
|
| 283 |
|
|
//=============================================================================
|
| 284 |
|
|
|
| 285 |
|
|
// R4
|
| 286 |
|
|
//------------
|
| 287 |
|
|
reg [15:0] r4;
|
| 288 |
|
|
wire r4_wr = inst_dest[4] & reg_dest_wr;
|
| 289 |
|
|
wire r4_inc = inst_src_in[4] & reg_incr;
|
| 290 |
|
|
|
| 291 |
|
|
`ifdef CLOCK_GATING
|
| 292 |
|
|
wire r4_en = r4_wr | r4_inc;
|
| 293 |
|
|
wire mclk_r4;
|
| 294 |
|
|
omsp_clock_gate clock_gate_r4 (.gclk(mclk_r4),
|
| 295 |
|
|
.clk (mclk), .enable(r4_en), .scan_enable(scan_enable));
|
| 296 |
|
|
`else
|
| 297 |
|
|
wire mclk_r4 = mclk;
|
| 298 |
|
|
`endif
|
| 299 |
|
|
|
| 300 |
|
|
always @(posedge mclk_r4 or posedge puc_rst)
|
| 301 |
|
|
if (puc_rst) r4 <= 16'h0000;
|
| 302 |
|
|
else if (r4_wr) r4 <= reg_dest_val_in;
|
| 303 |
|
|
`ifdef CLOCK_GATING
|
| 304 |
|
|
else r4 <= reg_incr_val;
|
| 305 |
|
|
`else
|
| 306 |
|
|
else if (r4_inc) r4 <= reg_incr_val;
|
| 307 |
|
|
`endif
|
| 308 |
|
|
|
| 309 |
|
|
// R5
|
| 310 |
|
|
//------------
|
| 311 |
|
|
reg [15:0] r5;
|
| 312 |
|
|
wire r5_wr = inst_dest[5] & reg_dest_wr;
|
| 313 |
|
|
wire r5_inc = inst_src_in[5] & reg_incr;
|
| 314 |
|
|
|
| 315 |
|
|
`ifdef CLOCK_GATING
|
| 316 |
|
|
wire r5_en = r5_wr | r5_inc;
|
| 317 |
|
|
wire mclk_r5;
|
| 318 |
|
|
omsp_clock_gate clock_gate_r5 (.gclk(mclk_r5),
|
| 319 |
|
|
.clk (mclk), .enable(r5_en), .scan_enable(scan_enable));
|
| 320 |
|
|
`else
|
| 321 |
|
|
wire mclk_r5 = mclk;
|
| 322 |
|
|
`endif
|
| 323 |
|
|
|
| 324 |
|
|
always @(posedge mclk_r5 or posedge puc_rst)
|
| 325 |
|
|
if (puc_rst) r5 <= 16'h0000;
|
| 326 |
|
|
else if (r5_wr) r5 <= reg_dest_val_in;
|
| 327 |
|
|
`ifdef CLOCK_GATING
|
| 328 |
|
|
else r5 <= reg_incr_val;
|
| 329 |
|
|
`else
|
| 330 |
|
|
else if (r5_inc) r5 <= reg_incr_val;
|
| 331 |
|
|
`endif
|
| 332 |
|
|
|
| 333 |
|
|
// R6
|
| 334 |
|
|
//------------
|
| 335 |
|
|
reg [15:0] r6;
|
| 336 |
|
|
wire r6_wr = inst_dest[6] & reg_dest_wr;
|
| 337 |
|
|
wire r6_inc = inst_src_in[6] & reg_incr;
|
| 338 |
|
|
|
| 339 |
|
|
`ifdef CLOCK_GATING
|
| 340 |
|
|
wire r6_en = r6_wr | r6_inc;
|
| 341 |
|
|
wire mclk_r6;
|
| 342 |
|
|
omsp_clock_gate clock_gate_r6 (.gclk(mclk_r6),
|
| 343 |
|
|
.clk (mclk), .enable(r6_en), .scan_enable(scan_enable));
|
| 344 |
|
|
`else
|
| 345 |
|
|
wire mclk_r6 = mclk;
|
| 346 |
|
|
`endif
|
| 347 |
|
|
|
| 348 |
|
|
always @(posedge mclk_r6 or posedge puc_rst)
|
| 349 |
|
|
if (puc_rst) r6 <= 16'h0000;
|
| 350 |
|
|
else if (r6_wr) r6 <= reg_dest_val_in;
|
| 351 |
|
|
`ifdef CLOCK_GATING
|
| 352 |
|
|
else r6 <= reg_incr_val;
|
| 353 |
|
|
`else
|
| 354 |
|
|
else if (r6_inc) r6 <= reg_incr_val;
|
| 355 |
|
|
`endif
|
| 356 |
|
|
|
| 357 |
|
|
// R7
|
| 358 |
|
|
//------------
|
| 359 |
|
|
reg [15:0] r7;
|
| 360 |
|
|
wire r7_wr = inst_dest[7] & reg_dest_wr;
|
| 361 |
|
|
wire r7_inc = inst_src_in[7] & reg_incr;
|
| 362 |
|
|
|
| 363 |
|
|
`ifdef CLOCK_GATING
|
| 364 |
|
|
wire r7_en = r7_wr | r7_inc;
|
| 365 |
|
|
wire mclk_r7;
|
| 366 |
|
|
omsp_clock_gate clock_gate_r7 (.gclk(mclk_r7),
|
| 367 |
|
|
.clk (mclk), .enable(r7_en), .scan_enable(scan_enable));
|
| 368 |
|
|
`else
|
| 369 |
|
|
wire mclk_r7 = mclk;
|
| 370 |
|
|
`endif
|
| 371 |
|
|
|
| 372 |
|
|
always @(posedge mclk_r7 or posedge puc_rst)
|
| 373 |
|
|
if (puc_rst) r7 <= 16'h0000;
|
| 374 |
|
|
else if (r7_wr) r7 <= reg_dest_val_in;
|
| 375 |
|
|
`ifdef CLOCK_GATING
|
| 376 |
|
|
else r7 <= reg_incr_val;
|
| 377 |
|
|
`else
|
| 378 |
|
|
else if (r7_inc) r7 <= reg_incr_val;
|
| 379 |
|
|
`endif
|
| 380 |
|
|
|
| 381 |
|
|
// R8
|
| 382 |
|
|
//------------
|
| 383 |
|
|
reg [15:0] r8;
|
| 384 |
|
|
wire r8_wr = inst_dest[8] & reg_dest_wr;
|
| 385 |
|
|
wire r8_inc = inst_src_in[8] & reg_incr;
|
| 386 |
|
|
|
| 387 |
|
|
`ifdef CLOCK_GATING
|
| 388 |
|
|
wire r8_en = r8_wr | r8_inc;
|
| 389 |
|
|
wire mclk_r8;
|
| 390 |
|
|
omsp_clock_gate clock_gate_r8 (.gclk(mclk_r8),
|
| 391 |
|
|
.clk (mclk), .enable(r8_en), .scan_enable(scan_enable));
|
| 392 |
|
|
`else
|
| 393 |
|
|
wire mclk_r8 = mclk;
|
| 394 |
|
|
`endif
|
| 395 |
|
|
|
| 396 |
|
|
always @(posedge mclk_r8 or posedge puc_rst)
|
| 397 |
|
|
if (puc_rst) r8 <= 16'h0000;
|
| 398 |
|
|
else if (r8_wr) r8 <= reg_dest_val_in;
|
| 399 |
|
|
`ifdef CLOCK_GATING
|
| 400 |
|
|
else r8 <= reg_incr_val;
|
| 401 |
|
|
`else
|
| 402 |
|
|
else if (r8_inc) r8 <= reg_incr_val;
|
| 403 |
|
|
`endif
|
| 404 |
|
|
|
| 405 |
|
|
// R9
|
| 406 |
|
|
//------------
|
| 407 |
|
|
reg [15:0] r9;
|
| 408 |
|
|
wire r9_wr = inst_dest[9] & reg_dest_wr;
|
| 409 |
|
|
wire r9_inc = inst_src_in[9] & reg_incr;
|
| 410 |
|
|
|
| 411 |
|
|
`ifdef CLOCK_GATING
|
| 412 |
|
|
wire r9_en = r9_wr | r9_inc;
|
| 413 |
|
|
wire mclk_r9;
|
| 414 |
|
|
omsp_clock_gate clock_gate_r9 (.gclk(mclk_r9),
|
| 415 |
|
|
.clk (mclk), .enable(r9_en), .scan_enable(scan_enable));
|
| 416 |
|
|
`else
|
| 417 |
|
|
wire mclk_r9 = mclk;
|
| 418 |
|
|
`endif
|
| 419 |
|
|
|
| 420 |
|
|
always @(posedge mclk_r9 or posedge puc_rst)
|
| 421 |
|
|
if (puc_rst) r9 <= 16'h0000;
|
| 422 |
|
|
else if (r9_wr) r9 <= reg_dest_val_in;
|
| 423 |
|
|
`ifdef CLOCK_GATING
|
| 424 |
|
|
else r9 <= reg_incr_val;
|
| 425 |
|
|
`else
|
| 426 |
|
|
else if (r9_inc) r9 <= reg_incr_val;
|
| 427 |
|
|
`endif
|
| 428 |
|
|
|
| 429 |
|
|
// R10
|
| 430 |
|
|
//------------
|
| 431 |
|
|
reg [15:0] r10;
|
| 432 |
|
|
wire r10_wr = inst_dest[10] & reg_dest_wr;
|
| 433 |
|
|
wire r10_inc = inst_src_in[10] & reg_incr;
|
| 434 |
|
|
|
| 435 |
|
|
`ifdef CLOCK_GATING
|
| 436 |
|
|
wire r10_en = r10_wr | r10_inc;
|
| 437 |
|
|
wire mclk_r10;
|
| 438 |
|
|
omsp_clock_gate clock_gate_r10 (.gclk(mclk_r10),
|
| 439 |
|
|
.clk (mclk), .enable(r10_en), .scan_enable(scan_enable));
|
| 440 |
|
|
`else
|
| 441 |
|
|
wire mclk_r10 = mclk;
|
| 442 |
|
|
`endif
|
| 443 |
|
|
|
| 444 |
|
|
always @(posedge mclk_r10 or posedge puc_rst)
|
| 445 |
|
|
if (puc_rst) r10 <= 16'h0000;
|
| 446 |
|
|
else if (r10_wr) r10 <= reg_dest_val_in;
|
| 447 |
|
|
`ifdef CLOCK_GATING
|
| 448 |
|
|
else r10 <= reg_incr_val;
|
| 449 |
|
|
`else
|
| 450 |
|
|
else if (r10_inc) r10 <= reg_incr_val;
|
| 451 |
|
|
`endif
|
| 452 |
|
|
|
| 453 |
|
|
// R11
|
| 454 |
|
|
//------------
|
| 455 |
|
|
reg [15:0] r11;
|
| 456 |
|
|
wire r11_wr = inst_dest[11] & reg_dest_wr;
|
| 457 |
|
|
wire r11_inc = inst_src_in[11] & reg_incr;
|
| 458 |
|
|
|
| 459 |
|
|
`ifdef CLOCK_GATING
|
| 460 |
|
|
wire r11_en = r11_wr | r11_inc;
|
| 461 |
|
|
wire mclk_r11;
|
| 462 |
|
|
omsp_clock_gate clock_gate_r11 (.gclk(mclk_r11),
|
| 463 |
|
|
.clk (mclk), .enable(r11_en), .scan_enable(scan_enable));
|
| 464 |
|
|
`else
|
| 465 |
|
|
wire mclk_r11 = mclk;
|
| 466 |
|
|
`endif
|
| 467 |
|
|
|
| 468 |
|
|
always @(posedge mclk_r11 or posedge puc_rst)
|
| 469 |
|
|
if (puc_rst) r11 <= 16'h0000;
|
| 470 |
|
|
else if (r11_wr) r11 <= reg_dest_val_in;
|
| 471 |
|
|
`ifdef CLOCK_GATING
|
| 472 |
|
|
else r11 <= reg_incr_val;
|
| 473 |
|
|
`else
|
| 474 |
|
|
else if (r11_inc) r11 <= reg_incr_val;
|
| 475 |
|
|
`endif
|
| 476 |
|
|
|
| 477 |
|
|
// R12
|
| 478 |
|
|
//------------
|
| 479 |
|
|
reg [15:0] r12;
|
| 480 |
|
|
wire r12_wr = inst_dest[12] & reg_dest_wr;
|
| 481 |
|
|
wire r12_inc = inst_src_in[12] & reg_incr;
|
| 482 |
|
|
|
| 483 |
|
|
`ifdef CLOCK_GATING
|
| 484 |
|
|
wire r12_en = r12_wr | r12_inc;
|
| 485 |
|
|
wire mclk_r12;
|
| 486 |
|
|
omsp_clock_gate clock_gate_r12 (.gclk(mclk_r12),
|
| 487 |
|
|
.clk (mclk), .enable(r12_en), .scan_enable(scan_enable));
|
| 488 |
|
|
`else
|
| 489 |
|
|
wire mclk_r12 = mclk;
|
| 490 |
|
|
`endif
|
| 491 |
|
|
|
| 492 |
|
|
always @(posedge mclk_r12 or posedge puc_rst)
|
| 493 |
|
|
if (puc_rst) r12 <= 16'h0000;
|
| 494 |
|
|
else if (r12_wr) r12 <= reg_dest_val_in;
|
| 495 |
|
|
`ifdef CLOCK_GATING
|
| 496 |
|
|
else r12 <= reg_incr_val;
|
| 497 |
|
|
`else
|
| 498 |
|
|
else if (r12_inc) r12 <= reg_incr_val;
|
| 499 |
|
|
`endif
|
| 500 |
|
|
|
| 501 |
|
|
// R13
|
| 502 |
|
|
//------------
|
| 503 |
|
|
reg [15:0] r13;
|
| 504 |
|
|
wire r13_wr = inst_dest[13] & reg_dest_wr;
|
| 505 |
|
|
wire r13_inc = inst_src_in[13] & reg_incr;
|
| 506 |
|
|
|
| 507 |
|
|
`ifdef CLOCK_GATING
|
| 508 |
|
|
wire r13_en = r13_wr | r13_inc;
|
| 509 |
|
|
wire mclk_r13;
|
| 510 |
|
|
omsp_clock_gate clock_gate_r13 (.gclk(mclk_r13),
|
| 511 |
|
|
.clk (mclk), .enable(r13_en), .scan_enable(scan_enable));
|
| 512 |
|
|
`else
|
| 513 |
|
|
wire mclk_r13 = mclk;
|
| 514 |
|
|
`endif
|
| 515 |
|
|
|
| 516 |
|
|
always @(posedge mclk_r13 or posedge puc_rst)
|
| 517 |
|
|
if (puc_rst) r13 <= 16'h0000;
|
| 518 |
|
|
else if (r13_wr) r13 <= reg_dest_val_in;
|
| 519 |
|
|
`ifdef CLOCK_GATING
|
| 520 |
|
|
else r13 <= reg_incr_val;
|
| 521 |
|
|
`else
|
| 522 |
|
|
else if (r13_inc) r13 <= reg_incr_val;
|
| 523 |
|
|
`endif
|
| 524 |
|
|
|
| 525 |
|
|
// R14
|
| 526 |
|
|
//------------
|
| 527 |
|
|
reg [15:0] r14;
|
| 528 |
|
|
wire r14_wr = inst_dest[14] & reg_dest_wr;
|
| 529 |
|
|
wire r14_inc = inst_src_in[14] & reg_incr;
|
| 530 |
|
|
|
| 531 |
|
|
`ifdef CLOCK_GATING
|
| 532 |
|
|
wire r14_en = r14_wr | r14_inc;
|
| 533 |
|
|
wire mclk_r14;
|
| 534 |
|
|
omsp_clock_gate clock_gate_r14 (.gclk(mclk_r14),
|
| 535 |
|
|
.clk (mclk), .enable(r14_en), .scan_enable(scan_enable));
|
| 536 |
|
|
`else
|
| 537 |
|
|
wire mclk_r14 = mclk;
|
| 538 |
|
|
`endif
|
| 539 |
|
|
|
| 540 |
|
|
always @(posedge mclk_r14 or posedge puc_rst)
|
| 541 |
|
|
if (puc_rst) r14 <= 16'h0000;
|
| 542 |
|
|
else if (r14_wr) r14 <= reg_dest_val_in;
|
| 543 |
|
|
`ifdef CLOCK_GATING
|
| 544 |
|
|
else r14 <= reg_incr_val;
|
| 545 |
|
|
`else
|
| 546 |
|
|
else if (r14_inc) r14 <= reg_incr_val;
|
| 547 |
|
|
`endif
|
| 548 |
|
|
|
| 549 |
|
|
// R15
|
| 550 |
|
|
//------------
|
| 551 |
|
|
reg [15:0] r15;
|
| 552 |
|
|
wire r15_wr = inst_dest[15] & reg_dest_wr;
|
| 553 |
|
|
wire r15_inc = inst_src_in[15] & reg_incr;
|
| 554 |
|
|
|
| 555 |
|
|
`ifdef CLOCK_GATING
|
| 556 |
|
|
wire r15_en = r15_wr | r15_inc;
|
| 557 |
|
|
wire mclk_r15;
|
| 558 |
|
|
omsp_clock_gate clock_gate_r15 (.gclk(mclk_r15),
|
| 559 |
|
|
.clk (mclk), .enable(r15_en), .scan_enable(scan_enable));
|
| 560 |
|
|
`else
|
| 561 |
|
|
wire mclk_r15 = mclk;
|
| 562 |
|
|
`endif
|
| 563 |
|
|
|
| 564 |
|
|
always @(posedge mclk_r15 or posedge puc_rst)
|
| 565 |
|
|
if (puc_rst) r15 <= 16'h0000;
|
| 566 |
|
|
else if (r15_wr) r15 <= reg_dest_val_in;
|
| 567 |
|
|
`ifdef CLOCK_GATING
|
| 568 |
|
|
else r15 <= reg_incr_val;
|
| 569 |
|
|
`else
|
| 570 |
|
|
else if (r15_inc) r15 <= reg_incr_val;
|
| 571 |
|
|
`endif
|
| 572 |
|
|
|
| 573 |
|
|
|
| 574 |
|
|
//=============================================================================
|
| 575 |
|
|
// 5) READ MUX
|
| 576 |
|
|
//=============================================================================
|
| 577 |
|
|
|
| 578 |
|
|
assign reg_src = (r0 & {16{inst_src_in[0]}}) |
|
| 579 |
|
|
(r1 & {16{inst_src_in[1]}}) |
|
| 580 |
|
|
(r2 & {16{inst_src_in[2]}}) |
|
| 581 |
|
|
(r3 & {16{inst_src_in[3]}}) |
|
| 582 |
|
|
(r4 & {16{inst_src_in[4]}}) |
|
| 583 |
|
|
(r5 & {16{inst_src_in[5]}}) |
|
| 584 |
|
|
(r6 & {16{inst_src_in[6]}}) |
|
| 585 |
|
|
(r7 & {16{inst_src_in[7]}}) |
|
| 586 |
|
|
(r8 & {16{inst_src_in[8]}}) |
|
| 587 |
|
|
(r9 & {16{inst_src_in[9]}}) |
|
| 588 |
|
|
(r10 & {16{inst_src_in[10]}}) |
|
| 589 |
|
|
(r11 & {16{inst_src_in[11]}}) |
|
| 590 |
|
|
(r12 & {16{inst_src_in[12]}}) |
|
| 591 |
|
|
(r13 & {16{inst_src_in[13]}}) |
|
| 592 |
|
|
(r14 & {16{inst_src_in[14]}}) |
|
| 593 |
|
|
(r15 & {16{inst_src_in[15]}});
|
| 594 |
|
|
|
| 595 |
|
|
assign reg_dest = (r0 & {16{inst_dest[0]}}) |
|
| 596 |
|
|
(r1 & {16{inst_dest[1]}}) |
|
| 597 |
|
|
(r2 & {16{inst_dest[2]}}) |
|
| 598 |
|
|
(r3 & {16{inst_dest[3]}}) |
|
| 599 |
|
|
(r4 & {16{inst_dest[4]}}) |
|
| 600 |
|
|
(r5 & {16{inst_dest[5]}}) |
|
| 601 |
|
|
(r6 & {16{inst_dest[6]}}) |
|
| 602 |
|
|
(r7 & {16{inst_dest[7]}}) |
|
| 603 |
|
|
(r8 & {16{inst_dest[8]}}) |
|
| 604 |
|
|
(r9 & {16{inst_dest[9]}}) |
|
| 605 |
|
|
(r10 & {16{inst_dest[10]}}) |
|
| 606 |
|
|
(r11 & {16{inst_dest[11]}}) |
|
| 607 |
|
|
(r12 & {16{inst_dest[12]}}) |
|
| 608 |
|
|
(r13 & {16{inst_dest[13]}}) |
|
| 609 |
|
|
(r14 & {16{inst_dest[14]}}) |
|
| 610 |
|
|
(r15 & {16{inst_dest[15]}});
|
| 611 |
|
|
|
| 612 |
|
|
|
| 613 |
|
|
endmodule // omsp_register_file
|
| 614 |
|
|
|
| 615 |
|
|
`ifdef OMSP_NO_INCLUDE
|
| 616 |
|
|
`else
|
| 617 |
|
|
`include "openMSP430_undefines.v"
|
| 618 |
|
|
`endif
|