@@ -86,8 +86,7 @@ async def _run(self):
86
86
tstart = utime .ticks_us ()
87
87
self ._sendrx ()
88
88
t = utime .ticks_diff (utime .ticks_us (), tstart )
89
- except OSError as e :
90
- # print('OSError:', e) # TEST
89
+ except OSError : # Reboot remote.
91
90
break
92
91
await asyncio .sleep_ms (Initiator .t_poll )
93
92
self .block_max = max (self .block_max , t ) # self measurement
@@ -99,27 +98,26 @@ async def _run(self):
99
98
if self .reset is None : # No means of recovery
100
99
raise OSError ('Responder fail.' )
101
100
102
- # Send payload length (may be 0) then payload (if any)
103
- def _sendrx (self , sn = bytearray (2 ), txnull = bytearray (2 )):
104
- siz = self .txsiz if self .cantx else txnull
105
- if self .rxbyt :
106
- siz [1 ] |= 0x80 # Hold off further received data
107
- else :
108
- siz [1 ] &= 0x7f
101
+ def _send (self , d ):
109
102
# CRITICAL TIMING. Trigger interrupt on responder immediately before
110
103
# send. Send must start before RX begins. Fast responders may need to
111
104
# do a short blocking wait to guarantee this.
112
105
self .own (1 ) # Trigger interrupt.
113
- self .i2c .send (siz ) # Blocks until RX complete.
106
+ self .i2c .send (d ) # Blocks until RX complete.
114
107
self .waitfor (1 )
115
108
self .own (0 )
116
109
self .waitfor (0 )
110
+
111
+ # Send payload length (may be 0) then payload (if any)
112
+ def _sendrx (self , sn = bytearray (2 ), txnull = bytearray (2 )):
113
+ siz = self .txsiz if self .cantx else txnull
114
+ if self .rxbyt :
115
+ siz [1 ] |= 0x80 # Hold off further received data
116
+ else :
117
+ siz [1 ] &= 0x7f
118
+ self ._send (siz )
117
119
if self .txbyt and self .cantx :
118
- self .own (1 )
119
- self .i2c .send (self .txbyt )
120
- self .waitfor (1 )
121
- self .own (0 )
122
- self .waitfor (0 )
120
+ self ._send (self .txbyt )
123
121
self ._txdone () # Invalidate source
124
122
# Send complete
125
123
self .waitfor (1 ) # Wait for responder to request send
@@ -133,7 +131,6 @@ def _sendrx(self, sn=bytearray(2), txnull=bytearray(2)):
133
131
self .cantx = not bool (sn [1 ] & 0x80 )
134
132
if n :
135
133
self .waitfor (1 ) # Wait for responder to request send
136
- # print('setting up receive', n,' bytes')
137
134
self .own (1 ) # Acknowledge
138
135
mv = self .rx_mv [0 : n ] # mv is a memoryview instance
139
136
self .i2c .recv (mv )
0 commit comments