-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtest_tap.py
77 lines (60 loc) · 2.74 KB
/
test_tap.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import functools
import unittest
from amaranth import *
from amaranth.sim import Simulator
from amaranth_stdio.jtag import tap
async def shift_tms(ctx, dut, tms, state_after, *, expected={}):
ctx.set(dut.tms.i, tms)
# HACK(bin): i'm so sorry?
(_, _, *sampled) = await ctx.tick("jtag").sample(*[getattr(dut, s).o for s in expected.keys()])
assert ctx.get(dut.state == state_after)
for (dut_value, (name, expected_value)) in zip(sampled, expected.items()):
assert dut_value == expected_value, f"dut.{name} != {expected_value:#b}"
class TAPTestCase(unittest.TestCase):
def test_tap_controller(self):
ir_idcode = 0b10101010
dr_idcode = 0b0011_1111000011110000_00001010100_1
m = Module()
m.submodules.dut = dut = tap.Controller(ir_length=8, ir_idcode=ir_idcode)
m.d.comb += dut.dr_idcode.cap.eq(dr_idcode)
async def testbench(ctx):
global shift_tms
shift_tms = functools.partial(shift_tms, ctx, dut)
assert ctx.get(dut.state) == tap.State.Test_Logic_Reset
await shift_tms(0, tap.State.Run_Test_Idle)
await shift_tms(1, tap.State.Select_DR_Scan)
await shift_tms(0, tap.State.Capture_DR)
await shift_tms(0, tap.State.Shift_DR)
for i in range(32):
await shift_tms(0, tap.State.Shift_DR, expected={
"tdo": (dr_idcode >> i) & 1
})
await shift_tms(1, tap.State.Exit1_DR)
await shift_tms(0, tap.State.Pause_DR)
await shift_tms(1, tap.State.Exit2_DR)
await shift_tms(1, tap.State.Update_DR)
await shift_tms(1, tap.State.Select_DR_Scan)
await shift_tms(1, tap.State.Select_IR_Scan)
ctx.set(dut.ir_cap, 0b111111)
await shift_tms(0, tap.State.Capture_IR)
await shift_tms(0, tap.State.Shift_IR)
await shift_tms(0, tap.State.Shift_IR, expected={
"tdo": 0b1
})
await shift_tms(1, tap.State.Exit1_IR, expected={
"tdo": 0b0
})
await shift_tms(0, tap.State.Pause_IR)
await shift_tms(1, tap.State.Exit2_IR)
await shift_tms(1, tap.State.Update_IR)
await shift_tms(1, tap.State.Select_DR_Scan)
assert ctx.get(dut.ir_upd) == 0b111111
await shift_tms(1, tap.State.Select_IR_Scan)
await shift_tms(1, tap.State.Test_Logic_Reset)
await shift_tms(1, tap.State.Test_Logic_Reset)
assert ctx.get(dut.ir_upd) == ir_idcode
sim = Simulator(m)
sim.add_clock(1e-3, domain="jtag")
sim.add_testbench(testbench)
with sim.write_vcd("test_tap.vcd"):
sim.run()