net: refactor to simplify lifetimes/generics.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Ipv4Address, Stack, StackResources};
|
||||
use embassy_net::{Ipv4Address, StackResources};
|
||||
use embassy_stm32::eth::generic_smi::GenericSMI;
|
||||
use embassy_stm32::eth::{Ethernet, PacketQueue};
|
||||
use embassy_stm32::peripherals::ETH;
|
||||
@@ -24,8 +24,8 @@ bind_interrupts!(struct Irqs {
|
||||
type Device = Ethernet<'static, ETH, GenericSMI>;
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<Device>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, Device>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -88,12 +88,11 @@ async fn main(spawner: Spawner) -> ! {
|
||||
//});
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
|
||||
let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
|
||||
|
||||
// Launch network task
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
// Ensure DHCP configuration is up before trying connect
|
||||
stack.wait_config_up().await;
|
||||
@@ -105,7 +104,7 @@ async fn main(spawner: Spawner) -> ! {
|
||||
let mut tx_buffer = [0; 4096];
|
||||
|
||||
loop {
|
||||
let mut socket = TcpSocket::new(&stack, &mut rx_buffer, &mut tx_buffer);
|
||||
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
|
||||
|
||||
socket.set_timeout(Some(embassy_time::Duration::from_secs(10)));
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Ipv4Address, Stack, StackResources};
|
||||
use embassy_net::{Ipv4Address, StackResources};
|
||||
use embassy_net_wiznet::chip::W5500;
|
||||
use embassy_net_wiznet::{Device, Runner, State};
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
@@ -31,8 +31,8 @@ async fn ethernet_task(runner: Runner<'static, W5500, EthernetSPI, ExtiInput<'st
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<Device<'static>>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static>>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -92,12 +92,11 @@ async fn main(spawner: Spawner) -> ! {
|
||||
// gateway: Some(Ipv4Address::new(10, 42, 0, 1)),
|
||||
//});
|
||||
|
||||
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
|
||||
let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
|
||||
|
||||
// Launch network task
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
// Ensure DHCP configuration is up before trying connect
|
||||
stack.wait_config_up().await;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Stack, StackResources};
|
||||
use embassy_net::StackResources;
|
||||
use embassy_stm32::rng::{self, Rng};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::usb::Driver;
|
||||
@@ -31,8 +31,8 @@ async fn usb_ncm_task(class: Runner<'static, UsbDriver, MTU>) -> ! {
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<Device<'static, MTU>>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, Device<'static, MTU>>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
@@ -144,11 +144,10 @@ async fn main(spawner: Spawner) {
|
||||
let seed = u64::from_le_bytes(seed);
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<Device<'static, MTU>>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<3>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(device, config, RESOURCES.init(StackResources::new()), seed));
|
||||
let (stack, runner) = embassy_net::new(device, config, RESOURCES.init(StackResources::new()), seed);
|
||||
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
// And now we can use it!
|
||||
|
||||
|
||||
Reference in New Issue
Block a user