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