Skyward boardcore
Loading...
Searching...
No Matches
Boardcore::Wiz5500 Class Reference

Driver for the WizNet W5500 ethernet. More...

#include <WIZ5500.h>

Classes

struct  PhyState
 

Public Types

using OnIpConflictCb = std::function<void()>
 
using OnDestUnreachableCb = std::function<void(WizIp, uint16_t)>
 

Public Member Functions

 Wiz5500 (SPIBus &bus, miosix::GpioPin cs, miosix::GpioPin intn, SPI::ClockDivider clock_divider)
 Build an instance of the driver.
 
 ~Wiz5500 ()
 
void setOnIpConflict (OnIpConflictCb cb)
 Sets the callback to be invoked when the device detects an IP. conflict.
 
void setOnDestUnreachable (OnDestUnreachableCb cb)
 Sets the callback to be invoked when the device detects an unreachable host.
 
bool checkVersion ()
 Checks the VERSION register. Can be used to detect device presence.
 
PhyState getPhyState ()
 Get current PHY state, can be used to poll link status, and wait for link up.
 
void reset ()
 Resets the device. Performs a software resets, resetting all registers and closing all sockets.
 
void handleINTn ()
 Handle an interrupt from INTn.
 
void setGatewayIp (WizIp ip)
 Set global gateway ip.
 
void setSubnetMask (WizIp mask)
 Set global subnet mask.
 
void setSourceMac (WizMac mac)
 Set the device MAC address.
 
void setSourceIp (WizIp ip)
 Set the device IP address.
 
bool connectTcp (int sock_n, uint16_t src_port, WizIp dst_ip, uint16_t dst_port, int timeout=-1)
 Connect to a remote socket via TCP.
 
bool listenTcp (int sock_n, uint16_t src_port, WizIp &dst_ip, uint16_t &dst_port, int timeout=-1)
 Listen for a single remote TCP connection.
 
bool openUdp (int sock_n, uint16_t src_port, WizIp dst_ip, uint16_t dst_port, int timeout=-1)
 Open a simple UDP socket.
 
bool send (int sock_n, const uint8_t *data, size_t len, int timeout=-1)
 Send data through the socket (works both in TCP and UDP).
 
ssize_t recv (int sock_n, uint8_t *data, size_t len, int timeout=-1)
 Receive data from the socket (works only in TCP).
 
ssize_t recvfrom (int sock_n, uint8_t *data, size_t len, WizIp &dst_ip, uint16_t &dst_port, int timeout=-1)
 Receive data from the socket (works only in UDP).
 
void close (int sock_n, int timeout=-1)
 Close a socket.
 

Detailed Description

Driver for the WizNet W5500 ethernet.

Definition at line 53 of file WIZ5500.h.

Member Typedef Documentation

◆ OnDestUnreachableCb

using Boardcore::Wiz5500::OnDestUnreachableCb = std::function<void(WizIp, uint16_t)>

Definition at line 65 of file WIZ5500.h.

◆ OnIpConflictCb

using Boardcore::Wiz5500::OnIpConflictCb = std::function<void()>

Definition at line 64 of file WIZ5500.h.

Constructor & Destructor Documentation

◆ Wiz5500()

Wiz5500::Wiz5500 ( SPIBus & bus,
miosix::GpioPin cs,
miosix::GpioPin intn,
SPI::ClockDivider clock_divider )

Build an instance of the driver.

Parameters
busThe underlying SPI bus.
csThe SPI cs pin.
intnThe INTn pin.
clock_dividerSelected SPI clock divider.

Definition at line 57 of file WIZ5500.cpp.

◆ ~Wiz5500()

Wiz5500::~Wiz5500 ( )

Definition at line 80 of file WIZ5500.cpp.

Member Function Documentation

◆ checkVersion()

bool Wiz5500::checkVersion ( )

Checks the VERSION register. Can be used to detect device presence.

Returns
False if the device is not connected properly (SPI comunication failure).

Definition at line 94 of file WIZ5500.cpp.

◆ close()

void Wiz5500::close ( int sock_n,
int timeout = -1 )

Close a socket.

Parameters
sock_nIndex of the socket, from 0 to 7.
timeoutTimeout for the operation in ms (or -1 if no timeout).

Definition at line 422 of file WIZ5500.cpp.

◆ connectTcp()

bool Wiz5500::connectTcp ( int sock_n,
uint16_t src_port,
WizIp dst_ip,
uint16_t dst_port,
int timeout = -1 )

Connect to a remote socket via TCP.

Parameters
sock_nIndex of the socket, from 0 to 7.
src_portLocal port of the TCP socket.
dst_ipRemote IP of the TCP socket.
dst_portRemote port of the TCP socket.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
True in case of success, false otherwise.

Definition at line 165 of file WIZ5500.cpp.

◆ getPhyState()

Wiz5500::PhyState Wiz5500::getPhyState ( )

Get current PHY state, can be used to poll link status, and wait for link up.

Returns
The current PHY state.

