8
8
from tqv import TinyQV
9
9
10
10
@cocotb .test ()
11
- async def test_project (dut ):
11
+ async def test_enabled_without_window (dut ):
12
12
dut ._log .info ("Start" )
13
13
14
14
# Set the clock period to 100 ns (10 MHz)
@@ -27,11 +27,11 @@ async def test_project(dut):
27
27
28
28
dut ._log .info ("Test project behavior" )
29
29
30
- # Test register write and read back
31
- await tqv .write_word_reg (0 , 0x12345678 )
32
- assert await tqv .read_byte_reg (0 ) == 0x78
33
- assert await tqv .read_hword_reg (0 ) == 0x5678
34
- assert await tqv .read_word_reg (0 ) == 0x12345678
30
+ # Test enabling watchdog timer by writing to interrupt.
31
+ await tqv .write_word_reg (0 , 0x1 )
32
+ assert await tqv .read_byte_reg (0 ) == 0x1
33
+ assert await tqv .read_hword_reg (0 ) == 0x1
34
+ assert await tqv .read_word_reg (0 ) == 0x1
35
35
36
36
# Set an input value, in the example this will be added to the register value
37
37
dut .ui_in .value = 30
@@ -40,19 +40,10 @@ async def test_project(dut):
40
40
# and a further clock is required for the output to propagate.
41
41
await ClockCycles (dut .clk , 3 )
42
42
43
- # The following assersion is just an example of how to check the output values.
44
- # Change it to match the actual expected output of your module:
45
- assert dut .uo_out .value == 0x96
43
+ assert dut .uo_out .value == 0b1001_0000
46
44
47
- # Input value should be read back from register 1
48
- assert await tqv .read_byte_reg (4 ) == 30
49
-
50
- # Zero should be read back from register 2
51
- assert await tqv .read_word_reg (8 ) == 0
52
-
53
- # A second write should work
54
- await tqv .write_word_reg (0 , 40 )
55
- assert dut .uo_out .value == 70
45
+ # Input value of 0 should be read back from register 1 as it was never set.
46
+ assert await tqv .read_byte_reg (1 ) == 0
56
47
57
48
# Test the interrupt, generated when ui_in[6] goes high
58
49
dut .ui_in [6 ].value = 1
@@ -66,7 +57,66 @@ async def test_project(dut):
66
57
# Interrupt doesn't clear
67
58
await ClockCycles (dut .clk , 10 )
68
59
assert dut .uio_out [0 ].value == 1
69
-
70
- # Write bottom bit of address 8 high to clear
71
- await tqv .write_byte_reg (8 , 1 )
72
- assert dut .uio_out [0 ].value == 0
60
+
61
+
62
+ # Test that enabling the watchdog timer with a WINDOW_CLOSE of results in a set watchdog
63
+ @cocotb .test ()
64
+ async def test_enabled_with_window_close (dut ):
65
+ dut ._log .info ("Start" )
66
+
67
+ # Set the clock period to 100 ns (10 MHz)
68
+ clock = Clock (dut .clk , 100 , units = "ns" )
69
+ cocotb .start_soon (clock .start ())
70
+
71
+ # Interact with your design's registers through this TinyQV class.
72
+ # This will allow the same test to be run when your design is integrated
73
+ # with TinyQV - the implementation of this class will be replaces with a
74
+ # different version that uses Risc-V instructions instead of the SPI
75
+ # interface to read and write the registers.
76
+ tqv = TinyQV (dut )
77
+ # Reset
78
+ await tqv .reset ()
79
+
80
+ dut ._log .info ("Test project behavior" )
81
+ # Test writing 10 to WATCHDOG_CLOSE register
82
+ await tqv .write_word_reg (1 , 0xA )
83
+
84
+ # Test enabling watchdog timer by writing to interrupt.
85
+ await tqv .write_word_reg (0 , 0x1 )
86
+
87
+ await ClockCycles (dut .clk , 5 )
88
+ # watchdog has been enabled, no pat seen, timer not expired
89
+ assert dut .uo_out .value == 0b01010000
90
+
91
+ # Test that enabling the watchdog timer with a WINDOW_CLOSE of 10 results in an expired timer in 10 cycles.
92
+ @cocotb .test ()
93
+ async def test_enabled_with_window_close (dut ):
94
+ dut ._log .info ("Start" )
95
+
96
+ # Set the clock period to 100 ns (10 MHz)
97
+ clock = Clock (dut .clk , 100 , units = "ns" )
98
+ cocotb .start_soon (clock .start ())
99
+
100
+ # Interact with your design's registers through this TinyQV class.
101
+ # This will allow the same test to be run when your design is integrated
102
+ # with TinyQV - the implementation of this class will be replaces with a
103
+ # different version that uses Risc-V instructions instead of the SPI
104
+ # interface to read and write the registers.
105
+ tqv = TinyQV (dut )
106
+ # Reset
107
+ await tqv .reset ()
108
+
109
+ dut ._log .info ("Test project behavior" )
110
+ # Test writing 10 to WATCHDOG_CLOSE register
111
+ await tqv .write_word_reg (1 , 0xA )
112
+
113
+ # Test enabling watchdog timer by writing to interrupt.
114
+ await tqv .write_word_reg (0 , 0x1 )
115
+
116
+ await ClockCycles (dut .clk , 10 )
117
+ # watchdog has been enabled, no pat seen, timer expired
118
+ assert dut .uo_out .value == 0b10010000
119
+
120
+
121
+ # Test that enabling the watchdog timer with a WINDOW_OPEN of 5 and a WINDOW_CLOSE of 10 doesn't
122
+ # trigger outside the window but does trigger inside the window.
0 commit comments