diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-05-31 01:01:30 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-05-31 01:01:30 +0200 |
| commit | d70994e4a8ea695f07b777fa99d7db4e5d4a7122 (patch) | |
| tree | e40d00e3f5493cce9ef65e8daa524a174f5fc407 /examples/rp/src/bin/ethernet_w5500_multisocket.rs | |
| parent | 82d765689aa0f922d0b43e402eaa3d911b2d461d (diff) | |
net-w5500: integrate into main repo.
Diffstat (limited to 'examples/rp/src/bin/ethernet_w5500_multisocket.rs')
| -rw-r--r-- | examples/rp/src/bin/ethernet_w5500_multisocket.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/examples/rp/src/bin/ethernet_w5500_multisocket.rs b/examples/rp/src/bin/ethernet_w5500_multisocket.rs index eb3b8de81..c8e6d46a6 100644 --- a/examples/rp/src/bin/ethernet_w5500_multisocket.rs +++ b/examples/rp/src/bin/ethernet_w5500_multisocket.rs | |||
| @@ -15,6 +15,7 @@ use embassy_rp::clocks::RoscRng; | |||
| 15 | use embassy_rp::gpio::{Input, Level, Output, Pull}; | 15 | use embassy_rp::gpio::{Input, Level, Output, Pull}; |
| 16 | use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0}; | 16 | use embassy_rp::peripherals::{PIN_17, PIN_20, PIN_21, SPI0}; |
| 17 | use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; | 17 | use embassy_rp::spi::{Async, Config as SpiConfig, Spi}; |
| 18 | use embassy_time::Duration; | ||
| 18 | use embedded_hal_async::spi::ExclusiveDevice; | 19 | use embedded_hal_async::spi::ExclusiveDevice; |
| 19 | use embedded_io::asynch::Write; | 20 | use embedded_io::asynch::Write; |
| 20 | use rand::RngCore; | 21 | use rand::RngCore; |
| @@ -62,14 +63,8 @@ async fn main(spawner: Spawner) { | |||
| 62 | 63 | ||
| 63 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; | 64 | let mac_addr = [0x02, 0x00, 0x00, 0x00, 0x00, 0x00]; |
| 64 | let state = singleton!(State::<8, 8>::new()); | 65 | let state = singleton!(State::<8, 8>::new()); |
| 65 | let (device, runner) = embassy_net_w5500::new( | 66 | let (device, runner) = |
| 66 | mac_addr, | 67 | embassy_net_w5500::new(mac_addr, state, ExclusiveDevice::new(spi, cs), w5500_int, w5500_reset).await; |
| 67 | state, | ||
| 68 | ExclusiveDevice::new(spi, cs), | ||
| 69 | w5500_int, | ||
| 70 | w5500_reset, | ||
| 71 | ) | ||
| 72 | .await; | ||
| 73 | unwrap!(spawner.spawn(ethernet_task(runner))); | 68 | unwrap!(spawner.spawn(ethernet_task(runner))); |
| 74 | 69 | ||
| 75 | // Generate random seed | 70 | // Generate random seed |
| @@ -103,18 +98,14 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16) | |||
| 103 | let mut buf = [0; 4096]; | 98 | let mut buf = [0; 4096]; |
| 104 | loop { | 99 | loop { |
| 105 | let mut socket = embassy_net::tcp::TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); | 100 | let mut socket = embassy_net::tcp::TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer); |
| 106 | socket.set_timeout(Some(embassy_net::SmolDuration::from_secs(10))); | 101 | socket.set_timeout(Some(Duration::from_secs(10))); |
| 107 | 102 | ||
| 108 | info!("SOCKET {}: Listening on TCP:{}...", id, port); | 103 | info!("SOCKET {}: Listening on TCP:{}...", id, port); |
| 109 | if let Err(e) = socket.accept(port).await { | 104 | if let Err(e) = socket.accept(port).await { |
| 110 | warn!("accept error: {:?}", e); | 105 | warn!("accept error: {:?}", e); |
| 111 | continue; | 106 | continue; |
| 112 | } | 107 | } |
| 113 | info!( | 108 | info!("SOCKET {}: Received connection from {:?}", id, socket.remote_endpoint()); |
| 114 | "SOCKET {}: Received connection from {:?}", | ||
| 115 | id, | ||
| 116 | socket.remote_endpoint() | ||
| 117 | ); | ||
| 118 | 109 | ||
| 119 | loop { | 110 | loop { |
| 120 | let n = match socket.read(&mut buf).await { | 111 | let n = match socket.read(&mut buf).await { |
| @@ -128,11 +119,7 @@ async fn listen_task(stack: &'static Stack<Device<'static>>, id: u8, port: u16) | |||
| 128 | break; | 119 | break; |
| 129 | } | 120 | } |
| 130 | }; | 121 | }; |
| 131 | info!( | 122 | info!("SOCKET {}: rxd {}", id, core::str::from_utf8(&buf[..n]).unwrap()); |
| 132 | "SOCKET {}: rxd {}", | ||
| 133 | id, | ||
| 134 | core::str::from_utf8(&buf[..n]).unwrap() | ||
| 135 | ); | ||
| 136 | 123 | ||
| 137 | if let Err(e) = socket.write_all(&buf[..n]).await { | 124 | if let Err(e) = socket.write_all(&buf[..n]).await { |
| 138 | warn!("write error: {:?}", e); | 125 | warn!("write error: {:?}", e); |
