@@ -15,16 +15,20 @@ configured for a transfer before the master attempts to access it.
15
15
16
16
The Pyboard or similar STM based boards are currently the only targets
17
17
supporting I2C slave mode. Consequently at least one end of the interface
18
- (known as the` Initiator ` ) must be a Pyboard. The other end may be any hardware
19
- running MicroPython.
18
+ (known as the` Initiator ` ) must be a Pyboard or other board supporting the ` pyb `
19
+ module. The ` Responder ` may be any hardware running MicroPython and supporting
20
+ ` machine ` .
20
21
21
- ` Initiator ` user applications may implement a timeout to enable detection of
22
- failure of the other end of the interface (the ` Responder ` ). The ` Initiator `
23
- can reset the ` Responder ` in this event.
22
+ If the ` Responder ` (typically an ESP8266) crashes the resultant I2C failure is
23
+ detected by the ` Initiator ` which can issue a hardware reboot to the
24
+ ` Responder ` enabling the link to recover. This can occur transparently to the
25
+ application and is covered in detail
26
+ [ in section 5.3] ( ./README.md#53-responder-crash-detection ) .
24
27
25
28
## Changes
26
29
27
- v0.16 Minor improvements and bugfixes. Eliminate ` timeout ` option which caused
30
+ V0.17 Dec 2018 Initiator: add optional "go" and "fail" user coroutines.
31
+ V0.16 Minor improvements and bugfixes. Eliminate ` timeout ` option which caused
28
32
failures where ` Responder ` was a Pyboard.
29
33
V0.15 RAM allocation reduced. Flow control implemented.
30
34
V0.1 Initial release.
@@ -40,6 +44,7 @@ V0.1 Initial release.
40
44
4.1 [ Channel class] ( ./README.md#41-channel-class )
41
45
4.2 [ Initiator class] ( ./README.md#42-initiator-class )
42
46
4.2.1 [ Configuration] ( ./README.md#421-configuration ) Fine-tuning the interface.
47
+ 4.2.2 [ Optional coroutines] ( ./README.md#422-optional-coroutines )
43
48
4.3 [ Responder class] ( ./README.md#43-responder-class )
44
49
5 . [ Limitations] ( ./README.md#5-limitations )
45
50
5.1 [ Blocking] ( ./README.md#51-blocking )
@@ -109,7 +114,7 @@ this interface.
109
114
110
115
A further issue common to most communications protocols is synchronisation:
111
116
the devices won't boot simultaneously. Initially, and after the ` Initiator `
112
- reboots the ` Responder ` , both ends run a synchronisation phase. The iterface
117
+ reboots the ` Responder ` , both ends run a synchronisation phase. The interface
113
118
starts to run once each end has determined that its counterpart is ready.
114
119
115
120
The design assumes exclusive use of the I2C interface. Hard or soft I2C may be
@@ -219,12 +224,17 @@ Coroutine:
219
224
220
225
## 4.2 Initiator class
221
226
222
- Constructor args:
227
+ ##### Constructor args:
223
228
1 . ` i2c ` An ` I2C ` instance.
224
229
2 . ` pin ` A ` Pin ` instance for the ` sync ` signal.
225
230
3 . ` pinack ` A ` Pin ` instance for the ` ack ` signal.
226
231
4 . ` reset=None ` Optional tuple defining a reset pin (see below).
227
232
5 . ` verbose=True ` If ` True ` causes debug messages to be output.
233
+ 6 . ` cr_go=False ` Optional coroutine to run at startup. See
234
+ [ 4.2.2] ( ./README.md#422-optional-coroutines ) .
235
+ 7 . ` go_args=() ` Optional tuple of args for above coro.
236
+ 8 . ` cr_fail=False ` Optional coro to run on ESP8266 fail or reboot.
237
+ 9 . ` f_args=() ` Optional tuple of args for above.
228
238
229
239
The ` reset ` tuple consists of (` pin ` , ` level ` , ` time ` ). If provided, and the
230
240
` Responder ` times out, ` pin ` will be set to ` level ` for duration ` time ` ms. A
@@ -239,26 +249,26 @@ If the `Initiator` has no `reset` tuple and the `Responder` times out, an
239
249
240
250
` Pin ` instances passed to the constructor must be instantiated by ` machine ` .
241
251
242
- Class variables:
252
+ ##### Class variables:
243
253
1 . ` t_poll=100 ` Interval (ms) for ` Initiator ` polling ` Responder ` .
244
254
2 . ` rxbufsize=200 ` Size of receive buffer. This should exceed the maximum
245
255
message length.
246
256
247
- Class variables should be set before instantiating ` Initiator ` or ` Responder ` .
248
- See [ Section 4.4] ( ./README.md#44-configuration ) .
257
+ See [ Section 4.2.1] ( ./README.md#421-configuration ) .
249
258
250
- Instance variables:
259
+ ##### Instance variables:
251
260
252
261
The ` Initiator ` maintains instance variables which may be used to measure its
253
- peformance. See [ Section 4.4 ] ( ./README.md#44 -configuration ) .
262
+ peformance. See [ Section 4.2.1 ] ( ./README.md#421 -configuration ) .
254
263
255
- Coroutine:
264
+ ##### Coroutine:
256
265
1 . ` reboot ` If a ` reset ` tuple was provided, reboot the ` Responder ` .
257
266
258
267
## 4.2.1 Configuration
259
268
260
269
The ` Initiator ` class variables determine the behaviour of the interface. Where
261
- these are altered, it should be done before instantiation.
270
+ these are altered, it should be done before instantiating ` Initiator ` or
271
+ ` Responder ` .
262
272
263
273
` Initiator.t_poll ` This defines the polling interval for incoming data. Shorter
264
274
values reduce the latency when the ` Responder ` sends data; at the cost of a
@@ -275,24 +285,55 @@ variables may be read:
275
285
276
286
See test program ` i2c_init.py ` for an example of using the above.
277
287
288
+ ## 4.2.2 Optional coroutines
289
+
290
+ These are intended for applications where the ` Responder ` may reboot at runtime
291
+ either because I2C failure was detected or because the application issues an
292
+ explicit reboot command.
293
+
294
+ The ` cr_go ` and ` cr_fail ` coroutines provide for applications which implement
295
+ an application-level initialisation sequence on first and subsequent boots of
296
+ the ` Responder ` . Such applications need to ensure that the initialisation
297
+ sequence does not conflict with other coros accessing the channel.
298
+
299
+ The ` cr_go ` coro runs after synchronisation has been achieved. It runs
300
+ concurrently with the coro which keeps the link open (` Initiator._run() ` ), but
301
+ should run to completion reasonably quickly. Typically it performs any app
302
+ level synchronisation, starts or re-enables application coros, and quits.
303
+
304
+ The ` cr_fail ` routine will prevent the automatic reboot from occurring until
305
+ it completes. This may be used to prevent user coros from accessing the channel
306
+ until reboot is complete. This may be done by means of locks or task
307
+ cancellation. Typically ` cr_fail ` will terminate when this is done, so that
308
+ ` cr_go ` has unique access to the channel.
309
+
310
+ If an explicit ` .reboot() ` is issued, a reset tuple was provided, and ` cr_fail `
311
+ exists, it will run and the physical reboot will be postponed until it
312
+ completes.
313
+
314
+ Typical usage:
315
+ ``` python
316
+ chan = asi2c_i.Initiator(i2c, syn, ack, rst, verbose, self ._go, (), self ._fail)
317
+ ```
318
+
278
319
###### [ Contents] ( ./README.md#contents )
279
320
280
321
## 4.3 Responder class
281
322
282
- Constructor args:
323
+ ##### Constructor args:
283
324
1 . ` i2c ` An ` I2C ` instance.
284
325
2 . ` pin ` A ` Pin ` instance for the ` sync ` signal.
285
326
3 . ` pinack ` A ` Pin ` instance for the ` ack ` signal.
286
327
4 . ` verbose=True ` If ` True ` causes debug messages to be output.
287
328
288
329
` Pin ` instances passed to the constructor must be instantiated by ` machine ` .
289
330
290
- Class variables:
331
+ ##### Class variables:
291
332
1 . ` addr=0x12 ` Address of I2C slave. This should be set before instantiating
292
333
` Initiator ` or ` Responder ` . If the default address (0x12) is to be overriden,
293
334
` Initiator ` application code must instantiate the I2C accordingly.
294
- 2 . ` rxbufsize ` Size of receive buffer. This should exceed the maximum message
295
- length. Consider reducing this in ESP8266 applications to save RAM.
335
+ 2 . ` rxbufsize=200 ` Size of receive buffer. This should exceed the maximum
336
+ message length. Consider reducing this in ESP8266 applications to save RAM.
296
337
297
338
###### [ Contents] ( ./README.md#contents )
298
339
0 commit comments