| 1 |
80 |
olivier.gi |
//----------------------------------------------------------------------------
|
| 2 |
136 |
olivier.gi |
// Copyright (C) 2009 , Olivier Girard
|
| 3 |
80 |
olivier.gi |
//
|
| 4 |
136 |
olivier.gi |
// 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 |
80 |
olivier.gi |
//
|
| 16 |
136 |
olivier.gi |
// 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 |
80 |
olivier.gi |
//
|
| 28 |
|
|
//----------------------------------------------------------------------------
|
| 29 |
|
|
//
|
| 30 |
|
|
// *File Name: omsp_clock_module.v
|
| 31 |
|
|
//
|
| 32 |
|
|
// *Module Description:
|
| 33 |
|
|
// Basic clock module implementation.
|
| 34 |
|
|
//
|
| 35 |
|
|
// *Author(s):
|
| 36 |
|
|
// - Olivier Girard, olgirard@gmail.com
|
| 37 |
|
|
//
|
| 38 |
|
|
//----------------------------------------------------------------------------
|
| 39 |
111 |
olivier.gi |
// $Rev: 103 $
|
| 40 |
80 |
olivier.gi |
// $LastChangedBy: olivier.girard $
|
| 41 |
111 |
olivier.gi |
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
|
| 42 |
80 |
olivier.gi |
//----------------------------------------------------------------------------
|
| 43 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
| 44 |
|
|
`else
|
| 45 |
80 |
olivier.gi |
`include "openMSP430_defines.v"
|
| 46 |
104 |
olivier.gi |
`endif
|
| 47 |
80 |
olivier.gi |
|
| 48 |
|
|
module omsp_clock_module (
|
| 49 |
|
|
|
| 50 |
|
|
// OUTPUTs
|
| 51 |
136 |
olivier.gi |
aclk, // ACLK
|
| 52 |
80 |
olivier.gi |
aclk_en, // ACLK enable
|
| 53 |
107 |
olivier.gi |
cpu_en_s, // Enable CPU code execution (synchronous)
|
| 54 |
|
|
dbg_clk, // Debug unit clock
|
| 55 |
|
|
dbg_en_s, // Debug interface enable (synchronous)
|
| 56 |
|
|
dbg_rst, // Debug unit reset
|
| 57 |
136 |
olivier.gi |
dco_enable, // Fast oscillator enable
|
| 58 |
|
|
dco_wkup, // Fast oscillator wake-up (asynchronous)
|
| 59 |
|
|
lfxt_enable, // Low frequency oscillator enable
|
| 60 |
|
|
lfxt_wkup, // Low frequency oscillator wake-up (asynchronous)
|
| 61 |
80 |
olivier.gi |
mclk, // Main system clock
|
| 62 |
|
|
per_dout, // Peripheral data output
|
| 63 |
|
|
por, // Power-on reset
|
| 64 |
136 |
olivier.gi |
puc_pnd_set, // PUC pending set for the serial debug interface
|
| 65 |
111 |
olivier.gi |
puc_rst, // Main system reset
|
| 66 |
136 |
olivier.gi |
smclk, // SMCLK
|
| 67 |
80 |
olivier.gi |
smclk_en, // SMCLK enable
|
| 68 |
|
|
|
| 69 |
|
|
// INPUTs
|
| 70 |
107 |
olivier.gi |
cpu_en, // Enable CPU code execution (asynchronous)
|
| 71 |
136 |
olivier.gi |
cpuoff, // Turns off the CPU
|
| 72 |
107 |
olivier.gi |
dbg_cpu_reset, // Reset CPU from debug interface
|
| 73 |
|
|
dbg_en, // Debug interface enable (asynchronous)
|
| 74 |
80 |
olivier.gi |
dco_clk, // Fast oscillator (fast clock)
|
| 75 |
|
|
lfxt_clk, // Low frequency oscillator (typ 32kHz)
|
| 76 |
136 |
olivier.gi |
mclk_enable, // Main System Clock enable
|
| 77 |
|
|
mclk_wkup, // Main System Clock wake-up (asynchronous)
|
| 78 |
80 |
olivier.gi |
oscoff, // Turns off LFXT1 clock input
|
| 79 |
|
|
per_addr, // Peripheral address
|
| 80 |
|
|
per_din, // Peripheral data input
|
| 81 |
|
|
per_en, // Peripheral enable (high active)
|
| 82 |
107 |
olivier.gi |
per_we, // Peripheral write enable (high active)
|
| 83 |
|
|
reset_n, // Reset Pin (low active, asynchronous)
|
| 84 |
136 |
olivier.gi |
scan_enable, // Scan enable (active during scan shifting)
|
| 85 |
|
|
scan_mode, // Scan mode
|
| 86 |
|
|
scg0, // System clock generator 1. Turns off the DCO
|
| 87 |
80 |
olivier.gi |
scg1, // System clock generator 1. Turns off the SMCLK
|
| 88 |
|
|
wdt_reset // Watchdog-timer reset
|
| 89 |
|
|
);
|
| 90 |
|
|
|
| 91 |
|
|
// OUTPUTs
|
| 92 |
|
|
//=========
|
| 93 |
136 |
olivier.gi |
output aclk; // ACLK
|
| 94 |
80 |
olivier.gi |
output aclk_en; // ACLK enable
|
| 95 |
107 |
olivier.gi |
output cpu_en_s; // Enable CPU code execution (synchronous)
|
| 96 |
|
|
output dbg_clk; // Debug unit clock
|
| 97 |
|
|
output dbg_en_s; // Debug unit enable (synchronous)
|
| 98 |
|
|
output dbg_rst; // Debug unit reset
|
| 99 |
136 |
olivier.gi |
output dco_enable; // Fast oscillator enable
|
| 100 |
|
|
output dco_wkup; // Fast oscillator wake-up (asynchronous)
|
| 101 |
|
|
output lfxt_enable; // Low frequency oscillator enable
|
| 102 |
|
|
output lfxt_wkup; // Low frequency oscillator wake-up (asynchronous)
|
| 103 |
80 |
olivier.gi |
output mclk; // Main system clock
|
| 104 |
|
|
output [15:0] per_dout; // Peripheral data output
|
| 105 |
|
|
output por; // Power-on reset
|
| 106 |
136 |
olivier.gi |
output puc_pnd_set; // PUC pending set for the serial debug interface
|
| 107 |
111 |
olivier.gi |
output puc_rst; // Main system reset
|
| 108 |
136 |
olivier.gi |
output smclk; // SMCLK
|
| 109 |
80 |
olivier.gi |
output smclk_en; // SMCLK enable
|
| 110 |
|
|
|
| 111 |
|
|
// INPUTs
|
| 112 |
|
|
//=========
|
| 113 |
107 |
olivier.gi |
input cpu_en; // Enable CPU code execution (asynchronous)
|
| 114 |
136 |
olivier.gi |
input cpuoff; // Turns off the CPU
|
| 115 |
107 |
olivier.gi |
input dbg_cpu_reset;// Reset CPU from debug interface
|
| 116 |
|
|
input dbg_en; // Debug interface enable (asynchronous)
|
| 117 |
80 |
olivier.gi |
input dco_clk; // Fast oscillator (fast clock)
|
| 118 |
|
|
input lfxt_clk; // Low frequency oscillator (typ 32kHz)
|
| 119 |
136 |
olivier.gi |
input mclk_enable; // Main System Clock enable
|
| 120 |
|
|
input mclk_wkup; // Main System Clock wake-up (asynchronous)
|
| 121 |
80 |
olivier.gi |
input oscoff; // Turns off LFXT1 clock input
|
| 122 |
111 |
olivier.gi |
input [13:0] per_addr; // Peripheral address
|
| 123 |
80 |
olivier.gi |
input [15:0] per_din; // Peripheral data input
|
| 124 |
|
|
input per_en; // Peripheral enable (high active)
|
| 125 |
107 |
olivier.gi |
input [1:0] per_we; // Peripheral write enable (high active)
|
| 126 |
|
|
input reset_n; // Reset Pin (low active, asynchronous)
|
| 127 |
136 |
olivier.gi |
input scan_enable; // Scan enable (active during scan shifting)
|
| 128 |
|
|
input scan_mode; // Scan mode
|
| 129 |
|
|
input scg0; // System clock generator 1. Turns off the DCO
|
| 130 |
80 |
olivier.gi |
input scg1; // System clock generator 1. Turns off the SMCLK
|
| 131 |
|
|
input wdt_reset; // Watchdog-timer reset
|
| 132 |
|
|
|
| 133 |
|
|
|
| 134 |
|
|
//=============================================================================
|
| 135 |
136 |
olivier.gi |
// 1) WIRES & PARAMETER DECLARATION
|
| 136 |
80 |
olivier.gi |
//=============================================================================
|
| 137 |
|
|
|
| 138 |
111 |
olivier.gi |
// Register base address (must be aligned to decoder bit width)
|
| 139 |
|
|
parameter [14:0] BASE_ADDR = 15'h0050;
|
| 140 |
80 |
olivier.gi |
|
| 141 |
111 |
olivier.gi |
// Decoder bit width (defines how many bits are considered for address decoding)
|
| 142 |
|
|
parameter DEC_WD = 4;
|
| 143 |
|
|
|
| 144 |
|
|
// Register addresses offset
|
| 145 |
|
|
parameter [DEC_WD-1:0] BCSCTL1 = 'h7,
|
| 146 |
|
|
BCSCTL2 = 'h8;
|
| 147 |
|
|
|
| 148 |
|
|
// Register one-hot decoder utilities
|
| 149 |
136 |
olivier.gi |
parameter DEC_SZ = (1 << DEC_WD);
|
| 150 |
111 |
olivier.gi |
parameter [DEC_SZ-1:0] BASE_REG = {{DEC_SZ-1{1'b0}}, 1'b1};
|
| 151 |
|
|
|
| 152 |
80 |
olivier.gi |
// Register one-hot decoder
|
| 153 |
111 |
olivier.gi |
parameter [DEC_SZ-1:0] BCSCTL1_D = (BASE_REG << BCSCTL1),
|
| 154 |
|
|
BCSCTL2_D = (BASE_REG << BCSCTL2);
|
| 155 |
80 |
olivier.gi |
|
| 156 |
136 |
olivier.gi |
// Local wire declarations
|
| 157 |
|
|
wire nodiv_mclk;
|
| 158 |
|
|
wire nodiv_mclk_n;
|
| 159 |
|
|
wire nodiv_smclk;
|
| 160 |
80 |
olivier.gi |
|
| 161 |
136 |
olivier.gi |
|
| 162 |
80 |
olivier.gi |
//============================================================================
|
| 163 |
|
|
// 2) REGISTER DECODER
|
| 164 |
|
|
//============================================================================
|
| 165 |
|
|
|
| 166 |
111 |
olivier.gi |
// Local register selection
|
| 167 |
|
|
wire reg_sel = per_en & (per_addr[13:DEC_WD-1]==BASE_ADDR[14:DEC_WD]);
|
| 168 |
|
|
|
| 169 |
|
|
// Register local address
|
| 170 |
|
|
wire [DEC_WD-1:0] reg_addr = {1'b0, per_addr[DEC_WD-2:0]};
|
| 171 |
|
|
|
| 172 |
80 |
olivier.gi |
// Register address decode
|
| 173 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_dec = (BCSCTL1_D & {DEC_SZ{(reg_addr==(BCSCTL1 >>1))}}) |
|
| 174 |
|
|
(BCSCTL2_D & {DEC_SZ{(reg_addr==(BCSCTL2 >>1))}});
|
| 175 |
80 |
olivier.gi |
|
| 176 |
|
|
// Read/Write probes
|
| 177 |
111 |
olivier.gi |
wire reg_lo_write = per_we[0] & reg_sel;
|
| 178 |
|
|
wire reg_hi_write = per_we[1] & reg_sel;
|
| 179 |
|
|
wire reg_read = ~|per_we & reg_sel;
|
| 180 |
80 |
olivier.gi |
|
| 181 |
|
|
// Read/Write vectors
|
| 182 |
111 |
olivier.gi |
wire [DEC_SZ-1:0] reg_hi_wr = reg_dec & {DEC_SZ{reg_hi_write}};
|
| 183 |
|
|
wire [DEC_SZ-1:0] reg_lo_wr = reg_dec & {DEC_SZ{reg_lo_write}};
|
| 184 |
|
|
wire [DEC_SZ-1:0] reg_rd = reg_dec & {DEC_SZ{reg_read}};
|
| 185 |
80 |
olivier.gi |
|
| 186 |
|
|
|
| 187 |
|
|
//============================================================================
|
| 188 |
|
|
// 3) REGISTERS
|
| 189 |
|
|
//============================================================================
|
| 190 |
|
|
|
| 191 |
|
|
// BCSCTL1 Register
|
| 192 |
|
|
//--------------
|
| 193 |
|
|
reg [7:0] bcsctl1;
|
| 194 |
111 |
olivier.gi |
wire bcsctl1_wr = BCSCTL1[0] ? reg_hi_wr[BCSCTL1] : reg_lo_wr[BCSCTL1];
|
| 195 |
|
|
wire [7:0] bcsctl1_nxt = BCSCTL1[0] ? per_din[15:8] : per_din[7:0];
|
| 196 |
80 |
olivier.gi |
|
| 197 |
136 |
olivier.gi |
`ifdef ASIC
|
| 198 |
|
|
`ifdef ACLK_DIVIDER
|
| 199 |
|
|
wire [7:0] divax_mask = 8'h30;
|
| 200 |
|
|
`else
|
| 201 |
|
|
wire [7:0] divax_mask = 8'h00;
|
| 202 |
|
|
`endif
|
| 203 |
|
|
`else
|
| 204 |
|
|
wire [7:0] divax_mask = 8'h30;
|
| 205 |
|
|
`endif
|
| 206 |
|
|
|
| 207 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
| 208 |
|
|
if (puc_rst) bcsctl1 <= 8'h00;
|
| 209 |
136 |
olivier.gi |
else if (bcsctl1_wr) bcsctl1 <= bcsctl1_nxt & divax_mask; // Mask unused bits
|
| 210 |
80 |
olivier.gi |
|
| 211 |
|
|
|
| 212 |
|
|
// BCSCTL2 Register
|
| 213 |
|
|
//--------------
|
| 214 |
|
|
reg [7:0] bcsctl2;
|
| 215 |
136 |
olivier.gi |
wire bcsctl2_wr = BCSCTL2[0] ? reg_hi_wr[BCSCTL2] : reg_lo_wr[BCSCTL2];
|
| 216 |
|
|
wire [7:0] bcsctl2_nxt = BCSCTL2[0] ? per_din[15:8] : per_din[7:0];
|
| 217 |
80 |
olivier.gi |
|
| 218 |
136 |
olivier.gi |
`ifdef MCLK_MUX
|
| 219 |
|
|
wire [7:0] selmx_mask = 8'h80;
|
| 220 |
|
|
`else
|
| 221 |
|
|
wire [7:0] selmx_mask = 8'h00;
|
| 222 |
|
|
`endif
|
| 223 |
|
|
`ifdef MCLK_DIVIDER
|
| 224 |
|
|
wire [7:0] divmx_mask = 8'h30;
|
| 225 |
|
|
`else
|
| 226 |
|
|
wire [7:0] divmx_mask = 8'h00;
|
| 227 |
|
|
`endif
|
| 228 |
|
|
`ifdef ASIC
|
| 229 |
|
|
`ifdef SMCLK_MUX
|
| 230 |
|
|
wire [7:0] sels_mask = 8'h08;
|
| 231 |
|
|
`else
|
| 232 |
|
|
wire [7:0] sels_mask = 8'h00;
|
| 233 |
|
|
`endif
|
| 234 |
|
|
`ifdef SMCLK_DIVIDER
|
| 235 |
|
|
wire [7:0] divsx_mask = 8'h06;
|
| 236 |
|
|
`else
|
| 237 |
|
|
wire [7:0] divsx_mask = 8'h00;
|
| 238 |
|
|
`endif
|
| 239 |
|
|
`else
|
| 240 |
|
|
wire [7:0] sels_mask = 8'h08;
|
| 241 |
|
|
wire [7:0] divsx_mask = 8'h06;
|
| 242 |
|
|
`endif
|
| 243 |
|
|
|
| 244 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
| 245 |
|
|
if (puc_rst) bcsctl2 <= 8'h00;
|
| 246 |
136 |
olivier.gi |
else if (bcsctl2_wr) bcsctl2 <= bcsctl2_nxt & ( sels_mask | divsx_mask |
|
| 247 |
|
|
selmx_mask | divmx_mask); // Mask unused bits
|
| 248 |
80 |
olivier.gi |
|
| 249 |
|
|
|
| 250 |
|
|
//============================================================================
|
| 251 |
|
|
// 4) DATA OUTPUT GENERATION
|
| 252 |
|
|
//============================================================================
|
| 253 |
|
|
|
| 254 |
|
|
// Data output mux
|
| 255 |
111 |
olivier.gi |
wire [15:0] bcsctl1_rd = {8'h00, (bcsctl1 & {8{reg_rd[BCSCTL1]}})} << (8 & {4{BCSCTL1[0]}});
|
| 256 |
|
|
wire [15:0] bcsctl2_rd = {8'h00, (bcsctl2 & {8{reg_rd[BCSCTL2]}})} << (8 & {4{BCSCTL2[0]}});
|
| 257 |
80 |
olivier.gi |
|
| 258 |
|
|
wire [15:0] per_dout = bcsctl1_rd |
|
| 259 |
|
|
bcsctl2_rd;
|
| 260 |
|
|
|
| 261 |
|
|
|
| 262 |
|
|
//=============================================================================
|
| 263 |
136 |
olivier.gi |
// 5) DCO_CLK / LFXT_CLK INTERFACES (WAKEUP, ENABLE, ...)
|
| 264 |
80 |
olivier.gi |
//=============================================================================
|
| 265 |
|
|
|
| 266 |
136 |
olivier.gi |
`ifdef ASIC
|
| 267 |
|
|
wire cpuoff_and_mclk_enable;
|
| 268 |
|
|
omsp_and_gate and_cpuoff_mclk_en (.y(cpuoff_and_mclk_enable), .a(cpuoff), .b(mclk_enable));
|
| 269 |
|
|
`endif
|
| 270 |
|
|
|
| 271 |
|
|
//-----------------------------------------------------------
|
| 272 |
|
|
// 5.1) HIGH SPEED SYSTEM CLOCK GENERATOR (DCO_CLK)
|
| 273 |
|
|
//-----------------------------------------------------------
|
| 274 |
|
|
// Note1: switching off the DCO osillator is only
|
| 275 |
|
|
// supported in ASIC mode with SCG0 low power mode
|
| 276 |
|
|
//
|
| 277 |
|
|
// Note2: unlike the original MSP430 specification,
|
| 278 |
|
|
// we allow to switch off the DCO even
|
| 279 |
|
|
// if it is selected by MCLK or SMCLK.
|
| 280 |
|
|
|
| 281 |
|
|
wire por_a;
|
| 282 |
|
|
wire dco_wkup;
|
| 283 |
|
|
wire cpu_en_wkup;
|
| 284 |
|
|
|
| 285 |
|
|
`ifdef SCG0_EN
|
| 286 |
|
|
|
| 287 |
|
|
// The DCO oscillator is synchronously disabled if:
|
| 288 |
|
|
// - the cpu pin is disabled (in that case, wait for mclk_enable==0)
|
| 289 |
|
|
// - the debug interface is disabled
|
| 290 |
|
|
// - SCG0 is set (in that case, wait for the mclk_enable==0 if selected by SELMx)
|
| 291 |
|
|
//
|
| 292 |
|
|
// Note that we make extensive use of the AND gate module in order
|
| 293 |
|
|
// to prevent glitch propagation on the wakeup logic cone.
|
| 294 |
|
|
wire cpu_enabled_with_dco;
|
| 295 |
|
|
wire dco_not_enabled_by_dbg;
|
| 296 |
|
|
wire dco_disable_by_scg0;
|
| 297 |
|
|
wire dco_disable_by_cpu_en;
|
| 298 |
|
|
wire dco_enable_nxt;
|
| 299 |
|
|
omsp_and_gate and_dco_dis1 (.y(cpu_enabled_with_dco), .a(~bcsctl2[`SELMx]), .b(cpuoff_and_mclk_enable));
|
| 300 |
|
|
omsp_and_gate and_dco_dis2 (.y(dco_not_enabled_by_dbg), .a(~dbg_en_s), .b(~cpu_enabled_with_dco));
|
| 301 |
|
|
omsp_and_gate and_dco_dis3 (.y(dco_disable_by_scg0), .a(scg0), .b(dco_not_enabled_by_dbg));
|
| 302 |
|
|
omsp_and_gate and_dco_dis4 (.y(dco_disable_by_cpu_en), .a(~cpu_en_s), .b(~mclk_enable));
|
| 303 |
|
|
omsp_and_gate and_dco_dis5 (.y(dco_enable_nxt), .a(~dco_disable_by_scg0), .b(~dco_disable_by_cpu_en));
|
| 304 |
|
|
|
| 305 |
|
|
// Register to prevent glitch propagation
|
| 306 |
|
|
reg dco_disable;
|
| 307 |
|
|
always @(posedge nodiv_mclk_n or posedge por)
|
| 308 |
|
|
if (por) dco_disable <= 1'b1;
|
| 309 |
|
|
else dco_disable <= ~dco_enable_nxt;
|
| 310 |
|
|
|
| 311 |
|
|
// Note that a synchronizer is required if the MCLK mux is included
|
| 312 |
|
|
wire dco_clk_n = ~dco_clk;
|
| 313 |
|
|
`ifdef MCLK_MUX
|
| 314 |
|
|
omsp_sync_cell sync_cell_dco_disable (
|
| 315 |
|
|
.data_out (dco_enable),
|
| 316 |
|
|
.data_in (~dco_disable),
|
| 317 |
|
|
.clk (dco_clk_n),
|
| 318 |
|
|
.rst (por)
|
| 319 |
|
|
);
|
| 320 |
|
|
`else
|
| 321 |
|
|
|
| 322 |
|
|
assign dco_enable = ~dco_disable;
|
| 323 |
|
|
`endif
|
| 324 |
|
|
|
| 325 |
|
|
// The DCO oscillator will get an asynchronous wakeup if:
|
| 326 |
|
|
// - the MCLK generates a wakeup (only if the MCLK mux selects dco_clk)
|
| 327 |
|
|
// - if the DCO wants to be synchronously enabled (i.e dco_enable_nxt=1)
|
| 328 |
|
|
wire dco_mclk_wkup;
|
| 329 |
|
|
wire dco_en_wkup;
|
| 330 |
|
|
omsp_and_gate and_dco_mclk_wkup (.y(dco_mclk_wkup), .a(mclk_wkup), .b(~bcsctl2[`SELMx]));
|
| 331 |
|
|
omsp_and_gate and_dco_en_wkup (.y(dco_en_wkup), .a(~dco_enable), .b(dco_enable_nxt));
|
| 332 |
|
|
|
| 333 |
|
|
wire dco_wkup_set = dco_mclk_wkup | dco_en_wkup | cpu_en_wkup;
|
| 334 |
|
|
|
| 335 |
|
|
// Scan MUX for the asynchronous SET
|
| 336 |
|
|
wire dco_wkup_set_scan;
|
| 337 |
|
|
omsp_scan_mux scan_mux_dco_wkup (
|
| 338 |
|
|
.scan_mode (scan_mode),
|
| 339 |
|
|
.data_in_scan (por_a),
|
| 340 |
|
|
.data_in_func (dco_wkup_set | por),
|
| 341 |
|
|
.data_out (dco_wkup_set_scan)
|
| 342 |
|
|
);
|
| 343 |
|
|
|
| 344 |
|
|
// Scan MUX to increase coverage
|
| 345 |
|
|
wire dco_wkup_clear;
|
| 346 |
|
|
omsp_scan_mux scan_mux_dco_wkup_clear (
|
| 347 |
|
|
.scan_mode (scan_mode),
|
| 348 |
|
|
.data_in_scan (dco_wkup_set),
|
| 349 |
|
|
.data_in_func (1'b1),
|
| 350 |
|
|
.data_out (dco_wkup_clear)
|
| 351 |
|
|
);
|
| 352 |
|
|
|
| 353 |
|
|
// The wakeup is asynchronously set, synchronously released
|
| 354 |
|
|
wire dco_wkup_n;
|
| 355 |
|
|
omsp_sync_cell sync_cell_dco_wkup (
|
| 356 |
|
|
.data_out (dco_wkup_n),
|
| 357 |
|
|
.data_in (dco_wkup_clear),
|
| 358 |
|
|
.clk (dco_clk_n),
|
| 359 |
|
|
.rst (dco_wkup_set_scan)
|
| 360 |
|
|
);
|
| 361 |
|
|
|
| 362 |
|
|
omsp_and_gate and_dco_wkup (.y(dco_wkup), .a(~dco_wkup_n), .b(cpu_en));
|
| 363 |
|
|
|
| 364 |
111 |
olivier.gi |
`else
|
| 365 |
136 |
olivier.gi |
assign dco_enable = 1'b1;
|
| 366 |
|
|
assign dco_wkup = 1'b1;
|
| 367 |
111 |
olivier.gi |
`endif
|
| 368 |
107 |
olivier.gi |
|
| 369 |
136 |
olivier.gi |
|
| 370 |
|
|
//-----------------------------------------------------------
|
| 371 |
|
|
// 5.2) LOW FREQUENCY CRYSTAL CLOCK GENERATOR (LFXT_CLK)
|
| 372 |
|
|
//-----------------------------------------------------------
|
| 373 |
|
|
|
| 374 |
|
|
// ASIC MODE
|
| 375 |
|
|
//------------------------------------------------
|
| 376 |
|
|
// Note: unlike the original MSP430 specification,
|
| 377 |
|
|
// we allow to switch off the LFXT even
|
| 378 |
|
|
// if it is selected by MCLK or SMCLK.
|
| 379 |
|
|
`ifdef ASIC
|
| 380 |
|
|
|
| 381 |
|
|
`ifdef OSCOFF_EN
|
| 382 |
|
|
|
| 383 |
|
|
// The LFXT is synchronously disabled if:
|
| 384 |
|
|
// - the cpu pin is disabled (in that case, wait for mclk_enable==0)
|
| 385 |
|
|
// - the debug interface is disabled
|
| 386 |
|
|
// - OSCOFF is set (in that case, wait for the mclk_enable==0 if selected by SELMx)
|
| 387 |
|
|
wire cpu_enabled_with_lfxt;
|
| 388 |
|
|
wire lfxt_not_enabled_by_dbg;
|
| 389 |
|
|
wire lfxt_disable_by_oscoff;
|
| 390 |
|
|
wire lfxt_disable_by_cpu_en;
|
| 391 |
|
|
wire lfxt_enable_nxt;
|
| 392 |
|
|
omsp_and_gate and_lfxt_dis1 (.y(cpu_enabled_with_lfxt), .a(bcsctl2[`SELMx]), .b(cpuoff_and_mclk_enable));
|
| 393 |
|
|
omsp_and_gate and_lfxt_dis2 (.y(lfxt_not_enabled_by_dbg), .a(~dbg_en_s), .b(~cpu_enabled_with_lfxt));
|
| 394 |
|
|
omsp_and_gate and_lfxt_dis3 (.y(lfxt_disable_by_oscoff), .a(oscoff), .b(lfxt_not_enabled_by_dbg));
|
| 395 |
|
|
omsp_and_gate and_lfxt_dis4 (.y(lfxt_disable_by_cpu_en), .a(~cpu_en_s), .b(~mclk_enable));
|
| 396 |
|
|
omsp_and_gate and_lfxt_dis5 (.y(lfxt_enable_nxt), .a(~lfxt_disable_by_oscoff), .b(~lfxt_disable_by_cpu_en));
|
| 397 |
|
|
|
| 398 |
|
|
// Register to prevent glitch propagation
|
| 399 |
|
|
reg lfxt_disable;
|
| 400 |
|
|
always @(posedge nodiv_mclk_n or posedge por)
|
| 401 |
|
|
if (por) lfxt_disable <= 1'b1;
|
| 402 |
|
|
else lfxt_disable <= ~lfxt_enable_nxt;
|
| 403 |
|
|
|
| 404 |
|
|
// Synchronize the OSCOFF control signal to the LFXT clock domain
|
| 405 |
|
|
wire lfxt_clk_n = ~lfxt_clk;
|
| 406 |
|
|
omsp_sync_cell sync_cell_lfxt_disable (
|
| 407 |
|
|
.data_out (lfxt_enable),
|
| 408 |
|
|
.data_in (~lfxt_disable),
|
| 409 |
|
|
.clk (lfxt_clk_n),
|
| 410 |
|
|
.rst (por)
|
| 411 |
|
|
);
|
| 412 |
|
|
|
| 413 |
|
|
// The LFXT will get an asynchronous wakeup if:
|
| 414 |
|
|
// - the MCLK generates a wakeup (only if the MCLK mux selects lfxt_clk)
|
| 415 |
|
|
// - if the LFXT wants to be synchronously enabled (i.e lfxt_enable_nxt=1)
|
| 416 |
|
|
wire lfxt_mclk_wkup;
|
| 417 |
|
|
wire lfxt_en_wkup;
|
| 418 |
|
|
omsp_and_gate and_lfxt_mclk_wkup (.y(lfxt_mclk_wkup), .a(mclk_wkup), .b(bcsctl2[`SELMx]));
|
| 419 |
|
|
omsp_and_gate and_lfxt_en_wkup (.y(lfxt_en_wkup), .a(~lfxt_enable), .b(lfxt_enable_nxt));
|
| 420 |
|
|
|
| 421 |
|
|
wire lfxt_wkup_set = lfxt_mclk_wkup | lfxt_en_wkup | cpu_en_wkup;
|
| 422 |
|
|
|
| 423 |
|
|
// Scan MUX for the asynchronous SET
|
| 424 |
|
|
wire lfxt_wkup_set_scan;
|
| 425 |
|
|
omsp_scan_mux scan_mux_lfxt_wkup (
|
| 426 |
|
|
.scan_mode (scan_mode),
|
| 427 |
|
|
.data_in_scan (por_a),
|
| 428 |
|
|
.data_in_func (lfxt_wkup_set | por),
|
| 429 |
|
|
.data_out (lfxt_wkup_set_scan)
|
| 430 |
|
|
);
|
| 431 |
|
|
|
| 432 |
|
|
// Scan MUX to increase coverage
|
| 433 |
|
|
wire lfxt_wkup_clear;
|
| 434 |
|
|
omsp_scan_mux scan_mux_lfxt_wkup_clear (
|
| 435 |
|
|
.scan_mode (scan_mode),
|
| 436 |
|
|
.data_in_scan (lfxt_wkup_set),
|
| 437 |
|
|
.data_in_func (1'b1),
|
| 438 |
|
|
.data_out (lfxt_wkup_clear)
|
| 439 |
|
|
);
|
| 440 |
|
|
|
| 441 |
|
|
// The wakeup is asynchronously set, synchronously released
|
| 442 |
|
|
wire lfxt_wkup_n;
|
| 443 |
|
|
omsp_sync_cell sync_cell_lfxt_wkup (
|
| 444 |
|
|
.data_out (lfxt_wkup_n),
|
| 445 |
|
|
.data_in (lfxt_wkup_clear),
|
| 446 |
|
|
.clk (lfxt_clk_n),
|
| 447 |
|
|
.rst (lfxt_wkup_set_scan)
|
| 448 |
|
|
);
|
| 449 |
|
|
|
| 450 |
|
|
omsp_and_gate and_lfxt_wkup (.y(lfxt_wkup), .a(~lfxt_wkup_n), .b(cpu_en));
|
| 451 |
|
|
|
| 452 |
|
|
`else
|
| 453 |
|
|
assign lfxt_enable = 1'b1;
|
| 454 |
|
|
assign lfxt_wkup = 1'b0;
|
| 455 |
|
|
`endif
|
| 456 |
|
|
|
| 457 |
|
|
|
| 458 |
|
|
// FPGA MODE
|
| 459 |
|
|
//---------------------------------------
|
| 460 |
80 |
olivier.gi |
// Synchronize LFXT_CLK & edge detection
|
| 461 |
136 |
olivier.gi |
`else
|
| 462 |
|
|
|
| 463 |
111 |
olivier.gi |
wire lfxt_clk_s;
|
| 464 |
|
|
|
| 465 |
|
|
omsp_sync_cell sync_cell_lfxt_clk (
|
| 466 |
136 |
olivier.gi |
.data_out (lfxt_clk_s),
|
| 467 |
|
|
.data_in (lfxt_clk),
|
| 468 |
|
|
.clk (mclk),
|
| 469 |
|
|
.rst (por)
|
| 470 |
111 |
olivier.gi |
);
|
| 471 |
|
|
|
| 472 |
|
|
reg lfxt_clk_dly;
|
| 473 |
80 |
olivier.gi |
|
| 474 |
107 |
olivier.gi |
always @ (posedge mclk or posedge por)
|
| 475 |
111 |
olivier.gi |
if (por) lfxt_clk_dly <= 1'b0;
|
| 476 |
|
|
else lfxt_clk_dly <= lfxt_clk_s;
|
| 477 |
80 |
olivier.gi |
|
| 478 |
136 |
olivier.gi |
wire lfxt_clk_en = (lfxt_clk_s & ~lfxt_clk_dly) & ~(oscoff & ~bcsctl2[`SELS]);
|
| 479 |
|
|
assign lfxt_enable = 1'b1;
|
| 480 |
|
|
assign lfxt_wkup = 1'b0;
|
| 481 |
|
|
`endif
|
| 482 |
|
|
|
| 483 |
80 |
olivier.gi |
|
| 484 |
136 |
olivier.gi |
//=============================================================================
|
| 485 |
|
|
// 6) CLOCK GENERATION
|
| 486 |
|
|
//=============================================================================
|
| 487 |
|
|
|
| 488 |
|
|
//-----------------------------------------------------------
|
| 489 |
|
|
// 6.1) GLOBAL CPU ENABLE
|
| 490 |
|
|
//-----------------------------------------------------------
|
| 491 |
|
|
// ACLK and SMCLK are directly switched-off
|
| 492 |
|
|
// with the cpu_en pin (after synchronization).
|
| 493 |
|
|
// MCLK will be switched off once the CPU reaches
|
| 494 |
|
|
// its IDLE state (through the mclk_enable signal)
|
| 495 |
|
|
|
| 496 |
|
|
|
| 497 |
|
|
// Synchronize CPU_EN signal to the MCLK domain
|
| 498 |
|
|
//----------------------------------------------
|
| 499 |
|
|
`ifdef SYNC_CPU_EN
|
| 500 |
|
|
omsp_sync_cell sync_cell_cpu_en (
|
| 501 |
|
|
.data_out (cpu_en_s),
|
| 502 |
|
|
.data_in (cpu_en),
|
| 503 |
|
|
.clk (nodiv_mclk),
|
| 504 |
|
|
.rst (por)
|
| 505 |
|
|
);
|
| 506 |
|
|
omsp_and_gate and_cpu_en_wkup (.y(cpu_en_wkup), .a(cpu_en), .b(~cpu_en_s));
|
| 507 |
|
|
`else
|
| 508 |
|
|
assign cpu_en_s = cpu_en;
|
| 509 |
|
|
assign cpu_en_wkup = 1'b0;
|
| 510 |
|
|
`endif
|
| 511 |
|
|
|
| 512 |
|
|
// Synchronize CPU_EN signal to the ACLK domain
|
| 513 |
|
|
//----------------------------------------------
|
| 514 |
|
|
`ifdef LFXT_DOMAIN
|
| 515 |
|
|
wire cpu_en_aux_s;
|
| 516 |
|
|
omsp_sync_cell sync_cell_cpu_aux_en (
|
| 517 |
|
|
.data_out (cpu_en_aux_s),
|
| 518 |
|
|
.data_in (cpu_en),
|
| 519 |
|
|
.clk (lfxt_clk),
|
| 520 |
|
|
.rst (por)
|
| 521 |
|
|
);
|
| 522 |
|
|
`else
|
| 523 |
|
|
wire cpu_en_aux_s = cpu_en_s;
|
| 524 |
|
|
`endif
|
| 525 |
|
|
|
| 526 |
|
|
// Synchronize CPU_EN signal to the SMCLK domain
|
| 527 |
|
|
//----------------------------------------------
|
| 528 |
|
|
// Note: the synchronizer is only required if there is a SMCLK_MUX
|
| 529 |
|
|
`ifdef ASIC
|
| 530 |
|
|
`ifdef SMCLK_MUX
|
| 531 |
|
|
wire cpu_en_sm_s;
|
| 532 |
|
|
omsp_sync_cell sync_cell_cpu_sm_en (
|
| 533 |
|
|
.data_out (cpu_en_sm_s),
|
| 534 |
|
|
.data_in (cpu_en),
|
| 535 |
|
|
.clk (nodiv_smclk),
|
| 536 |
|
|
.rst (por)
|
| 537 |
|
|
);
|
| 538 |
|
|
`else
|
| 539 |
|
|
wire cpu_en_sm_s = cpu_en_s;
|
| 540 |
|
|
`endif
|
| 541 |
|
|
`endif
|
| 542 |
|
|
|
| 543 |
|
|
|
| 544 |
|
|
//-----------------------------------------------------------
|
| 545 |
|
|
// 6.2) MCLK GENERATION
|
| 546 |
|
|
//-----------------------------------------------------------
|
| 547 |
|
|
|
| 548 |
|
|
// Clock MUX
|
| 549 |
|
|
//----------------------------
|
| 550 |
|
|
`ifdef MCLK_MUX
|
| 551 |
|
|
omsp_clock_mux clock_mux_mclk (
|
| 552 |
|
|
.clk_out (nodiv_mclk),
|
| 553 |
|
|
.clk_in0 (dco_clk),
|
| 554 |
|
|
.clk_in1 (lfxt_clk),
|
| 555 |
|
|
.reset (por),
|
| 556 |
|
|
.scan_mode (scan_mode),
|
| 557 |
|
|
.select (bcsctl2[`SELMx])
|
| 558 |
|
|
);
|
| 559 |
|
|
`else
|
| 560 |
|
|
assign nodiv_mclk = dco_clk;
|
| 561 |
|
|
`endif
|
| 562 |
|
|
assign nodiv_mclk_n = ~nodiv_mclk;
|
| 563 |
|
|
|
| 564 |
|
|
|
| 565 |
|
|
// Wakeup synchronizer
|
| 566 |
|
|
//----------------------------
|
| 567 |
|
|
wire mclk_wkup_s;
|
| 568 |
|
|
|
| 569 |
|
|
`ifdef CPUOFF_EN
|
| 570 |
|
|
omsp_sync_cell sync_cell_mclk_wkup (
|
| 571 |
|
|
.data_out (mclk_wkup_s),
|
| 572 |
|
|
.data_in (mclk_wkup),
|
| 573 |
|
|
.clk (nodiv_mclk),
|
| 574 |
|
|
.rst (puc_rst)
|
| 575 |
|
|
);
|
| 576 |
|
|
`else
|
| 577 |
|
|
assign mclk_wkup_s = 1'b0;
|
| 578 |
|
|
`endif
|
| 579 |
|
|
|
| 580 |
|
|
|
| 581 |
|
|
// Clock Divider
|
| 582 |
|
|
//----------------------------
|
| 583 |
|
|
// No need for extra synchronizer as bcsctl2
|
| 584 |
|
|
// comes from the same clock domain.
|
| 585 |
|
|
|
| 586 |
|
|
`ifdef CPUOFF_EN
|
| 587 |
|
|
wire mclk_active = mclk_enable | mclk_wkup_s | (dbg_en_s & cpu_en_s);
|
| 588 |
|
|
`else
|
| 589 |
|
|
wire mclk_active = 1'b1;
|
| 590 |
|
|
`endif
|
| 591 |
|
|
|
| 592 |
|
|
`ifdef MCLK_DIVIDER
|
| 593 |
|
|
reg [2:0] mclk_div;
|
| 594 |
|
|
always @ (posedge nodiv_mclk or posedge puc_rst)
|
| 595 |
|
|
if (puc_rst) mclk_div <= 3'h0;
|
| 596 |
|
|
else if ((bcsctl2[`DIVMx]!=2'b00)) mclk_div <= mclk_div+3'h1;
|
| 597 |
|
|
|
| 598 |
|
|
wire mclk_div_en = mclk_active & ((bcsctl2[`DIVMx]==2'b00) ? 1'b1 :
|
| 599 |
|
|
(bcsctl2[`DIVMx]==2'b01) ? mclk_div[0] :
|
| 600 |
|
|
(bcsctl2[`DIVMx]==2'b10) ? &mclk_div[1:0] :
|
| 601 |
|
|
&mclk_div[2:0]);
|
| 602 |
|
|
`else
|
| 603 |
|
|
wire mclk_div_en = mclk_active;
|
| 604 |
|
|
`endif
|
| 605 |
|
|
|
| 606 |
|
|
|
| 607 |
80 |
olivier.gi |
// Generate main system clock
|
| 608 |
|
|
//----------------------------
|
| 609 |
136 |
olivier.gi |
`ifdef MCLK_CGATE
|
| 610 |
80 |
olivier.gi |
|
| 611 |
136 |
olivier.gi |
omsp_clock_gate clock_gate_mclk (
|
| 612 |
|
|
.gclk (mclk),
|
| 613 |
|
|
.clk (nodiv_mclk),
|
| 614 |
|
|
.enable (mclk_div_en),
|
| 615 |
|
|
.scan_enable (scan_enable)
|
| 616 |
|
|
);
|
| 617 |
|
|
`else
|
| 618 |
|
|
assign mclk = nodiv_mclk;
|
| 619 |
|
|
`endif
|
| 620 |
80 |
olivier.gi |
|
| 621 |
|
|
|
| 622 |
136 |
olivier.gi |
//-----------------------------------------------------------
|
| 623 |
|
|
// 6.3) ACLK GENERATION
|
| 624 |
|
|
//-----------------------------------------------------------
|
| 625 |
|
|
|
| 626 |
|
|
// ASIC MODE
|
| 627 |
80 |
olivier.gi |
//----------------------------
|
| 628 |
136 |
olivier.gi |
`ifdef ASIC
|
| 629 |
80 |
olivier.gi |
|
| 630 |
136 |
olivier.gi |
`ifdef ACLK_DIVIDER
|
| 631 |
|
|
`ifdef LFXT_DOMAIN
|
| 632 |
80 |
olivier.gi |
|
| 633 |
136 |
olivier.gi |
wire nodiv_aclk = lfxt_clk;
|
| 634 |
85 |
olivier.gi |
|
| 635 |
136 |
olivier.gi |
// Local Reset synchronizer
|
| 636 |
|
|
wire puc_lfxt_rst;
|
| 637 |
|
|
wire puc_lfxt_noscan_n;
|
| 638 |
|
|
omsp_sync_cell sync_cell_puc_lfxt (
|
| 639 |
|
|
.data_out (puc_lfxt_noscan_n),
|
| 640 |
|
|
.data_in (1'b1),
|
| 641 |
|
|
.clk (nodiv_aclk),
|
| 642 |
|
|
.rst (puc_rst)
|
| 643 |
|
|
);
|
| 644 |
|
|
omsp_scan_mux scan_mux_puc_lfxt (
|
| 645 |
|
|
.scan_mode (scan_mode),
|
| 646 |
|
|
.data_in_scan (por_a),
|
| 647 |
|
|
.data_in_func (~puc_lfxt_noscan_n),
|
| 648 |
|
|
.data_out (puc_lfxt_rst)
|
| 649 |
|
|
);
|
| 650 |
85 |
olivier.gi |
|
| 651 |
136 |
olivier.gi |
// Local synchronizer for the bcsctl1.DIVAx configuration
|
| 652 |
|
|
// (note that we can live with a full bus synchronizer as
|
| 653 |
|
|
// it won't hurt if we get a wrong DIVAx value for a single clock cycle)
|
| 654 |
|
|
reg [1:0] divax_s;
|
| 655 |
|
|
reg [1:0] divax_ss;
|
| 656 |
|
|
always @ (posedge nodiv_aclk or posedge puc_lfxt_rst)
|
| 657 |
|
|
if (puc_lfxt_rst)
|
| 658 |
|
|
begin
|
| 659 |
|
|
divax_s <= 2'h0;
|
| 660 |
|
|
divax_ss <= 2'h0;
|
| 661 |
|
|
end
|
| 662 |
|
|
else
|
| 663 |
|
|
begin
|
| 664 |
|
|
divax_s <= bcsctl1[`DIVAx];
|
| 665 |
|
|
divax_ss <= divax_s;
|
| 666 |
|
|
end
|
| 667 |
80 |
olivier.gi |
|
| 668 |
136 |
olivier.gi |
// If the OSCOFF mode is enabled synchronize OSCOFF signal
|
| 669 |
|
|
wire oscoff_s;
|
| 670 |
|
|
`ifdef OSCOFF_EN
|
| 671 |
|
|
omsp_sync_cell sync_cell_oscoff (
|
| 672 |
|
|
.data_out (oscoff_s),
|
| 673 |
|
|
.data_in (oscoff),
|
| 674 |
|
|
.clk (nodiv_aclk),
|
| 675 |
|
|
.rst (puc_lfxt_rst)
|
| 676 |
|
|
);
|
| 677 |
|
|
`else
|
| 678 |
|
|
assign oscoff_s = 1'b0;
|
| 679 |
|
|
`endif
|
| 680 |
|
|
`else
|
| 681 |
|
|
wire puc_lfxt_rst = puc_rst;
|
| 682 |
|
|
wire nodiv_aclk = dco_clk;
|
| 683 |
|
|
wire [1:0] divax_ss = bcsctl1[`DIVAx];
|
| 684 |
|
|
wire oscoff_s = oscoff;
|
| 685 |
|
|
`endif
|
| 686 |
85 |
olivier.gi |
|
| 687 |
136 |
olivier.gi |
// Divider
|
| 688 |
|
|
reg [2:0] aclk_div;
|
| 689 |
|
|
always @ (posedge nodiv_aclk or posedge puc_lfxt_rst)
|
| 690 |
|
|
if (puc_lfxt_rst) aclk_div <= 3'h0;
|
| 691 |
|
|
else if ((divax_ss!=2'b00)) aclk_div <= aclk_div+3'h1;
|
| 692 |
|
|
|
| 693 |
|
|
wire aclk_div_en = cpu_en_aux_s & ~oscoff_s & ((divax_ss==2'b00) ? 1'b1 :
|
| 694 |
|
|
(divax_ss==2'b01) ? aclk_div[0] :
|
| 695 |
|
|
(divax_ss==2'b10) ? &aclk_div[1:0] :
|
| 696 |
|
|
&aclk_div[2:0]);
|
| 697 |
|
|
|
| 698 |
|
|
// Clock gate
|
| 699 |
|
|
omsp_clock_gate clock_gate_aclk (
|
| 700 |
|
|
.gclk (aclk),
|
| 701 |
|
|
.clk (nodiv_aclk),
|
| 702 |
|
|
.enable (aclk_div_en),
|
| 703 |
|
|
.scan_enable (scan_enable)
|
| 704 |
|
|
);
|
| 705 |
|
|
|
| 706 |
|
|
`else
|
| 707 |
|
|
`ifdef LFXT_DOMAIN
|
| 708 |
|
|
assign aclk = lfxt_clk;
|
| 709 |
|
|
`else
|
| 710 |
|
|
assign aclk = dco_clk;
|
| 711 |
|
|
`endif
|
| 712 |
|
|
`endif
|
| 713 |
|
|
|
| 714 |
|
|
|
| 715 |
|
|
assign aclk_en = 1'b1;
|
| 716 |
|
|
|
| 717 |
|
|
|
| 718 |
|
|
// FPGA MODE
|
| 719 |
80 |
olivier.gi |
//----------------------------
|
| 720 |
136 |
olivier.gi |
`else
|
| 721 |
|
|
reg aclk_en;
|
| 722 |
|
|
reg [2:0] aclk_div;
|
| 723 |
|
|
wire aclk_en_nxt = lfxt_clk_en & ((bcsctl1[`DIVAx]==2'b00) ? 1'b1 :
|
| 724 |
|
|
(bcsctl1[`DIVAx]==2'b01) ? aclk_div[0] :
|
| 725 |
|
|
(bcsctl1[`DIVAx]==2'b10) ? &aclk_div[1:0] :
|
| 726 |
|
|
&aclk_div[2:0]);
|
| 727 |
80 |
olivier.gi |
|
| 728 |
136 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
| 729 |
|
|
if (puc_rst) aclk_div <= 3'h0;
|
| 730 |
|
|
else if ((bcsctl1[`DIVAx]!=2'b00) & lfxt_clk_en) aclk_div <= aclk_div+3'h1;
|
| 731 |
|
|
|
| 732 |
|
|
always @ (posedge mclk or posedge puc_rst)
|
| 733 |
|
|
if (puc_rst) aclk_en <= 1'b0;
|
| 734 |
|
|
else aclk_en <= aclk_en_nxt & cpu_en_s;
|
| 735 |
|
|
|
| 736 |
|
|
assign aclk = mclk;
|
| 737 |
|
|
`endif
|
| 738 |
|
|
|
| 739 |
|
|
//-----------------------------------------------------------
|
| 740 |
|
|
// 6.4) SMCLK GENERATION
|
| 741 |
|
|
//-----------------------------------------------------------
|
| 742 |
|
|
|
| 743 |
|
|
// Clock MUX
|
| 744 |
|
|
//----------------------------
|
| 745 |
|
|
`ifdef SMCLK_MUX
|
| 746 |
|
|
omsp_clock_mux clock_mux_smclk (
|
| 747 |
|
|
.clk_out (nodiv_smclk),
|
| 748 |
|
|
.clk_in0 (dco_clk),
|
| 749 |
|
|
.clk_in1 (lfxt_clk),
|
| 750 |
|
|
.reset (por),
|
| 751 |
|
|
.scan_mode (scan_mode),
|
| 752 |
|
|
.select (bcsctl2[`SELS])
|
| 753 |
|
|
);
|
| 754 |
|
|
`else
|
| 755 |
|
|
assign nodiv_smclk = dco_clk;
|
| 756 |
|
|
`endif
|
| 757 |
|
|
|
| 758 |
|
|
|
| 759 |
|
|
// ASIC MODE
|
| 760 |
|
|
//----------------------------
|
| 761 |
|
|
`ifdef ASIC
|
| 762 |
|
|
`ifdef SMCLK_MUX
|
| 763 |
|
|
|
| 764 |
|
|
// Synchronizers
|
| 765 |
|
|
//------------------------------------------------------
|
| 766 |
|
|
// When the SMCLK MUX is enabled, the reset and DIVSx
|
| 767 |
|
|
// and SCG1 signals must be synchronized, otherwise not.
|
| 768 |
|
|
|
| 769 |
|
|
// Local Reset synchronizer
|
| 770 |
|
|
wire puc_sm_noscan_n;
|
| 771 |
|
|
wire puc_sm_rst;
|
| 772 |
|
|
omsp_sync_cell sync_cell_puc_sm (
|
| 773 |
|
|
.data_out (puc_sm_noscan_n),
|
| 774 |
|
|
.data_in (1'b1),
|
| 775 |
|
|
.clk (nodiv_smclk),
|
| 776 |
|
|
.rst (puc_rst)
|
| 777 |
|
|
);
|
| 778 |
|
|
omsp_scan_mux scan_mux_puc_sm (
|
| 779 |
|
|
.scan_mode (scan_mode),
|
| 780 |
|
|
.data_in_scan (por_a),
|
| 781 |
|
|
.data_in_func (~puc_sm_noscan_n),
|
| 782 |
|
|
.data_out (puc_sm_rst)
|
| 783 |
|
|
);
|
| 784 |
|
|
|
| 785 |
|
|
// SCG1 synchronizer
|
| 786 |
|
|
`ifdef SCG1_EN
|
| 787 |
|
|
wire scg1_s;
|
| 788 |
|
|
omsp_sync_cell sync_cell_scg1 (
|
| 789 |
|
|
.data_out (scg1_s),
|
| 790 |
|
|
.data_in (scg1),
|
| 791 |
|
|
.clk (nodiv_smclk),
|
| 792 |
|
|
.rst (puc_sm_rst)
|
| 793 |
|
|
);
|
| 794 |
|
|
`else
|
| 795 |
|
|
wire scg1_s = 1'b0;
|
| 796 |
|
|
`endif
|
| 797 |
|
|
|
| 798 |
|
|
`ifdef SMCLK_DIVIDER
|
| 799 |
|
|
// Local synchronizer for the bcsctl2.DIVSx configuration
|
| 800 |
|
|
// (note that we can live with a full bus synchronizer as
|
| 801 |
|
|
// it won't hurt if we get a wrong DIVSx value for a single clock cycle)
|
| 802 |
|
|
reg [1:0] divsx_s;
|
| 803 |
|
|
reg [1:0] divsx_ss;
|
| 804 |
|
|
always @ (posedge nodiv_smclk or posedge puc_sm_rst)
|
| 805 |
|
|
if (puc_sm_rst)
|
| 806 |
|
|
begin
|
| 807 |
|
|
divsx_s <= 2'h0;
|
| 808 |
|
|
divsx_ss <= 2'h0;
|
| 809 |
|
|
end
|
| 810 |
|
|
else
|
| 811 |
|
|
begin
|
| 812 |
|
|
divsx_s <= bcsctl2[`DIVSx];
|
| 813 |
|
|
divsx_ss <= divsx_s;
|
| 814 |
|
|
end
|
| 815 |
|
|
`endif
|
| 816 |
|
|
|
| 817 |
|
|
`else
|
| 818 |
|
|
|
| 819 |
|
|
wire puc_sm_rst = puc_rst;
|
| 820 |
|
|
wire [1:0] divsx_ss = bcsctl2[`DIVSx];
|
| 821 |
|
|
wire scg1_s = scg1;
|
| 822 |
|
|
`endif
|
| 823 |
|
|
|
| 824 |
|
|
|
| 825 |
|
|
|
| 826 |
|
|
// Clock Divider
|
| 827 |
|
|
//----------------------------
|
| 828 |
|
|
`ifdef SMCLK_DIVIDER
|
| 829 |
|
|
|
| 830 |
|
|
reg [2:0] smclk_div;
|
| 831 |
|
|
always @ (posedge nodiv_smclk or posedge puc_sm_rst)
|
| 832 |
|
|
if (puc_sm_rst) smclk_div <= 3'h0;
|
| 833 |
|
|
else if ((divsx_ss!=2'b00)) smclk_div <= smclk_div+3'h1;
|
| 834 |
|
|
|
| 835 |
|
|
wire smclk_div_en = cpu_en_sm_s & ~scg1_s & ((divsx_ss==2'b00) ? 1'b1 :
|
| 836 |
|
|
(divsx_ss==2'b01) ? smclk_div[0] :
|
| 837 |
|
|
(divsx_ss==2'b10) ? &smclk_div[1:0] :
|
| 838 |
|
|
&smclk_div[2:0]);
|
| 839 |
|
|
`else
|
| 840 |
|
|
`ifdef SCG1_EN
|
| 841 |
|
|
wire smclk_div_en = cpu_en_sm_s & ~scg1_s;
|
| 842 |
|
|
`else
|
| 843 |
|
|
wire smclk_div_en = cpu_en_sm_s;
|
| 844 |
|
|
`endif
|
| 845 |
|
|
`endif
|
| 846 |
|
|
|
| 847 |
|
|
|
| 848 |
|
|
// Generate sub-system clock
|
| 849 |
|
|
//----------------------------
|
| 850 |
|
|
`ifdef SMCLK_CGATE
|
| 851 |
|
|
omsp_clock_gate clock_gate_smclk (
|
| 852 |
|
|
.gclk (smclk),
|
| 853 |
|
|
.clk (nodiv_smclk),
|
| 854 |
|
|
.enable (smclk_div_en),
|
| 855 |
|
|
.scan_enable (scan_enable)
|
| 856 |
|
|
);
|
| 857 |
|
|
`else
|
| 858 |
|
|
assign smclk = nodiv_smclk;
|
| 859 |
|
|
`endif
|
| 860 |
|
|
|
| 861 |
|
|
assign smclk_en = 1'b1;
|
| 862 |
|
|
|
| 863 |
|
|
|
| 864 |
|
|
// FPGA MODE
|
| 865 |
|
|
//----------------------------
|
| 866 |
|
|
`else
|
| 867 |
85 |
olivier.gi |
reg smclk_en;
|
| 868 |
80 |
olivier.gi |
reg [2:0] smclk_div;
|
| 869 |
|
|
|
| 870 |
85 |
olivier.gi |
wire smclk_in = ~scg1 & (bcsctl2[`SELS] ? lfxt_clk_en : 1'b1);
|
| 871 |
80 |
olivier.gi |
|
| 872 |
85 |
olivier.gi |
wire smclk_en_nxt = smclk_in & ((bcsctl2[`DIVSx]==2'b00) ? 1'b1 :
|
| 873 |
|
|
(bcsctl2[`DIVSx]==2'b01) ? smclk_div[0] :
|
| 874 |
|
|
(bcsctl2[`DIVSx]==2'b10) ? &smclk_div[1:0] :
|
| 875 |
|
|
&smclk_div[2:0]);
|
| 876 |
80 |
olivier.gi |
|
| 877 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
| 878 |
|
|
if (puc_rst) smclk_en <= 1'b0;
|
| 879 |
|
|
else smclk_en <= smclk_en_nxt & cpu_en_s;
|
| 880 |
85 |
olivier.gi |
|
| 881 |
111 |
olivier.gi |
always @ (posedge mclk or posedge puc_rst)
|
| 882 |
|
|
if (puc_rst) smclk_div <= 3'h0;
|
| 883 |
80 |
olivier.gi |
else if ((bcsctl2[`DIVSx]!=2'b00) & smclk_in) smclk_div <= smclk_div+3'h1;
|
| 884 |
|
|
|
| 885 |
136 |
olivier.gi |
wire smclk = mclk;
|
| 886 |
80 |
olivier.gi |
|
| 887 |
136 |
olivier.gi |
`endif
|
| 888 |
107 |
olivier.gi |
|
| 889 |
136 |
olivier.gi |
//-----------------------------------------------------------
|
| 890 |
|
|
// 6.5) DEBUG INTERFACE CLOCK GENERATION (DBG_CLK)
|
| 891 |
|
|
//-----------------------------------------------------------
|
| 892 |
107 |
olivier.gi |
|
| 893 |
136 |
olivier.gi |
// Synchronize DBG_EN signal to MCLK domain
|
| 894 |
|
|
//------------------------------------------
|
| 895 |
|
|
`ifdef DBG_EN
|
| 896 |
|
|
`ifdef SYNC_DBG_EN
|
| 897 |
|
|
wire dbg_en_n_s;
|
| 898 |
|
|
omsp_sync_cell sync_cell_dbg_en (
|
| 899 |
|
|
.data_out (dbg_en_n_s),
|
| 900 |
|
|
.data_in (~dbg_en),
|
| 901 |
|
|
.clk (mclk),
|
| 902 |
|
|
.rst (por)
|
| 903 |
|
|
);
|
| 904 |
|
|
assign dbg_en_s = ~dbg_en_n_s;
|
| 905 |
|
|
wire dbg_rst_nxt = dbg_en_n_s;
|
| 906 |
|
|
`else
|
| 907 |
|
|
assign dbg_en_s = dbg_en;
|
| 908 |
|
|
wire dbg_rst_nxt = ~dbg_en;
|
| 909 |
|
|
`endif
|
| 910 |
|
|
`else
|
| 911 |
|
|
assign dbg_en_s = 1'b0;
|
| 912 |
|
|
wire dbg_rst_nxt = 1'b0;
|
| 913 |
|
|
`endif
|
| 914 |
107 |
olivier.gi |
|
| 915 |
136 |
olivier.gi |
|
| 916 |
|
|
// Serial Debug Interface Clock gate
|
| 917 |
|
|
//------------------------------------------------
|
| 918 |
|
|
`ifdef DBG_EN
|
| 919 |
|
|
`ifdef ASIC
|
| 920 |
|
|
omsp_clock_gate clock_gate_dbg_clk (
|
| 921 |
|
|
.gclk (dbg_clk),
|
| 922 |
|
|
.clk (mclk),
|
| 923 |
|
|
.enable (dbg_en_s),
|
| 924 |
|
|
.scan_enable (scan_enable)
|
| 925 |
|
|
);
|
| 926 |
|
|
`else
|
| 927 |
|
|
assign dbg_clk = dco_clk;
|
| 928 |
|
|
`endif
|
| 929 |
|
|
`else
|
| 930 |
|
|
assign dbg_clk = 1'b0;
|
| 931 |
|
|
`endif
|
| 932 |
|
|
|
| 933 |
|
|
|
| 934 |
80 |
olivier.gi |
//=============================================================================
|
| 935 |
136 |
olivier.gi |
// 7) RESET GENERATION
|
| 936 |
80 |
olivier.gi |
//=============================================================================
|
| 937 |
136 |
olivier.gi |
//
|
| 938 |
|
|
// Whenever the reset pin (reset_n) is deasserted, the internal resets of the
|
| 939 |
|
|
// openMSP430 will be released in the following order:
|
| 940 |
|
|
// 1- POR
|
| 941 |
|
|
// 2- DBG_RST (if the sdi interface is enabled, i.e. dbg_en=1)
|
| 942 |
|
|
// 3- PUC
|
| 943 |
|
|
//
|
| 944 |
|
|
// Note: releasing the DBG_RST before PUC is particularly important in order
|
| 945 |
|
|
// to allow the sdi interface to halt the cpu immediately after a PUC.
|
| 946 |
|
|
//
|
| 947 |
|
|
|
| 948 |
|
|
// Generate synchronized POR to MCLK domain
|
| 949 |
|
|
//------------------------------------------
|
| 950 |
80 |
olivier.gi |
|
| 951 |
136 |
olivier.gi |
// Asynchronous reset source
|
| 952 |
|
|
assign por_a = !reset_n;
|
| 953 |
|
|
wire por_noscan;
|
| 954 |
80 |
olivier.gi |
|
| 955 |
136 |
olivier.gi |
// Reset Synchronizer
|
| 956 |
|
|
omsp_sync_reset sync_reset_por (
|
| 957 |
|
|
.rst_s (por_noscan),
|
| 958 |
|
|
.clk (nodiv_mclk),
|
| 959 |
|
|
.rst_a (por_a)
|
| 960 |
111 |
olivier.gi |
);
|
| 961 |
80 |
olivier.gi |
|
| 962 |
136 |
olivier.gi |
// Scan Reset Mux
|
| 963 |
|
|
`ifdef ASIC
|
| 964 |
|
|
omsp_scan_mux scan_mux_por (
|
| 965 |
|
|
.scan_mode (scan_mode),
|
| 966 |
|
|
.data_in_scan (por_a),
|
| 967 |
|
|
.data_in_func (por_noscan),
|
| 968 |
|
|
.data_out (por)
|
| 969 |
|
|
);
|
| 970 |
|
|
`else
|
| 971 |
|
|
assign por = por_noscan;
|
| 972 |
|
|
`endif
|
| 973 |
107 |
olivier.gi |
|
| 974 |
136 |
olivier.gi |
// Generate synchronized reset for the SDI
|
| 975 |
|
|
//------------------------------------------
|
| 976 |
|
|
`ifdef DBG_EN
|
| 977 |
111 |
olivier.gi |
|
| 978 |
136 |
olivier.gi |
// Reset Generation
|
| 979 |
|
|
reg dbg_rst_noscan;
|
| 980 |
|
|
always @ (posedge mclk or posedge por)
|
| 981 |
|
|
if (por) dbg_rst_noscan <= 1'b1;
|
| 982 |
|
|
else dbg_rst_noscan <= dbg_rst_nxt;
|
| 983 |
80 |
olivier.gi |
|
| 984 |
136 |
olivier.gi |
// Scan Reset Mux
|
| 985 |
|
|
`ifdef ASIC
|
| 986 |
|
|
omsp_scan_mux scan_mux_dbg_rst (
|
| 987 |
|
|
.scan_mode (scan_mode),
|
| 988 |
|
|
.data_in_scan (por_a),
|
| 989 |
|
|
.data_in_func (dbg_rst_noscan),
|
| 990 |
|
|
.data_out (dbg_rst)
|
| 991 |
|
|
);
|
| 992 |
111 |
olivier.gi |
`else
|
| 993 |
136 |
olivier.gi |
assign dbg_rst = dbg_rst_noscan;
|
| 994 |
111 |
olivier.gi |
`endif
|
| 995 |
|
|
|
| 996 |
107 |
olivier.gi |
`else
|
| 997 |
136 |
olivier.gi |
wire dbg_rst_noscan = 1'b1;
|
| 998 |
|
|
assign dbg_rst = 1'b1;
|
| 999 |
107 |
olivier.gi |
`endif
|
| 1000 |
|
|
|
| 1001 |
|
|
|
| 1002 |
136 |
olivier.gi |
// Generate main system reset (PUC_RST)
|
| 1003 |
|
|
//--------------------------------------
|
| 1004 |
|
|
wire puc_noscan_n;
|
| 1005 |
|
|
wire puc_a_scan;
|
| 1006 |
107 |
olivier.gi |
|
| 1007 |
136 |
olivier.gi |
// Asynchronous PUC reset
|
| 1008 |
|
|
wire puc_a = por | wdt_reset;
|
| 1009 |
|
|
|
| 1010 |
|
|
// Synchronous PUC reset
|
| 1011 |
|
|
wire puc_s = dbg_cpu_reset | // With the debug interface command
|
| 1012 |
|
|
|
| 1013 |
|
|
(dbg_en_s & dbg_rst_noscan & ~puc_noscan_n); // Sequencing making sure PUC is released
|
| 1014 |
|
|
// after DBG_RST if the debug interface is
|
| 1015 |
|
|
// enabled at power-on-reset time
|
| 1016 |
|
|
// Scan Reset Mux
|
| 1017 |
|
|
`ifdef ASIC
|
| 1018 |
|
|
omsp_scan_mux scan_mux_puc_rst_a (
|
| 1019 |
|
|
.scan_mode (scan_mode),
|
| 1020 |
|
|
.data_in_scan (por_a),
|
| 1021 |
|
|
.data_in_func (puc_a),
|
| 1022 |
|
|
.data_out (puc_a_scan)
|
| 1023 |
|
|
);
|
| 1024 |
|
|
`else
|
| 1025 |
|
|
assign puc_a_scan = puc_a;
|
| 1026 |
|
|
`endif
|
| 1027 |
|
|
|
| 1028 |
|
|
// Reset Synchronizer
|
| 1029 |
|
|
// (required because of the asynchronous watchdog reset)
|
| 1030 |
|
|
omsp_sync_cell sync_cell_puc (
|
| 1031 |
|
|
.data_out (puc_noscan_n),
|
| 1032 |
|
|
.data_in (~puc_s),
|
| 1033 |
|
|
.clk (mclk),
|
| 1034 |
|
|
.rst (puc_a_scan)
|
| 1035 |
|
|
);
|
| 1036 |
|
|
|
| 1037 |
|
|
// Scan Reset Mux
|
| 1038 |
|
|
`ifdef ASIC
|
| 1039 |
|
|
omsp_scan_mux scan_mux_puc_rst (
|
| 1040 |
|
|
.scan_mode (scan_mode),
|
| 1041 |
|
|
.data_in_scan (por_a),
|
| 1042 |
|
|
.data_in_func (~puc_noscan_n),
|
| 1043 |
|
|
.data_out (puc_rst)
|
| 1044 |
|
|
);
|
| 1045 |
|
|
`else
|
| 1046 |
|
|
assign puc_rst = ~puc_noscan_n;
|
| 1047 |
|
|
`endif
|
| 1048 |
|
|
|
| 1049 |
|
|
// PUC pending set the serial debug interface
|
| 1050 |
|
|
assign puc_pnd_set = ~puc_noscan_n;
|
| 1051 |
|
|
|
| 1052 |
|
|
|
| 1053 |
80 |
olivier.gi |
endmodule // omsp_clock_module
|
| 1054 |
|
|
|
| 1055 |
104 |
olivier.gi |
`ifdef OMSP_NO_INCLUDE
|
| 1056 |
|
|
`else
|
| 1057 |
80 |
olivier.gi |
`include "openMSP430_undefines.v"
|
| 1058 |
104 |
olivier.gi |
`endif
|