fn tcp_listen(&mut self, sn: Sn, port: u16) -> Result<(), Self::Error> {
        debug_assert!(
            port_is_unique(self, sn, port)?,
            "Local port {port} is in use"
        );

        self.set_sn_cr(sn, SocketCommand::Close)?;
        // This will not hang, the socket status will always change to closed
        // after a close command.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Closed) {}
        const MODE: SocketMode = SocketMode::DEFAULT.set_protocol(Protocol::Tcp);
        self.set_sn_mr(sn, MODE)?;
        self.set_sn_port(sn, port)?;
        self.set_sn_cr(sn, SocketCommand::Open)?;
        // This will not hang, the socket status will always change to Init
        // after a open command with SN_MR set to TCP.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Init) {}
        self.set_sn_cr(sn, SocketCommand::Listen)
    }
/// Open a TCP listener on the given port.
///
/// After opening a listener with [`tcp_listen`] and receiving the
/// [`con`] interrupt data can be transmitting by using [`tcp_read`] and
/// [`tcp_write`].
///
/// # Arguments
///
/// * `socket` - The socket number to use for this TCP listener.
/// * `port` - The local port to listen for remote connections on.
///
/// # Panics
///
/// * (debug) The port must not be in use by any other socket on the W5500.
///
/// # Example
///
/// Create an HTTP server.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// use w5500_hl::{
///     ll::{Registers, Sn, SocketInterrupt},
///     net::{Ipv4Addr, SocketAddrV4},
///     Tcp,
/// };
/// // global_allocator is currently avaliable on nightly for embedded rust
/// extern crate alloc;
/// use alloc::vec::{self, Vec};
///
/// const HTTP_SOCKET: Sn = Sn::Sn1;
/// const HTTP_PORT: u16 = 80;
///
/// // start serving
/// w5500.tcp_listen(HTTP_SOCKET, HTTP_PORT)?;
///
/// // wait for the RECV interrupt, indicating there is data to read from a client
/// loop {
///     let sn_ir = w5500.sn_ir(HTTP_SOCKET).unwrap();
///     if sn_ir.recv_raised() {
///         w5500.set_sn_ir(HTTP_SOCKET, sn_ir).unwrap();
///         break;
///     }
///     if sn_ir.discon_raised() | sn_ir.timeout_raised() {
///         panic!("Socket disconnected while waiting for RECV");
///     }
/// }
///
/// let mut buf: Vec<u8> = vec![0; 256];
/// let rx_bytes: u16 = w5500.tcp_read(HTTP_SOCKET, &mut buf)?;
/// // Truncate the buffer to the number of bytes read
/// // Safety: BUF is only borrowed mutably in one location
/// let filled_buf: &[u8] = &buf[..rx_bytes.into()];
///
/// // parse HTTP request here using filled_buf
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// ```
///
/// [`tcp_write`]: Tcp::tcp_write
/// [`tcp_read`]: Tcp::tcp_read
/// [`tcp_listen`]: Tcp::tcp_listen
/// [`con`]: w5500_ll::SocketInterrupt::con_raised
Open a TCP listener on the given port.
Open a TCP listener on the given port .
fn tcp_listen(&mut self, sn: Sn, port: u16) -> Result<(), Self::Error> {
        debug_assert!(
            port_is_unique(self, sn, port)?,
            "Local port {port} is in use"
        );
        self.set_sn_cr(sn, SocketCommand::Close)?;
        // This will not hang, the socket status will always change to closed
        // after a close command.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Closed) {}
        const MODE: SocketMode = SocketMode::DEFAULT.set_protocol(Protocol::Tcp);
        self.set_sn_mr(sn, MODE)?;
        self.set_sn_port(sn, port)?;
        self.set_sn_cr(sn, SocketCommand::Open)?;
        // This will not hang, the socket status will always change to Init
        // after a open command with SN_MR set to TCP.
        // (unless you do somthing silly like holding the W5500 in reset)
        while self.sn_sr(sn)? != Ok(SocketStatus::Init) {}
        self.set_sn_cr(sn, SocketCommand::Listen)
    }
