Support for different IO types in VHDL code.
[c4m-jtag.git] / test / vhdl / cocotb / ioblock / test.py
1 import cocotb
2 from cocotb.utils import get_sim_steps
3 from cocotb.binary import BinaryValue
4 from cocotb.triggers import Timer
5
6 def report_bdsr(dut):
7 for handle in dut.blck:
8 if handle._name.startswith("iogen"):
9 for handle2 in handle:
10 if handle2._name == "iocell":
11 values = {}
12 for handle3 in handle2:
13 if handle3._name in ("bdsr_in", "bdsr_out", "sr_ioin", "sr_ioout", "sr_ioen"):
14 values[handle3._name] = handle3.value.binstr
15 dut._log.info("{}: {!r}".format(handle2._path, values))
16
17 @cocotb.test()
18 def test01_boundaryscan(dut):
19 """
20 Check initialization
21 """
22 dut.ir = 0
23 dut.tck = 0
24 dut.tdi = 1
25 dut.capture = 0
26 dut.shift = 0
27 dut.update = 0
28
29 # Boundary scan: IN > OUT > OUT3 > INOUT3
30 # Length: 1 + 1 + 2 + 3 = 7
31
32 yield Timer(1)
33
34 report_bdsr(dut)
35
36 assert dut.core_in.value.binstr == "UXXU"
37 assert dut.pad_out.value.binstr == "XUUU"
38 assert dut.pad_en.value.binstr == "XXUU"
39
40 dut.ir = BinaryValue("10") # SAMPLEPRELOAD
41 dut.core_out = BinaryValue("0000")
42 dut.core_en = BinaryValue("0000")
43 dut.pad_in = BinaryValue("0000")
44 yield Timer(1)
45
46 assert dut.core_in.value.binstr == "0XX0"
47 assert dut.pad_out.value.binstr == "X000"
48 assert dut.pad_en.value.binstr == "XX00"
49
50 dut.capture = 1
51 yield Timer(1)
52 dut.tck = 1
53 yield Timer(1)
54 dut.capture = 0
55 dut.tck = 0
56 yield Timer(1)
57
58 assert dut.core_in.value.binstr == "0XX0"
59 assert dut.pad_out.value.binstr == "X000"
60 assert dut.pad_en.value.binstr == "XX00"
61
62 dut.shift = 1
63 yield Timer(1)
64 for i in range(7):
65 dut._log.info("Cycle {}".format(i))
66 report_bdsr(dut)
67 assert dut.tdo.value.binstr == "0"
68 dut.tck = 1
69 yield Timer(1)
70 dut.tck = 0
71 yield Timer(1)
72 dut._log.info("Cycle 7")
73 report_bdsr(dut)
74 assert dut.tdo.value.binstr == "1"
75
76 dut.shift = 0
77 dut.update = 1
78 yield Timer(1)
79 dut.tck = 1
80 yield Timer(1)
81 dut.update = 0
82 dut.tck = 0
83 yield Timer(1)
84
85 assert dut.core_in.value.binstr == "0XX0"
86 assert dut.pad_out.value.binstr == "X000"
87 assert dut.pad_en.value.binstr == "XX00"
88
89 dut.ir = BinaryValue("00") # EXTEST
90 yield Timer(1)
91
92 assert dut.core_in.value.binstr == "0XX0"
93 assert dut.pad_out.value.binstr == "X111"
94 assert dut.pad_en.value.binstr == "XX11"