7b465fb7b5797a2a44d62d1a0920917b5941233e
[c4m-jtag.git] / test / nmigen / 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.tap_bus__tck, dut.tap_bus__tms, dut.tap_bus__tdi, dut.tap_bus__tdo, clk_period=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.tap_bus__tck, dut.tap_bus__tms, dut.tap_bus__tdi, dut.tap_bus__tdo, clk_period=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.tap_bus__tck, dut.tap_bus__tms, dut.tap_bus__tdi, dut.tap_bus__tdo, clk_period=clk_period)
61
62
63 dut._log.info("Load SAMPLEPRELOAD command")
64 yield master.load_ir(master.SAMPLEPRELOAD)
65
66 data_in.binstr = "011000"
67 dut._log.info(" preloading data {}".format(data_in.binstr))
68
69 # Set the ios pins
70 dut.top_coreo = 2
71 dut.top_coreoe = 0
72 dut.top_padi = 1
73 yield master.shift_data(data_in)
74 dut._log.info(" output: {}".format(master.result.binstr))
75 assert(master.result.binstr == "100010")
76
77
78 dut._log.info("Load EXTEST command")
79 yield master.load_ir(master.EXTEST)
80
81 data_in.binstr = "100111"
82 dut._log.info(" input data {}".format(data_in.binstr))
83
84 # Set the ios pins
85 dut.top_coreo = 1
86 dut.top_coreoe = 3
87 dut.top_padi = 2
88 yield master.shift_data(data_in)
89 dut._log.info(" output: {}".format(master.result.binstr))
90 assert(master.result.binstr == "011101")
91
92 dut._log.info("Do a capture of the last loaded data")
93 yield master.shift_data([])
94