Skyward boardcore
|
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. | |
using Boardcore::Wiz5500::OnDestUnreachableCb = std::function<void(WizIp, uint16_t)> |
using Boardcore::Wiz5500::OnIpConflictCb = std::function<void()> |
Wiz5500::Wiz5500 | ( | SPIBus & | bus, |
miosix::GpioPin | cs, | ||
miosix::GpioPin | intn, | ||
SPI::ClockDivider | clock_divider ) |
Build an instance of the driver.
bus | The underlying SPI bus. |
cs | The SPI cs pin. |
intn | The INTn pin. |
clock_divider | Selected SPI clock divider. |
Definition at line 57 of file WIZ5500.cpp.
Wiz5500::~Wiz5500 | ( | ) |
Definition at line 80 of file WIZ5500.cpp.
bool Wiz5500::checkVersion | ( | ) |
Checks the VERSION register. Can be used to detect device presence.
Definition at line 94 of file WIZ5500.cpp.
void Wiz5500::close | ( | int | sock_n, |
int | timeout = -1 ) |
Close a socket.
sock_n | Index of the socket, from 0 to 7. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 422 of file WIZ5500.cpp.
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.
sock_n | Index of the socket, from 0 to 7. |
src_port | Local port of the TCP socket. |
dst_ip | Remote IP of the TCP socket. |
dst_port | Remote port of the TCP socket. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 165 of file WIZ5500.cpp.
Wiz5500::PhyState Wiz5500::getPhyState | ( | ) |
Get current PHY state, can be used to poll link status, and wait for link up.
Definition at line 101 of file WIZ5500.cpp.
void Wiz5500::handleINTn | ( | ) |
Handle an interrupt from INTn.
Definition at line 128 of file WIZ5500.cpp.
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.
sock_n | Index of the socket, from 0 to 7. |
src_port | Local port of the TCP socket. |
dst_ip | Remote IP of the TCP socket. |
dst_port | Remote port of the TCP socket. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 210 of file WIZ5500.cpp.
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.
sock_n | Index of the socket, from 0 to 7. |
src_port | Local port of the UDP socket. |
dst_ip | Remote IP of the UDP socket. |
dst_port | Remote port of the UDP socket. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 260 of file WIZ5500.cpp.
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).
sock_n | Index of the socket, from 0 to 7. |
data | Buffer to store the data. |
len | Maximum length of the data. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 327 of file WIZ5500.cpp.
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).
sock_n | Index of the socket, from 0 to 7. |
data | Buffer to store the data. |
len | Maximum length of the data. |
dst_ip | Remote IP of the UDP socket. |
dst_port | Remote port of the UDP socket. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 365 of file WIZ5500.cpp.
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.
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).
sock_n | Index of the socket, from 0 to 7. |
data | Data to be transmitted. |
len | Length of the data. |
timeout | Timeout for the operation in ms (or -1 if no timeout). |
Definition at line 293 of file WIZ5500.cpp.
void Wiz5500::setGatewayIp | ( | WizIp | ip | ) |
Set global gateway ip.
Definition at line 141 of file WIZ5500.cpp.
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.
cb | Callback to be invoked. |
Definition at line 88 of file WIZ5500.cpp.
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.
cb | Callback to be invoked. |
Definition at line 82 of file WIZ5500.cpp.
void Wiz5500::setSourceIp | ( | WizIp | ip | ) |
Set the device IP address.
Definition at line 159 of file WIZ5500.cpp.
void Wiz5500::setSourceMac | ( | WizMac | mac | ) |
Set the device MAC address.
Definition at line 153 of file WIZ5500.cpp.
void Wiz5500::setSubnetMask | ( | WizIp | mask | ) |
Set global subnet mask.
Definition at line 147 of file WIZ5500.cpp.