fn tcp_listen ( & mut self , sn : Sn , port : u16 ) -> Result < ( ) , Self :: Error > { debug_assert ! ( port_is_unique ( self sn port ) " " ) ; self . set_sn_cr ( sn , SocketCommand :: Close ) ? ; // This will not hang, the socket status will always change to closed // after a close command. // (unless you do somthing silly like holding the W5500 in reset) while self . sn_sr ( sn ) ? != Ok ( SocketStatus :: Closed ) { } const MODE : SocketMode = SocketMode :: DEFAULT . set_protocol ( Protocol :: Tcp ) ; self . set_sn_mr ( sn , MODE ) ? ; self . set_sn_port ( sn , port ) ? ; self . set_sn_cr ( sn , SocketCommand :: Open ) ? ; // This will not hang, the socket status will always change to Init // after a open command with SN_MR set to TCP. // (unless you do somthing silly like holding the W5500 in reset) while self . sn_sr ( sn ) ? != Ok ( SocketStatus :: Init ) { } self . set_sn_cr ( sn , SocketCommand :: Listen ) }
Open a TCP listener on the given port.
Open a TCP listener on the given port .
&mut self
sn
Sn
port
u16
&mut self
sn
Sn
port
u16
panics
(debug) The port must not be in use by any other socket on the W5500.
( debug ) The port must not be in use by any other socket on the W5500 .
example
Create an HTTP server.


Create an HTTP server .
use embedded_hal_mock as h;
None
let mut w5500 = w5500_ll::blocking::vdm::w5500::new(h::spi::mock::new(&[]), h::pin::mock::new(&[]));
use w5500_hl::{
ll::{Registers, Sn, SocketInterrupt},
net::{Ipv4Addr, SocketAddrV4},
Tcp,
};
global_allocator is currently avaliable on nightly for embedded rust
extern crate alloc;
use alloc::vec::{self, Vec}.

const HTTP_SOCKET: Sn = Sn::Sn1;
const HTTP_PORT: u16 = 80.

start serving
w5500.tcp_listen(HTTP_SOCKET, HTTP_PORT)?.

wait for the RECV interrupt, indicating there is data to read from a client
loop {
let sn_ir = w5500.sn_ir(HTTP_SOCKET).unwrap();
if sn_ir.recv_raised() {
w5500.set_sn_ir(HTTP_SOCKET, sn_ir).unwrap();
break;
}
if sn_ir.discon_raised() | sn_ir.timeout_raised() {
panic!("Socket disconnected while waiting for RECV");
}
}

let mut buf: Vec = vec![0; 256];
let rx_bytes: u16 = w5500.tcp_read(HTTP_SOCKET, &mut buf)?;
Truncate the buffer to the number of bytes read
Safety: BUF is only borrowed mutably in one location
let filled_buf: &[u8] = &buf[..rx_bytes.into()].

parse HTTP request here using filled_buf
use w5500_hl :: { ll :: { Registers Sn SocketInterrupt } net :: { Ipv4Addr SocketAddrV4 } Tcp } ; global_allocator is currently avaliable on nightly for embedded rust extern crate alloc ; use alloc :: vec :: { self Vec } . const HTTP_SOCKET : Sn = Sn :: Sn1 ; const HTTP_PORT : u16 = 80 . start serving w5500 . tcp_listen ( HTTP_SOCKET HTTP_PORT ) ? . wait for the RECV interrupt indicating there is data to read from a client loop { let sn_ir = w5500 . sn_ir ( HTTP_SOCKET ) . unwrap () ; if sn_ir . recv_raised () { w5500 . set_sn_ir ( HTTP_SOCKET sn_ir ) . unwrap () ; break ; } if sn_ir . discon_raised () | sn_ir . timeout_raised () { panic! ( " Socket disconnected while waiting for RECV " ) ; } } let mut buf : Vec = vec! [ 0 ; 256 ] ; let rx_bytes : u16 = w5500 . tcp_read ( HTTP_SOCKET &mut buf ) ? ; Truncate the buffer to the number of bytes read Safety : BUF is only borrowed mutably in one location let filled_buf : & [ u8 ] = &buf [ .. rx_bytes . into () ] . parse HTTP request here using filled_buf
ok::<(), w5500_hl::ll::blocking::vdm::error<_, _>>(())
None