feat: publish FreeRTOS C FC05 card
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// APB-to-APB asynchronous bridge for connecting DTM to DM, in case DTM is in
|
||||
// a different clock domain (e.g. running directly from crystal to get a
|
||||
// fixed baud reference)
|
||||
//
|
||||
// Note this module depends on the hazard3_sync_1bit module (a flop-chain
|
||||
// synchroniser) which should be reimplemented for your FPGA/process.
|
||||
|
||||
`ifndef HAZARD3_REG_KEEP_ATTRIBUTE
|
||||
`define HAZARD3_REG_KEEP_ATTRIBUTE (* keep = 1'b1 *)
|
||||
`endif
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_apb_async_bridge #(
|
||||
parameter W_ADDR = 8,
|
||||
parameter W_DATA = 32,
|
||||
parameter N_SYNC_STAGES = 2
|
||||
) (
|
||||
// Resets assumed to be synchronised externally
|
||||
input wire clk_src,
|
||||
input wire rst_n_src,
|
||||
|
||||
input wire clk_dst,
|
||||
input wire rst_n_dst,
|
||||
|
||||
// APB port from Transport Module
|
||||
input wire src_psel,
|
||||
input wire src_penable,
|
||||
input wire src_pwrite,
|
||||
input wire [W_ADDR-1:0] src_paddr,
|
||||
input wire [W_DATA-1:0] src_pwdata,
|
||||
output wire [W_DATA-1:0] src_prdata,
|
||||
output wire src_pready,
|
||||
output wire src_pslverr,
|
||||
|
||||
// APB port to Debug Module
|
||||
output wire dst_psel,
|
||||
output wire dst_penable,
|
||||
output wire dst_pwrite,
|
||||
output wire [W_ADDR-1:0] dst_paddr,
|
||||
output wire [W_DATA-1:0] dst_pwdata,
|
||||
input wire [W_DATA-1:0] dst_prdata,
|
||||
input wire dst_pready,
|
||||
input wire dst_pslverr
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Clock-crossing registers
|
||||
|
||||
// We're using a modified req/ack handshake:
|
||||
//
|
||||
// - Initially both req and ack are low
|
||||
// - src asserts req high
|
||||
// - dst responds with ack high and begins transfer
|
||||
// - src deasserts req once it sees ack high
|
||||
// - dst deasserts ack once:
|
||||
// - transfer is complete *and*
|
||||
// - dst sees req deasserted
|
||||
// - Once src sees ack low, a new transfer can begin.
|
||||
//
|
||||
// A NRZI toggle handshake might be more appropriate, but can cause spurious
|
||||
// bus accesses when only one side of the link is reset.
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg src_req;
|
||||
wire dst_req;
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg dst_ack;
|
||||
wire src_ack;
|
||||
|
||||
// Note the launch registers are not resettable. We maintain setup/hold on
|
||||
// launch-to-capture paths thanks to the req/ack handshake. A stray reset
|
||||
// could violate this.
|
||||
//
|
||||
// The req/ack logic itself can be reset safely because the receiving domain
|
||||
// is protected from metastability by a 2FF synchroniser.
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [W_ADDR + W_DATA + 1 -1:0] src_paddr_pwdata_pwrite; // launch
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [W_ADDR + W_DATA + 1 -1:0] dst_paddr_pwdata_pwrite; // capture
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [W_DATA + 1 -1:0] dst_prdata_pslverr; // launch
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [W_DATA + 1 -1:0] src_prdata_pslverr; // capture
|
||||
|
||||
hazard3_sync_1bit #(
|
||||
.N_STAGES (N_SYNC_STAGES)
|
||||
) sync_req (
|
||||
.clk (clk_dst),
|
||||
.rst_n (rst_n_dst),
|
||||
.i (src_req),
|
||||
.o (dst_req)
|
||||
);
|
||||
|
||||
hazard3_sync_1bit #(
|
||||
.N_STAGES (N_SYNC_STAGES)
|
||||
) sync_ack (
|
||||
.clk (clk_src),
|
||||
.rst_n (rst_n_src),
|
||||
.i (dst_ack),
|
||||
.o (src_ack)
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// src state machine
|
||||
|
||||
reg src_waiting_for_downstream;
|
||||
reg src_pready_r;
|
||||
|
||||
always @ (posedge clk_src or negedge rst_n_src) begin
|
||||
if (!rst_n_src) begin
|
||||
src_req <= 1'b0;
|
||||
src_waiting_for_downstream <= 1'b0;
|
||||
src_prdata_pslverr <= {W_DATA + 1{1'b0}};
|
||||
src_pready_r <= 1'b1;
|
||||
end else if (src_waiting_for_downstream) begin
|
||||
if (src_req && src_ack) begin
|
||||
// Request was acknowledged, so deassert.
|
||||
src_req <= 1'b0;
|
||||
end else if (!(src_req || src_ack)) begin
|
||||
// Downstream transfer has finished, data is valid.
|
||||
src_pready_r <= 1'b1;
|
||||
src_waiting_for_downstream <= 1'b0;
|
||||
// Note this assignment is cross-domain (but data has been stable
|
||||
// for duration of ack synchronisation delay):
|
||||
src_prdata_pslverr <= dst_prdata_pslverr;
|
||||
end
|
||||
end else begin
|
||||
// paddr, pwdata and pwrite are all valid during the setup phase, and
|
||||
// APB defines the setup phase to always last one cycle and proceed
|
||||
// to access phase. So, we can ignore penable, and pready is ignored.
|
||||
if (src_psel) begin
|
||||
src_pready_r <= 1'b0;
|
||||
src_req <= 1'b1;
|
||||
src_waiting_for_downstream <= 1'b1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// Bus request launch register is not resettable
|
||||
always @ (posedge clk_src) begin
|
||||
if (src_psel && !src_waiting_for_downstream)
|
||||
src_paddr_pwdata_pwrite <= {src_paddr, src_pwdata, src_pwrite};
|
||||
end
|
||||
|
||||
assign {src_prdata, src_pslverr} = src_prdata_pslverr;
|
||||
assign src_pready = src_pready_r;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// dst state machine
|
||||
|
||||
wire dst_bus_finish = dst_penable && dst_pready;
|
||||
reg dst_psel_r;
|
||||
reg dst_penable_r;
|
||||
|
||||
always @ (posedge clk_dst or negedge rst_n_dst) begin
|
||||
if (!rst_n_dst) begin
|
||||
dst_ack <= 1'b0;
|
||||
end else if (dst_req) begin
|
||||
dst_ack <= 1'b1;
|
||||
end else if (!dst_req && dst_ack && !dst_psel_r) begin
|
||||
dst_ack <= 1'b0;
|
||||
end
|
||||
end
|
||||
|
||||
always @ (posedge clk_dst or negedge rst_n_dst) begin
|
||||
if (!rst_n_dst) begin
|
||||
dst_psel_r <= 1'b0;
|
||||
dst_penable_r <= 1'b0;
|
||||
dst_paddr_pwdata_pwrite <= {W_ADDR + W_DATA + 1{1'b0}};
|
||||
end else if (dst_req && !dst_ack) begin
|
||||
dst_psel_r <= 1'b1;
|
||||
// Note this assignment is cross-domain. The src register has been
|
||||
// stable for the duration of the req sync delay.
|
||||
dst_paddr_pwdata_pwrite <= src_paddr_pwdata_pwrite;
|
||||
end else if (dst_psel_r && !dst_penable_r) begin
|
||||
dst_penable_r <= 1'b1;
|
||||
end else if (dst_bus_finish) begin
|
||||
dst_psel_r <= 1'b0;
|
||||
dst_penable_r <= 1'b0;
|
||||
end
|
||||
end
|
||||
|
||||
// Bus response launch register is not resettable
|
||||
always @ (posedge clk_dst) begin
|
||||
if (dst_bus_finish)
|
||||
dst_prdata_pslverr <= {dst_prdata, dst_pslverr};
|
||||
end
|
||||
|
||||
assign dst_psel = dst_psel_r;
|
||||
assign dst_penable = dst_penable_r;
|
||||
assign {dst_paddr, dst_pwdata, dst_pwrite} = dst_paddr_pwdata_pwrite;
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// The output is asserted asynchronously when the input is asserted,
|
||||
// but deasserted synchronously when clocked with the input deasserted.
|
||||
// Input and output are both active-low.
|
||||
//
|
||||
// This is a baseline implementation -- you should replace it with cells
|
||||
// specific to your FPGA/process
|
||||
|
||||
`ifndef HAZARD3_REG_KEEP_ATTRIBUTE
|
||||
`define HAZARD3_REG_KEEP_ATTRIBUTE (* keep = 1'b1 *)
|
||||
`endif
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_reset_sync #(
|
||||
parameter N_STAGES = 2 // Should be >= 2
|
||||
) (
|
||||
input wire clk,
|
||||
input wire rst_n_in,
|
||||
output wire rst_n_out
|
||||
);
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [N_STAGES-1:0] delay;
|
||||
|
||||
always @ (posedge clk or negedge rst_n_in)
|
||||
if (!rst_n_in)
|
||||
delay <= {N_STAGES{1'b0}};
|
||||
else
|
||||
delay <= {delay[N_STAGES-2:0], 1'b1};
|
||||
|
||||
assign rst_n_out = delay[N_STAGES-1];
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,39 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// A 2FF synchronizer to mitigate metastabilities. This is a baseline
|
||||
// implementation -- you should replace it with cells specific to your
|
||||
// FPGA/process
|
||||
|
||||
`ifndef HAZARD3_REG_KEEP_ATTRIBUTE
|
||||
`define HAZARD3_REG_KEEP_ATTRIBUTE (* keep = 1'b1 *) (* async_reg *)
|
||||
`endif
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_sync_1bit #(
|
||||
parameter N_STAGES = 2 // Should be >=2
|
||||
) (
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
input wire i,
|
||||
output wire o
|
||||
);
|
||||
|
||||
`HAZARD3_REG_KEEP_ATTRIBUTE reg [N_STAGES-1:0] sync_flops;
|
||||
|
||||
always @ (posedge clk or negedge rst_n)
|
||||
if (!rst_n)
|
||||
sync_flops <= {N_STAGES{1'b0}};
|
||||
else
|
||||
sync_flops <= {sync_flops[N_STAGES-2:0], i};
|
||||
|
||||
assign o = sync_flops[N_STAGES-1];
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
+1
@@ -0,0 +1 @@
|
||||
file hazard3_dm.v
|
||||
+904
@@ -0,0 +1,904 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// RISC-V Debug Module for Hazard3. Supports up to 32 cores (1 hart per core).
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_dm #(
|
||||
// Where there are multiple harts per DM, the least-indexed hart is the
|
||||
// least-significant on each concatenated hart access bus.
|
||||
parameter N_HARTS = 1,
|
||||
// Where there are multiple DMs, the address of each DM should be a
|
||||
// multiple of 'h200, so that bits[8:2] decode correctly.
|
||||
parameter NEXT_DM_ADDR = 32'h0000_0000,
|
||||
// Implement support for system bus access:
|
||||
parameter HAVE_SBA = 0,
|
||||
|
||||
// Do not modify:
|
||||
parameter XLEN = 32, // Do not modify
|
||||
parameter W_HARTSEL = N_HARTS > 1 ? $clog2(N_HARTS) : 1 // Do not modify
|
||||
) (
|
||||
// DM is assumed to be in same clock domain as core; clock crossing
|
||||
// (if any) is inside DTM, or between DTM and DM.
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
|
||||
// APB access from Debug Transport Module
|
||||
input wire dmi_psel,
|
||||
input wire dmi_penable,
|
||||
input wire dmi_pwrite,
|
||||
input wire [8:0] dmi_paddr,
|
||||
input wire [31:0] dmi_pwdata,
|
||||
output reg [31:0] dmi_prdata,
|
||||
output wire dmi_pready,
|
||||
output wire dmi_pslverr,
|
||||
|
||||
// Reset request/acknowledge. "req" is a pulse >= 1 cycle wide. "done" is
|
||||
// level-sensitive, goes high once component is out of reset.
|
||||
//
|
||||
// The "sys" reset (ndmreset) is conventionally everything apart from DM +
|
||||
// DTM, but, as per section 3.2 in 0.13.2 debug spec: "Exactly what is
|
||||
// affected by this reset is implementation dependent, as long as it is
|
||||
// possible to debug programs from the first instruction executed." So
|
||||
// this could simply be an all-hart reset.
|
||||
output wire sys_reset_req,
|
||||
input wire sys_reset_done,
|
||||
output wire [N_HARTS-1:0] hart_reset_req,
|
||||
input wire [N_HARTS-1:0] hart_reset_done,
|
||||
|
||||
// Hart run/halt control
|
||||
output wire [N_HARTS-1:0] hart_req_halt,
|
||||
output wire [N_HARTS-1:0] hart_req_halt_on_reset,
|
||||
output wire [N_HARTS-1:0] hart_req_resume,
|
||||
input wire [N_HARTS-1:0] hart_halted,
|
||||
input wire [N_HARTS-1:0] hart_running,
|
||||
|
||||
// Hart access to data0 CSR (assumed to be core-internal but per-hart)
|
||||
output wire [N_HARTS*XLEN-1:0] hart_data0_rdata,
|
||||
input wire [N_HARTS*XLEN-1:0] hart_data0_wdata,
|
||||
input wire [N_HARTS-1:0] hart_data0_wen,
|
||||
|
||||
// Hart instruction injection
|
||||
output wire [N_HARTS*32-1:0] hart_instr_data,
|
||||
output reg [N_HARTS-1:0] hart_instr_data_vld,
|
||||
input wire [N_HARTS-1:0] hart_instr_data_rdy,
|
||||
input wire [N_HARTS-1:0] hart_instr_caught_exception,
|
||||
input wire [N_HARTS-1:0] hart_instr_caught_ebreak,
|
||||
|
||||
// System bus access (optional) -- can be hooked up to the standalone AHB
|
||||
// shim (hazard3_sbus_to_ahb.v) or the SBA input port on the processor
|
||||
// wrapper, which muxes SBA into the processor's load/store bus access
|
||||
// port. SBA does not increase debugger bus throughput, but supports
|
||||
// minimally intrusive debug bus access for e.g. Segger RTT.
|
||||
output wire [31:0] sbus_addr,
|
||||
output wire sbus_write,
|
||||
output wire [1:0] sbus_size,
|
||||
output wire sbus_vld,
|
||||
input wire sbus_rdy,
|
||||
input wire sbus_err,
|
||||
output wire [31:0] sbus_wdata,
|
||||
input wire [31:0] sbus_rdata
|
||||
);
|
||||
|
||||
wire dmi_write = dmi_psel && dmi_penable && dmi_pready && dmi_pwrite;
|
||||
wire dmi_read = dmi_psel && dmi_penable && dmi_pready && !dmi_pwrite;
|
||||
assign dmi_pready = 1'b1;
|
||||
assign dmi_pslverr = 1'b0;
|
||||
|
||||
// Program buffer is fixed at 2 words plus impebreak. The main thing we care
|
||||
// about is support for efficient memory block transfers using abstractauto;
|
||||
// in this case 2 words + impebreak is sufficient for RV32I, and 1 word +
|
||||
// impebreak is sufficient for RV32IC.
|
||||
localparam PROGBUF_SIZE = 2;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Address constants
|
||||
|
||||
localparam ADDR_DATA0 = 7'h04;
|
||||
// Other data registers not present.
|
||||
localparam ADDR_DMCONTROL = 7'h10;
|
||||
localparam ADDR_DMSTATUS = 7'h11;
|
||||
localparam ADDR_HARTINFO = 7'h12;
|
||||
localparam ADDR_HALTSUM1 = 7'h13;
|
||||
localparam ADDR_HALTSUM0 = 7'h40;
|
||||
// No HALTSUM2+ registers (we don't support >32 harts anyway)
|
||||
localparam ADDR_HAWINDOWSEL = 7'h14;
|
||||
localparam ADDR_HAWINDOW = 7'h15;
|
||||
localparam ADDR_ABSTRACTCS = 7'h16;
|
||||
localparam ADDR_COMMAND = 7'h17;
|
||||
localparam ADDR_ABSTRACTAUTO = 7'h18;
|
||||
localparam ADDR_CONFSTRPTR0 = 7'h19;
|
||||
localparam ADDR_CONFSTRPTR1 = 7'h1a;
|
||||
localparam ADDR_CONFSTRPTR2 = 7'h1b;
|
||||
localparam ADDR_CONFSTRPTR3 = 7'h1c;
|
||||
localparam ADDR_NEXTDM = 7'h1d;
|
||||
localparam ADDR_PROGBUF0 = 7'h20;
|
||||
localparam ADDR_PROGBUF1 = 7'h21;
|
||||
// No authentication
|
||||
localparam ADDR_SBCS = 7'h38;
|
||||
localparam ADDR_SBADDRESS0 = 7'h39;
|
||||
localparam ADDR_SBDATA0 = 7'h3c;
|
||||
|
||||
// APB is byte-addressed, DM registers are word-addressed.
|
||||
wire [6:0] dmi_regaddr = dmi_paddr[8:2];
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Hart selection
|
||||
|
||||
reg dmactive;
|
||||
|
||||
// Some fiddliness to make sure we get a single-wide zero-valued signal when
|
||||
// N_HARTS == 1 (so we can use this for indexing of per-hart signals)
|
||||
reg [W_HARTSEL-1:0] hartsel;
|
||||
wire [W_HARTSEL-1:0] hartsel_next;
|
||||
|
||||
generate
|
||||
if (N_HARTS > 1) begin: has_hartsel
|
||||
|
||||
// Only the lower 10 bits of hartsel are supported
|
||||
assign hartsel_next = dmi_write && dmi_regaddr == ADDR_DMCONTROL ?
|
||||
dmi_pwdata[16 +: W_HARTSEL] : hartsel;
|
||||
|
||||
end else begin: has_no_hartsel
|
||||
|
||||
assign hartsel_next = 1'b0;
|
||||
|
||||
end
|
||||
endgenerate
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
hartsel <= {W_HARTSEL{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
hartsel <= {W_HARTSEL{1'b0}};
|
||||
end else begin
|
||||
hartsel <= hartsel_next;
|
||||
end
|
||||
end
|
||||
|
||||
// Also implement the hart array mask if there is more than one hart.
|
||||
reg [N_HARTS-1:0] hart_array_mask;
|
||||
reg hasel;
|
||||
wire [N_HARTS-1:0] hart_array_mask_next;
|
||||
wire hasel_next;
|
||||
|
||||
generate
|
||||
if (N_HARTS > 1) begin: has_array_mask
|
||||
|
||||
assign hart_array_mask_next = dmi_write && dmi_regaddr == ADDR_HAWINDOW ?
|
||||
dmi_pwdata[N_HARTS-1:0] : hart_array_mask;
|
||||
assign hasel_next = dmi_write && dmi_regaddr == ADDR_DMCONTROL ?
|
||||
dmi_pwdata[26] : hasel;
|
||||
|
||||
end else begin: has_no_array_mask
|
||||
|
||||
assign hart_array_mask_next = 1'b0;
|
||||
assign hasel_next = 1'b0;
|
||||
|
||||
end
|
||||
endgenerate
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
hart_array_mask <= {N_HARTS{1'b0}};
|
||||
hasel <= 1'b0;
|
||||
end else if (!dmactive) begin
|
||||
hart_array_mask <= {N_HARTS{1'b0}};
|
||||
hasel <= 1'b0;
|
||||
end else begin
|
||||
hart_array_mask <= hart_array_mask_next;
|
||||
hasel <= hasel_next;
|
||||
end
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Run/halt/reset control
|
||||
|
||||
// Normal read/write fields for dmcontrol (note some of these are per-hart
|
||||
// fields that get rotated into dmcontrol based on the current/next hartsel).
|
||||
reg [N_HARTS-1:0] dmcontrol_haltreq;
|
||||
reg [N_HARTS-1:0] dmcontrol_hartreset;
|
||||
reg [N_HARTS-1:0] dmcontrol_resethaltreq;
|
||||
reg dmcontrol_ndmreset;
|
||||
|
||||
wire [N_HARTS-1:0] dmcontrol_op_mask;
|
||||
|
||||
generate
|
||||
if (N_HARTS > 1) begin: dmcontrol_multiple_harts
|
||||
|
||||
// Selection is the hart selected by hartsel, *plus* the hart array mask
|
||||
// if hasel is set. Note we don't need to use the "next" version of
|
||||
// hart_array_mask since it can't change simultaneously with dmcontrol.
|
||||
assign dmcontrol_op_mask =
|
||||
(hartsel_next >= N_HARTS ? {N_HARTS{1'b0}} : {{N_HARTS-1{1'b0}}, 1'b1} << hartsel_next)
|
||||
| ({N_HARTS{hasel_next}} & hart_array_mask);
|
||||
|
||||
end else begin: dmcontrol_single_hart
|
||||
|
||||
assign dmcontrol_op_mask = 1'b1;
|
||||
|
||||
end
|
||||
endgenerate
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
dmactive <= 1'b0;
|
||||
dmcontrol_ndmreset <= 1'b0;
|
||||
dmcontrol_haltreq <= {N_HARTS{1'b0}};
|
||||
dmcontrol_hartreset <= {N_HARTS{1'b0}};
|
||||
dmcontrol_resethaltreq <= {N_HARTS{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
// Only dmactive is writable when !dmactive
|
||||
if (dmi_write && dmi_regaddr == ADDR_DMCONTROL)
|
||||
dmactive <= dmi_pwdata[0];
|
||||
dmcontrol_ndmreset <= 1'b0;
|
||||
dmcontrol_haltreq <= {N_HARTS{1'b0}};
|
||||
dmcontrol_hartreset <= {N_HARTS{1'b0}};
|
||||
dmcontrol_resethaltreq <= {N_HARTS{1'b0}};
|
||||
end else if (dmi_write && dmi_regaddr == ADDR_DMCONTROL) begin
|
||||
dmactive <= dmi_pwdata[0];
|
||||
dmcontrol_ndmreset <= dmi_pwdata[1];
|
||||
|
||||
dmcontrol_haltreq <= (dmcontrol_haltreq & ~dmcontrol_op_mask) |
|
||||
({N_HARTS{dmi_pwdata[31]}} & dmcontrol_op_mask);
|
||||
|
||||
dmcontrol_hartreset <= (dmcontrol_hartreset & ~dmcontrol_op_mask) |
|
||||
({N_HARTS{dmi_pwdata[29]}} & dmcontrol_op_mask);
|
||||
|
||||
dmcontrol_resethaltreq <= (dmcontrol_resethaltreq
|
||||
& ~({N_HARTS{dmi_pwdata[2]}} & dmcontrol_op_mask))
|
||||
| ({N_HARTS{dmi_pwdata[3]}} & dmcontrol_op_mask);
|
||||
end
|
||||
end
|
||||
|
||||
assign sys_reset_req = dmcontrol_ndmreset;
|
||||
assign hart_reset_req = dmcontrol_hartreset;
|
||||
assign hart_req_halt = dmcontrol_haltreq;
|
||||
assign hart_req_halt_on_reset = dmcontrol_resethaltreq;
|
||||
|
||||
reg [N_HARTS-1:0] hart_reset_done_prev;
|
||||
reg [N_HARTS-1:0] dmstatus_havereset;
|
||||
wire [N_HARTS-1:0] hart_available = hart_reset_done & {N_HARTS{sys_reset_done}};
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
hart_reset_done_prev <= {N_HARTS{1'b0}};
|
||||
end else begin
|
||||
hart_reset_done_prev <= hart_reset_done;
|
||||
end
|
||||
end
|
||||
|
||||
wire dmcontrol_ackhavereset = dmi_write && dmi_regaddr == ADDR_DMCONTROL && dmi_pwdata[28];
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
dmstatus_havereset <= {N_HARTS{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
dmstatus_havereset <= {N_HARTS{1'b0}};
|
||||
end else begin
|
||||
dmstatus_havereset <= (dmstatus_havereset | (hart_reset_done & ~hart_reset_done_prev))
|
||||
& ~({N_HARTS{dmcontrol_ackhavereset}} & dmcontrol_op_mask);
|
||||
end
|
||||
end
|
||||
|
||||
reg [N_HARTS-1:0] dmstatus_resumeack;
|
||||
reg [N_HARTS-1:0] dmcontrol_resumereq_sticky;
|
||||
|
||||
// Note: we are required to ignore resumereq when haltreq is also set, as per
|
||||
// spec (odd since the host is forbidden from writing both at once anyway).
|
||||
// The wording is odd, it refers only to `haltreq` which is specifically the
|
||||
// write-only `dmcontrol` field, not the underlying halt request state bits.
|
||||
wire dmcontrol_resumereq = dmi_write && dmi_regaddr == ADDR_DMCONTROL &&
|
||||
dmi_pwdata[30] && !dmi_pwdata[31];
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
dmstatus_resumeack <= {N_HARTS{1'b0}};
|
||||
dmcontrol_resumereq_sticky <= {N_HARTS{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
dmstatus_resumeack <= {N_HARTS{1'b0}};
|
||||
dmcontrol_resumereq_sticky <= {N_HARTS{1'b0}};
|
||||
end else begin
|
||||
dmstatus_resumeack <= (dmstatus_resumeack
|
||||
| (dmcontrol_resumereq_sticky & hart_running & hart_available))
|
||||
& ~({N_HARTS{dmcontrol_resumereq}} & dmcontrol_op_mask);
|
||||
|
||||
dmcontrol_resumereq_sticky <= (dmcontrol_resumereq_sticky
|
||||
& ~(hart_running & hart_available))
|
||||
| ({N_HARTS{dmcontrol_resumereq}} & dmcontrol_op_mask);
|
||||
end
|
||||
end
|
||||
|
||||
assign hart_req_resume = dmcontrol_resumereq_sticky;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// System bus access
|
||||
|
||||
reg [31:0] sbaddress;
|
||||
reg [31:0] sbdata;
|
||||
|
||||
// Update logic for address/data registers:
|
||||
|
||||
reg sbbusy;
|
||||
reg sbautoincrement;
|
||||
reg [2:0] sbaccess; // Size of the transfer
|
||||
|
||||
wire sbdata_write_blocked;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
sbaddress <= {32{1'b0}};
|
||||
sbdata <= {32{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
sbaddress <= {32{1'b0}};
|
||||
sbdata <= {32{1'b0}};
|
||||
end else if (HAVE_SBA) begin
|
||||
if (dmi_write && dmi_regaddr == ADDR_SBDATA0 && !sbdata_write_blocked) begin
|
||||
// Note sbbusyerror and sberror block writes to sbdata0, as the
|
||||
// write is required to have no side effects when they are set.
|
||||
sbdata <= dmi_pwdata;
|
||||
end else if (sbus_vld && sbus_rdy && !sbus_write && !sbus_err) begin
|
||||
// Make sure the lower byte lanes see appropriately shifted data as
|
||||
// long as the transfer is naturally aligned
|
||||
sbdata <= sbaddress[1:0] == 2'b01 ? {sbus_rdata[31:8], sbus_rdata[15:8]} :
|
||||
sbaddress[1:0] == 2'b10 ? {sbus_rdata[31:16], sbus_rdata[31:16]} :
|
||||
sbaddress[1:0] == 2'b11 ? {sbus_rdata[31:8], sbus_rdata[31:24]} : sbus_rdata;
|
||||
end
|
||||
if (dmi_write && dmi_regaddr == ADDR_SBADDRESS0 && !sbbusy) begin
|
||||
// Note sbaddress can't be written when busy, but
|
||||
// sberror/sbbusyerror do not prevent writes.
|
||||
sbaddress <= dmi_pwdata;
|
||||
end else if (sbus_vld && sbus_rdy && !sbus_err && sbautoincrement) begin
|
||||
// Note: address increments only following a successful transfer.
|
||||
// Spec 0.13.2 weirdly implies address should increment following
|
||||
// a sbdata0 read with sbautoincrement=1 and sbreadondata=0, but
|
||||
// this seems to be a typo, fixed in later versions.
|
||||
sbaddress <= sbaddress + (
|
||||
sbaccess[1:0] == 2'b00 ? 32'd1 :
|
||||
sbaccess[1:0] == 2'b01 ? 32'd2 : 32'd4
|
||||
);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// Control logic:
|
||||
|
||||
reg sbbusyerror;
|
||||
reg sbreadonaddr;
|
||||
reg sbreadondata;
|
||||
reg [2:0] sberror;
|
||||
reg sb_current_is_write;
|
||||
|
||||
localparam SBERROR_OK = 3'h0;
|
||||
localparam SBERROR_BADADDR = 3'h2;
|
||||
localparam SBERROR_BADALIGN = 3'h3;
|
||||
localparam SBERROR_BADSIZE = 3'h4;
|
||||
|
||||
assign sbdata_write_blocked = sbbusy || sbbusyerror || |sberror;
|
||||
|
||||
// Notes on behaviour of sbbusyerror: the sbbusyerror description says:
|
||||
//
|
||||
// "Set when the debugger attempts to read data while a read is in progress,
|
||||
// or when the debugger initiates a new access while one is already in
|
||||
// progress (while sbbusy is set)."
|
||||
//
|
||||
// However, sbaddress0 description says:
|
||||
//
|
||||
// "When the system bus master is busy, writes to this register will set
|
||||
// sbbusyerror and don’t do anything else."
|
||||
//
|
||||
// ...not conditioned on sbreadonaddr. Likewise the sbdata0 description says:
|
||||
//
|
||||
// "If the bus master is busy then accesses set sbbusyerror, and don’t do
|
||||
// anything else."
|
||||
//
|
||||
// ...not conditioned on sbreadondata. We are going to take the union of all
|
||||
// the cases where the spec says we should raise an error:
|
||||
|
||||
wire sb_access_illegal_when_busy =
|
||||
dmi_regaddr == ADDR_SBDATA0 && (dmi_read || dmi_write) ||
|
||||
dmi_regaddr == ADDR_SBADDRESS0 && dmi_write;
|
||||
|
||||
wire sb_want_start_write = dmi_write && dmi_regaddr == ADDR_SBDATA0;
|
||||
|
||||
wire sb_want_start_read =
|
||||
(sbreadonaddr && dmi_write && dmi_regaddr == ADDR_SBADDRESS0) ||
|
||||
(sbreadondata && dmi_read && dmi_regaddr == ADDR_SBDATA0);
|
||||
|
||||
wire [1:0] sb_next_align = sbreadonaddr && dmi_write && dmi_regaddr == ADDR_SBADDRESS0 ?
|
||||
dmi_pwdata[1:0] : sbaddress[1:0];
|
||||
|
||||
wire sb_badalign =
|
||||
(sbaccess == 3'h1 && sb_next_align[0]) ||
|
||||
(sbaccess == 3'h2 && |sb_next_align[1:0]);
|
||||
|
||||
wire sb_badsize = sbaccess > 3'h2;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
sbbusy <= 1'b0;
|
||||
sbbusyerror <= 1'b0;
|
||||
sbreadonaddr <= 1'b0;
|
||||
sbreadondata <= 1'b0;
|
||||
sbaccess <= 3'h0;
|
||||
sbautoincrement <= 1'b0;
|
||||
sberror <= 3'h0;
|
||||
sb_current_is_write <= 1'b0;
|
||||
end else if (!dmactive) begin
|
||||
sbbusy <= 1'b0;
|
||||
sbbusyerror <= 1'b0;
|
||||
sbreadonaddr <= 1'b0;
|
||||
sbreadondata <= 1'b0;
|
||||
sbaccess <= 3'h0;
|
||||
sbautoincrement <= 1'b0;
|
||||
sberror <= 3'h0;
|
||||
sb_current_is_write <= 1'b0;
|
||||
end else if (HAVE_SBA) begin
|
||||
if (dmi_write && dmi_regaddr == ADDR_SBCS) begin
|
||||
// Assume a transfer is not in progress when written (per spec)
|
||||
sbbusyerror <= sbbusyerror && !dmi_pwdata[22];
|
||||
sbreadonaddr <= dmi_pwdata[20];
|
||||
sbaccess <= dmi_pwdata[19:17];
|
||||
sbautoincrement <= dmi_pwdata[16];
|
||||
sbreadondata <= dmi_pwdata[15];
|
||||
sberror <= sberror & ~dmi_pwdata[14:12];
|
||||
end
|
||||
if (sbbusy) begin
|
||||
if (sb_access_illegal_when_busy) begin
|
||||
sbbusyerror <= 1'b1;
|
||||
end
|
||||
if (sbus_vld && sbus_rdy) begin
|
||||
sbbusy <= 1'b0;
|
||||
if (sbus_err) begin
|
||||
sberror <= SBERROR_BADADDR;
|
||||
end
|
||||
end
|
||||
end else if ((sb_want_start_read || sb_want_start_write) && ~|sberror && !sbbusyerror) begin
|
||||
if (sb_badsize) begin
|
||||
sberror <= SBERROR_BADSIZE;
|
||||
end else if (sb_badalign) begin
|
||||
sberror <= SBERROR_BADALIGN;
|
||||
end else begin
|
||||
sbbusy <= 1'b1;
|
||||
sb_current_is_write <= sb_want_start_write;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assign sbus_addr = sbaddress;
|
||||
assign sbus_write = sb_current_is_write;
|
||||
assign sbus_size = sbaccess[1:0];
|
||||
assign sbus_vld = sbbusy;
|
||||
|
||||
// Replicate byte lanes to handle naturally-aligned cases.
|
||||
assign sbus_wdata = sbaccess[1:0] == 2'b00 ? {4{sbdata[7:0]}} :
|
||||
sbaccess[1:0] == 2'b01 ? {2{sbdata[15:0]}} : sbdata;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Abstract command data registers
|
||||
|
||||
wire abstractcs_busy;
|
||||
|
||||
// The same data0 register is aliased as a CSR on all harts connected to this
|
||||
// DM. Cores may read data0 as a CSR when in debug mode, and may write it when:
|
||||
//
|
||||
// - That core is in debug mode, and...
|
||||
// - We are currently executing an abstract command on that core
|
||||
//
|
||||
// The DM can also read/write data0 at all times.
|
||||
|
||||
reg [XLEN-1:0] abstract_data0;
|
||||
|
||||
assign hart_data0_rdata = {N_HARTS{abstract_data0}};
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin: update_hart_data0
|
||||
reg signed [31:0] i;
|
||||
if (!rst_n) begin
|
||||
abstract_data0 <= {XLEN{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
abstract_data0 <= {XLEN{1'b0}};
|
||||
end else if (dmi_write && dmi_regaddr == ADDR_DATA0) begin
|
||||
abstract_data0 <= dmi_pwdata;
|
||||
end else begin
|
||||
for (i = 0; i < N_HARTS; i = i + 1) begin
|
||||
if (hartsel == i[W_HARTSEL-1:0] && hart_data0_wen[i] && hart_halted[i] && abstractcs_busy)
|
||||
abstract_data0 <= hart_data0_wdata[i * XLEN +: XLEN];
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
reg [XLEN-1:0] progbuf0;
|
||||
reg [XLEN-1:0] progbuf1;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
progbuf0 <= {XLEN{1'b0}};
|
||||
progbuf1 <= {XLEN{1'b0}};
|
||||
end else if (!dmactive) begin
|
||||
progbuf0 <= {XLEN{1'b0}};
|
||||
progbuf1 <= {XLEN{1'b0}};
|
||||
end else if (dmi_write && !abstractcs_busy) begin
|
||||
if (dmi_regaddr == ADDR_PROGBUF0)
|
||||
progbuf0 <= dmi_pwdata;
|
||||
if (dmi_regaddr == ADDR_PROGBUF1)
|
||||
progbuf1 <= dmi_pwdata;
|
||||
end
|
||||
end
|
||||
|
||||
reg abstractauto_autoexecdata;
|
||||
reg [1:0] abstractauto_autoexecprogbuf;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
abstractauto_autoexecdata <= 1'b0;
|
||||
abstractauto_autoexecprogbuf <= 2'b00;
|
||||
end else if (!dmactive) begin
|
||||
abstractauto_autoexecdata <= 1'b0;
|
||||
abstractauto_autoexecprogbuf <= 2'b00;
|
||||
end else if (dmi_write && dmi_regaddr == ADDR_ABSTRACTAUTO) begin
|
||||
abstractauto_autoexecdata <= dmi_pwdata[0];
|
||||
abstractauto_autoexecprogbuf <= dmi_pwdata[17:16];
|
||||
end
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Abstract command state machine
|
||||
|
||||
localparam W_STATE = 4;
|
||||
localparam S_IDLE = 4'd0;
|
||||
|
||||
localparam S_ISSUE_REGREAD = 4'd1;
|
||||
localparam S_ISSUE_REGWRITE = 4'd2;
|
||||
localparam S_ISSUE_REGEBREAK = 4'd3;
|
||||
localparam S_WAIT_REGEBREAK = 4'd4;
|
||||
|
||||
localparam S_ISSUE_PROGBUF0 = 4'd5;
|
||||
localparam S_ISSUE_PROGBUF1 = 4'd6;
|
||||
localparam S_ISSUE_IMPEBREAK = 4'd7;
|
||||
localparam S_WAIT_IMPEBREAK = 4'd8;
|
||||
|
||||
localparam CMDERR_OK = 3'h0;
|
||||
localparam CMDERR_BUSY = 3'h1;
|
||||
localparam CMDERR_UNSUPPORTED = 3'h2;
|
||||
localparam CMDERR_EXCEPTION = 3'h3;
|
||||
localparam CMDERR_HALTRESUME = 3'h4;
|
||||
|
||||
reg [2:0] abstractcs_cmderr;
|
||||
reg [2:0] abstractcs_cmderr_nxt;
|
||||
reg [W_STATE-1:0] acmd_state;
|
||||
reg [W_STATE-1:0] acmd_state_nxt;
|
||||
|
||||
assign abstractcs_busy = acmd_state != S_IDLE;
|
||||
|
||||
wire start_abstract_cmd = abstractcs_cmderr == CMDERR_OK && !abstractcs_busy && (
|
||||
(dmi_write && dmi_regaddr == ADDR_COMMAND) ||
|
||||
((dmi_write || dmi_read) && abstractauto_autoexecdata && dmi_regaddr == ADDR_DATA0) ||
|
||||
((dmi_write || dmi_read) && abstractauto_autoexecprogbuf[0] && dmi_regaddr == ADDR_PROGBUF0) ||
|
||||
((dmi_write || dmi_read) && abstractauto_autoexecprogbuf[1] && dmi_regaddr == ADDR_PROGBUF1)
|
||||
);
|
||||
|
||||
wire dmi_access_illegal_when_busy =
|
||||
(dmi_write && (
|
||||
dmi_regaddr == ADDR_ABSTRACTCS || dmi_regaddr == ADDR_COMMAND || dmi_regaddr == ADDR_ABSTRACTAUTO ||
|
||||
dmi_regaddr == ADDR_DATA0 || dmi_regaddr == ADDR_PROGBUF0 || dmi_regaddr == ADDR_PROGBUF1)) ||
|
||||
(dmi_read && (
|
||||
dmi_regaddr == ADDR_DATA0 || dmi_regaddr == ADDR_PROGBUF0 || dmi_regaddr == ADDR_PROGBUF1));
|
||||
|
||||
// Decode what acmd may be triggered on this cycle, and whether it is
|
||||
// supported -- command source may be a registered version of most recent
|
||||
// command (if abstractauto is used) or a fresh command off the bus. We don't
|
||||
// register the entire write data; repeats of unsupported commands are
|
||||
// detected by just registering that the last written command was
|
||||
// unsupported.
|
||||
|
||||
wire acmd_new = dmi_write && dmi_regaddr == ADDR_COMMAND;
|
||||
|
||||
wire acmd_new_postexec = dmi_pwdata[18];
|
||||
wire acmd_new_transfer = dmi_pwdata[17];
|
||||
wire acmd_new_write = dmi_pwdata[16];
|
||||
wire [4:0] acmd_new_regno = dmi_pwdata[4:0];
|
||||
|
||||
// Note: regno and aarsize are permitted to have otherwise-invalid values if
|
||||
// the transfer flag is not set.
|
||||
wire acmd_new_unsupported =
|
||||
(dmi_pwdata[31:24] != 8'h00 ) || // Only Access Register command supported
|
||||
(dmi_pwdata[22:20] != 3'h2 && acmd_new_transfer) || // Must be 32 bits in size
|
||||
(dmi_pwdata[19] ) || // aarpostincrement not supported
|
||||
(dmi_pwdata[15:12] != 4'h1 && acmd_new_transfer) || // Only core register access supported
|
||||
(dmi_pwdata[11:5] != 7'h0 && acmd_new_transfer); // Only GPRs supported
|
||||
|
||||
reg acmd_prev_postexec;
|
||||
reg acmd_prev_transfer;
|
||||
reg acmd_prev_write;
|
||||
reg [4:0] acmd_prev_regno;
|
||||
reg acmd_prev_unsupported;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
acmd_prev_postexec <= 1'b0;
|
||||
acmd_prev_transfer <= 1'b0;
|
||||
acmd_prev_write <= 1'b0;
|
||||
acmd_prev_regno <= 5'h0;
|
||||
acmd_prev_unsupported <= 1'b1;
|
||||
end else if (!dmactive) begin
|
||||
acmd_prev_postexec <= 1'b0;
|
||||
acmd_prev_transfer <= 1'b0;
|
||||
acmd_prev_write <= 1'b0;
|
||||
acmd_prev_regno <= 5'h0;
|
||||
acmd_prev_unsupported <= 1'b1;
|
||||
end else if (start_abstract_cmd && acmd_new) begin
|
||||
acmd_prev_postexec <= acmd_new_postexec;
|
||||
acmd_prev_transfer <= acmd_new_transfer;
|
||||
acmd_prev_write <= acmd_new_write;
|
||||
acmd_prev_regno <= acmd_new_regno;
|
||||
acmd_prev_unsupported <= acmd_new_unsupported;
|
||||
end
|
||||
end
|
||||
|
||||
wire acmd_postexec = acmd_new ? acmd_new_postexec : acmd_prev_postexec ;
|
||||
wire acmd_transfer = acmd_new ? acmd_new_transfer : acmd_prev_transfer ;
|
||||
wire acmd_write = acmd_new ? acmd_new_write : acmd_prev_write ;
|
||||
wire [4:0] acmd_regno = acmd_new ? acmd_new_regno : acmd_prev_regno ;
|
||||
wire acmd_unsupported = acmd_new ? acmd_new_unsupported : acmd_prev_unsupported;
|
||||
|
||||
always @ (*) begin
|
||||
// Default: no state change
|
||||
acmd_state_nxt = acmd_state;
|
||||
abstractcs_cmderr_nxt = abstractcs_cmderr;
|
||||
|
||||
if (dmi_write && dmi_regaddr == ADDR_ABSTRACTCS && !abstractcs_busy)
|
||||
abstractcs_cmderr_nxt = abstractcs_cmderr & ~dmi_pwdata[10:8];
|
||||
if (abstractcs_cmderr == CMDERR_OK && abstractcs_busy && dmi_access_illegal_when_busy)
|
||||
abstractcs_cmderr_nxt = CMDERR_BUSY;
|
||||
if (acmd_state != S_IDLE && hart_instr_caught_exception[hartsel])
|
||||
abstractcs_cmderr_nxt = CMDERR_EXCEPTION;
|
||||
|
||||
case (acmd_state)
|
||||
S_IDLE: begin
|
||||
if (start_abstract_cmd) begin
|
||||
if (!hart_halted[hartsel] || !hart_available[hartsel]) begin
|
||||
abstractcs_cmderr_nxt = CMDERR_HALTRESUME;
|
||||
end else if (acmd_unsupported) begin
|
||||
abstractcs_cmderr_nxt = CMDERR_UNSUPPORTED;
|
||||
end else begin
|
||||
if (acmd_transfer && acmd_write)
|
||||
acmd_state_nxt = S_ISSUE_REGWRITE;
|
||||
else if (acmd_transfer && !acmd_write)
|
||||
acmd_state_nxt = S_ISSUE_REGREAD;
|
||||
else if (acmd_postexec)
|
||||
acmd_state_nxt = S_ISSUE_PROGBUF0;
|
||||
else
|
||||
acmd_state_nxt = S_IDLE;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
S_ISSUE_REGREAD: begin
|
||||
if (hart_instr_data_rdy[hartsel])
|
||||
acmd_state_nxt = S_ISSUE_REGEBREAK;
|
||||
end
|
||||
S_ISSUE_REGWRITE: begin
|
||||
if (hart_instr_data_rdy[hartsel])
|
||||
acmd_state_nxt = S_ISSUE_REGEBREAK;
|
||||
end
|
||||
S_ISSUE_REGEBREAK: begin
|
||||
if (hart_instr_data_rdy[hartsel])
|
||||
acmd_state_nxt = S_WAIT_REGEBREAK;
|
||||
end
|
||||
S_WAIT_REGEBREAK: begin
|
||||
if (hart_instr_caught_ebreak[hartsel]) begin
|
||||
if (acmd_prev_postexec)
|
||||
acmd_state_nxt = S_ISSUE_PROGBUF0;
|
||||
else
|
||||
acmd_state_nxt = S_IDLE;
|
||||
end
|
||||
end
|
||||
|
||||
S_ISSUE_PROGBUF0: begin
|
||||
if (hart_instr_data_rdy[hartsel])
|
||||
acmd_state_nxt = S_ISSUE_PROGBUF1;
|
||||
end
|
||||
S_ISSUE_PROGBUF1: begin
|
||||
if (hart_instr_caught_exception[hartsel] || hart_instr_caught_ebreak[hartsel]) begin
|
||||
acmd_state_nxt = S_IDLE;
|
||||
end else if (hart_instr_data_rdy[hartsel]) begin
|
||||
acmd_state_nxt = S_ISSUE_IMPEBREAK;
|
||||
end
|
||||
end
|
||||
S_ISSUE_IMPEBREAK: begin
|
||||
if (hart_instr_caught_exception[hartsel] || hart_instr_caught_ebreak[hartsel]) begin
|
||||
acmd_state_nxt = S_IDLE;
|
||||
end else if (hart_instr_data_rdy[hartsel]) begin
|
||||
acmd_state_nxt = S_WAIT_IMPEBREAK;
|
||||
end
|
||||
end
|
||||
S_WAIT_IMPEBREAK: begin
|
||||
if (hart_instr_caught_exception[hartsel] || hart_instr_caught_ebreak[hartsel]) begin
|
||||
acmd_state_nxt = S_IDLE;
|
||||
end
|
||||
end
|
||||
|
||||
default: begin
|
||||
// Unreachable
|
||||
end
|
||||
|
||||
endcase
|
||||
end
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
abstractcs_cmderr <= CMDERR_OK;
|
||||
acmd_state <= S_IDLE;
|
||||
end else if (!dmactive) begin
|
||||
abstractcs_cmderr <= CMDERR_OK;
|
||||
acmd_state <= S_IDLE;
|
||||
end else begin
|
||||
abstractcs_cmderr <= abstractcs_cmderr_nxt;
|
||||
acmd_state <= acmd_state_nxt;
|
||||
end
|
||||
end
|
||||
|
||||
wire [N_HARTS-1:0] hart_instr_data_vld_nxt = {{N_HARTS-1{1'b0}},
|
||||
acmd_state_nxt == S_ISSUE_REGREAD || acmd_state_nxt == S_ISSUE_REGWRITE || acmd_state_nxt == S_ISSUE_REGEBREAK ||
|
||||
acmd_state_nxt == S_ISSUE_PROGBUF0 || acmd_state_nxt == S_ISSUE_PROGBUF1 || acmd_state_nxt == S_ISSUE_IMPEBREAK
|
||||
} << hartsel;
|
||||
|
||||
wire [31:0] hart_instr_data_nxt =
|
||||
acmd_state_nxt == S_ISSUE_REGWRITE ? 32'hbff02073 | {20'd0, acmd_regno, 7'd0} : // csrr xx, dmdata0
|
||||
acmd_state_nxt == S_ISSUE_REGREAD ? 32'hbff01073 | {12'd0, acmd_regno, 15'd0} : // csrw dmdata0, xx
|
||||
acmd_state_nxt == S_ISSUE_PROGBUF0 ? progbuf0 :
|
||||
acmd_state_nxt == S_ISSUE_PROGBUF1 ? progbuf1 :
|
||||
32'h00100073; // ebreak
|
||||
|
||||
reg [31:0] hart_instr_data_reg;
|
||||
assign hart_instr_data = {N_HARTS{hart_instr_data_reg}};
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
hart_instr_data_vld <= 1'b0;
|
||||
hart_instr_data_reg <= 32'h00000000;
|
||||
end else begin
|
||||
hart_instr_data_vld <= hart_instr_data_vld_nxt;
|
||||
if (hart_instr_data_vld_nxt) begin
|
||||
hart_instr_data_reg <= hart_instr_data_nxt;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Status helper functions
|
||||
|
||||
function status_any;
|
||||
input [N_HARTS-1:0] status_mask;
|
||||
begin
|
||||
status_any = status_mask[hartsel] || (hasel && |(status_mask & hart_array_mask));
|
||||
end
|
||||
endfunction
|
||||
|
||||
function status_all;
|
||||
input [N_HARTS-1:0] status_mask;
|
||||
begin
|
||||
status_all = status_mask[hartsel] && (!hasel || ~|(~status_mask & hart_array_mask));
|
||||
end
|
||||
endfunction
|
||||
|
||||
function [1:0] status_all_any;
|
||||
input [N_HARTS-1:0] status_mask;
|
||||
begin
|
||||
status_all_any = {
|
||||
status_all(status_mask),
|
||||
status_any(status_mask)
|
||||
};
|
||||
end
|
||||
endfunction
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DMI read data mux
|
||||
|
||||
always @ (*) begin
|
||||
case (dmi_regaddr)
|
||||
ADDR_DATA0: dmi_prdata = abstract_data0;
|
||||
ADDR_DMCONTROL: dmi_prdata = {
|
||||
1'b0, // haltreq is a W-only field
|
||||
1'b0, // resumereq is a W1 field
|
||||
status_any(dmcontrol_hartreset),
|
||||
1'b0, // ackhavereset is a W1 field
|
||||
1'b0, // reserved
|
||||
hasel,
|
||||
{{10-W_HARTSEL{1'b0}}, hartsel}, // hartsello
|
||||
10'h0, // hartselhi
|
||||
2'h0, // reserved
|
||||
2'h0, // set/clrresethaltreq are W1 fields
|
||||
dmcontrol_ndmreset,
|
||||
dmactive
|
||||
};
|
||||
ADDR_DMSTATUS: dmi_prdata = {
|
||||
9'h0, // reserved
|
||||
1'b1, // impebreak = 1
|
||||
2'h0, // reserved
|
||||
status_all_any(dmstatus_havereset), // allhavereset, anyhavereset
|
||||
status_all_any(dmstatus_resumeack), // allresumeack, anyresumeack
|
||||
hartsel >= N_HARTS && !(hasel && |hart_array_mask), // allnonexistent
|
||||
hartsel >= N_HARTS, // anynonexistent
|
||||
status_all_any(~hart_available), // allunavail, anyunavail
|
||||
status_all_any(hart_running & hart_available), // allrunning, anyrunning
|
||||
status_all_any(hart_halted & hart_available), // allhalted, anyhalted
|
||||
1'b1, // authenticated
|
||||
1'b0, // authbusy
|
||||
1'b1, // hasresethaltreq = 1 (we do support it)
|
||||
1'b0, // confstrptrvalid
|
||||
4'd2 // version = 2: RISC-V debug spec 0.13.2
|
||||
};
|
||||
ADDR_HARTINFO: dmi_prdata = {
|
||||
8'h0, // reserved
|
||||
4'h0, // nscratch = 0
|
||||
3'h0, // reserved
|
||||
1'b0, // dataccess = 0, data0 is mapped to each hart's CSR space
|
||||
4'h1, // datasize = 1, a single data CSR (data0) is available
|
||||
12'hbff // dataaddr, placed at the top of the M-custom space since
|
||||
// the spec doesn't reserve a location for it.
|
||||
};
|
||||
ADDR_HALTSUM0: dmi_prdata = {
|
||||
{XLEN - N_HARTS{1'b0}},
|
||||
hart_halted & hart_available
|
||||
};
|
||||
ADDR_HALTSUM1: dmi_prdata = {
|
||||
{XLEN - 1{1'b0}},
|
||||
|(hart_halted & hart_available)
|
||||
};
|
||||
ADDR_HAWINDOWSEL: dmi_prdata = 32'h00000000;
|
||||
ADDR_HAWINDOW: dmi_prdata = {
|
||||
{32-N_HARTS{1'b0}},
|
||||
hart_array_mask
|
||||
};
|
||||
ADDR_ABSTRACTCS: dmi_prdata = {
|
||||
3'h0, // reserved
|
||||
5'd2, // progbufsize = 2
|
||||
11'h0, // reserved
|
||||
abstractcs_busy,
|
||||
1'b0,
|
||||
abstractcs_cmderr,
|
||||
4'h0,
|
||||
4'd1 // datacount = 1
|
||||
};
|
||||
ADDR_ABSTRACTAUTO: dmi_prdata = {
|
||||
14'h0,
|
||||
abstractauto_autoexecprogbuf, // only progbuf0,1 present
|
||||
15'h0,
|
||||
abstractauto_autoexecdata // only data0 present
|
||||
};
|
||||
ADDR_SBCS: dmi_prdata = {
|
||||
3'h1, // version = 1
|
||||
6'h00,
|
||||
sbbusyerror,
|
||||
sbbusy,
|
||||
sbreadonaddr,
|
||||
sbaccess,
|
||||
sbautoincrement,
|
||||
sbreadondata,
|
||||
sberror,
|
||||
7'h20, // sbasize = 32
|
||||
5'b00111 // 8, 16, 32-bit transfers supported
|
||||
} & {32{|HAVE_SBA}};
|
||||
ADDR_SBDATA0: dmi_prdata = sbdata & {32{|HAVE_SBA}};
|
||||
ADDR_SBADDRESS0: dmi_prdata = sbaddress & {32{|HAVE_SBA}};
|
||||
ADDR_CONFSTRPTR0: dmi_prdata = 32'h4c296328;
|
||||
ADDR_CONFSTRPTR1: dmi_prdata = 32'h20656b75;
|
||||
ADDR_CONFSTRPTR2: dmi_prdata = 32'h6e657257;
|
||||
ADDR_CONFSTRPTR3: dmi_prdata = 32'h31322720;
|
||||
ADDR_NEXTDM: dmi_prdata = NEXT_DM_ADDR;
|
||||
ADDR_PROGBUF0: dmi_prdata = progbuf0;
|
||||
ADDR_PROGBUF1: dmi_prdata = progbuf1;
|
||||
default: dmi_prdata = {XLEN{1'b0}};
|
||||
endcase
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,74 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// Standalone bus shim for connecting the DM's System Bus Access to AHB
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_sbus_to_ahb #(
|
||||
parameter W_ADDR = 32,
|
||||
parameter W_DATA = 32
|
||||
) (
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
|
||||
input wire [W_ADDR-1:0] sbus_addr,
|
||||
input wire sbus_write,
|
||||
input wire [1:0] sbus_size,
|
||||
input wire sbus_vld,
|
||||
output wire sbus_rdy,
|
||||
output wire sbus_err,
|
||||
input wire [W_DATA-1:0] sbus_wdata,
|
||||
output wire [W_DATA-1:0] sbus_rdata,
|
||||
|
||||
output wire [W_ADDR-1:0] ahblm_haddr,
|
||||
output wire ahblm_hwrite,
|
||||
output wire [1:0] ahblm_htrans,
|
||||
output wire [2:0] ahblm_hsize,
|
||||
output wire [2:0] ahblm_hburst,
|
||||
output wire [3:0] ahblm_hprot,
|
||||
output wire ahblm_hmastlock,
|
||||
input wire ahblm_hready,
|
||||
input wire ahblm_hresp,
|
||||
output wire [W_DATA-1:0] ahblm_hwdata,
|
||||
input wire [W_DATA-1:0] ahblm_hrdata
|
||||
);
|
||||
|
||||
// Most signals are simple tie-throughs
|
||||
|
||||
assign ahblm_haddr = sbus_addr;
|
||||
assign ahblm_hwrite = sbus_write;
|
||||
assign ahblm_hsize = {1'b0, sbus_size};
|
||||
assign ahblm_hwdata = sbus_wdata;
|
||||
|
||||
// HPROT = noncacheable nonbufferable privileged data access:
|
||||
assign ahblm_hprot = 4'b0011;
|
||||
assign ahblm_hmastlock = 1'b0;
|
||||
assign ahblm_hburst = 3'h0;
|
||||
|
||||
assign sbus_err = ahblm_hresp;
|
||||
assign sbus_rdata = ahblm_hrdata;
|
||||
|
||||
// Handshaking
|
||||
|
||||
reg dph_active;
|
||||
|
||||
always @ (posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
dph_active <= 1'b0;
|
||||
end else if (ahblm_hready) begin
|
||||
dph_active <= ahblm_htrans[1];
|
||||
end
|
||||
end
|
||||
|
||||
assign ahblm_htrans = sbus_vld && !dph_active ? 2'b10 : 2'b00;
|
||||
|
||||
assign sbus_rdy = ahblm_hready && dph_active;
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,6 @@
|
||||
file hazard3_ecp5_jtag_dtm.v
|
||||
file hazard3_jtag_dtm_core.v
|
||||
|
||||
file ../cdc/hazard3_apb_async_bridge.v
|
||||
file ../cdc/hazard3_reset_sync.v
|
||||
file ../cdc/hazard3_sync_1bit.v
|
||||
@@ -0,0 +1,194 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// The ECP5 JTAGG primitive (yes that is the correct spelling) allows you to
|
||||
// add two custom DRs to the FPGA's chip TAP, selected using the 8-bit ER1
|
||||
// (0x32) and ER2 (0x38) instructions.
|
||||
//
|
||||
// Brian Swetland pointed out on Twitter that the standard RISC-V JTAG-DTM
|
||||
// only uses two DRs (DTMCS and DMI), besides the standard IDCODE and BYPASS
|
||||
// which are provided already by the ECP5 TAP. This file instantiates the
|
||||
// guts of Hazard3's standard JTAG-DTM and connects the DTMCS and DMI
|
||||
// registers to the JTAGG primitive's ER1/ER2 DRs.
|
||||
//
|
||||
// The exciting part is that upstream OpenOCD already allows you to set the IR
|
||||
// length *and* set custom DTMCS/DMI IR values for RISC-V JTAG DTMs. This
|
||||
// means with the right config file, you can access a debug module hung from
|
||||
// the ECP5 TAP in this fashion using only upstream OpenOCD and gdb.
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_ecp5_jtag_dtm #(
|
||||
parameter DTMCS_IDLE_HINT = 3'd4,
|
||||
parameter W_PADDR = 9,
|
||||
parameter ABITS = W_PADDR - 2 // do not modify
|
||||
) (
|
||||
// This is synchronous to TCK and asserted for one TCK cycle only
|
||||
output wire dmihardreset_req,
|
||||
|
||||
// Bus clock + reset for Debug Module Interface
|
||||
input wire clk_dmi,
|
||||
input wire rst_n_dmi,
|
||||
|
||||
// Debug Module Interface (APB)
|
||||
output wire dmi_psel,
|
||||
output wire dmi_penable,
|
||||
output wire dmi_pwrite,
|
||||
output wire [W_PADDR-1:0] dmi_paddr,
|
||||
output wire [31:0] dmi_pwdata,
|
||||
input wire [31:0] dmi_prdata,
|
||||
input wire dmi_pready,
|
||||
input wire dmi_pslverr
|
||||
);
|
||||
|
||||
// Signals to/from the ECP5 TAP
|
||||
|
||||
wire jtdo2;
|
||||
wire jtdo1;
|
||||
wire jtdi;
|
||||
wire jtck_posedge_dont_use;
|
||||
wire jshift;
|
||||
wire jupdate;
|
||||
wire jrst_n;
|
||||
wire jce2;
|
||||
wire jce1;
|
||||
|
||||
JTAGG jtag_u (
|
||||
.JTDO2 (jtdo2),
|
||||
.JTDO1 (jtdo1),
|
||||
.JTDI (jtdi),
|
||||
.JTCK (jtck_posedge_dont_use),
|
||||
.JRTI2 (/* unused */),
|
||||
.JRTI1 (/* unused */),
|
||||
.JSHIFT (jshift),
|
||||
.JUPDATE (jupdate),
|
||||
.JRSTN (jrst_n),
|
||||
.JCE2 (jce2),
|
||||
.JCE1 (jce1)
|
||||
);
|
||||
|
||||
// JTAGG primitive asserts its signals synchronously to JTCK's posedge, but
|
||||
// you get weird and inconsistent results if you try to consume them
|
||||
// synchronously on JTCK's posedge, possibly due to a lack of hold
|
||||
// constraints in nextpnr.
|
||||
//
|
||||
// A quick hack is to move the sampling onto the negedge of the clock. This
|
||||
// then creates more problems because we would be running our shift logic on
|
||||
// a different edge from the control + CDC logic in the DTM core.
|
||||
//
|
||||
// So, even worse hack, move all our JTAG-domain logic onto the negedge
|
||||
// (or near enough) by inverting the clock.
|
||||
|
||||
wire jtck = !jtck_posedge_dont_use;
|
||||
|
||||
localparam W_DR_SHIFT = ABITS + 32 + 2;
|
||||
|
||||
reg core_dr_wen;
|
||||
reg core_dr_ren;
|
||||
reg core_dr_sel_dmi_ndtmcs;
|
||||
reg dr_shift_en;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_wdata;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_rdata;
|
||||
|
||||
// Decode our shift controls from the interesting ECP5 ones, and re-register
|
||||
// onto JTCK negedge (our posedge). Note without re-registering we observe
|
||||
// them a half-cycle (effectively one cycle) too early. This is another
|
||||
// consequence of the stupid JTDI thing
|
||||
|
||||
always @ (posedge jtck or negedge jrst_n) begin
|
||||
if (!jrst_n) begin
|
||||
core_dr_sel_dmi_ndtmcs <= 1'b0;
|
||||
core_dr_wen <= 1'b0;
|
||||
core_dr_ren <= 1'b0;
|
||||
dr_shift_en <= 1'b0;
|
||||
end else begin
|
||||
if (jce1 || jce2)
|
||||
core_dr_sel_dmi_ndtmcs <= jce2;
|
||||
core_dr_ren <= (jce1 || jce2) && !jshift;
|
||||
core_dr_wen <= jupdate;
|
||||
dr_shift_en <= jshift;
|
||||
end
|
||||
end
|
||||
|
||||
reg [W_DR_SHIFT-1:0] dr_shift;
|
||||
assign core_dr_wdata = dr_shift;
|
||||
|
||||
always @ (posedge jtck or negedge jrst_n) begin
|
||||
if (!jrst_n) begin
|
||||
dr_shift <= {W_DR_SHIFT{1'b0}};
|
||||
end else if (core_dr_ren) begin
|
||||
dr_shift <= core_dr_rdata;
|
||||
end else if (dr_shift_en) begin
|
||||
dr_shift <= {jtdi, dr_shift[W_DR_SHIFT-1:1]};
|
||||
if (!core_dr_sel_dmi_ndtmcs)
|
||||
dr_shift[31] <= jtdi;
|
||||
end
|
||||
end
|
||||
|
||||
// Not documented on ECP5: as well as the posedge flop on JTDI, the ECP5 puts
|
||||
// a negedge flop on JTDO1, JTDO2. (Conjecture based on dicking around with a
|
||||
// logic analyser.) To get JTDOx to appear with the same timing as our shifter
|
||||
// LSB (which we update on every JTCK negedge) we:
|
||||
//
|
||||
// - Register the LSB of the *next* value of dr_shift on the JTCK posedge, so
|
||||
// half a cycle earlier than the actual dr_shift update
|
||||
//
|
||||
// - This then gets re-registered with the pointless JTDO negedge flops, so
|
||||
// that it appears with the same timing as our DR shifter update.
|
||||
|
||||
reg dr_shift_next_halfcycle;
|
||||
always @ (negedge jtck or negedge jrst_n) begin
|
||||
if (!jrst_n) begin
|
||||
dr_shift_next_halfcycle <= 1'b0;
|
||||
end else begin
|
||||
dr_shift_next_halfcycle <=
|
||||
core_dr_ren ? core_dr_rdata[0] :
|
||||
dr_shift_en ? dr_shift[1] : dr_shift[0];
|
||||
end
|
||||
end
|
||||
|
||||
// We have only a single shifter for the ER1 and ER2 chains, so these are tied
|
||||
// together:
|
||||
|
||||
assign jtdo1 = dr_shift_next_halfcycle;
|
||||
assign jtdo2 = dr_shift_next_halfcycle;
|
||||
|
||||
// The actual DTM is in here:
|
||||
|
||||
hazard3_jtag_dtm_core #(
|
||||
.DTMCS_IDLE_HINT (DTMCS_IDLE_HINT),
|
||||
.W_ADDR (ABITS)
|
||||
) inst_hazard3_jtag_dtm_core (
|
||||
.tck (jtck),
|
||||
.trst_n (jrst_n),
|
||||
|
||||
.clk_dmi (clk_dmi),
|
||||
.rst_n_dmi (rst_n_dmi),
|
||||
|
||||
.dr_wen (core_dr_wen),
|
||||
.dr_ren (core_dr_ren),
|
||||
.dr_sel_dmi_ndtmcs (core_dr_sel_dmi_ndtmcs),
|
||||
.dr_wdata (core_dr_wdata),
|
||||
.dr_rdata (core_dr_rdata),
|
||||
|
||||
.dmihardreset_req (dmihardreset_req),
|
||||
|
||||
.dmi_psel (dmi_psel),
|
||||
.dmi_penable (dmi_penable),
|
||||
.dmi_pwrite (dmi_pwrite),
|
||||
.dmi_paddr (dmi_paddr[W_PADDR-1:2]),
|
||||
.dmi_pwdata (dmi_pwdata),
|
||||
.dmi_prdata (dmi_prdata),
|
||||
.dmi_pready (dmi_pready),
|
||||
.dmi_pslverr (dmi_pslverr)
|
||||
);
|
||||
|
||||
assign dmi_paddr[1:0] = 2'b00;
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,6 @@
|
||||
file hazard3_jtag_dtm.v
|
||||
file hazard3_jtag_dtm_core.v
|
||||
|
||||
file ../cdc/hazard3_apb_async_bridge.v
|
||||
file ../cdc/hazard3_reset_sync.v
|
||||
file ../cdc/hazard3_sync_1bit.v
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// Implementation of standard RISC-V JTAG-DTM with an APB Debug Module
|
||||
// Interface. The TAP itself is clocked directly by JTAG TCK; a clock
|
||||
// crossing is instantiated internally between the TCK domain and the DMI bus
|
||||
// clock domain.
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_jtag_dtm #(
|
||||
parameter IDCODE = 32'h0000_0001,
|
||||
parameter DTMCS_IDLE_HINT = 3'd4,
|
||||
parameter W_PADDR = 9,
|
||||
parameter ABITS = W_PADDR - 2 // do not modify
|
||||
) (
|
||||
// Standard JTAG signals -- the JTAG hardware is clocked directly by TCK.
|
||||
input wire tck,
|
||||
input wire trst_n,
|
||||
input wire tms,
|
||||
input wire tdi,
|
||||
output reg tdo,
|
||||
|
||||
// This is synchronous to TCK and asserted for one TCK cycle only
|
||||
output wire dmihardreset_req,
|
||||
|
||||
// Bus clock + reset for Debug Module Interface
|
||||
input wire clk_dmi,
|
||||
input wire rst_n_dmi,
|
||||
|
||||
// Debug Module Interface (APB)
|
||||
output wire dmi_psel,
|
||||
output wire dmi_penable,
|
||||
output wire dmi_pwrite,
|
||||
output wire [W_PADDR-1:0] dmi_paddr,
|
||||
output wire [31:0] dmi_pwdata,
|
||||
input wire [31:0] dmi_prdata,
|
||||
input wire dmi_pready,
|
||||
input wire dmi_pslverr
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// TAP state machine
|
||||
|
||||
reg [3:0] tap_state;
|
||||
localparam S_RESET = 4'd0;
|
||||
localparam S_RUN_IDLE = 4'd1;
|
||||
localparam S_SELECT_DR = 4'd2;
|
||||
localparam S_CAPTURE_DR = 4'd3;
|
||||
localparam S_SHIFT_DR = 4'd4;
|
||||
localparam S_EXIT1_DR = 4'd5;
|
||||
localparam S_PAUSE_DR = 4'd6;
|
||||
localparam S_EXIT2_DR = 4'd7;
|
||||
localparam S_UPDATE_DR = 4'd8;
|
||||
localparam S_SELECT_IR = 4'd9;
|
||||
localparam S_CAPTURE_IR = 4'd10;
|
||||
localparam S_SHIFT_IR = 4'd11;
|
||||
localparam S_EXIT1_IR = 4'd12;
|
||||
localparam S_PAUSE_IR = 4'd13;
|
||||
localparam S_EXIT2_IR = 4'd14;
|
||||
localparam S_UPDATE_IR = 4'd15;
|
||||
|
||||
always @ (posedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
tap_state <= S_RESET;
|
||||
end else case(tap_state)
|
||||
S_RESET : tap_state <= tms ? S_RESET : S_RUN_IDLE ;
|
||||
S_RUN_IDLE : tap_state <= tms ? S_SELECT_DR : S_RUN_IDLE ;
|
||||
|
||||
S_SELECT_DR : tap_state <= tms ? S_SELECT_IR : S_CAPTURE_DR;
|
||||
S_CAPTURE_DR : tap_state <= tms ? S_EXIT1_DR : S_SHIFT_DR ;
|
||||
S_SHIFT_DR : tap_state <= tms ? S_EXIT1_DR : S_SHIFT_DR ;
|
||||
S_EXIT1_DR : tap_state <= tms ? S_UPDATE_DR : S_PAUSE_DR ;
|
||||
S_PAUSE_DR : tap_state <= tms ? S_EXIT2_DR : S_PAUSE_DR ;
|
||||
S_EXIT2_DR : tap_state <= tms ? S_UPDATE_DR : S_SHIFT_DR ;
|
||||
S_UPDATE_DR : tap_state <= tms ? S_SELECT_DR : S_RUN_IDLE ;
|
||||
|
||||
S_SELECT_IR : tap_state <= tms ? S_RESET : S_CAPTURE_IR;
|
||||
S_CAPTURE_IR : tap_state <= tms ? S_EXIT1_IR : S_SHIFT_IR ;
|
||||
S_SHIFT_IR : tap_state <= tms ? S_EXIT1_IR : S_SHIFT_IR ;
|
||||
S_EXIT1_IR : tap_state <= tms ? S_UPDATE_IR : S_PAUSE_IR ;
|
||||
S_PAUSE_IR : tap_state <= tms ? S_EXIT2_IR : S_PAUSE_IR ;
|
||||
S_EXIT2_IR : tap_state <= tms ? S_UPDATE_IR : S_SHIFT_IR ;
|
||||
S_UPDATE_IR : tap_state <= tms ? S_SELECT_DR : S_RUN_IDLE ;
|
||||
endcase
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Instruction register
|
||||
|
||||
localparam W_IR = 5;
|
||||
// All other encodings behave as BYPASS:
|
||||
localparam IR_IDCODE = 5'h01;
|
||||
localparam IR_DTMCS = 5'h10;
|
||||
localparam IR_DMI = 5'h11;
|
||||
|
||||
reg [W_IR-1:0] ir_shift;
|
||||
reg [W_IR-1:0] ir;
|
||||
|
||||
always @ (posedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
ir_shift <= {W_IR{1'b0}};
|
||||
ir <= IR_IDCODE;
|
||||
end else if (tap_state == S_RESET) begin
|
||||
ir_shift <= {W_IR{1'b0}};
|
||||
ir <= IR_IDCODE;
|
||||
end else if (tap_state == S_CAPTURE_IR) begin
|
||||
ir_shift <= ir;
|
||||
end else if (tap_state == S_SHIFT_IR) begin
|
||||
ir_shift <= {tdi, ir_shift[W_IR-1:1]};
|
||||
end else if (tap_state == S_UPDATE_IR) begin
|
||||
ir <= ir_shift;
|
||||
end
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Data registers
|
||||
|
||||
// Shift register is sized to largest DR, which is DMI:
|
||||
// {addr[7:0], data[31:0], op[1:0]}
|
||||
localparam W_DR_SHIFT = ABITS + 32 + 2;
|
||||
|
||||
reg [W_DR_SHIFT-1:0] dr_shift;
|
||||
|
||||
// Signals to/from the DTM core, which implements the DTMCS and DMI registers
|
||||
wire core_dr_wen;
|
||||
wire core_dr_ren;
|
||||
wire core_dr_sel_dmi_ndtmcs;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_wdata;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_rdata;
|
||||
|
||||
always @ (posedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
dr_shift <= {W_DR_SHIFT{1'b0}};
|
||||
end else if (tap_state == S_SHIFT_DR) begin
|
||||
dr_shift <= {tdi, dr_shift[W_DR_SHIFT-1:1]};
|
||||
// Shorten DR shift chain according to IR
|
||||
if (ir == IR_DMI)
|
||||
dr_shift[W_DR_SHIFT - 1] <= tdi;
|
||||
else if (ir == IR_IDCODE || ir == IR_DTMCS)
|
||||
dr_shift[31] <= tdi;
|
||||
else // BYPASS
|
||||
dr_shift[0] <= tdi;
|
||||
end else if (tap_state == S_CAPTURE_DR) begin
|
||||
if (ir == IR_DMI || ir == IR_DTMCS) begin
|
||||
dr_shift <= core_dr_rdata;
|
||||
end else if (ir == IR_IDCODE) begin
|
||||
dr_shift <= {{W_DR_SHIFT-32{1'b0}}, IDCODE};
|
||||
end else begin // BYPASS
|
||||
dr_shift <= {W_DR_SHIFT{1'b0}};
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// Must retime shift data onto negedge before presenting on TDO
|
||||
|
||||
always @ (negedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
tdo <= 1'b0;
|
||||
end else begin
|
||||
tdo <= tap_state == S_SHIFT_IR ? ir_shift[0] :
|
||||
tap_state == S_SHIFT_DR ? dr_shift[0] : 1'b0;
|
||||
end
|
||||
end
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Core logic and bus interface
|
||||
|
||||
assign core_dr_sel_dmi_ndtmcs = ir == IR_DMI;
|
||||
assign core_dr_wen = (ir == IR_DMI || ir == IR_DTMCS) && tap_state == S_UPDATE_DR;
|
||||
assign core_dr_ren = (ir == IR_DMI || ir == IR_DTMCS) && tap_state == S_CAPTURE_DR;
|
||||
|
||||
assign core_dr_wdata = dr_shift;
|
||||
|
||||
hazard3_jtag_dtm_core #(
|
||||
.DTMCS_IDLE_HINT (DTMCS_IDLE_HINT),
|
||||
.W_ADDR (ABITS)
|
||||
) dtm_core (
|
||||
.tck (tck),
|
||||
.trst_n (trst_n),
|
||||
.clk_dmi (clk_dmi),
|
||||
.rst_n_dmi (rst_n_dmi),
|
||||
|
||||
.dmihardreset_req (dmihardreset_req),
|
||||
|
||||
.dr_wen (core_dr_wen),
|
||||
.dr_ren (core_dr_ren),
|
||||
.dr_sel_dmi_ndtmcs (core_dr_sel_dmi_ndtmcs),
|
||||
.dr_wdata (core_dr_wdata),
|
||||
.dr_rdata (core_dr_rdata),
|
||||
|
||||
.dmi_psel (dmi_psel),
|
||||
.dmi_penable (dmi_penable),
|
||||
.dmi_pwrite (dmi_pwrite),
|
||||
.dmi_paddr (dmi_paddr[W_PADDR-1:2]),
|
||||
.dmi_pwdata (dmi_pwdata),
|
||||
.dmi_prdata (dmi_prdata),
|
||||
.dmi_pready (dmi_pready),
|
||||
.dmi_pslverr (dmi_pslverr)
|
||||
);
|
||||
|
||||
assign dmi_paddr[1:0] = 2'b00;
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,185 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2022 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// DTMCS + DMI control logic, bus interface and bus clock domain crossing for
|
||||
// a standard RISC-V APB JTAG-DTM. Essentially everything apart from the
|
||||
// actual TAP controller, IR and shift registers. Instantiated by
|
||||
// hazard3_jtag_dtm.v.
|
||||
//
|
||||
// This core logic can be reused and connected to some other serial transport
|
||||
// or, for example, the ECP5 JTAGG primitive (see hazard5_ecp5_jtag_dtm.v)
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_jtag_dtm_core #(
|
||||
parameter DTMCS_IDLE_HINT = 3'd4,
|
||||
parameter W_ADDR = 8,
|
||||
parameter W_DR_SHIFT = W_ADDR + 32 + 2 // do not modify
|
||||
) (
|
||||
input wire tck,
|
||||
input wire trst_n,
|
||||
|
||||
input wire clk_dmi,
|
||||
input wire rst_n_dmi,
|
||||
|
||||
// DR capture/update (read/write) signals
|
||||
input wire dr_wen,
|
||||
input wire dr_ren,
|
||||
input wire dr_sel_dmi_ndtmcs,
|
||||
input wire [W_DR_SHIFT-1:0] dr_wdata,
|
||||
output wire [W_DR_SHIFT-1:0] dr_rdata,
|
||||
|
||||
// This is synchronous to TCK and asserted for one TCK cycle only
|
||||
output reg dmihardreset_req,
|
||||
|
||||
// Debug Module Interface (APB)
|
||||
output wire dmi_psel,
|
||||
output wire dmi_penable,
|
||||
output wire dmi_pwrite,
|
||||
output wire [W_ADDR-1:0] dmi_paddr,
|
||||
output wire [31:0] dmi_pwdata,
|
||||
input wire [31:0] dmi_prdata,
|
||||
input wire dmi_pready,
|
||||
input wire dmi_pslverr
|
||||
);
|
||||
|
||||
wire write_dmi = dr_wen && dr_sel_dmi_ndtmcs;
|
||||
wire write_dtmcs = dr_wen && !dr_sel_dmi_ndtmcs;
|
||||
wire read_dmi = dr_ren && dr_sel_dmi_ndtmcs;
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DMI bus adapter
|
||||
|
||||
reg [1:0] dmi_cmderr;
|
||||
reg dmi_busy;
|
||||
|
||||
// DTM-domain bus, connected to a matching DM-domain bus via an APB crossing:
|
||||
wire dtm_psel;
|
||||
wire dtm_penable;
|
||||
wire dtm_pwrite;
|
||||
wire [W_ADDR-1:0] dtm_paddr;
|
||||
wire [31:0] dtm_pwdata;
|
||||
wire [31:0] dtm_prdata;
|
||||
wire dtm_pready;
|
||||
wire dtm_pslverr;
|
||||
|
||||
// We are relying on some particular features of our APB clock crossing here
|
||||
// to save some registers:
|
||||
//
|
||||
// - The transfer is launched immediately when psel is seen, no need to
|
||||
// actually assert an access phase (as the standard allows the CDC to
|
||||
// assume that access immediately follows setup) and no need to maintain
|
||||
// pwrite/paddr/pwdata valid after the setup phase
|
||||
//
|
||||
// - prdata/pslverr remain valid after the transfer completes, until the next
|
||||
// transfer completes
|
||||
//
|
||||
// These allow us to connect the upstream side of the CDC directly to our DR
|
||||
// shifter without any sample/hold registers in between.
|
||||
|
||||
// psel is only pulsed for one cycle, penable is not asserted.
|
||||
assign dtm_psel = write_dmi &&
|
||||
(dr_wdata[1:0] == 2'd1 || dr_wdata[1:0] == 2'd2) &&
|
||||
!(dmi_busy || dmi_cmderr != 2'd0) && dtm_pready;
|
||||
assign dtm_penable = 1'b0;
|
||||
|
||||
// paddr/pwdata/pwrite are valid momentarily when psel is asserted.
|
||||
assign dtm_paddr = dr_wdata[34 +: W_ADDR];
|
||||
assign dtm_pwrite = dr_wdata[1];
|
||||
assign dtm_pwdata = dr_wdata[2 +: 32];
|
||||
|
||||
always @ (posedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
dmi_busy <= 1'b0;
|
||||
dmi_cmderr <= 2'd0;
|
||||
end else if (read_dmi) begin
|
||||
// Reading while busy sets the busy sticky error. Note the capture
|
||||
// into shift register should also reflect this update on-the-fly
|
||||
if (dmi_busy && dmi_cmderr == 2'd0)
|
||||
dmi_cmderr <= 2'h3;
|
||||
end else if (write_dtmcs) begin
|
||||
// Writing dtmcs.dmireset = 1 clears a sticky error
|
||||
if (dr_wdata[16])
|
||||
dmi_cmderr <= 2'd0;
|
||||
end else if (write_dmi) begin
|
||||
if (dtm_psel) begin
|
||||
dmi_busy <= 1'b1;
|
||||
end else if (dr_wdata[1:0] != 2'd0) begin
|
||||
// DMI ignored operation, so set sticky busy
|
||||
if (dmi_cmderr == 2'd0)
|
||||
dmi_cmderr <= 2'd3;
|
||||
end
|
||||
end else if (dmi_busy && dtm_pready) begin
|
||||
dmi_busy <= 1'b0;
|
||||
if (dmi_cmderr == 2'd0 && dtm_pslverr)
|
||||
dmi_cmderr <= 2'd2;
|
||||
end
|
||||
end
|
||||
|
||||
// DTM logic is in TCK domain, actual DMI + DM is in processor domain
|
||||
|
||||
hazard3_apb_async_bridge #(
|
||||
.W_ADDR (W_ADDR),
|
||||
.W_DATA (32),
|
||||
.N_SYNC_STAGES (2)
|
||||
) inst_hazard3_apb_async_bridge (
|
||||
.clk_src (tck),
|
||||
.rst_n_src (trst_n),
|
||||
|
||||
.clk_dst (clk_dmi),
|
||||
.rst_n_dst (rst_n_dmi),
|
||||
|
||||
.src_psel (dtm_psel),
|
||||
.src_penable (dtm_penable),
|
||||
.src_pwrite (dtm_pwrite),
|
||||
.src_paddr (dtm_paddr),
|
||||
.src_pwdata (dtm_pwdata),
|
||||
.src_prdata (dtm_prdata),
|
||||
.src_pready (dtm_pready),
|
||||
.src_pslverr (dtm_pslverr),
|
||||
|
||||
.dst_psel (dmi_psel),
|
||||
.dst_penable (dmi_penable),
|
||||
.dst_pwrite (dmi_pwrite),
|
||||
.dst_paddr (dmi_paddr),
|
||||
.dst_pwdata (dmi_pwdata),
|
||||
.dst_prdata (dmi_prdata),
|
||||
.dst_pready (dmi_pready),
|
||||
.dst_pslverr (dmi_pslverr)
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// DR read/write
|
||||
|
||||
wire [W_DR_SHIFT-1:0] dtmcs_rdata = {
|
||||
{W_ADDR{1'b0}},
|
||||
19'h0,
|
||||
DTMCS_IDLE_HINT[2:0],
|
||||
dmi_cmderr,
|
||||
W_ADDR[5:0], // abits
|
||||
4'd1 // version
|
||||
};
|
||||
|
||||
wire [W_DR_SHIFT-1:0] dmi_rdata = {
|
||||
{W_ADDR{1'b0}},
|
||||
dtm_prdata,
|
||||
dmi_busy && dmi_cmderr == 2'd0 ? 2'd3 : dmi_cmderr
|
||||
};
|
||||
|
||||
assign dr_rdata = dr_sel_dmi_ndtmcs ? dmi_rdata : dtmcs_rdata;
|
||||
|
||||
always @ (posedge tck or negedge trst_n) begin
|
||||
if (!trst_n) begin
|
||||
dmihardreset_req <= 1'b0;
|
||||
end else begin
|
||||
dmihardreset_req <= write_dtmcs && dr_wdata[17];
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
@@ -0,0 +1,162 @@
|
||||
/*****************************************************************************\
|
||||
| Copyright (C) 2021-2025 Luke Wren |
|
||||
| SPDX-License-Identifier: Apache-2.0 |
|
||||
\*****************************************************************************/
|
||||
|
||||
// Implement a RISC-V JTAG DTM tunnelled through a Xilinx BSCANE2 primitive.
|
||||
//
|
||||
// Xilinx allows up to four custom DRs to be added to the FPGA TAP controller.
|
||||
// A JTAG-DTM only needs two: DTMCS and DMI.
|
||||
//
|
||||
// With the correct config, OpenOCD can treat the FPGA TAP as a JTAG DTM and
|
||||
// access RISC-V debug directly. This allows you to debug internal RISC-V
|
||||
// cores with the same JTAG interface you use to load the FPGA.
|
||||
//
|
||||
// CHAIN_DTMCS and CHAIN_DMI select which JTAG IR values are used to access
|
||||
// these DRs. Values 1 through 4 correspond to Xilinx USER1 through USER4
|
||||
// instructions, which have IR values 0x02, 0x03, 0x22, 0x23.
|
||||
|
||||
`default_nettype none
|
||||
|
||||
module hazard3_xilinx7_jtag_dtm #(
|
||||
parameter SEL_DTMCS = 3,
|
||||
parameter SEL_DMI = 4,
|
||||
parameter DTMCS_IDLE_HINT = 3'd4,
|
||||
parameter W_PADDR = 9,
|
||||
parameter ABITS = W_PADDR - 2 // do not modify
|
||||
) (
|
||||
// This is synchronous to TCK and asserted for one TCK cycle only
|
||||
output wire dmihardreset_req,
|
||||
|
||||
// Bus clock + reset for Debug Module Interface
|
||||
input wire clk_dmi,
|
||||
input wire rst_n_dmi,
|
||||
|
||||
// Debug Module Interface (APB)
|
||||
output wire dmi_psel,
|
||||
output wire dmi_penable,
|
||||
output wire dmi_pwrite,
|
||||
output wire [W_PADDR-1:0] dmi_paddr,
|
||||
output wire [31:0] dmi_pwdata,
|
||||
input wire [31:0] dmi_prdata,
|
||||
input wire dmi_pready,
|
||||
input wire dmi_pslverr
|
||||
);
|
||||
|
||||
// Signals to/from the Xilinx TAP
|
||||
|
||||
wire jtck_unbuf;
|
||||
wire jtck;
|
||||
wire jtdo2;
|
||||
wire jtdo1;
|
||||
wire jtdi;
|
||||
wire jshift;
|
||||
wire jupdate;
|
||||
wire jcapture;
|
||||
wire jrst;
|
||||
wire jrst_n = !jrst;
|
||||
wire jce2;
|
||||
wire jce1;
|
||||
|
||||
BSCANE2 #(
|
||||
.JTAG_CHAIN (SEL_DTMCS) // Value for USER command.
|
||||
) bscan_dtmcs (
|
||||
.CAPTURE (jcapture), // CAPTURE output from TAP controller.
|
||||
.DRCK (/* unused */), // Gated TCK output. When SEL is asserted, DRCK toggles when CAPTURE or SHIFT are asserted.
|
||||
.RESET (jrst), // Reset output for TAP controller.
|
||||
.RUNTEST (/* unused */), // Output asserted when TAP controller is in Run Test/Idle state.
|
||||
.SEL (jce1), // USER instruction active output.
|
||||
.SHIFT (jshift), // SHIFT output from TAP controller.
|
||||
.TCK (jtck_unbuf), // Test Clock output. Fabric connection to TAP Clock pin.
|
||||
.TDI (jtdi), // Test Data Input (TDI) output from TAP controller.
|
||||
.TMS (/* unused */), // Test Mode Select output. Fabric connection to TAP.
|
||||
.UPDATE (jupdate), // UPDATE output from TAP controller
|
||||
.TDO (jtdo1) // Test Data Output (TDO) input for USER function.
|
||||
);
|
||||
|
||||
BSCANE2 #(
|
||||
.JTAG_CHAIN (SEL_DMI)
|
||||
) bscan_dmi (
|
||||
.CAPTURE (/* unused */),
|
||||
.DRCK (/* unused */),
|
||||
.RESET (/* unused */),
|
||||
.RUNTEST (/* unused */),
|
||||
.SEL (jce2),
|
||||
.SHIFT (/* unused */),
|
||||
.TCK (/* unused */),
|
||||
.TDI (/* unused */),
|
||||
.TMS (/* unused */),
|
||||
.UPDATE (/* unused */),
|
||||
.TDO (jtdo2)
|
||||
);
|
||||
|
||||
BUFG bufg_jtck (
|
||||
.I (jtck_unbuf),
|
||||
.O (jtck)
|
||||
);
|
||||
|
||||
localparam W_DR_SHIFT = ABITS + 32 + 2;
|
||||
|
||||
wire core_dr_wen = jupdate;
|
||||
wire core_dr_ren = jcapture;
|
||||
wire core_dr_sel_dmi_ndtmcs = !jce1;
|
||||
wire dr_shift_en = jshift;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_wdata;
|
||||
wire [W_DR_SHIFT-1:0] core_dr_rdata;
|
||||
|
||||
reg [W_DR_SHIFT-1:0] dr_shift;
|
||||
assign core_dr_wdata = dr_shift;
|
||||
|
||||
always @ (posedge jtck or negedge jrst_n) begin
|
||||
if (!jrst_n) begin
|
||||
dr_shift <= {W_DR_SHIFT{1'b0}};
|
||||
end else if (core_dr_ren) begin
|
||||
dr_shift <= core_dr_rdata;
|
||||
end else if (dr_shift_en) begin
|
||||
dr_shift <= {jtdi, dr_shift[W_DR_SHIFT-1:1]};
|
||||
if (!core_dr_sel_dmi_ndtmcs)
|
||||
dr_shift[31] <= jtdi;
|
||||
end
|
||||
end
|
||||
|
||||
// We have only a single shifter for the two DRs, so these are tied together:
|
||||
assign jtdo1 = dr_shift[0];
|
||||
assign jtdo2 = dr_shift[0];
|
||||
|
||||
// The actual DTM is in here:
|
||||
|
||||
hazard3_jtag_dtm_core #(
|
||||
.DTMCS_IDLE_HINT (DTMCS_IDLE_HINT),
|
||||
.W_ADDR (ABITS)
|
||||
) inst_hazard3_jtag_dtm_core (
|
||||
.tck (jtck),
|
||||
.trst_n (jrst_n),
|
||||
|
||||
.clk_dmi (clk_dmi),
|
||||
.rst_n_dmi (rst_n_dmi),
|
||||
|
||||
.dr_wen (core_dr_wen),
|
||||
.dr_ren (core_dr_ren),
|
||||
.dr_sel_dmi_ndtmcs (core_dr_sel_dmi_ndtmcs),
|
||||
.dr_wdata (core_dr_wdata),
|
||||
.dr_rdata (core_dr_rdata),
|
||||
|
||||
.dmihardreset_req (dmihardreset_req),
|
||||
|
||||
.dmi_psel (dmi_psel),
|
||||
.dmi_penable (dmi_penable),
|
||||
.dmi_pwrite (dmi_pwrite),
|
||||
.dmi_paddr (dmi_paddr[W_PADDR-1:2]),
|
||||
.dmi_pwdata (dmi_pwdata),
|
||||
.dmi_prdata (dmi_prdata),
|
||||
.dmi_pready (dmi_pready),
|
||||
.dmi_pslverr (dmi_pslverr)
|
||||
);
|
||||
|
||||
assign dmi_paddr[1:0] = 2'b00;
|
||||
|
||||
endmodule
|
||||
|
||||
`ifndef YOSYS
|
||||
`default_nettype wire
|
||||
`endif
|
||||
Reference in New Issue
Block a user