@@ -131,10 +131,10 @@ The following modules are provided which may be copied to the target hardware.
131
131
132
132
** Libraries**
133
133
134
- 1 . ` asyn.py ` Provides synchronisation primitives ` Lock ` , ` Event ` , ` Barrier ` ,
135
- ` Semaphore ` , ` BoundedSemaphore ` , ` Condition ` and ` gather ` . Provides support
136
- for task cancellation via ` NamedTask ` and ` Cancellable ` classes.
137
- 2 . ` aswitch.py ` This provides classes for interfacing switches and
134
+ 1 . [ asyn.py] ( ./asyn.py ) Provides synchronisation primitives ` Lock ` , ` Event ` ,
135
+ ` Barrier ` , ` Semaphore ` , ` BoundedSemaphore ` , ` Condition ` and ` gather ` . Provides
136
+ support for task cancellation via ` NamedTask ` and ` Cancellable ` classes.
137
+ 2 . [ aswitch.py] ( ./aswitch.py ) Provides classes for interfacing switches and
138
138
pushbuttons and also a software retriggerable delay object. Pushbuttons are a
139
139
generalisation of switches providing logical rather than physical status along
140
140
with double-clicked and long pressed events.
@@ -144,34 +144,41 @@ The following modules are provided which may be copied to the target hardware.
144
144
The first two are the most immediately rewarding as they produce visible
145
145
results by accessing Pyboard hardware.
146
146
147
- 1 . ` aledflash.py ` Flashes the four Pyboard LED's asynchronously for 10s. The
148
- simplest uasyncio demo. Import it to run.
149
- 2 . ` apoll.py ` A device driver for the Pyboard accelerometer. Demonstrates
150
- the use of a coroutine to poll a device. Runs for 20s. Import it to run.
151
- 3 . ` astests.py ` Test/demonstration programs for the ` aswitch ` module.
152
- 4 . ` asyn_demos.py ` Simple task cancellation demos.
153
- 5 . ` roundrobin.py ` Demo of round-robin scheduling. Also a benchmark of
154
- scheduling performance.
155
- 6 . ` awaitable.py ` Demo of an awaitable class. One way of implementing a
156
- device driver which polls an interface.
157
- 7 . ` chain.py ` Copied from the Python docs. Demo of chaining coroutines.
158
- 8 . ` aqtest.py ` Demo of uasyncio ` Queue ` class.
159
- 9 . ` aremote.py ` Example device driver for NEC protocol IR remote control.
160
- 10 . ` auart.py ` Demo of streaming I/O via a Pyboard UART.
161
- 11 . ` auart_hd.py ` Use of the Pyboard UART to communicate with a device using a
162
- half-duplex protocol. Suits devices such as those using the 'AT' modem command
163
- set.
164
- 12 . ` iorw.py ` Demo of a read/write device driver using the stream I/O mechanism.
147
+ 1 . [ aledflash.py] ( ./aledflash.py ) Flashes the four Pyboard LEDs asynchronously
148
+ for 10s. The simplest uasyncio demo. Import it to run.
149
+ 2 . [ apoll.py] ( ./apoll.py ) A device driver for the Pyboard accelerometer.
150
+ Demonstrates the use of a coroutine to poll a device. Runs for 20s. Import it
151
+ to run.
152
+ 3 . [ astests.py] ( ./astests.py ) Test/demonstration programs for the
153
+ [ aswitch] ( ./aswitch ) module.
154
+ 4 . [ asyn_demos.py] ( ./asyn_demos.py ) Simple task cancellation demos.
155
+ 5 . [ roundrobin.py] ( ./roundrobin.py ) Demo of round-robin scheduling. Also a
156
+ benchmark of scheduling performance.
157
+ 6 . [ awaitable.py] ( ./awaitable.py ) Demo of an awaitable class. One way of
158
+ implementing a device driver which polls an interface.
159
+ 7 . [ chain.py] ( ./chain.py ) Copied from the Python docs. Demo of chaining
160
+ coroutines.
161
+ 8 . [ aqtest.py] ( ./aqtest.py ) Demo of uasyncio ` Queue ` class.
162
+ 9 . [ aremote.py] ( ./aremote.py ) Example device driver for NEC protocol IR remote
163
+ control.
164
+ 10 . [ auart.py] ( ./auart.py ) Demo of streaming I/O via a Pyboard UART.
165
+ 11 . [ auart_hd.py] ( ./auart_hd.py ) Use of the Pyboard UART to communicate with a
166
+ device using a half-duplex protocol. Suits devices such as those using the
167
+ 'AT' modem command set.
168
+ 12 . [ iorw.py] ( ./iorw.py ) Demo of a read/write device driver using the stream
169
+ I/O mechanism.
165
170
166
171
** Test Programs**
167
172
168
- 1 . ` asyntest.py ` Tests for the synchronisation primitives in ` asyn.py ` .
169
- 2 . ` cantest.py ` Task cancellation tests.
173
+ 1 . [ asyntest.py] ( ./asyntest.py ) Tests for the synchronisation primitives in
174
+ [ asyn.py] ( ./asyn.py ) .
175
+ 2 . [ cantest.py] ( ./cantest.py ) Task cancellation tests.
170
176
171
177
** Utility**
172
178
173
- 1 . ` check_async_code.py ` A Python3 utility to locate a particular coding
174
- error which can be hard to find. See [ this para] ( ./TUTORIAL.md#65-a-common-error ) .
179
+ 1 . [ check_async_code.py] ( ./check_async_code.py ) A Python3 utility to locate a
180
+ particular coding error which can be hard to find. See
181
+ [ para 6.5] ( ./TUTORIAL.md#65-a-common-error ) .
175
182
176
183
** Benchmarks**
177
184
@@ -215,7 +222,7 @@ the scheduler would schedule them in periods when `bar` was paused.
215
222
Most embedded applications have an event loop which runs continuously. The event
216
223
loop can also be started in a way which permits termination, by using the event
217
224
loop's ` run_until_complete ` method; this is mainly of use in testing. Examples
218
- may be found in the ` astests.py ` module.
225
+ may be found in the [ astests.py] ( ./astests.py ) module.
219
226
220
227
The event loop instance is a singleton, instantiated by a program's first call
221
228
to ` asyncio.get_event_loop() ` . This takes two optional integer args being the
@@ -340,9 +347,10 @@ be unable to schedule other coros while the delay is in progress.
340
347
341
348
There is often a need to provide synchronisation between coros. A common
342
349
example is to avoid what are known as "race conditions" where multiple coros
343
- compete to access a single resource. An example is provided in the ` astests.py `
344
- program and discussed in [ the docs] ( ./DRIVERS.md ) . Another hazard is the "deadly
345
- embrace" where two coros each wait on the other's completion.
350
+ compete to access a single resource. An example is provided in the
351
+ [ astests.py] ( ./astests.py ) program and discussed in [ the docs] ( ./DRIVERS.md ) .
352
+ Another hazard is the "deadly embrace" where two coros each wait on the other's
353
+ completion.
346
354
347
355
In simple applications communication may be achieved with global flags or bound
348
356
variables. A more elegant approach is to use synchronisation primitives. The
@@ -409,10 +417,10 @@ and the timeout is triggered while it is waiting on a lock, the timeout will be
409
417
ineffective. It will not receive the ` TimeoutError ` until it has acquired the
410
418
lock. The same observation applies to task cancellation.
411
419
412
- The module ` asyn.py ` offers a ` Lock ` class which works in these situations
413
- [ see docs] ( ./PRIMITIVES.md#32-class-lock ) . It is significantly less efficient
414
- than the official class but supports additional interfaces as per the CPython
415
- version including context manager usage.
420
+ The module [ asyn.py] ( ./asyn.py ) offers a ` Lock ` class which works in these
421
+ situations [ see docs] ( ./PRIMITIVES.md#32-class-lock ) . It is significantly less
422
+ efficient than the official class but supports additional interfaces as per the
423
+ CPython version including context manager usage.
416
424
417
425
###### [ Contents] ( ./TUTORIAL.md#contents )
418
426
@@ -649,9 +657,9 @@ code even though descheduled. This is likely to have unwanted consequences.
649
657
650
658
## 3.7 Other synchronisation primitives
651
659
652
- The ` asyn.py ` library provides 'micro' implementations of CPython capabilities,
653
- namely the [ Condition class] ( ./PRIMITIVES.md#36-class-condition ) and the
654
- [ gather] ( ./PRIMITIVES.md#37-class-gather ) method.
660
+ The [ asyn.py] ( ./asyn.py ) library provides 'micro' implementations of CPython
661
+ capabilities, namely the [ Condition class] ( ./PRIMITIVES.md#36-class-condition )
662
+ and the [ gather] ( ./PRIMITIVES.md#37-class-gather ) method.
655
663
656
664
The ` Condition ` class enables a coro to notify other coros which are waiting on
657
665
a locked resource. Once notified they will access the resource and release the
@@ -705,7 +713,7 @@ Currently MicroPython doesn't support `__await__`
705
713
[ issue #2678 ] ( https://github.com/micropython/micropython/issues/2678 ) and
706
714
` __iter__ ` must be used. The line ` __iter__ = __await__ ` enables portability
707
715
between CPython and MicroPython. Example code may be found in the ` Event ` ,
708
- ` Barrier ` , ` Cancellable ` and ` Condition ` classes in asyn.py.
716
+ ` Barrier ` , ` Cancellable ` and ` Condition ` classes in [ asyn.py] ( ./asyn.py ) .
709
717
710
718
### 4.1.1 Use in context managers
711
719
@@ -1155,10 +1163,10 @@ provide a solution if the data source supports it.
1155
1163
1156
1164
### 5.3.1 A UART driver example
1157
1165
1158
- The program ` auart_hd.py ` illustrates a method of communicating with a half
1159
- duplex device such as one responding to the modem 'AT' command set. Half duplex
1160
- means that the device never sends unsolicited data: its transmissions are
1161
- always in response to a command from the master.
1166
+ The program [ auart_hd.py] ( ./auart_hd.py ) illustrates a method of communicating
1167
+ with a half duplex device such as one responding to the modem 'AT' command set.
1168
+ Half duplex means that the device never sends unsolicited data: its
1169
+ transmissions are always in response to a command from the master.
1162
1170
1163
1171
The device is emulated, enabling the test to be run on a Pyboard with two wire
1164
1172
links.
@@ -1349,10 +1357,10 @@ The `fast_io` version addresses this issue.
1349
1357
1350
1358
## 5.5 A complete example: aremote.py
1351
1359
1352
- This may be found in the ` nec_ir ` directory. Its use is documented
1353
- [ here ] ( ./nec_ir/README.md ) . The demo provides a complete device driver example:
1354
- a receiver/decoder for an infra red remote controller. The following notes are
1355
- salient points regarding its ` asyncio ` usage.
1360
+ See [ aremote.py ] ( ./ nec_ir/aremote.py ) documented [ here ] ( ./nec_ir/README.md ) .
1361
+ The demo provides a complete device driver example: a receiver/decoder for an
1362
+ infra red remote controller. The following notes are salient points regarding
1363
+ its ` asyncio ` usage.
1356
1364
1357
1365
A pin interrupt records the time of a state change (in us) and sets an event,
1358
1366
passing the time when the first state change occurred. A coro waits on the
0 commit comments