Definition at line 101 of file WIZ5500.cpp.

◆ handleINTn()

void Wiz5500::handleINTn ( )

Handle an interrupt from INTn.

Definition at line 128 of file WIZ5500.cpp.

◆ listenTcp()

bool Wiz5500::listenTcp ( int sock_n,
uint16_t src_port,
WizIp & dst_ip,
uint16_t & dst_port,
int timeout = -1 )

Listen for a single remote TCP connection.

Parameters
sock_nIndex of the socket, from 0 to 7.
src_portLocal port of the TCP socket.
dst_ipRemote IP of the TCP socket.
dst_portRemote port of the TCP socket.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
True in case of success, false otherwise.

Definition at line 210 of file WIZ5500.cpp.

◆ openUdp()

bool Wiz5500::openUdp ( int sock_n,
uint16_t src_port,
WizIp dst_ip,
uint16_t dst_port,
int timeout = -1 )

Open a simple UDP socket.

Parameters
sock_nIndex of the socket, from 0 to 7.
src_portLocal port of the UDP socket.
dst_ipRemote IP of the UDP socket.
dst_portRemote port of the UDP socket.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
True in case of success, false otherwise.

Definition at line 260 of file WIZ5500.cpp.

◆ recv()

ssize_t Wiz5500::recv ( int sock_n,
uint8_t * data,
size_t len,
int timeout = -1 )

Receive data from the socket (works only in TCP).

Parameters
sock_nIndex of the socket, from 0 to 7.
dataBuffer to store the data.
lenMaximum length of the data.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
The length of the received data in case of success, -1 otherwise.

Definition at line 327 of file WIZ5500.cpp.

◆ recvfrom()

ssize_t Wiz5500::recvfrom ( int sock_n,
uint8_t * data,
size_t len,
WizIp & dst_ip,
uint16_t & dst_port,
int timeout = -1 )

Receive data from the socket (works only in UDP).

Parameters
sock_nIndex of the socket, from 0 to 7.
dataBuffer to store the data.
lenMaximum length of the data.
dst_ipRemote IP of the UDP socket.
dst_portRemote port of the UDP socket.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
The length of the received data in case of success, -1 otherwise.

Definition at line 365 of file WIZ5500.cpp.

◆ reset()

void Wiz5500::reset ( )

Resets the device. Performs a software resets, resetting all registers and closing all sockets.

Definition at line 113 of file WIZ5500.cpp.

◆ send()

bool Wiz5500::send ( int sock_n,
const uint8_t * data,
size_t len,
int timeout = -1 )

Send data through the socket (works both in TCP and UDP).

Parameters
sock_nIndex of the socket, from 0 to 7.
dataData to be transmitted.
lenLength of the data.
timeoutTimeout for the operation in ms (or -1 if no timeout).
Returns
True in case of success, false otherwise.

Definition at line 293 of file WIZ5500.cpp.

◆ setGatewayIp()

void Wiz5500::setGatewayIp ( WizIp ip)

Set global gateway ip.

Definition at line 141 of file WIZ5500.cpp.

◆ setOnDestUnreachable()

void Wiz5500::setOnDestUnreachable ( OnDestUnreachableCb cb)

Sets the callback to be invoked when the device detects an unreachable host.

WARNING: DO NOT BLOCK IN THIS FUNCTION! ESPECIALLY DO NOT CALL connectTcp, listenTcp, send, recv, recvfrom, close, AS THEY WILL DEADLOCK! DO NOT CALL close!

This callback will run in the interrupt service routine, and blocking this will block interrupt handling. This is not an issue, but while the thread is blocked no interrupt will be dispatched, and the aforementioned functions will not return.

Parameters
cbCallback to be invoked.

Definition at line 88 of file WIZ5500.cpp.

◆ setOnIpConflict()

void Wiz5500::setOnIpConflict ( OnIpConflictCb cb)

Sets the callback to be invoked when the device detects an IP. conflict.

WARNING: DO NOT BLOCK IN THIS FUNCTION! ESPECIALLY DO NOT CALL connectTcp, listenTcp, send, recv, recvfrom, close, AS THEY WILL DEADLOCK!

This callback will run in the interrupt service routine, and blocking this will block interrupt handling. This is not an issue, but while the thread is blocked no interrupt will be dispatched, and the aforementioned functions will not return.

Parameters
cbCallback to be invoked.

Definition at line 82 of file WIZ5500.cpp.

◆ setSourceIp()

void Wiz5500::setSourceIp ( WizIp ip)

Set the device IP address.

Definition at line 159 of file WIZ5500.cpp.

◆ setSourceMac()

void Wiz5500::setSourceMac ( WizMac mac)

Set the device MAC address.

Definition at line 153 of file WIZ5500.cpp.

◆ setSubnetMask()

void Wiz5500::setSubnetMask ( WizIp mask)

Set global subnet mask.

Definition at line 147 of file WIZ5500.cpp.


The documentation for this class was generated from the following files: