aboutsummaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-06-29 19:51:16 +0200
committerDario Nieuwenhuis <[email protected]>2023-06-29 19:55:32 +0200
commit6eac49186d5a5da4c310027e59adcd0bf44ae514 (patch)
tree3cbd9c15c68c7ee3859a17ec6d6fc7150e569686 /embassy-net
parent4feabb13bfbda46de74be09566118adc1ba49d5d (diff)
Release embassy-net v0.1
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/Cargo.toml9
-rw-r--r--embassy-net/README.md64
-rw-r--r--embassy-net/src/lib.rs24
3 files changed, 75 insertions, 22 deletions
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml
index cef8247eb..e89039daa 100644
--- a/embassy-net/Cargo.toml
+++ b/embassy-net/Cargo.toml
@@ -3,7 +3,13 @@ name = "embassy-net"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0" 5license = "MIT OR Apache-2.0"
6 6description = "Async TCP/IP network stack for embedded systems"
7repository = "https://github.com/embassy-rs/embassy"
8categories = [
9 "embedded",
10 "no-std",
11 "asynchronous",
12]
7 13
8[package.metadata.embassy_docs] 14[package.metadata.embassy_docs]
9src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" 15src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/"
@@ -44,7 +50,6 @@ smoltcp = { version = "0.10.0", default-features = false, features = [
44] } 50] }
45 51
46embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" } 52embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" }
47embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common" }
48embassy-time = { version = "0.1.0", path = "../embassy-time" } 53embassy-time = { version = "0.1.0", path = "../embassy-time" }
49embassy-sync = { version = "0.2.0", path = "../embassy-sync" } 54embassy-sync = { version = "0.2.0", path = "../embassy-sync" }
50embedded-io = { version = "0.4.0", optional = true } 55embedded-io = { version = "0.4.0", optional = true }
diff --git a/embassy-net/README.md b/embassy-net/README.md
index 470926c58..48f9fd832 100644
--- a/embassy-net/README.md
+++ b/embassy-net/README.md
@@ -1,30 +1,56 @@
1# embassy-net 1# embassy-net
2 2
3embassy-net contains an async network API based on smoltcp and embassy, designed 3`embassy-net` is a no-std no-alloc async network stack, designed for embedded systems.
4for embedded systems.
5 4
6## Running the example 5It builds on [`smoltcp`](https://github.com/smoltcp-rs/smoltcp). It provides a higher-level and more opinionated
6API. It glues together the components provided by `smoltcp`, handling the low-level details with defaults and
7memory management designed to work well for embedded systems, aiiming for a more "Just Works" experience.
7 8
8First, create the tap0 interface. You only need to do this once. 9## Features
9 10
10```sh 11- IPv4, IPv6
11sudo ip tuntap add name tap0 mode tap user $USER 12- Ethernet and bare-IP mediums.
12sudo ip link set tap0 up 13- TCP, UDP, DNS, DHCPv4, IGMPv4
13sudo ip addr add 192.168.69.100/24 dev tap0 14- TCP sockets implement the `embedded-io` async traits.
14sudo ip -6 addr add fe80::100/64 dev tap0
15sudo ip -6 addr add fdaa::100/64 dev tap0
16sudo ip -6 route add fe80::/64 dev tap0
17sudo ip -6 route add fdaa::/64 dev tap0
18```
19 15
20Second, have something listening there. For example `nc -l 8000` 16See the [`smoltcp`](https://github.com/smoltcp-rs/smoltcp) README for a detailed list of implemented and
17unimplemented features of the network protocols.
21 18
22Then run the example located in the `examples` folder: 19## Hardware support
23 20
24```sh 21- [`esp-wifi`](https://github.com/esp-rs/esp-wifi) for WiFi support on bare-metal ESP32 chips. Maintained by Espressif.
25cd $EMBASSY_ROOT/examples/std/ 22- [`cyw43`](https://github.com/embassy-rs/embassy/tree/main/cyw43) for WiFi on CYW43xx chips, used in the Raspberry Pi Pico W
26cargo run --bin net -- --static-ip 23- [`embassy-usb`](https://github.com/embassy-rs/embassy/tree/main/embassy-usb) for Ethernet-over-USB (CDC NCM) support.
27``` 24- [`embassy-stm32`](https://github.com/embassy-rs/embassy/tree/main/embassy-stm32) for the builtin Ethernet MAC in all STM32 chips (STM32F1, STM32F2, STM32F4, STM32F7, STM32H7, STM32H5).
25- [`embassy-net-w5500`](https://github.com/embassy-rs/embassy/tree/main/embassy-net-w5500) for Wiznet W5500 SPI Ethernet MAC+PHY chip.
26- [`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.
27
28## Examples
29
30- For usage with Embassy HALs and network chip drivers, search [here](https://github.com/embassy-rs/embassy/tree/main/examples) for `eth` or `wifi`.
31- The [`esp-wifi` repo](https://github.com/esp-rs/esp-wifi) has examples for use on bare-metal ESP32 chips.
32- For usage on `std` platforms, see [the `std` examples](https://github.com/embassy-rs/embassy/tree/main/examples/std/src/bin)
33
34## Adding support for new hardware
35
36To add `embassy-net` support for new hardware (i.e. a new Ethernet or WiFi chip, or
37an Ethernet/WiFi MCU peripheral), you have to implement the [`embassy-net-driver`](https://crates.io/crates/embassy-net-driver)
38traits.
39
40Alternatively, [`embassy-net-driver-channel`](https://crates.io/crates/embassy-net-driver-channel) provides a higer-level API
41to construct a driver that processes packets in its own background task and communicates with the `embassy-net` task via
42packet queues for RX and TX.
43
44Drivers should depend only on `embassy-net-driver` or `embassy-net-driver-channel`. Never on the main `embassy-net` crate.
45This allows existing drivers to continue working for newer `embassy-net` major versions, without needing an update, if the driver
46trait has not had breaking changes.
47
48## Interoperability
49
50This crate can run on any executor.
51
52[`embassy-time`](https://crates.io/crates/embassy-net-driver) is used for timekeeping and timeouts. You must
53link an `embassy-time` driver in your project to use this crate.
28 54
29## License 55## License
30 56
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 17a7a22a2..840d7a09a 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -419,7 +419,29 @@ impl<D: Driver + 'static> Stack<D> {
419 }) 419 })
420 .await?; 420 .await?;
421 421
422 use embassy_hal_common::drop::OnDrop; 422 #[must_use = "to delay the drop handler invocation to the end of the scope"]
423 struct OnDrop<F: FnOnce()> {
424 f: core::mem::MaybeUninit<F>,
425 }
426
427 impl<F: FnOnce()> OnDrop<F> {
428 fn new(f: F) -> Self {
429 Self {
430 f: core::mem::MaybeUninit::new(f),
431 }
432 }
433
434 fn defuse(self) {
435 core::mem::forget(self)
436 }
437 }
438
439 impl<F: FnOnce()> Drop for OnDrop<F> {
440 fn drop(&mut self) {
441 unsafe { self.f.as_ptr().read()() }
442 }
443 }
444
423 let drop = OnDrop::new(|| { 445 let drop = OnDrop::new(|| {
424 self.with_mut(|s, i| { 446 self.with_mut(|s, i| {
425 let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket); 447 let socket = s.sockets.get_mut::<dns::Socket>(i.dns_socket);