Skip to content

Commit

Permalink
write to TDO on the negative edge. This adds a half-cycle delay to av…
Browse files Browse the repository at this point in the history
…oid hold time violations. This changes how long it takes to get IDCODE out.
  • Loading branch information
stevej committed Nov 4, 2024
1 parent ef61f98 commit 4e0398f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/byte_transmitter.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ module byte_transmitter (
reg r_done;
assign done = r_done;

always @(posedge clk) begin
// TDO must be written on the falling edge
// to avoid hold violations.
always @(negedge clk) begin
if (reset) begin
byte_count <= 6'h20;
r_done <= 1'b0;
Expand Down
12 changes: 11 additions & 1 deletion src/jtag.v
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ module jtag (

bit been_reset;

always @(negedge tck) begin
if (r_output_selector_transmitter) tap_channel <= 1'b0;
end

always @(posedge tck) begin
if (~trst_n) begin
current_state <= TestLogicReset; // State 0
Expand All @@ -116,7 +120,6 @@ module jtag (
cycles <= cycles + 1'd1;
current_ir_instruction <= current_ir_instruction;
r_output_selector_transmitter <= r_output_selector_transmitter;
tap_channel <= 1'b0;
byte_transmitter_enable <= byte_transmitter_enable;
reset_byte_transmitter <= reset_byte_transmitter;
// TAP state machine
Expand Down Expand Up @@ -157,6 +160,13 @@ module jtag (
r_output_selector_transmitter <= 1'b0;
byte_transmitter_enable <= 1'b1;
end
Abort: begin
current_state <= ShiftDr;
end
Bypass: begin
// TODO: disable pins connected to the scan chain
current_state <= ShiftDr;
end
default: begin
current_state <= ShiftDr;
end
Expand Down
19 changes: 11 additions & 8 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,25 +112,28 @@ async def test_idcode(dut):
dut.ui_in.value = 0
dut.uio_in.value = 0
dut.rst_n.value = 1
# We start with TRST being high per the spec.
dut.ui_in.value = 0b0000_1001
dut.ui_in.value = 0b0000_0001
await ClockCycles(dut.clk, 1)
dut.rst_n.value = 0
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_0000
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_0001
dut.rst_n.value = 1
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_0000
await ClockCycles(dut.clk, 1)


# Drive TRST and TCK high then low to reset tap controller
dut._log.info("Reset the jtag tap controller")
dut.ui_in.value = 0b0000_0001
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_1000
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_1101
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_1000
await ClockCycles(dut.clk, 1)
#dut.ui_in.value = 0b0000_1001
#await ClockCycles(dut.clk, 1)
#dut.ui_in.value = 0b0000_1000
#await ClockCycles(dut.clk, 1)

# Should be nothing on the output lines as there hasn't been enough
# for an interrupt and we haven't changed out of the initial JTAG state.
Expand All @@ -148,7 +151,7 @@ async def test_idcode(dut):
expected_idcode = 0xFAF01
given_idcode = 0
# Drive TCK high/low enough times to see 0xFAF01, our IDCODE
for i in range(32):
for i in range(31):
dut.ui_in.value = 0b0000_1001
await ClockCycles(dut.clk, 1)
dut.ui_in.value = 0b0000_1000
Expand Down

0 comments on commit 4e0398f

Please sign in to comment.