55@copyright: Copyright (C) 2024 Pat Deegan, https://psychogenic.com
66'''
77from ttboard .demoboard import DemoBoard , Pins
8+ import ttboard .util .platform as plat
89import microcotb .dut
910from microcotb .testcase import TestCase
1011from microcotb .dut import NoopSignal
@@ -25,6 +26,25 @@ def value(self, set_to:int):
2526 if self ._pin .mode != Pins .OUT :
2627 self ._pin .mode = Pins .OUT
2728 self ._pin .value (set_to )
29+
30+ class ClockPin (microcotb .dut .PinWrapper ):
31+ '''
32+ clock pin is use *a lot*, needs
33+ to be optimized a little by
34+ calling the low level platform func
35+ '''
36+
37+ def __init__ (self , name :str , pin ):
38+ super ().__init__ (name , pin )
39+
40+ @property
41+ def value (self ):
42+ return plat .read_clock ()
43+
44+ @value .setter
45+ def value (self , set_to :int ):
46+ plat .write_clock (set_to )
47+
2848
2949
3050class DUT (microcotb .dut .DUT ):
@@ -36,9 +56,10 @@ def __init__(self, name:str='DUT'):
3656 self .tt = tt # give ourselves access to demoboard object
3757
3858 # wrap the bare clock pin
39- self .clk = PinWrapper ('clk' , self .tt .pins .rp_projclk )
59+ self .clk = ClockPin ('clk' , self .tt .pins .rp_projclk )
4060 self .rst_n = PinWrapper ('rst_n' , self .tt .rst_n )
4161
62+
4263 # provide the I/O ports from DemoBoard
4364 # as attribs here, so we have dut.ui_in.value etc.
4465
@@ -57,21 +78,29 @@ def testing_will_begin(self):
5778 self ._log .info ('autoclocking... will stop it.' )
5879 self .tt .clock_project_stop ()
5980
81+ # and this: make sure is an output
82+ self .tt .pins .rp_projclk .mode = Pins .OUT
83+
6084 def testing_unit_start (self , test :TestCase ):
6185 # override if desired
6286 self ._log .debug (f'Test { test .name } about to start' )
6387
6488
6589 def testing_unit_done (self , test :TestCase ):
6690 # override if desired
91+
6792 if test .failed :
6893 self ._log .debug (f'{ test .name } failed because: { test .failed_msg } ' )
6994 else :
7095 self ._log .debug (f'{ test .name } passed!' )
7196
7297
7398 def testing_done (self ):
74- # override if desired
99+ # override if desired, but good idea to reset clock pin mode
100+ # or just call super().testing_unit_done(test) to get it done
101+ # make sure is an input
102+ self .tt .pins .rp_projclk .mode = Pins .IN
103+
75104 self ._log .debug ('All testing done' )
76105
77106
0 commit comments