//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// dbg_top.v ////
|
//// dbg_top.v ////
|
//// ////
|
//// ////
|
//// ////
|
//// ////
|
//// This file is part of the SoC/OpenRISC Development Interface ////
|
//// This file is part of the SoC/OpenRISC Development Interface ////
|
//// http://www.opencores.org/cores/DebugInterface/ ////
|
//// http://www.opencores.org/cores/DebugInterface/ ////
|
//// ////
|
//// ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// Igor Mohor ////
|
//// Igor Mohor ////
|
//// igorm@opencores.org ////
|
//// igorm@opencores.org ////
|
//// ////
|
//// ////
|
//// ////
|
//// ////
|
//// All additional information is avaliable in the README.txt ////
|
//// All additional information is avaliable in the README.txt ////
|
//// file. ////
|
//// file. ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2000,2001 Authors ////
|
//// Copyright (C) 2000,2001 Authors ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// Public License along with this source; if not, download it ////
|
//// Public License along with this source; if not, download it ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
|
// Revision 1.15 2001/12/05 13:28:21 mohor
|
|
// trst signal is synchronized to wb_clk_i.
|
|
//
|
// Revision 1.14 2001/11/28 09:36:15 mohor
|
// Revision 1.14 2001/11/28 09:36:15 mohor
|
// Register length fixed.
|
// Register length fixed.
|
//
|
//
|
// Revision 1.13 2001/11/27 13:37:43 mohor
|
// Revision 1.13 2001/11/27 13:37:43 mohor
|
// CRC is returned when chain selection data is transmitted.
|
// CRC is returned when chain selection data is transmitted.
|
//
|
//
|
// Revision 1.12 2001/11/26 10:47:09 mohor
|
// Revision 1.12 2001/11/26 10:47:09 mohor
|
// Crc generation is different for read or write commands. Small synthesys fixes.
|
// Crc generation is different for read or write commands. Small synthesys fixes.
|
//
|
//
|
// Revision 1.11 2001/11/14 10:10:41 mohor
|
// Revision 1.11 2001/11/14 10:10:41 mohor
|
// Wishbone data latched on wb_clk_i instead of risc_clk.
|
// Wishbone data latched on wb_clk_i instead of risc_clk.
|
//
|
//
|
// Revision 1.10 2001/11/12 01:11:27 mohor
|
// Revision 1.10 2001/11/12 01:11:27 mohor
|
// Reset signals are not combined any more.
|
// Reset signals are not combined any more.
|
//
|
//
|
// Revision 1.9 2001/10/19 11:40:01 mohor
|
// Revision 1.9 2001/10/19 11:40:01 mohor
|
// dbg_timescale.v changed to timescale.v This is done for the simulation of
|
// dbg_timescale.v changed to timescale.v This is done for the simulation of
|
// few different cores in a single project.
|
// few different cores in a single project.
|
//
|
//
|
// Revision 1.8 2001/10/17 10:39:03 mohor
|
// Revision 1.8 2001/10/17 10:39:03 mohor
|
// bs_chain_o added.
|
// bs_chain_o added.
|
//
|
//
|
// Revision 1.7 2001/10/16 10:09:56 mohor
|
// Revision 1.7 2001/10/16 10:09:56 mohor
|
// Signal names changed to lowercase.
|
// Signal names changed to lowercase.
|
//
|
//
|
//
|
//
|
// Revision 1.6 2001/10/15 09:55:47 mohor
|
// Revision 1.6 2001/10/15 09:55:47 mohor
|
// Wishbone interface added, few fixes for better performance,
|
// Wishbone interface added, few fixes for better performance,
|
// hooks for boundary scan testing added.
|
// hooks for boundary scan testing added.
|
//
|
//
|
// Revision 1.5 2001/09/24 14:06:42 mohor
|
// Revision 1.5 2001/09/24 14:06:42 mohor
|
// Changes connected to the OpenRISC access (SPR read, SPR write).
|
// Changes connected to the OpenRISC access (SPR read, SPR write).
|
//
|
//
|
// Revision 1.4 2001/09/20 10:11:25 mohor
|
// Revision 1.4 2001/09/20 10:11:25 mohor
|
// Working version. Few bugs fixed, comments added.
|
// Working version. Few bugs fixed, comments added.
|
//
|
//
|
// Revision 1.3 2001/09/19 11:55:13 mohor
|
// Revision 1.3 2001/09/19 11:55:13 mohor
|
// Asynchronous set/reset not used in trace any more.
|
// Asynchronous set/reset not used in trace any more.
|
//
|
//
|
// Revision 1.2 2001/09/18 14:13:47 mohor
|
// Revision 1.2 2001/09/18 14:13:47 mohor
|
// Trace fixed. Some registers changed, trace simplified.
|
// Trace fixed. Some registers changed, trace simplified.
|
//
|
//
|
// Revision 1.1.1.1 2001/09/13 13:49:19 mohor
|
// Revision 1.1.1.1 2001/09/13 13:49:19 mohor
|
// Initial official release.
|
// Initial official release.
|
//
|
//
|
// Revision 1.3 2001/06/01 22:22:35 mohor
|
// Revision 1.3 2001/06/01 22:22:35 mohor
|
// This is a backup. It is not a fully working version. Not for use, yet.
|
// This is a backup. It is not a fully working version. Not for use, yet.
|
//
|
//
|
// Revision 1.2 2001/05/18 13:10:00 mohor
|
// Revision 1.2 2001/05/18 13:10:00 mohor
|
// Headers changed. All additional information is now avaliable in the README.txt file.
|
// Headers changed. All additional information is now avaliable in the README.txt file.
|
//
|
//
|
// Revision 1.1.1.1 2001/05/18 06:35:02 mohor
|
// Revision 1.1.1.1 2001/05/18 06:35:02 mohor
|
// Initial release
|
// Initial release
|
//
|
//
|
//
|
//
|
|
|
// synopsys translate_off
|
// synopsys translate_off
|
`include "timescale.v"
|
`include "timescale.v"
|
// synopsys translate_on
|
// synopsys translate_on
|
`include "dbg_defines.v"
|
`include "dbg_defines.v"
|
|
|
// Top module
|
// Top module
|
module dbg_top(
|
module dbg_top(
|
// JTAG pins
|
// JTAG pins
|
tms_pad_i, tck_pad_i, trst_pad_i, tdi_pad_i, tdo_pad_o,
|
tms_pad_i, tck_pad_i, trst_pad_i, tdi_pad_i, tdo_pad_o, tdo_padoen_o,
|
|
|
// Boundary Scan signals
|
// Boundary Scan signals
|
capture_dr_o, shift_dr_o, update_dr_o, extest_selected_o, bs_chain_i, bs_chain_o,
|
capture_dr_o, shift_dr_o, update_dr_o, extest_selected_o, bs_chain_i, bs_chain_o,
|
|
|
// RISC signals
|
// RISC signals
|
risc_clk_i, risc_addr_o, risc_data_i, risc_data_o, wp_i,
|
risc_clk_i, risc_addr_o, risc_data_i, risc_data_o, wp_i,
|
bp_i, opselect_o, lsstatus_i, istatus_i, risc_stall_o, reset_o,
|
bp_i, opselect_o, lsstatus_i, istatus_i, risc_stall_o, reset_o,
|
|
|
// WISHBONE common signals
|
// WISHBONE common signals
|
wb_rst_i, wb_clk_i,
|
wb_rst_i, wb_clk_i,
|
|
|
// WISHBONE master interface
|
// WISHBONE master interface
|
wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
|
wb_adr_o, wb_dat_o, wb_dat_i, wb_cyc_o, wb_stb_o, wb_sel_o,
|
wb_we_o, wb_ack_i, wb_cab_o, wb_err_i
|
wb_we_o, wb_ack_i, wb_cab_o, wb_err_i
|
|
|
|
|
);
|
);
|
|
|
parameter Tp = 1;
|
parameter Tp = 1;
|
|
|
// JTAG pins
|
// JTAG pins
|
input tms_pad_i; // JTAG test mode select pad
|
input tms_pad_i; // JTAG test mode select pad
|
input tck_pad_i; // JTAG test clock pad
|
input tck_pad_i; // JTAG test clock pad
|
input trst_pad_i; // JTAG test reset pad
|
input trst_pad_i; // JTAG test reset pad
|
input tdi_pad_i; // JTAG test data input pad
|
input tdi_pad_i; // JTAG test data input pad
|
output tdo_pad_o; // JTAG test data output pad
|
output tdo_pad_o; // JTAG test data output pad
|
|
output tdo_padoen_o; // Output enable for JTAG test data output pad
|
|
|
|
|
// Boundary Scan signals
|
// Boundary Scan signals
|
output capture_dr_o;
|
output capture_dr_o;
|
output shift_dr_o;
|
output shift_dr_o;
|
output update_dr_o;
|
output update_dr_o;
|
output extest_selected_o;
|
output extest_selected_o;
|
input bs_chain_i;
|
input bs_chain_i;
|
output bs_chain_o;
|
output bs_chain_o;
|
|
|
// RISC signals
|
// RISC signals
|
input risc_clk_i; // Master clock (RISC clock)
|
input risc_clk_i; // Master clock (RISC clock)
|
input [31:0] risc_data_i; // RISC data inputs (data that is written to the RISC registers)
|
input [31:0] risc_data_i; // RISC data inputs (data that is written to the RISC registers)
|
input [10:0] wp_i; // Watchpoint inputs
|
input [10:0] wp_i; // Watchpoint inputs
|
input bp_i; // Breakpoint input
|
input bp_i; // Breakpoint input
|
input [3:0] lsstatus_i; // Load/store status inputs
|
input [3:0] lsstatus_i; // Load/store status inputs
|
input [1:0] istatus_i; // Instruction status inputs
|
input [1:0] istatus_i; // Instruction status inputs
|
output [31:0] risc_addr_o; // RISC address output (for adressing registers within RISC)
|
output [31:0] risc_addr_o; // RISC address output (for adressing registers within RISC)
|
output [31:0] risc_data_o; // RISC data output (data read from risc registers)
|
output [31:0] risc_data_o; // RISC data output (data read from risc registers)
|
output [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
output [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
output risc_stall_o; // Stalls the RISC
|
output risc_stall_o; // Stalls the RISC
|
output reset_o; // Resets the RISC
|
output reset_o; // Resets the RISC
|
|
|
|
|
// WISHBONE common signals
|
// WISHBONE common signals
|
input wb_rst_i; // WISHBONE reset
|
input wb_rst_i; // WISHBONE reset
|
input wb_clk_i; // WISHBONE clock
|
input wb_clk_i; // WISHBONE clock
|
|
|
// WISHBONE master interface
|
// WISHBONE master interface
|
output [31:0] wb_adr_o;
|
output [31:0] wb_adr_o;
|
output [31:0] wb_dat_o;
|
output [31:0] wb_dat_o;
|
input [31:0] wb_dat_i;
|
input [31:0] wb_dat_i;
|
output wb_cyc_o;
|
output wb_cyc_o;
|
output wb_stb_o;
|
output wb_stb_o;
|
output [3:0] wb_sel_o;
|
output [3:0] wb_sel_o;
|
output wb_we_o;
|
output wb_we_o;
|
input wb_ack_i;
|
input wb_ack_i;
|
output wb_cab_o;
|
output wb_cab_o;
|
input wb_err_i;
|
input wb_err_i;
|
|
|
reg wb_cyc_o;
|
reg wb_cyc_o;
|
|
|
// TAP states
|
// TAP states
|
reg TestLogicReset;
|
reg TestLogicReset;
|
reg RunTestIdle;
|
reg RunTestIdle;
|
reg SelectDRScan;
|
reg SelectDRScan;
|
reg CaptureDR;
|
reg CaptureDR;
|
reg ShiftDR;
|
reg ShiftDR;
|
reg Exit1DR;
|
reg Exit1DR;
|
reg PauseDR;
|
reg PauseDR;
|
reg Exit2DR;
|
reg Exit2DR;
|
reg UpdateDR;
|
reg UpdateDR;
|
|
|
reg SelectIRScan;
|
reg SelectIRScan;
|
reg CaptureIR;
|
reg CaptureIR;
|
reg ShiftIR;
|
reg ShiftIR;
|
reg Exit1IR;
|
reg Exit1IR;
|
reg PauseIR;
|
reg PauseIR;
|
reg Exit2IR;
|
reg Exit2IR;
|
reg UpdateIR;
|
reg UpdateIR;
|
|
|
|
|
// Defining which instruction is selected
|
// Defining which instruction is selected
|
reg EXTESTSelected;
|
reg EXTESTSelected;
|
reg SAMPLE_PRELOADSelected;
|
reg SAMPLE_PRELOADSelected;
|
reg IDCODESelected;
|
reg IDCODESelected;
|
reg CHAIN_SELECTSelected;
|
reg CHAIN_SELECTSelected;
|
reg INTESTSelected;
|
reg INTESTSelected;
|
reg CLAMPSelected;
|
reg CLAMPSelected;
|
reg CLAMPZSelected;
|
reg CLAMPZSelected;
|
reg HIGHZSelected;
|
reg HIGHZSelected;
|
reg DEBUGSelected;
|
reg DEBUGSelected;
|
reg BYPASSSelected;
|
reg BYPASSSelected;
|
|
|
reg [31:0] ADDR;
|
reg [31:0] ADDR;
|
reg [31:0] DataOut;
|
reg [31:0] DataOut;
|
|
|
reg [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
reg [`OPSELECTWIDTH-1:0] opselect_o; // Operation selection (selecting what kind of data is set to the risc_data_i)
|
|
|
reg [`CHAIN_ID_LENGTH-1:0] Chain; // Selected chain
|
reg [`CHAIN_ID_LENGTH-1:0] Chain; // Selected chain
|
reg [31:0] RISC_DATAINLatch; // Data from DataIn is latched one risc_clk_i clock cycle after RISC register is
|
reg [31:0] RISC_DATAINLatch; // Data from DataIn is latched one risc_clk_i clock cycle after RISC register is
|
// accessed for reading
|
// accessed for reading
|
reg [31:0] RegisterReadLatch; // Data when reading register is latched one TCK clock after the register is read.
|
reg [31:0] RegisterReadLatch; // Data when reading register is latched one TCK clock after the register is read.
|
reg RegAccessTck; // Indicates access to the registers (read or write)
|
reg RegAccessTck; // Indicates access to the registers (read or write)
|
reg RISCAccessTck; // Indicates access to the RISC (read or write)
|
reg RISCAccessTck; // Indicates access to the RISC (read or write)
|
reg [7:0] BitCounter; // Counting bits in the ShiftDR and Exit1DR stages
|
reg [7:0] BitCounter; // Counting bits in the ShiftDR and Exit1DR stages
|
reg RW; // Read/Write bit
|
reg RW; // Read/Write bit
|
reg CrcMatch; // The crc that is shifted in and the internaly calculated crc are equal
|
reg CrcMatch; // The crc that is shifted in and the internaly calculated crc are equal
|
|
|
reg RegAccess_q; // Delayed signals used for accessing the registers
|
reg RegAccess_q; // Delayed signals used for accessing the registers
|
reg RegAccess_q2; // Delayed signals used for accessing the registers
|
reg RegAccess_q2; // Delayed signals used for accessing the registers
|
reg RISCAccess_q; // Delayed signals used for accessing the RISC
|
reg RISCAccess_q; // Delayed signals used for accessing the RISC
|
reg RISCAccess_q2; // Delayed signals used for accessing the RISC
|
reg RISCAccess_q2; // Delayed signals used for accessing the RISC
|
|
|
reg wb_AccessTck; // Indicates access to the WISHBONE
|
reg wb_AccessTck; // Indicates access to the WISHBONE
|
reg [31:0] WBReadLatch; // Data latched during WISHBONE read
|
reg [31:0] WBReadLatch; // Data latched during WISHBONE read
|
reg WBErrorLatch; // Error latched during WISHBONE read
|
reg WBErrorLatch; // Error latched during WISHBONE read
|
reg trst; // trst is active high while trst_pad_i is active low
|
reg trst; // trst is active high while trst_pad_i is active low
|
|
|
wire TCK = tck_pad_i;
|
wire TCK = tck_pad_i;
|
wire TMS = tms_pad_i;
|
wire TMS = tms_pad_i;
|
wire TDI = tdi_pad_i;
|
wire TDI = tdi_pad_i;
|
|
|
wire [31:0] RegDataIn; // Data from registers (read data)
|
wire [31:0] RegDataIn; // Data from registers (read data)
|
wire [`CRC_LENGTH-1:0] CalculatedCrcOut; // CRC calculated in this module. This CRC is apended at the end of the TDO.
|
wire [`CRC_LENGTH-1:0] CalculatedCrcOut; // CRC calculated in this module. This CRC is apended at the end of the TDO.
|
|
|
wire RiscStall_reg; // RISC is stalled by setting the register bit
|
wire RiscStall_reg; // RISC is stalled by setting the register bit
|
wire RiscReset_reg; // RISC is reset by setting the register bit
|
wire RiscReset_reg; // RISC is reset by setting the register bit
|
wire RiscStall_trace; // RISC is stalled by trace module
|
wire RiscStall_trace; // RISC is stalled by trace module
|
|
|
|
|
wire RegisterScanChain; // Register Scan chain selected
|
wire RegisterScanChain; // Register Scan chain selected
|
wire RiscDebugScanChain; // Risc Debug Scan chain selected
|
wire RiscDebugScanChain; // Risc Debug Scan chain selected
|
wire WishboneScanChain; // WISHBONE Scan chain selected
|
wire WishboneScanChain; // WISHBONE Scan chain selected
|
|
|
wire RiscStall_read_access; // Stalling RISC because of the read access (SPR read)
|
wire RiscStall_read_access; // Stalling RISC because of the read access (SPR read)
|
wire RiscStall_write_access; // Stalling RISC because of the write access (SPR write)
|
wire RiscStall_write_access; // Stalling RISC because of the write access (SPR write)
|
wire RiscStall_access; // Stalling RISC because of the read or write access
|
wire RiscStall_access; // Stalling RISC because of the read or write access
|
|
|
|
|
assign capture_dr_o = CaptureDR;
|
assign capture_dr_o = CaptureDR;
|
assign shift_dr_o = ShiftDR;
|
assign shift_dr_o = ShiftDR;
|
assign update_dr_o = UpdateDR;
|
assign update_dr_o = UpdateDR;
|
assign extest_selected_o = EXTESTSelected;
|
assign extest_selected_o = EXTESTSelected;
|
wire BS_CHAIN_I = bs_chain_i;
|
wire BS_CHAIN_I = bs_chain_i;
|
assign bs_chain_o = tdi_pad_i;
|
assign bs_chain_o = tdi_pad_i;
|
|
|
|
|
// This signals are used only when TRACE is used in the design
|
// This signals are used only when TRACE is used in the design
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
wire [39:0] TraceChain; // Chain that comes from trace module
|
wire [39:0] TraceChain; // Chain that comes from trace module
|
reg ReadBuffer_Tck; // Command for incrementing the trace read pointer (synchr with TCK)
|
reg ReadBuffer_Tck; // Command for incrementing the trace read pointer (synchr with TCK)
|
wire ReadTraceBuffer; // Command for incrementing the trace read pointer (synchr with MClk)
|
wire ReadTraceBuffer; // Command for incrementing the trace read pointer (synchr with MClk)
|
reg ReadTraceBuffer_q; // Delayed command for incrementing the trace read pointer (synchr with MClk)
|
reg ReadTraceBuffer_q; // Delayed command for incrementing the trace read pointer (synchr with MClk)
|
wire ReadTraceBufferPulse; // Pulse for reading the trace buffer (valid for only one Mclk command)
|
wire ReadTraceBufferPulse; // Pulse for reading the trace buffer (valid for only one Mclk command)
|
|
|
// Outputs from registers
|
// Outputs from registers
|
wire ContinMode; // Trace working in continous mode
|
wire ContinMode; // Trace working in continous mode
|
wire TraceEnable; // Trace enabled
|
wire TraceEnable; // Trace enabled
|
|
|
wire [10:0] WpTrigger; // Watchpoint starts trigger
|
wire [10:0] WpTrigger; // Watchpoint starts trigger
|
wire BpTrigger; // Breakpoint starts trigger
|
wire BpTrigger; // Breakpoint starts trigger
|
wire [3:0] LSSTrigger; // Load/store status starts trigger
|
wire [3:0] LSSTrigger; // Load/store status starts trigger
|
wire [1:0] ITrigger; // Instruction status starts trigger
|
wire [1:0] ITrigger; // Instruction status starts trigger
|
wire [1:0] TriggerOper; // Trigger operation
|
wire [1:0] TriggerOper; // Trigger operation
|
|
|
wire WpTriggerValid; // Watchpoint trigger is valid
|
wire WpTriggerValid; // Watchpoint trigger is valid
|
wire BpTriggerValid; // Breakpoint trigger is valid
|
wire BpTriggerValid; // Breakpoint trigger is valid
|
wire LSSTriggerValid; // Load/store status trigger is valid
|
wire LSSTriggerValid; // Load/store status trigger is valid
|
wire ITriggerValid; // Instruction status trigger is valid
|
wire ITriggerValid; // Instruction status trigger is valid
|
|
|
wire [10:0] WpQualif; // Watchpoint starts qualifier
|
wire [10:0] WpQualif; // Watchpoint starts qualifier
|
wire BpQualif; // Breakpoint starts qualifier
|
wire BpQualif; // Breakpoint starts qualifier
|
wire [3:0] LSSQualif; // Load/store status starts qualifier
|
wire [3:0] LSSQualif; // Load/store status starts qualifier
|
wire [1:0] IQualif; // Instruction status starts qualifier
|
wire [1:0] IQualif; // Instruction status starts qualifier
|
wire [1:0] QualifOper; // Qualifier operation
|
wire [1:0] QualifOper; // Qualifier operation
|
|
|
wire WpQualifValid; // Watchpoint qualifier is valid
|
wire WpQualifValid; // Watchpoint qualifier is valid
|
wire BpQualifValid; // Breakpoint qualifier is valid
|
wire BpQualifValid; // Breakpoint qualifier is valid
|
wire LSSQualifValid; // Load/store status qualifier is valid
|
wire LSSQualifValid; // Load/store status qualifier is valid
|
wire IQualifValid; // Instruction status qualifier is valid
|
wire IQualifValid; // Instruction status qualifier is valid
|
|
|
wire [10:0] WpStop; // Watchpoint stops recording of the trace
|
wire [10:0] WpStop; // Watchpoint stops recording of the trace
|
wire BpStop; // Breakpoint stops recording of the trace
|
wire BpStop; // Breakpoint stops recording of the trace
|
wire [3:0] LSSStop; // Load/store status stops recording of the trace
|
wire [3:0] LSSStop; // Load/store status stops recording of the trace
|
wire [1:0] IStop; // Instruction status stops recording of the trace
|
wire [1:0] IStop; // Instruction status stops recording of the trace
|
wire [1:0] StopOper; // Stop operation
|
wire [1:0] StopOper; // Stop operation
|
|
|
wire WpStopValid; // Watchpoint stop is valid
|
wire WpStopValid; // Watchpoint stop is valid
|
wire BpStopValid; // Breakpoint stop is valid
|
wire BpStopValid; // Breakpoint stop is valid
|
wire LSSStopValid; // Load/store status stop is valid
|
wire LSSStopValid; // Load/store status stop is valid
|
wire IStopValid; // Instruction status stop is valid
|
wire IStopValid; // Instruction status stop is valid
|
|
|
wire RecordPC; // Recording program counter
|
wire RecordPC; // Recording program counter
|
wire RecordLSEA; // Recording load/store effective address
|
wire RecordLSEA; // Recording load/store effective address
|
wire RecordLDATA; // Recording load data
|
wire RecordLDATA; // Recording load data
|
wire RecordSDATA; // Recording store data
|
wire RecordSDATA; // Recording store data
|
wire RecordReadSPR; // Recording read SPR
|
wire RecordReadSPR; // Recording read SPR
|
wire RecordWriteSPR; // Recording write SPR
|
wire RecordWriteSPR; // Recording write SPR
|
wire RecordINSTR; // Recording instruction
|
wire RecordINSTR; // Recording instruction
|
|
|
// End: Outputs from registers
|
// End: Outputs from registers
|
|
|
wire TraceTestScanChain; // Trace Test Scan chain selected
|
wire TraceTestScanChain; // Trace Test Scan chain selected
|
wire [47:0] Trace_Data; // Trace data
|
wire [47:0] Trace_Data; // Trace data
|
|
|
wire [`OPSELECTWIDTH-1:0]opselect_trace;// Operation selection (trace selecting what kind of
|
wire [`OPSELECTWIDTH-1:0]opselect_trace;// Operation selection (trace selecting what kind of
|
// data is set to the risc_data_i)
|
// data is set to the risc_data_i)
|
|
|
`endif
|
`endif
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Synchronizing TRST to clock signal *
|
* Synchronizing TRST to clock signal *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
always @ (posedge wb_clk_i)
|
always @ (posedge wb_clk_i)
|
begin
|
begin
|
trst <=#Tp ~trst_pad_i; // trst_pad_i is active low
|
trst <=#Tp ~trst_pad_i; // trst_pad_i is active low
|
end
|
end
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* TAP State Machine: Fully JTAG compliant *
|
* TAP State Machine: Fully JTAG compliant *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
// TestLogicReset state
|
// TestLogicReset state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
TestLogicReset<=#Tp 1;
|
TestLogicReset<=#Tp 1;
|
else
|
else
|
begin
|
begin
|
if(TMS & (TestLogicReset | SelectIRScan))
|
if(TMS & (TestLogicReset | SelectIRScan))
|
TestLogicReset<=#Tp 1;
|
TestLogicReset<=#Tp 1;
|
else
|
else
|
TestLogicReset<=#Tp 0;
|
TestLogicReset<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// RunTestIdle state
|
// RunTestIdle state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
RunTestIdle<=#Tp 0;
|
RunTestIdle<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & (TestLogicReset | RunTestIdle | UpdateDR | UpdateIR))
|
if(~TMS & (TestLogicReset | RunTestIdle | UpdateDR | UpdateIR))
|
RunTestIdle<=#Tp 1;
|
RunTestIdle<=#Tp 1;
|
else
|
else
|
RunTestIdle<=#Tp 0;
|
RunTestIdle<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// SelectDRScan state
|
// SelectDRScan state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
SelectDRScan<=#Tp 0;
|
SelectDRScan<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & (RunTestIdle | UpdateDR | UpdateIR))
|
if(TMS & (RunTestIdle | UpdateDR | UpdateIR))
|
SelectDRScan<=#Tp 1;
|
SelectDRScan<=#Tp 1;
|
else
|
else
|
SelectDRScan<=#Tp 0;
|
SelectDRScan<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// CaptureDR state
|
// CaptureDR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
CaptureDR<=#Tp 0;
|
CaptureDR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & SelectDRScan)
|
if(~TMS & SelectDRScan)
|
CaptureDR<=#Tp 1;
|
CaptureDR<=#Tp 1;
|
else
|
else
|
CaptureDR<=#Tp 0;
|
CaptureDR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// ShiftDR state
|
// ShiftDR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
ShiftDR<=#Tp 0;
|
ShiftDR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & (CaptureDR | ShiftDR | Exit2DR))
|
if(~TMS & (CaptureDR | ShiftDR | Exit2DR))
|
ShiftDR<=#Tp 1;
|
ShiftDR<=#Tp 1;
|
else
|
else
|
ShiftDR<=#Tp 0;
|
ShiftDR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// Exit1DR state
|
// Exit1DR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
Exit1DR<=#Tp 0;
|
Exit1DR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & (CaptureDR | ShiftDR))
|
if(TMS & (CaptureDR | ShiftDR))
|
Exit1DR<=#Tp 1;
|
Exit1DR<=#Tp 1;
|
else
|
else
|
Exit1DR<=#Tp 0;
|
Exit1DR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// PauseDR state
|
// PauseDR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
PauseDR<=#Tp 0;
|
PauseDR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & (Exit1DR | PauseDR))
|
if(~TMS & (Exit1DR | PauseDR))
|
PauseDR<=#Tp 1;
|
PauseDR<=#Tp 1;
|
else
|
else
|
PauseDR<=#Tp 0;
|
PauseDR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// Exit2DR state
|
// Exit2DR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
Exit2DR<=#Tp 0;
|
Exit2DR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & PauseDR)
|
if(TMS & PauseDR)
|
Exit2DR<=#Tp 1;
|
Exit2DR<=#Tp 1;
|
else
|
else
|
Exit2DR<=#Tp 0;
|
Exit2DR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// UpdateDR state
|
// UpdateDR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
UpdateDR<=#Tp 0;
|
UpdateDR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & (Exit1DR | Exit2DR))
|
if(TMS & (Exit1DR | Exit2DR))
|
UpdateDR<=#Tp 1;
|
UpdateDR<=#Tp 1;
|
else
|
else
|
UpdateDR<=#Tp 0;
|
UpdateDR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// Delayed UpdateDR state
|
// Delayed UpdateDR state
|
reg UpdateDR_q;
|
reg UpdateDR_q;
|
always @ (posedge TCK)
|
always @ (posedge TCK)
|
begin
|
begin
|
UpdateDR_q<=#Tp UpdateDR;
|
UpdateDR_q<=#Tp UpdateDR;
|
end
|
end
|
|
|
|
|
// SelectIRScan state
|
// SelectIRScan state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
SelectIRScan<=#Tp 0;
|
SelectIRScan<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & SelectDRScan)
|
if(TMS & SelectDRScan)
|
SelectIRScan<=#Tp 1;
|
SelectIRScan<=#Tp 1;
|
else
|
else
|
SelectIRScan<=#Tp 0;
|
SelectIRScan<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// CaptureIR state
|
// CaptureIR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
CaptureIR<=#Tp 0;
|
CaptureIR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & SelectIRScan)
|
if(~TMS & SelectIRScan)
|
CaptureIR<=#Tp 1;
|
CaptureIR<=#Tp 1;
|
else
|
else
|
CaptureIR<=#Tp 0;
|
CaptureIR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// ShiftIR state
|
// ShiftIR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
ShiftIR<=#Tp 0;
|
ShiftIR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & (CaptureIR | ShiftIR | Exit2IR))
|
if(~TMS & (CaptureIR | ShiftIR | Exit2IR))
|
ShiftIR<=#Tp 1;
|
ShiftIR<=#Tp 1;
|
else
|
else
|
ShiftIR<=#Tp 0;
|
ShiftIR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// Exit1IR state
|
// Exit1IR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
Exit1IR<=#Tp 0;
|
Exit1IR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & (CaptureIR | ShiftIR))
|
if(TMS & (CaptureIR | ShiftIR))
|
Exit1IR<=#Tp 1;
|
Exit1IR<=#Tp 1;
|
else
|
else
|
Exit1IR<=#Tp 0;
|
Exit1IR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// PauseIR state
|
// PauseIR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
PauseIR<=#Tp 0;
|
PauseIR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(~TMS & (Exit1IR | PauseIR))
|
if(~TMS & (Exit1IR | PauseIR))
|
PauseIR<=#Tp 1;
|
PauseIR<=#Tp 1;
|
else
|
else
|
PauseIR<=#Tp 0;
|
PauseIR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// Exit2IR state
|
// Exit2IR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
Exit2IR<=#Tp 0;
|
Exit2IR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & PauseIR)
|
if(TMS & PauseIR)
|
Exit2IR<=#Tp 1;
|
Exit2IR<=#Tp 1;
|
else
|
else
|
Exit2IR<=#Tp 0;
|
Exit2IR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
// UpdateIR state
|
// UpdateIR state
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
UpdateIR<=#Tp 0;
|
UpdateIR<=#Tp 0;
|
else
|
else
|
begin
|
begin
|
if(TMS & (Exit1IR | Exit2IR))
|
if(TMS & (Exit1IR | Exit2IR))
|
UpdateIR<=#Tp 1;
|
UpdateIR<=#Tp 1;
|
else
|
else
|
UpdateIR<=#Tp 0;
|
UpdateIR<=#Tp 0;
|
end
|
end
|
end
|
end
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: TAP State Machine *
|
* End: TAP State Machine *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* JTAG_IR: JTAG Instruction Register *
|
* JTAG_IR: JTAG Instruction Register *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
wire [1:0]Status = 2'b10; // Holds current chip status. Core should return this status. For now a constant is used.
|
wire [1:0]Status = 2'b10; // Holds current chip status. Core should return this status. For now a constant is used.
|
|
|
reg [`IR_LENGTH-1:0]JTAG_IR; // Instruction register
|
reg [`IR_LENGTH-1:0]JTAG_IR; // Instruction register
|
reg [`IR_LENGTH-1:0]LatchedJTAG_IR;
|
reg [`IR_LENGTH-1:0]LatchedJTAG_IR;
|
|
|
reg TDOInstruction;
|
reg TDOInstruction;
|
|
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp 0;
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp 0;
|
else
|
else
|
begin
|
begin
|
if(CaptureIR)
|
if(CaptureIR)
|
begin
|
begin
|
JTAG_IR[1:0] <= #Tp 2'b01; // This value is fixed for easier fault detection
|
JTAG_IR[1:0] <= #Tp 2'b01; // This value is fixed for easier fault detection
|
JTAG_IR[3:2] <= #Tp Status[1:0]; // Current status of chip
|
JTAG_IR[3:2] <= #Tp Status[1:0]; // Current status of chip
|
end
|
end
|
else
|
else
|
begin
|
begin
|
if(ShiftIR)
|
if(ShiftIR)
|
begin
|
begin
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp {TDI, JTAG_IR[`IR_LENGTH-1:1]};
|
JTAG_IR[`IR_LENGTH-1:0] <= #Tp {TDI, JTAG_IR[`IR_LENGTH-1:1]};
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
|
|
//TDO is changing on the falling edge of TCK
|
//TDO is changing on the falling edge of TCK
|
always @ (negedge TCK)
|
always @ (negedge TCK)
|
begin
|
begin
|
if(ShiftIR)
|
if(ShiftIR)
|
TDOInstruction <= #Tp JTAG_IR[0];
|
TDOInstruction <= #Tp JTAG_IR[0];
|
end
|
end
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: JTAG_IR *
|
* End: JTAG_IR *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* JTAG_DR: JTAG Data Register *
|
* JTAG_DR: JTAG Data Register *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
wire [31:0] IDCodeValue = `IDCODE_VALUE; // IDCODE value is 32-bit long.
|
wire [31:0] IDCodeValue = `IDCODE_VALUE; // IDCODE value is 32-bit long.
|
|
|
reg [`DR_LENGTH-1:0]JTAG_DR_IN; // Data register
|
reg [`DR_LENGTH-1:0]JTAG_DR_IN; // Data register
|
reg TDOData;
|
reg TDOData;
|
|
|
|
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
JTAG_DR_IN[`DR_LENGTH-1:0]<=#Tp 0;
|
JTAG_DR_IN[`DR_LENGTH-1:0]<=#Tp 0;
|
else
|
else
|
if(ShiftDR)
|
if(ShiftDR)
|
JTAG_DR_IN[BitCounter]<=#Tp TDI;
|
JTAG_DR_IN[BitCounter]<=#Tp TDI;
|
end
|
end
|
|
|
wire [73:0] RISC_Data;
|
wire [73:0] RISC_Data;
|
wire [46:0] Register_Data;
|
wire [46:0] Register_Data;
|
wire [73:0] WISHBONE_Data;
|
wire [73:0] WISHBONE_Data;
|
wire [12:0] chain_sel_data;
|
wire [12:0] chain_sel_data;
|
wire wb_Access_wbClk;
|
wire wb_Access_wbClk;
|
|
|
// assign RISC_Data = {CalculatedCrcOut, RISC_DATAINLatch, 33'h0};
|
// assign RISC_Data = {CalculatedCrcOut, RISC_DATAINLatch, 33'h0};
|
// assign Register_Data = {CalculatedCrcOut, RegisterReadLatch, 6'h0};
|
// assign Register_Data = {CalculatedCrcOut, RegisterReadLatch, 6'h0};
|
// assign WISHBONE_Data = {CalculatedCrcOut, WBReadLatch, 32'h0, WBErrorLatch};
|
// assign WISHBONE_Data = {CalculatedCrcOut, WBReadLatch, 32'h0, WBErrorLatch};
|
|
|
wire select_crc_out;
|
wire select_crc_out;
|
assign select_crc_out = RegisterScanChain & JTAG_DR_IN[5] | // Calculated CRC is returned when read operation is
|
assign select_crc_out = RegisterScanChain & JTAG_DR_IN[5] | // Calculated CRC is returned when read operation is
|
RiscDebugScanChain & JTAG_DR_IN[32] | // performed, else received crc is returned (loopback).
|
RiscDebugScanChain & JTAG_DR_IN[32] | // performed, else received crc is returned (loopback).
|
WishboneScanChain & JTAG_DR_IN[32] |
|
WishboneScanChain & JTAG_DR_IN[32] |
|
CHAIN_SELECTSelected; // When chain is selected, received crc is returned
|
CHAIN_SELECTSelected; // When chain is selected, received crc is returned
|
|
|
wire [8:0] send_crc;
|
wire [8:0] send_crc;
|
|
|
assign send_crc = select_crc_out? {9{JTAG_DR_IN[BitCounter-1]}} : // Calculated CRC is returned when read operation is
|
assign send_crc = select_crc_out? {9{JTAG_DR_IN[BitCounter-1]}} : // Calculated CRC is returned when read operation is
|
{1'b0, CalculatedCrcOut} ; // performed, else received crc is returned (loopback).
|
{1'b0, CalculatedCrcOut} ; // performed, else received crc is returned (loopback).
|
|
|
assign RISC_Data = {send_crc, RISC_DATAINLatch, 33'h0};
|
assign RISC_Data = {send_crc, RISC_DATAINLatch, 33'h0};
|
assign Register_Data = {send_crc, RegisterReadLatch, 6'h0};
|
assign Register_Data = {send_crc, RegisterReadLatch, 6'h0};
|
assign WISHBONE_Data = {send_crc, WBReadLatch, 32'h0, WBErrorLatch};
|
assign WISHBONE_Data = {send_crc, WBReadLatch, 32'h0, WBErrorLatch};
|
assign chain_sel_data = {send_crc, 4'h0};
|
assign chain_sel_data = {send_crc, 4'h0};
|
|
|
|
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
assign Trace_Data = {CalculatedCrcOut, TraceChain};
|
assign Trace_Data = {CalculatedCrcOut, TraceChain};
|
`endif
|
`endif
|
|
|
//TDO is changing on the falling edge of TCK
|
//TDO is changing on the falling edge of TCK
|
always @ (negedge TCK or posedge trst)
|
always @ (negedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
begin
|
begin
|
TDOData <= #Tp 0;
|
TDOData <= #Tp 0;
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
ReadBuffer_Tck<=#Tp 0;
|
ReadBuffer_Tck<=#Tp 0;
|
`endif
|
`endif
|
end
|
end
|
else
|
else
|
if(UpdateDR)
|
if(UpdateDR)
|
begin
|
begin
|
TDOData <= #Tp CrcMatch;
|
TDOData <= #Tp CrcMatch;
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
if(DEBUGSelected & TraceTestScanChain & TraceChain[0]) // Sample in the trace buffer is valid
|
if(DEBUGSelected & TraceTestScanChain & TraceChain[0]) // Sample in the trace buffer is valid
|
ReadBuffer_Tck<=#Tp 1; // Increment read pointer
|
ReadBuffer_Tck<=#Tp 1; // Increment read pointer
|
`endif
|
`endif
|
end
|
end
|
else
|
else
|
begin
|
begin
|
if(ShiftDR)
|
if(ShiftDR)
|
begin
|
begin
|
if(IDCODESelected)
|
if(IDCODESelected)
|
TDOData <= #Tp IDCodeValue[BitCounter]; // IDCODE is shifted out
|
TDOData <= #Tp IDCodeValue[BitCounter]; // IDCODE is shifted out
|
else
|
else
|
if(CHAIN_SELECTSelected)
|
if(CHAIN_SELECTSelected)
|
TDOData <= #Tp chain_sel_data[BitCounter]; // Received crc is sent back
|
TDOData <= #Tp chain_sel_data[BitCounter]; // Received crc is sent back
|
else
|
else
|
if(DEBUGSelected)
|
if(DEBUGSelected)
|
begin
|
begin
|
if(RiscDebugScanChain)
|
if(RiscDebugScanChain)
|
TDOData <= #Tp RISC_Data[BitCounter]; // Data read from RISC in the previous cycle is shifted out
|
TDOData <= #Tp RISC_Data[BitCounter]; // Data read from RISC in the previous cycle is shifted out
|
else
|
else
|
if(RegisterScanChain)
|
if(RegisterScanChain)
|
TDOData <= #Tp Register_Data[BitCounter]; // Data read from register in the previous cycle is shifted out
|
TDOData <= #Tp Register_Data[BitCounter]; // Data read from register in the previous cycle is shifted out
|
else
|
else
|
if(WishboneScanChain)
|
if(WishboneScanChain)
|
TDOData <= #Tp WISHBONE_Data[BitCounter]; // Data read from the WISHBONE slave
|
TDOData <= #Tp WISHBONE_Data[BitCounter]; // Data read from the WISHBONE slave
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
else
|
else
|
if(TraceTestScanChain)
|
if(TraceTestScanChain)
|
TDOData <= #Tp Trace_Data[BitCounter]; // Data from the trace buffer is shifted out
|
TDOData <= #Tp Trace_Data[BitCounter]; // Data from the trace buffer is shifted out
|
`endif
|
`endif
|
end
|
end
|
end
|
end
|
else
|
else
|
begin
|
begin
|
TDOData <= #Tp 0;
|
TDOData <= #Tp 0;
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
ReadBuffer_Tck<=#Tp 0;
|
ReadBuffer_Tck<=#Tp 0;
|
`endif
|
`endif
|
end
|
end
|
end
|
end
|
end
|
end
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: JTAG_DR *
|
* End: JTAG_DR *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* CHAIN_SELECT logic *
|
* CHAIN_SELECT logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp `GLOBAL_BS_CHAIN; // Global BS chain is selected after reset
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp `GLOBAL_BS_CHAIN; // Global BS chain is selected after reset
|
else
|
else
|
if(UpdateDR & CHAIN_SELECTSelected & CrcMatch)
|
if(UpdateDR & CHAIN_SELECTSelected & CrcMatch)
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp JTAG_DR_IN[3:0]; // New chain is selected
|
Chain[`CHAIN_ID_LENGTH-1:0]<=#Tp JTAG_DR_IN[3:0]; // New chain is selected
|
end
|
end
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Register read/write logic *
|
* Register read/write logic *
|
* RISC registers read/write logic *
|
* RISC registers read/write logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
begin
|
begin
|
ADDR[31:0] <=#Tp 32'h0;
|
ADDR[31:0] <=#Tp 32'h0;
|
DataOut[31:0] <=#Tp 32'h0;
|
DataOut[31:0] <=#Tp 32'h0;
|
RW <=#Tp 1'b0;
|
RW <=#Tp 1'b0;
|
RegAccessTck <=#Tp 1'b0;
|
RegAccessTck <=#Tp 1'b0;
|
RISCAccessTck <=#Tp 1'b0;
|
RISCAccessTck <=#Tp 1'b0;
|
wb_AccessTck <=#Tp 1'h0;
|
wb_AccessTck <=#Tp 1'h0;
|
end
|
end
|
else
|
else
|
if(UpdateDR & DEBUGSelected & CrcMatch)
|
if(UpdateDR & DEBUGSelected & CrcMatch)
|
begin
|
begin
|
if(RegisterScanChain)
|
if(RegisterScanChain)
|
begin
|
begin
|
ADDR[4:0] <=#Tp JTAG_DR_IN[4:0]; // Latching address for register access
|
ADDR[4:0] <=#Tp JTAG_DR_IN[4:0]; // Latching address for register access
|
RW <=#Tp JTAG_DR_IN[5]; // latch R/W bit
|
RW <=#Tp JTAG_DR_IN[5]; // latch R/W bit
|
DataOut[31:0] <=#Tp JTAG_DR_IN[37:6]; // latch data for write
|
DataOut[31:0] <=#Tp JTAG_DR_IN[37:6]; // latch data for write
|
RegAccessTck <=#Tp 1'b1;
|
RegAccessTck <=#Tp 1'b1;
|
end
|
end
|
else
|
else
|
if(RiscDebugScanChain)
|
if(RiscDebugScanChain)
|
begin
|
begin
|
ADDR[31:0] <=#Tp JTAG_DR_IN[31:0]; // Latching address for RISC register access
|
ADDR[31:0] <=#Tp JTAG_DR_IN[31:0]; // Latching address for RISC register access
|
RW <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
RW <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
DataOut[31:0] <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
DataOut[31:0] <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
RISCAccessTck <=#Tp 1'b1;
|
RISCAccessTck <=#Tp 1'b1;
|
end
|
end
|
else
|
else
|
if(WishboneScanChain)
|
if(WishboneScanChain)
|
begin
|
begin
|
ADDR <=#Tp JTAG_DR_IN[31:0]; // Latching address for WISHBONE slave access
|
ADDR <=#Tp JTAG_DR_IN[31:0]; // Latching address for WISHBONE slave access
|
RW <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
RW <=#Tp JTAG_DR_IN[32]; // latch R/W bit
|
DataOut <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
DataOut <=#Tp JTAG_DR_IN[64:33]; // latch data for write
|
wb_AccessTck <=#Tp 1'b1; //
|
wb_AccessTck <=#Tp 1'b1; //
|
end
|
end
|
end
|
end
|
else
|
else
|
begin
|
begin
|
RegAccessTck <=#Tp 1'b0; // This signals are valid for one TCK clock period only
|
RegAccessTck <=#Tp 1'b0; // This signals are valid for one TCK clock period only
|
RISCAccessTck <=#Tp 1'b0;
|
RISCAccessTck <=#Tp 1'b0;
|
wb_AccessTck <=#Tp 1'b0;
|
wb_AccessTck <=#Tp 1'b0;
|
end
|
end
|
end
|
end
|
|
|
|
|
assign wb_adr_o = ADDR;
|
assign wb_adr_o = ADDR;
|
assign wb_we_o = RW;
|
assign wb_we_o = RW;
|
assign wb_dat_o = DataOut;
|
assign wb_dat_o = DataOut;
|
assign wb_sel_o[3:0] = 4'hf;
|
assign wb_sel_o[3:0] = 4'hf;
|
assign wb_cab_o = 1'b0;
|
assign wb_cab_o = 1'b0;
|
|
|
|
|
// Synchronizing the RegAccess signal to risc_clk_i clock
|
// Synchronizing the RegAccess signal to risc_clk_i clock
|
dbg_sync_clk1_clk2 syn1 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
dbg_sync_clk1_clk2 syn1 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
.set2(RegAccessTck), .sync_out(RegAccess)
|
.set2(RegAccessTck), .sync_out(RegAccess)
|
);
|
);
|
|
|
// Synchronizing the RISCAccess signal to risc_clk_i clock
|
// Synchronizing the RISCAccess signal to risc_clk_i clock
|
dbg_sync_clk1_clk2 syn2 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
dbg_sync_clk1_clk2 syn2 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
.set2(RISCAccessTck), .sync_out(RISCAccess)
|
.set2(RISCAccessTck), .sync_out(RISCAccess)
|
);
|
);
|
|
|
|
|
// Synchronizing the wb_Access signal to wishbone clock
|
// Synchronizing the wb_Access signal to wishbone clock
|
dbg_sync_clk1_clk2 syn3 (.clk1(wb_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
dbg_sync_clk1_clk2 syn3 (.clk1(wb_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
.set2(wb_AccessTck), .sync_out(wb_Access_wbClk)
|
.set2(wb_AccessTck), .sync_out(wb_Access_wbClk)
|
);
|
);
|
|
|
|
|
|
|
|
|
|
|
// Delayed signals used for accessing registers and RISC
|
// Delayed signals used for accessing registers and RISC
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
begin
|
begin
|
RegAccess_q <=#Tp 1'b0;
|
RegAccess_q <=#Tp 1'b0;
|
RegAccess_q2 <=#Tp 1'b0;
|
RegAccess_q2 <=#Tp 1'b0;
|
RISCAccess_q <=#Tp 1'b0;
|
RISCAccess_q <=#Tp 1'b0;
|
RISCAccess_q2 <=#Tp 1'b0;
|
RISCAccess_q2 <=#Tp 1'b0;
|
end
|
end
|
else
|
else
|
begin
|
begin
|
RegAccess_q <=#Tp RegAccess;
|
RegAccess_q <=#Tp RegAccess;
|
RegAccess_q2 <=#Tp RegAccess_q;
|
RegAccess_q2 <=#Tp RegAccess_q;
|
RISCAccess_q <=#Tp RISCAccess;
|
RISCAccess_q <=#Tp RISCAccess;
|
RISCAccess_q2 <=#Tp RISCAccess_q;
|
RISCAccess_q2 <=#Tp RISCAccess_q;
|
end
|
end
|
end
|
end
|
|
|
|
|
// Latching data read from registers
|
// Latching data read from registers
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
RegisterReadLatch[31:0]<=#Tp 0;
|
RegisterReadLatch[31:0]<=#Tp 0;
|
else
|
else
|
if(RegAccess_q & ~RegAccess_q2)
|
if(RegAccess_q & ~RegAccess_q2)
|
RegisterReadLatch[31:0]<=#Tp RegDataIn[31:0];
|
RegisterReadLatch[31:0]<=#Tp RegDataIn[31:0];
|
end
|
end
|
|
|
|
|
// Chip select and read/write signals for accessing RISC
|
// Chip select and read/write signals for accessing RISC
|
assign RiscStall_write_access = RISCAccess & ~RISCAccess_q & RW;
|
assign RiscStall_write_access = RISCAccess & ~RISCAccess_q & RW;
|
assign RiscStall_read_access = RISCAccess & ~RISCAccess_q2 & ~RW;
|
assign RiscStall_read_access = RISCAccess & ~RISCAccess_q2 & ~RW;
|
assign RiscStall_access = RiscStall_write_access | RiscStall_read_access;
|
assign RiscStall_access = RiscStall_write_access | RiscStall_read_access;
|
|
|
|
|
reg wb_Access_wbClk_q;
|
reg wb_Access_wbClk_q;
|
// Delayed signals used for accessing WISHBONE
|
// Delayed signals used for accessing WISHBONE
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
wb_Access_wbClk_q <=#Tp 1'b0;
|
wb_Access_wbClk_q <=#Tp 1'b0;
|
else
|
else
|
wb_Access_wbClk_q <=#Tp wb_Access_wbClk;
|
wb_Access_wbClk_q <=#Tp wb_Access_wbClk;
|
end
|
end
|
|
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
wb_cyc_o <=#Tp 1'b0;
|
wb_cyc_o <=#Tp 1'b0;
|
else
|
else
|
if(wb_Access_wbClk & ~wb_Access_wbClk_q & ~(wb_ack_i | wb_err_i))
|
if(wb_Access_wbClk & ~wb_Access_wbClk_q & ~(wb_ack_i | wb_err_i))
|
wb_cyc_o <=#Tp 1'b1;
|
wb_cyc_o <=#Tp 1'b1;
|
else
|
else
|
if(wb_ack_i | wb_err_i)
|
if(wb_ack_i | wb_err_i)
|
wb_cyc_o <=#Tp 1'b0;
|
wb_cyc_o <=#Tp 1'b0;
|
end
|
end
|
|
|
assign wb_stb_o = wb_cyc_o;
|
assign wb_stb_o = wb_cyc_o;
|
|
|
|
|
// Latching data read from registers
|
// Latching data read from registers
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
WBReadLatch[31:0]<=#Tp 32'h0;
|
WBReadLatch[31:0]<=#Tp 32'h0;
|
else
|
else
|
if(wb_ack_i)
|
if(wb_ack_i)
|
WBReadLatch[31:0]<=#Tp wb_dat_i[31:0];
|
WBReadLatch[31:0]<=#Tp wb_dat_i[31:0];
|
end
|
end
|
|
|
// Latching WISHBONE error cycle
|
// Latching WISHBONE error cycle
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
always @ (posedge wb_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
WBErrorLatch<=#Tp 1'b0;
|
WBErrorLatch<=#Tp 1'b0;
|
else
|
else
|
if(wb_err_i)
|
if(wb_err_i)
|
WBErrorLatch<=#Tp 1'b1; // Latching wb_err_i while performing WISHBONE access
|
WBErrorLatch<=#Tp 1'b1; // Latching wb_err_i while performing WISHBONE access
|
else
|
else
|
if(wb_ack_i)
|
if(wb_ack_i)
|
WBErrorLatch<=#Tp 1'b0; // Clearing status
|
WBErrorLatch<=#Tp 1'b0; // Clearing status
|
end
|
end
|
|
|
|
|
// Whan enabled, TRACE stalls RISC while saving data to the trace buffer.
|
// Whan enabled, TRACE stalls RISC while saving data to the trace buffer.
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
assign risc_stall_o = RiscStall_access | RiscStall_reg | RiscStall_trace ;
|
assign risc_stall_o = RiscStall_access | RiscStall_reg | RiscStall_trace ;
|
`else
|
`else
|
assign risc_stall_o = RiscStall_access | RiscStall_reg;
|
assign risc_stall_o = RiscStall_access | RiscStall_reg;
|
`endif
|
`endif
|
|
|
assign reset_o = RiscReset_reg;
|
assign reset_o = RiscReset_reg;
|
|
|
|
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
always @ (RiscStall_write_access or RiscStall_read_access or opselect_trace)
|
always @ (RiscStall_write_access or RiscStall_read_access or opselect_trace)
|
`else
|
`else
|
always @ (RiscStall_write_access or RiscStall_read_access)
|
always @ (RiscStall_write_access or RiscStall_read_access)
|
`endif
|
`endif
|
begin
|
begin
|
if(RiscStall_write_access)
|
if(RiscStall_write_access)
|
opselect_o = `DEBUG_WRITE_SPR; // Write spr
|
opselect_o = `DEBUG_WRITE_SPR; // Write spr
|
else
|
else
|
if(RiscStall_read_access)
|
if(RiscStall_read_access)
|
opselect_o = `DEBUG_READ_SPR; // Read spr
|
opselect_o = `DEBUG_READ_SPR; // Read spr
|
else
|
else
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
opselect_o = opselect_trace;
|
opselect_o = opselect_trace;
|
`else
|
`else
|
opselect_o = 3'h0;
|
opselect_o = 3'h0;
|
`endif
|
`endif
|
end
|
end
|
|
|
|
|
|
|
// Latching data read from RISC
|
// Latching data read from RISC
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
always @ (posedge risc_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
RISC_DATAINLatch[31:0]<=#Tp 0;
|
RISC_DATAINLatch[31:0]<=#Tp 0;
|
else
|
else
|
if(RISCAccess_q & ~RISCAccess_q2)
|
if(RISCAccess_q & ~RISCAccess_q2)
|
RISC_DATAINLatch[31:0]<=#Tp risc_data_i[31:0];
|
RISC_DATAINLatch[31:0]<=#Tp risc_data_i[31:0];
|
end
|
end
|
|
|
assign risc_addr_o = ADDR;
|
assign risc_addr_o = ADDR;
|
assign risc_data_o = DataOut;
|
assign risc_data_o = DataOut;
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Read Trace buffer logic *
|
* Read Trace buffer logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
|
|
|
|
// Synchronizing the trace read buffer signal to risc_clk_i clock
|
// Synchronizing the trace read buffer signal to risc_clk_i clock
|
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
dbg_sync_clk1_clk2 syn4 (.clk1(risc_clk_i), .clk2(TCK), .reset1(wb_rst_i), .reset2(trst),
|
.set2(ReadBuffer_Tck), .sync_out(ReadTraceBuffer)
|
.set2(ReadBuffer_Tck), .sync_out(ReadTraceBuffer)
|
);
|
);
|
|
|
|
|
|
|
always @(posedge risc_clk_i or posedge wb_rst_i)
|
always @(posedge risc_clk_i or posedge wb_rst_i)
|
begin
|
begin
|
if(wb_rst_i)
|
if(wb_rst_i)
|
ReadTraceBuffer_q <=#Tp 0;
|
ReadTraceBuffer_q <=#Tp 0;
|
else
|
else
|
ReadTraceBuffer_q <=#Tp ReadTraceBuffer;
|
ReadTraceBuffer_q <=#Tp ReadTraceBuffer;
|
end
|
end
|
|
|
assign ReadTraceBufferPulse = ReadTraceBuffer & ~ReadTraceBuffer_q;
|
assign ReadTraceBufferPulse = ReadTraceBuffer & ~ReadTraceBuffer_q;
|
|
|
`endif
|
`endif
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Read Trace buffer logic *
|
* End: Read Trace buffer logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Bypass logic *
|
* Bypass logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
reg BypassRegister;
|
reg BypassRegister;
|
reg TDOBypassed;
|
reg TDOBypassed;
|
|
|
always @ (posedge TCK)
|
always @ (posedge TCK)
|
begin
|
begin
|
if(ShiftDR)
|
if(ShiftDR)
|
BypassRegister<=#Tp TDI;
|
BypassRegister<=#Tp TDI;
|
end
|
end
|
|
|
always @ (negedge TCK)
|
always @ (negedge TCK)
|
begin
|
begin
|
TDOBypassed<=#Tp BypassRegister;
|
TDOBypassed<=#Tp BypassRegister;
|
end
|
end
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Bypass logic *
|
* End: Bypass logic *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Activating Instructions *
|
* Activating Instructions *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
// Updating JTAG_IR (Instruction Register)
|
// Updating JTAG_IR (Instruction Register)
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
LatchedJTAG_IR <=#Tp `IDCODE; // IDCODE selected after reset
|
LatchedJTAG_IR <=#Tp `IDCODE; // IDCODE selected after reset
|
else
|
else
|
if(UpdateIR)
|
if(UpdateIR)
|
LatchedJTAG_IR <=#Tp JTAG_IR;
|
LatchedJTAG_IR <=#Tp JTAG_IR;
|
end
|
end
|
|
|
|
|
|
|
// Updating JTAG_IR (Instruction Register)
|
// Updating JTAG_IR (Instruction Register)
|
always @ (LatchedJTAG_IR)
|
always @ (LatchedJTAG_IR)
|
begin
|
begin
|
EXTESTSelected = 0;
|
EXTESTSelected = 0;
|
SAMPLE_PRELOADSelected = 0;
|
SAMPLE_PRELOADSelected = 0;
|
IDCODESelected = 0;
|
IDCODESelected = 0;
|
CHAIN_SELECTSelected = 0;
|
CHAIN_SELECTSelected = 0;
|
INTESTSelected = 0;
|
INTESTSelected = 0;
|
CLAMPSelected = 0;
|
CLAMPSelected = 0;
|
CLAMPZSelected = 0;
|
CLAMPZSelected = 0;
|
HIGHZSelected = 0;
|
HIGHZSelected = 0;
|
DEBUGSelected = 0;
|
DEBUGSelected = 0;
|
BYPASSSelected = 0;
|
BYPASSSelected = 0;
|
|
|
case(LatchedJTAG_IR)
|
case(LatchedJTAG_IR)
|
`EXTEST: EXTESTSelected = 1; // External test
|
`EXTEST: EXTESTSelected = 1; // External test
|
`SAMPLE_PRELOAD: SAMPLE_PRELOADSelected = 1; // Sample preload
|
`SAMPLE_PRELOAD: SAMPLE_PRELOADSelected = 1; // Sample preload
|
`IDCODE: IDCODESelected = 1; // ID Code
|
`IDCODE: IDCODESelected = 1; // ID Code
|
`CHAIN_SELECT: CHAIN_SELECTSelected = 1; // Chain select
|
`CHAIN_SELECT: CHAIN_SELECTSelected = 1; // Chain select
|
`INTEST: INTESTSelected = 1; // Internal test
|
`INTEST: INTESTSelected = 1; // Internal test
|
`CLAMP: CLAMPSelected = 1; // Clamp
|
`CLAMP: CLAMPSelected = 1; // Clamp
|
`CLAMPZ: CLAMPZSelected = 1; // ClampZ
|
`CLAMPZ: CLAMPZSelected = 1; // ClampZ
|
`HIGHZ: HIGHZSelected = 1; // High Z
|
`HIGHZ: HIGHZSelected = 1; // High Z
|
`DEBUG: DEBUGSelected = 1; // Debug
|
`DEBUG: DEBUGSelected = 1; // Debug
|
`BYPASS: BYPASSSelected = 1; // BYPASS
|
`BYPASS: BYPASSSelected = 1; // BYPASS
|
default: BYPASSSelected = 1; // BYPASS
|
default: BYPASSSelected = 1; // BYPASS
|
endcase
|
endcase
|
end
|
end
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Multiplexing TDO and Tristate control *
|
* Multiplexing TDO and Tristate control *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
wire TDOShifted;
|
wire TDOShifted;
|
assign TDOShifted = (ShiftIR | Exit1IR)? TDOInstruction : TDOData;
|
assign TDOShifted = (ShiftIR | Exit1IR)? TDOInstruction : TDOData;
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Multiplexing TDO and Tristate control *
|
* End: Multiplexing TDO and Tristate control *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
// This multiplexer can be expanded with number of user registers
|
// This multiplexer can be expanded with number of user registers
|
reg TDOMuxed;
|
reg TDOMuxed;
|
always @ (JTAG_IR or TDOShifted or TDOBypassed or BS_CHAIN_I)
|
always @ (JTAG_IR or TDOShifted or TDOBypassed or BS_CHAIN_I)
|
begin
|
begin
|
case(JTAG_IR)
|
case(JTAG_IR)
|
`IDCODE: // Reading ID code
|
`IDCODE: // Reading ID code
|
begin
|
begin
|
TDOMuxed<=#Tp TDOShifted;
|
TDOMuxed<=#Tp TDOShifted;
|
end
|
end
|
`CHAIN_SELECT: // Selecting the chain
|
`CHAIN_SELECT: // Selecting the chain
|
begin
|
begin
|
TDOMuxed<=#Tp TDOShifted;
|
TDOMuxed<=#Tp TDOShifted;
|
end
|
end
|
`DEBUG: // Debug
|
`DEBUG: // Debug
|
begin
|
begin
|
TDOMuxed<=#Tp TDOShifted;
|
TDOMuxed<=#Tp TDOShifted;
|
end
|
end
|
`SAMPLE_PRELOAD: // Sampling/Preloading
|
`SAMPLE_PRELOAD: // Sampling/Preloading
|
begin
|
begin
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
end
|
end
|
`EXTEST: // External test
|
`EXTEST: // External test
|
begin
|
begin
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
TDOMuxed<=#Tp BS_CHAIN_I;
|
end
|
end
|
default: // BYPASS instruction
|
default: // BYPASS instruction
|
begin
|
begin
|
TDOMuxed<=#Tp TDOBypassed;
|
TDOMuxed<=#Tp TDOBypassed;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
|
|
// Tristate control for tdo_pad_o pin
|
// Tristate control for tdo_pad_o pin
|
assign tdo_pad_o = (ShiftIR | ShiftDR | Exit1IR | Exit1DR | UpdateDR)? TDOMuxed : 1'bz;
|
//assign tdo_pad_o = (ShiftIR | ShiftDR | Exit1IR | Exit1DR | UpdateDR)? TDOMuxed : 1'bz;
|
|
assign tdo_pad_o = TDOMuxed;
|
|
assign tdo_padoen_o = ShiftIR | ShiftDR | Exit1IR | Exit1DR | UpdateDR;
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Activating Instructions *
|
* End: Activating Instructions *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Bit counter *
|
* Bit counter *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
BitCounter[7:0]<=#Tp 0;
|
BitCounter[7:0]<=#Tp 0;
|
else
|
else
|
if(ShiftDR)
|
if(ShiftDR)
|
BitCounter[7:0]<=#Tp BitCounter[7:0]+1;
|
BitCounter[7:0]<=#Tp BitCounter[7:0]+1;
|
else
|
else
|
if(UpdateDR)
|
if(UpdateDR)
|
BitCounter[7:0]<=#Tp 0;
|
BitCounter[7:0]<=#Tp 0;
|
end
|
end
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Bit counter *
|
* End: Bit counter *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Connecting Registers *
|
* Connecting Registers *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
dbg_registers dbgregs(.DataIn(DataOut[31:0]), .DataOut(RegDataIn[31:0]),
|
dbg_registers dbgregs(.DataIn(DataOut[31:0]), .DataOut(RegDataIn[31:0]),
|
.Address(ADDR[4:0]), .RW(RW), .Access(RegAccess & ~RegAccess_q), .Clk(risc_clk_i),
|
.Address(ADDR[4:0]), .RW(RW), .Access(RegAccess & ~RegAccess_q), .Clk(risc_clk_i),
|
.Bp(bp_i), .Reset(wb_rst_i),
|
.Bp(bp_i), .Reset(wb_rst_i),
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
.ContinMode(ContinMode), .TraceEnable(TraceEnable),
|
.ContinMode(ContinMode), .TraceEnable(TraceEnable),
|
.WpTrigger(WpTrigger), .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger),
|
.WpTrigger(WpTrigger), .BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger),
|
.ITrigger(ITrigger), .TriggerOper(TriggerOper), .WpQualif(WpQualif),
|
.ITrigger(ITrigger), .TriggerOper(TriggerOper), .WpQualif(WpQualif),
|
.BpQualif(BpQualif), .LSSQualif(LSSQualif), .IQualif(IQualif),
|
.BpQualif(BpQualif), .LSSQualif(LSSQualif), .IQualif(IQualif),
|
.QualifOper(QualifOper), .RecordPC(RecordPC),
|
.QualifOper(QualifOper), .RecordPC(RecordPC),
|
.RecordLSEA(RecordLSEA), .RecordLDATA(RecordLDATA),
|
.RecordLSEA(RecordLSEA), .RecordLDATA(RecordLDATA),
|
.RecordSDATA(RecordSDATA), .RecordReadSPR(RecordReadSPR),
|
.RecordSDATA(RecordSDATA), .RecordReadSPR(RecordReadSPR),
|
.RecordWriteSPR(RecordWriteSPR), .RecordINSTR(RecordINSTR),
|
.RecordWriteSPR(RecordWriteSPR), .RecordINSTR(RecordINSTR),
|
.WpTriggerValid(WpTriggerValid),
|
.WpTriggerValid(WpTriggerValid),
|
.BpTriggerValid(BpTriggerValid), .LSSTriggerValid(LSSTriggerValid),
|
.BpTriggerValid(BpTriggerValid), .LSSTriggerValid(LSSTriggerValid),
|
.ITriggerValid(ITriggerValid), .WpQualifValid(WpQualifValid),
|
.ITriggerValid(ITriggerValid), .WpQualifValid(WpQualifValid),
|
.BpQualifValid(BpQualifValid), .LSSQualifValid(LSSQualifValid),
|
.BpQualifValid(BpQualifValid), .LSSQualifValid(LSSQualifValid),
|
.IQualifValid(IQualifValid),
|
.IQualifValid(IQualifValid),
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid),
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid),
|
`endif
|
`endif
|
.RiscStall(RiscStall_reg), .RiscReset(RiscReset_reg)
|
.RiscStall(RiscStall_reg), .RiscReset(RiscReset_reg)
|
|
|
);
|
);
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Connecting Registers *
|
* End: Connecting Registers *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Connecting CRC module *
|
* Connecting CRC module *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
wire AsyncResetCrc = trst;
|
wire AsyncResetCrc = trst;
|
wire SyncResetCrc = UpdateDR_q;
|
wire SyncResetCrc = UpdateDR_q;
|
wire [7:0] CalculatedCrcIn; // crc calculated from the input data (shifted in)
|
wire [7:0] CalculatedCrcIn; // crc calculated from the input data (shifted in)
|
|
|
wire EnableCrcIn = ShiftDR &
|
wire EnableCrcIn = ShiftDR &
|
( (CHAIN_SELECTSelected & (BitCounter<4)) |
|
( (CHAIN_SELECTSelected & (BitCounter<4)) |
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
);
|
);
|
|
|
wire EnableCrcOut= ShiftDR &
|
wire EnableCrcOut= ShiftDR &
|
(
|
(
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
((DEBUGSelected & RegisterScanChain) & (BitCounter<38)) |
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
((DEBUGSelected & RiscDebugScanChain) & (BitCounter<65)) |
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
((DEBUGSelected & WishboneScanChain) & (BitCounter<65))
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
|
|
|
|
((DEBUGSelected & TraceTestScanChain) & (BitCounter<40))
|
((DEBUGSelected & TraceTestScanChain) & (BitCounter<40))
|
`endif
|
`endif
|
);
|
);
|
|
|
// Calculating crc for input data
|
// Calculating crc for input data
|
dbg_crc8_d1 crc1 (.Data(TDI), .EnableCrc(EnableCrcIn), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
dbg_crc8_d1 crc1 (.Data(TDI), .EnableCrc(EnableCrcIn), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
.CrcOut(CalculatedCrcIn), .Clk(TCK));
|
.CrcOut(CalculatedCrcIn), .Clk(TCK));
|
|
|
// Calculating crc for output data
|
// Calculating crc for output data
|
dbg_crc8_d1 crc2 (.Data(TDOData), .EnableCrc(EnableCrcOut), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
dbg_crc8_d1 crc2 (.Data(TDOData), .EnableCrc(EnableCrcOut), .Reset(AsyncResetCrc), .SyncResetCrc(SyncResetCrc),
|
.CrcOut(CalculatedCrcOut), .Clk(TCK));
|
.CrcOut(CalculatedCrcOut), .Clk(TCK));
|
|
|
|
|
// Generating CrcMatch signal
|
// Generating CrcMatch signal
|
always @ (posedge TCK or posedge trst)
|
always @ (posedge TCK or posedge trst)
|
begin
|
begin
|
if(trst)
|
if(trst)
|
CrcMatch <=#Tp 1'b0;
|
CrcMatch <=#Tp 1'b0;
|
else
|
else
|
if(Exit1DR)
|
if(Exit1DR)
|
begin
|
begin
|
if(CHAIN_SELECTSelected)
|
if(CHAIN_SELECTSelected)
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[11:4];
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[11:4];
|
else
|
else
|
if(RegisterScanChain & ~CHAIN_SELECTSelected)
|
if(RegisterScanChain & ~CHAIN_SELECTSelected)
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[45:38];
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[45:38];
|
else
|
else
|
if(RiscDebugScanChain & ~CHAIN_SELECTSelected)
|
if(RiscDebugScanChain & ~CHAIN_SELECTSelected)
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
else
|
else
|
if(WishboneScanChain & ~CHAIN_SELECTSelected)
|
if(WishboneScanChain & ~CHAIN_SELECTSelected)
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
CrcMatch <=#Tp CalculatedCrcIn == JTAG_DR_IN[72:65];
|
end
|
end
|
end
|
end
|
|
|
|
|
// Active chain
|
// Active chain
|
assign RegisterScanChain = Chain == `REGISTER_SCAN_CHAIN;
|
assign RegisterScanChain = Chain == `REGISTER_SCAN_CHAIN;
|
assign RiscDebugScanChain = Chain == `RISC_DEBUG_CHAIN;
|
assign RiscDebugScanChain = Chain == `RISC_DEBUG_CHAIN;
|
assign WishboneScanChain = Chain == `WISHBONE_SCAN_CHAIN;
|
assign WishboneScanChain = Chain == `WISHBONE_SCAN_CHAIN;
|
|
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
assign TraceTestScanChain = Chain == `TRACE_TEST_CHAIN;
|
assign TraceTestScanChain = Chain == `TRACE_TEST_CHAIN;
|
`endif
|
`endif
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Connecting CRC module *
|
* End: Connecting CRC module *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* Connecting trace module *
|
* Connecting trace module *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
`ifdef TRACE_ENABLED
|
`ifdef TRACE_ENABLED
|
dbg_trace dbgTrace1(.Wp(wp_i), .Bp(bp_i), .DataIn(risc_data_i), .OpSelect(opselect_trace),
|
dbg_trace dbgTrace1(.Wp(wp_i), .Bp(bp_i), .DataIn(risc_data_i), .OpSelect(opselect_trace),
|
.LsStatus(lsstatus_i), .IStatus(istatus_i), .RiscStall_O(RiscStall_trace),
|
.LsStatus(lsstatus_i), .IStatus(istatus_i), .RiscStall_O(RiscStall_trace),
|
.Mclk(risc_clk_i), .Reset(wb_rst_i), .TraceChain(TraceChain),
|
.Mclk(risc_clk_i), .Reset(wb_rst_i), .TraceChain(TraceChain),
|
.ContinMode(ContinMode), .TraceEnable_reg(TraceEnable),
|
.ContinMode(ContinMode), .TraceEnable_reg(TraceEnable),
|
.WpTrigger(WpTrigger),
|
.WpTrigger(WpTrigger),
|
.BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger), .ITrigger(ITrigger),
|
.BpTrigger(BpTrigger), .LSSTrigger(LSSTrigger), .ITrigger(ITrigger),
|
.TriggerOper(TriggerOper), .WpQualif(WpQualif), .BpQualif(BpQualif),
|
.TriggerOper(TriggerOper), .WpQualif(WpQualif), .BpQualif(BpQualif),
|
.LSSQualif(LSSQualif), .IQualif(IQualif), .QualifOper(QualifOper),
|
.LSSQualif(LSSQualif), .IQualif(IQualif), .QualifOper(QualifOper),
|
.RecordPC(RecordPC), .RecordLSEA(RecordLSEA),
|
.RecordPC(RecordPC), .RecordLSEA(RecordLSEA),
|
.RecordLDATA(RecordLDATA), .RecordSDATA(RecordSDATA),
|
.RecordLDATA(RecordLDATA), .RecordSDATA(RecordSDATA),
|
.RecordReadSPR(RecordReadSPR), .RecordWriteSPR(RecordWriteSPR),
|
.RecordReadSPR(RecordReadSPR), .RecordWriteSPR(RecordWriteSPR),
|
.RecordINSTR(RecordINSTR),
|
.RecordINSTR(RecordINSTR),
|
.WpTriggerValid(WpTriggerValid), .BpTriggerValid(BpTriggerValid),
|
.WpTriggerValid(WpTriggerValid), .BpTriggerValid(BpTriggerValid),
|
.LSSTriggerValid(LSSTriggerValid), .ITriggerValid(ITriggerValid),
|
.LSSTriggerValid(LSSTriggerValid), .ITriggerValid(ITriggerValid),
|
.WpQualifValid(WpQualifValid), .BpQualifValid(BpQualifValid),
|
.WpQualifValid(WpQualifValid), .BpQualifValid(BpQualifValid),
|
.LSSQualifValid(LSSQualifValid), .IQualifValid(IQualifValid),
|
.LSSQualifValid(LSSQualifValid), .IQualifValid(IQualifValid),
|
.ReadBuffer(ReadTraceBufferPulse),
|
.ReadBuffer(ReadTraceBufferPulse),
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
.WpStop(WpStop), .BpStop(BpStop), .LSSStop(LSSStop), .IStop(IStop),
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
.StopOper(StopOper), .WpStopValid(WpStopValid), .BpStopValid(BpStopValid),
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid)
|
.LSSStopValid(LSSStopValid), .IStopValid(IStopValid)
|
);
|
);
|
`endif
|
`endif
|
/**********************************************************************************
|
/**********************************************************************************
|
* *
|
* *
|
* End: Connecting trace module *
|
* End: Connecting trace module *
|
* *
|
* *
|
**********************************************************************************/
|
**********************************************************************************/
|
|
|
|
|
|
|
endmodule
|
endmodule
|
|
|