net: refactor to simplify lifetimes/generics.
This commit is contained in:
@@ -6,7 +6,7 @@ teleprobe_meta::timeout!(120);
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::{Stack, StackResources};
|
||||
use embassy_net::StackResources;
|
||||
use embassy_net_enc28j60::Enc28j60;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_nrf::rng::Rng;
|
||||
@@ -25,8 +25,8 @@ bind_interrupts!(struct Irqs {
|
||||
type MyDriver = Enc28j60<ExclusiveDevice<Spim<'static, peripherals::SPI3>, Output<'static>, Delay>, Output<'static>>;
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<MyDriver>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, MyDriver>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -65,11 +65,10 @@ async fn main(spawner: Spawner) {
|
||||
let seed = u64::from_le_bytes(seed);
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<MyDriver>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<2>> = 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)));
|
||||
|
||||
perf_client::run(
|
||||
stack,
|
||||
|
||||
@@ -6,7 +6,7 @@ teleprobe_meta::timeout!(120);
|
||||
|
||||
use defmt::{info, unwrap};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::{Config, Stack, StackResources};
|
||||
use embassy_net::{Config, StackResources};
|
||||
use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
|
||||
use embassy_nrf::rng::Rng;
|
||||
use embassy_nrf::spim::{self, Spim};
|
||||
@@ -40,8 +40,8 @@ async fn wifi_task(
|
||||
type MyDriver = hosted::NetDriver<'static>;
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<MyDriver>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, MyDriver>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -86,16 +86,15 @@ async fn main(spawner: Spawner) {
|
||||
let seed = u64::from_le_bytes(seed);
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<MyDriver>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(
|
||||
let (stack, runner) = embassy_net::new(
|
||||
device,
|
||||
Config::dhcpv4(Default::default()),
|
||||
RESOURCES.init(StackResources::new()),
|
||||
seed,
|
||||
));
|
||||
);
|
||||
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
perf_client::run(
|
||||
stack,
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use defmt::{assert, *};
|
||||
use embassy_futures::join::join;
|
||||
use embassy_net::driver::Driver;
|
||||
use embassy_net::tcp::TcpSocket;
|
||||
use embassy_net::{Ipv4Address, Stack};
|
||||
use embassy_time::{with_timeout, Duration, Timer};
|
||||
@@ -13,7 +12,7 @@ pub struct Expected {
|
||||
pub updown_kbps: usize,
|
||||
}
|
||||
|
||||
pub async fn run<D: Driver>(stack: &Stack<D>, expected: Expected) {
|
||||
pub async fn run(stack: Stack<'_>, expected: Expected) {
|
||||
info!("Waiting for DHCP up...");
|
||||
while stack.config_v4().is_none() {
|
||||
Timer::after_millis(100).await;
|
||||
@@ -38,7 +37,7 @@ const DOWNLOAD_PORT: u16 = 4321;
|
||||
const UPLOAD_PORT: u16 = 4322;
|
||||
const UPLOAD_DOWNLOAD_PORT: u16 = 4323;
|
||||
|
||||
async fn test_download<D: Driver>(stack: &Stack<D>) -> usize {
|
||||
async fn test_download(stack: Stack<'_>) -> usize {
|
||||
info!("Testing download...");
|
||||
|
||||
let mut rx_buffer = [0; RX_BUFFER_SIZE];
|
||||
@@ -78,7 +77,7 @@ async fn test_download<D: Driver>(stack: &Stack<D>) -> usize {
|
||||
kbps
|
||||
}
|
||||
|
||||
async fn test_upload<D: Driver>(stack: &Stack<D>) -> usize {
|
||||
async fn test_upload(stack: Stack<'_>) -> usize {
|
||||
info!("Testing upload...");
|
||||
|
||||
let mut rx_buffer = [0; RX_BUFFER_SIZE];
|
||||
@@ -118,7 +117,7 @@ async fn test_upload<D: Driver>(stack: &Stack<D>) -> usize {
|
||||
kbps
|
||||
}
|
||||
|
||||
async fn test_upload_download<D: Driver>(stack: &Stack<D>) -> usize {
|
||||
async fn test_upload_download(stack: Stack<'_>) -> usize {
|
||||
info!("Testing upload+download...");
|
||||
|
||||
let mut rx_buffer = [0; RX_BUFFER_SIZE];
|
||||
|
||||
@@ -6,7 +6,7 @@ use cyw43::JoinOptions;
|
||||
use cyw43_pio::PioSpi;
|
||||
use defmt::{panic, *};
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::{Config, Stack, StackResources};
|
||||
use embassy_net::{Config, StackResources};
|
||||
use embassy_rp::gpio::{Level, Output};
|
||||
use embassy_rp::peripherals::{DMA_CH0, PIO0};
|
||||
use embassy_rp::pio::{InterruptHandler, Pio};
|
||||
@@ -30,8 +30,8 @@ async fn wifi_task(runner: cyw43::Runner<'static, Output<'static>, PioSpi<'stati
|
||||
}
|
||||
|
||||
#[embassy_executor::task]
|
||||
async fn net_task(stack: &'static Stack<cyw43::NetDriver<'static>>) -> ! {
|
||||
stack.run().await
|
||||
async fn net_task(mut runner: embassy_net::Runner<'static, cyw43::NetDriver<'static>>) -> ! {
|
||||
runner.run().await
|
||||
}
|
||||
|
||||
#[embassy_executor::main]
|
||||
@@ -70,16 +70,15 @@ async fn main(spawner: Spawner) {
|
||||
let seed = 0x0123_4567_89ab_cdef; // chosen by fair dice roll. guarenteed to be random.
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<cyw43::NetDriver<'static>>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(
|
||||
let (stack, runner) = embassy_net::new(
|
||||
net_device,
|
||||
Config::dhcpv4(Default::default()),
|
||||
RESOURCES.init(StackResources::new()),
|
||||
seed,
|
||||
));
|
||||
);
|
||||
|
||||
unwrap!(spawner.spawn(net_task(stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
loop {
|
||||
match control
|
||||
|
||||
@@ -5,7 +5,7 @@ teleprobe_meta::timeout!(120);
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::{Stack, StackResources};
|
||||
use embassy_net::StackResources;
|
||||
use embassy_net_wiznet::chip::W5100S;
|
||||
use embassy_net_wiznet::*;
|
||||
use embassy_rp::clocks::RoscRng;
|
||||
@@ -32,8 +32,8 @@ async fn ethernet_task(
|
||||
}
|
||||
|
||||
#[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]
|
||||
@@ -67,17 +67,16 @@ async fn main(spawner: Spawner) {
|
||||
let seed = rng.next_u64();
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<Device<'static>>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<2>> = StaticCell::new();
|
||||
let stack = &*STACK.init(Stack::new(
|
||||
let (stack, runner) = embassy_net::new(
|
||||
device,
|
||||
embassy_net::Config::dhcpv4(Default::default()),
|
||||
RESOURCES.init(StackResources::new()),
|
||||
seed,
|
||||
));
|
||||
);
|
||||
|
||||
// Launch network task
|
||||
unwrap!(spawner.spawn(net_task(&stack)));
|
||||
unwrap!(spawner.spawn(net_task(runner)));
|
||||
|
||||
perf_client::run(
|
||||
stack,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
mod common;
|
||||
use common::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_net::{Stack, StackResources};
|
||||
use embassy_net::StackResources;
|
||||
use embassy_stm32::eth::generic_smi::GenericSMI;
|
||||
use embassy_stm32::eth::{Ethernet, PacketQueue};
|
||||
use embassy_stm32::peripherals::ETH;
|
||||
@@ -32,8 +32,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]
|
||||
@@ -99,12 +99,11 @@ async fn main(spawner: Spawner) {
|
||||
//});
|
||||
|
||||
// Init network stack
|
||||
static STACK: StaticCell<Stack<Device>> = StaticCell::new();
|
||||
static RESOURCES: StaticCell<StackResources<2>> = 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)));
|
||||
|
||||
perf_client::run(
|
||||
stack,
|
||||
|
||||
Reference in New Issue
Block a user