2
2
from artiq .test .hardware_testbench import ExperimentCase
3
3
4
4
5
+ class WrongError (Exception ):
6
+ pass
7
+
8
+
5
9
class Collision (EnvExperiment ):
6
10
def build (self ):
7
11
self .setattr_device ("core" )
@@ -11,7 +15,10 @@ def build(self):
11
15
def run (self ):
12
16
self .core .break_realtime ()
13
17
t = now_mu ()
14
- self .spi0 .set_config_mu ()
18
+ try :
19
+ self .spi0 .set_config_mu ()
20
+ except RTIOBusy :
21
+ raise WrongError ()
15
22
at_mu (t )
16
23
self .spi0 .set_config_mu ()
17
24
@@ -24,18 +31,49 @@ def build(self):
24
31
25
32
@kernel
26
33
def run (self ):
27
- self .core .break_realtime ()
28
- t = now_mu ()
29
- self .spi0 .set_config_mu ()
30
- at_mu (t + self .spi0 .ref_period_mu )
31
- self .spi0 .set_config_mu () # causes the error
32
- self .led .on ()
33
- self .led .sync () # registers the error
34
- self .core .break_realtime ()
34
+ try :
35
+ self .core .break_realtime ()
36
+ self .spi0 .set_config_mu ()
37
+ t = now_mu ()
38
+ self .spi0 .set_config_mu ()
39
+ at_mu (t + self .spi0 .ref_period_mu )
40
+ self .spi0 .set_config_mu () # causes the error
41
+ self .led .on ()
42
+ self .led .sync () # registers the error
43
+ self .core .break_realtime ()
44
+ except RTIOBusy :
45
+ raise WrongError () # we don't expect RTIOBusy so far
35
46
self .spi0 .set_config_mu () # raises the error
36
47
37
48
49
+ class DrainErrors (EnvExperiment ):
50
+ def build (self ):
51
+ self .setattr_device ("core" )
52
+ self .setattr_device ("spi0" )
53
+ self .setattr_device ("led" )
54
+
55
+ @kernel
56
+ def run (self ):
57
+ while True :
58
+ try :
59
+ self .core .break_realtime ()
60
+ delay (100 * us )
61
+ self .spi0 .set_config_mu ()
62
+ self .led .on ()
63
+ self .led .sync ()
64
+ self .core .break_realtime ()
65
+ self .spi0 .set_config_mu ()
66
+ self .led .off ()
67
+ return
68
+ except :
69
+ pass
70
+
71
+
38
72
class SPITest (ExperimentCase ):
73
+ def tearDown (self ):
74
+ self .execute (DrainErrors )
75
+ ExperimentCase .tearDown (self )
76
+
39
77
def test_collision (self ):
40
78
with self .assertRaises (RTIOCollision ):
41
79
self .execute (Collision )
0 commit comments