aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-driver-channel/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net-driver-channel/README.md')
-rw-r--r--embassy-net-driver-channel/README.md18
1 files changed, 9 insertions, 9 deletions
diff --git a/embassy-net-driver-channel/README.md b/embassy-net-driver-channel/README.md
index 8f904ce95..90a216388 100644
--- a/embassy-net-driver-channel/README.md
+++ b/embassy-net-driver-channel/README.md
@@ -7,7 +7,9 @@ The `embassy-net-driver` trait is polling-based. To implement it, you must write
7hand, and hook up the `Waker`s provided by `embassy-net` to the right interrupt handlers so that `embassy-net` 7hand, and hook up the `Waker`s provided by `embassy-net` to the right interrupt handlers so that `embassy-net`
8knows when to poll your driver again to make more progress. 8knows when to poll your driver again to make more progress.
9 9
10With `embassy-net-driver-channel` 10With `embassy-net-driver-channel` you get a "channel-like" interface instead, where you can send/receive packets
11to/from embassy-net. The intended usage is to spawn a "driver task" in the background that does this, passing
12packets between the hardware and the channel.
11 13
12## A note about deadlocks 14## A note about deadlocks
13 15
@@ -18,19 +20,19 @@ loop {
18 // Wait for either.. 20 // Wait for either..
19 match select( 21 match select(
20 // ... the chip signaling an interrupt, indicating a packet is available to receive, or 22 // ... the chip signaling an interrupt, indicating a packet is available to receive, or
21 irq_pin.wait_for_low(), 23 irq_pin.wait_for_low(),
22 // ... a TX buffer becoming available, i.e. embassy-net wants to send a packet 24 // ... a TX buffer becoming available, i.e. embassy-net wants to send a packet
23 tx_chan.tx_buf(), 25 tx_chan.tx_buf(),
24 ).await { 26 ).await {
25 Either::First(_) => { 27 Either::First(_) => {
26 // a packet is ready to be received! 28 // a packet is ready to be received!
27 let buf = rx_chan.rx_buf().await; // allocate a rx buf from the packet queue 29 let buf = rx_chan.rx_buf().await; // allocate a rx buf from the packet queue
28 let n = receive_packet_over_spi(buf).await; 30 let n = receive_packet_over_spi(buf).await;
29 rx_chan.rx_done(n); 31 rx_chan.rx_done(n);
30 } 32 }
31 Either::Second(buf) => { 33 Either::Second(buf) => {
32 // a packet is ready to be sent! 34 // a packet is ready to be sent!
33 send_packet_over_spi(buf).await; 35 send_packet_over_spi(buf).await;
34 tx_chan.tx_done(); 36 tx_chan.tx_done();
35 } 37 }
36 } 38 }
@@ -41,7 +43,7 @@ However, this code has a latent deadlock bug. The symptom is it can hang at `rx_
41 43
42The reason is that, under load, both the TX and RX queues can get full at the same time. When this happens, the `embassy-net` task stalls trying to send because the TX queue is full, therefore it stops processing packets in the RX queue. Your driver task also stalls because the RX queue is full, therefore it stops processing packets in the TX queue. 44The reason is that, under load, both the TX and RX queues can get full at the same time. When this happens, the `embassy-net` task stalls trying to send because the TX queue is full, therefore it stops processing packets in the RX queue. Your driver task also stalls because the RX queue is full, therefore it stops processing packets in the TX queue.
43 45
44The fix is to make sure to always service the TX queue while you're waiting for space to become available in the TX queue. For example, select on either "tx_chan.tx_buf() available" or "INT is low AND rx_chan.rx_buf() available": 46The fix is to make sure to always service the TX queue while you're waiting for space to become available in the RX queue. For example, select on either "tx_chan.tx_buf() available" or "INT is low AND rx_chan.rx_buf() available":
45 47
46```rust,ignore 48```rust,ignore
47loop { 49loop {
@@ -58,12 +60,12 @@ loop {
58 ).await { 60 ).await {
59 Either::First(buf) => { 61 Either::First(buf) => {
60 // a packet is ready to be received! 62 // a packet is ready to be received!
61 let n = receive_packet_over_spi(buf).await; 63 let n = receive_packet_over_spi(buf).await;
62 rx_chan.rx_done(n); 64 rx_chan.rx_done(n);
63 } 65 }
64 Either::Second(buf) => { 66 Either::Second(buf) => {
65 // a packet is ready to be sent! 67 // a packet is ready to be sent!
66 send_packet_over_spi(buf).await; 68 send_packet_over_spi(buf).await;
67 tx_chan.tx_done(); 69 tx_chan.tx_done();
68 } 70 }
69 } 71 }
@@ -79,12 +81,10 @@ These `embassy-net` drivers are implemented using this crate. You can look at th
79- [`embassy-net-wiznet`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-wiznet) for Wiznet SPI Ethernet MAC+PHY chips. 81- [`embassy-net-wiznet`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-wiznet) for Wiznet SPI Ethernet MAC+PHY chips.
80- [`embassy-net-esp-hosted`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-esp-hosted) for using ESP32 chips with the [`esp-hosted`](https://github.com/espressif/esp-hosted) firmware as WiFi adapters for another non-ESP32 MCU. 82- [`embassy-net-esp-hosted`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-esp-hosted) for using ESP32 chips with the [`esp-hosted`](https://github.com/espressif/esp-hosted) firmware as WiFi adapters for another non-ESP32 MCU.
81 83
82
83## Interoperability 84## Interoperability
84 85
85This crate can run on any executor. 86This crate can run on any executor.
86 87
87
88## License 88## License
89 89
90This work is licensed under either of 90This work is licensed under either of