Support for different IO types in VHDL code.
[c4m-jtag.git] / test / vhdl / cocotb / controller / test.py
1 import cocotb
2 from cocotb.utils import get_sim_steps
3 from cocotb.binary import BinaryValue
4
5 from c4m.cocotb.jtag.c4m_jtag import JTAG_Master
6
7 @cocotb.test()
8 def test01_idcode(dut):
9 """
10 Test the IDCODE command
11 """
12
13 # Run @ 1MHz
14 clk_period = get_sim_steps(1, "us")
15 master = JTAG_Master(dut.tck, dut.tms, dut.tdi, dut.tdo, dut.trst_n, clk_period)
16
17 dut._log.info("Trying to get IDCODE...")
18
19 yield master.idcode()
20 result1 = master.result
21 dut._log.info("IDCODE1: {}".format(result1))
22
23 yield master.idcode()
24 result2 = master.result
25 dut._log.info("IDCODE2: {}".format(result2))
26
27 assert(result1 == result2)
28
29 @cocotb.test()
30 def test02_bypass(dut):
31 """
32 Test of BYPASS mode
33 """
34
35 # Run @ 1MHz
36 clk_period = get_sim_steps(1, "us")
37 master = JTAG_Master(dut.tck, dut.tms, dut.tdi, dut.tdo, dut.trst_n, clk_period)
38
39 dut._log.info("Loading BYPASS command")
40 yield master.load_ir(master.BYPASS)
41
42 dut._log.info("Sending data")
43
44 data_in = BinaryValue()
45 data_in.binstr = "01001101"
46 yield master.shift_data(data_in)
47
48 dut._log.info("bypass out: {}".format(master.result.binstr))
49 assert(master.result.binstr[:-1] == data_in.binstr[1:])
50
51 @cocotb.test()
52 def test03_sample(dut):
53 """
54 Test of SAMPLEPRELOAD and EXTEST
55 """
56 data_in = BinaryValue()
57
58 # Run @ 1MHz
59 clk_period = get_sim_steps(1, "us")
60 master = JTAG_Master(dut.tck, dut.tms, dut.tdi, dut.tdo, dut.trst_n, clk_period)
61
62
63 dut._log.info("Load SAMPLEPRELOAD command")
64 yield master.load_ir(master.SAMPLEPRELOAD)
65
66 data_in.binstr = "0101110"
67 dut._log.info(" preloading data {}".format(data_in.binstr))
68
69 # Set the ios pins
70 dut.core_out = BinaryValue("X010")
71 dut.core_en = BinaryValue("XX01")
72 dut.pad_in = BinaryValue("1XX0")
73 yield master.shift_data(data_in)
74 dut._log.info(" output: {}".format(master.result.binstr))
75 assert(master.result.binstr == "1010001")
76
77
78 dut._log.info("Load EXTEST command")
79 yield master.load_ir(master.EXTEST)
80
81 data_in.binstr = "1010001"
82 dut._log.info(" input data {}".format(data_in.binstr))
83
84 # Set the ios pins
85 dut.core_out = BinaryValue("X101")
86 dut.core_en = BinaryValue("XX10")
87 dut.pad_in = BinaryValue("0XX1")
88 yield master.shift_data(data_in)
89 dut._log.info(" output: {}".format(master.result.binstr))
90 assert(master.result.binstr == "0101110")
91
92 dut._log.info("Do a capture of the last loaded data")
93 yield master.shift_data([])
94