@@ -58,19 +58,27 @@ async def test_enabled_with_window_close(dut):
58
58
59
59
dut ._log .info ("Test project behavior" )
60
60
# Test writing 10 to WATCHDOG_CLOSE register
61
- await tqv .write_word_reg (2 , 0xA )
62
- assert await tqv .read_word_reg (2 ) == 0xA
61
+ await tqv .write_word_reg (2 , 0xAAA )
62
+ assert await tqv .read_word_reg (2 ) == 0xAAA
63
63
64
64
# Test enabling watchdog timer by writing to interrupt.
65
65
await tqv .write_word_reg (0 , 0x1 )
66
+ assert await tqv .read_word_reg (0 ) == 0x1
67
+
68
+ # Send pat immediately
69
+ await tqv .write_word_reg (3 , 0x1 )
70
+ assert await tqv .read_word_reg (3 ) == 0x1
66
71
67
- await ClockCycles (dut .clk , 5 )
68
- # no interrupts, no pat seen, watchdog has been enabled, timer not expired
69
- assert dut .uo_out .value == 0b01010000
72
+ await ClockCycles (dut .clk , 0xAA )
73
+ assert dut .uo_out .value != 0b10111100 # we should not trigger at this point.
74
+
75
+ # Checking that the watchdog does eventually fire
76
+ await ClockCycles (dut .clk , 0xAAA )
77
+ assert dut .uo_out .value == 0b10111100
70
78
71
79
# Test that enabling the watchdog timer with a WINDOW_CLOSE of 10 results in an expired timer in 10 cycles.
72
80
@cocotb .test ()
73
- async def test_enabled_with_window_close (dut ):
81
+ async def test_enabled_with_window_close2_and_immediate_pat (dut ):
74
82
dut ._log .info ("Start" )
75
83
76
84
# Set the clock period to 100 ns (10 MHz)
@@ -89,84 +97,47 @@ async def test_enabled_with_window_close(dut):
89
97
dut ._log .info ("Test project behavior" )
90
98
# Set WINDOW_CLOSE
91
99
await tqv .write_word_reg (2 , 0xAAA ) # 2730 cycles
100
+ assert await tqv .read_word_reg (2 ) == 0xAAA
92
101
93
102
# Test enabling watchdog timer by writing to interrupt.
94
103
await tqv .write_word_reg (0 , 0x1 )
95
104
105
+ # Send pat immediately
106
+ await tqv .write_word_reg (3 , 0x1 )
107
+ assert await tqv .read_word_reg (3 ) == 0x1
108
+
96
109
await ClockCycles (dut .clk , 1 )
97
110
# watchdog has been enabled, no pat seen, timer expired
98
111
# no interrupt, no pat seen, watchdog enabled, after_window_start, window has not closed.
99
- assert dut .uo_out .value == 0b01011000 # this is actually 0b10011100 so the timer has expired after 1 clock cycle.
112
+ assert dut .uo_out .value != 0b10011100 # we should not have triggered.
113
+ assert dut .uo_out .value == 0b01111000
100
114
101
115
# Check that the watchdog is enabled but not triggered for 10 cycles.
102
116
for _ in range (10 ):
103
117
await ClockCycles (dut .clk , 1 )
104
118
# watchdog has been enabled, no pat seen, timer expired
105
119
# no interrupt, no pat seen, watchdog enabled, after_window_start, window has not closed.
106
- assert dut .uo_out .value == 0b01011000
120
+ assert dut .uo_out .value == 0b01111000
107
121
108
122
# TODO: Mystery! For some unknown reason we only need 101, and not (2730 - already used) cycles, for the watchdog to trigger.
109
- await ClockCycles (dut .clk , 101 )
123
+ await ClockCycles (dut .clk , 0xAAA )
110
124
# interrupt, watchdog enabled, after_window_start, after_window_close
111
- assert dut .uo_out .value == 0b1001_1100
125
+ assert dut .uo_out .value == 0b1011_1100
112
126
113
127
# interrupts, no pat seen, watchdog enabled, after_window_start
114
128
# After enough clock cycles, this should be 0b10011000 which indicates the watchdog has been triggered.
115
129
timer_elapsed = 0
116
130
for _ in range (10 ):
117
- if dut .uo_out .value != 0b0101_1000 :
118
- assert dut .uo_out .value == 0b1001_1100
119
- if dut .uo_out .value == 0b1001_1100 :
131
+ if dut .uo_out .value != 0b0111_1000 :
132
+ assert dut .uo_out .value == 0b1011_1100
133
+ if dut .uo_out .value == 0b1011_1100 :
120
134
timer_elapsed = 1
121
135
assert timer_elapsed
122
136
123
137
124
138
# Test that enabling the watchdog timer with a WINDOW_OPEN of 5 and a WINDOW_CLOSE of 10 doesn't
125
139
# trigger outside the window but does trigger inside the window.
126
140
127
- # Test that enabling the watchdog timer with a WINDOW_CLOSE of 10 results in an expired timer in 10 cycles.
128
- @cocotb .test ()
129
- async def test_enabled_with_window_start_and_close_no_pat (dut ):
130
- dut ._log .info ("Start" )
131
-
132
- # Set the clock period to 100 ns (10 MHz)
133
- clock = Clock (dut .clk , 100 , units = "ns" )
134
- cocotb .start_soon (clock .start ())
135
-
136
- # Interact with your design's registers through this TinyQV class.
137
- # This will allow the same test to be run when your design is integrated
138
- # with TinyQV - the implementation of this class will be replaces with a
139
- # different version that uses Risc-V instructions instead of the SPI
140
- # interface to read and write the registers.
141
- tqv = TinyQV (dut )
142
- # Reset
143
- await tqv .reset ()
144
-
145
- dut ._log .info ("Test project behavior" )
146
- # Writing 5 to WATCHDOG_START register
147
- await tqv .write_word_reg (1 , 0x5 )
148
- # Writing 10 to WATCHDOG_CLOSE register
149
- await tqv .write_word_reg (2 , 0xBBB )
150
- # Enabling watchdog timer
151
- await tqv .write_word_reg (0 , 0x1 )
152
-
153
- await ClockCycles (dut .clk , 1 )
154
- # watchdog should not have tripped after 1 cycle when configured for 0xBBB cycles
155
- assert dut .uo_out .value != 0b10011000
156
- assert dut .uo_out .value == 0b01011100
157
-
158
- # The watchdog should not trigger in less cycles than configured.
159
- await ClockCycles (dut .clk , 0xAA )
160
- # If this assertion fails, the watchdog triggered too quickly from our perspective.
161
- assert dut .uo_out .value != 0b10011100
162
-
163
- await ClockCycles (dut .clk , 0xA00 )
164
- assert dut .uo_out .value == 0b01111000
165
-
166
- await ClockCycles (dut .clk , 0xBBB )
167
- assert dut .uo_out .value == 0b10111100
168
-
169
-
170
141
171
142
# Test that enabling the watchdog timer with a WINDOW_CLOSE of 10 results in an expired timer in 10 cycles.
172
143
@cocotb .test ()
@@ -194,7 +165,7 @@ async def test_enabled_with_window_start_and_close_early_pat(dut):
194
165
# Enabling watchdog timer
195
166
await tqv .write_word_reg (0 , 0x1 )
196
167
197
- # immediately patting
168
+ # immediately patting to reset the timer.
198
169
await tqv .write_word_reg (3 , 0x1 )
199
170
200
171
0 commit comments