75 Wiz5500(
SPIBus& bus, miosix::GpioPin cs, miosix::GpioPin intn,
174 uint16_t dst_port,
int timeout = -1);
188 uint16_t& dst_port,
int timeout = -1);
201 bool openUdp(
int sock_n, uint16_t src_port,
WizIp dst_ip, uint16_t dst_port,
214 bool send(
int sock_n,
const uint8_t* data,
size_t len,
int timeout = -1);
226 ssize_t
recv(
int sock_n, uint8_t* data,
size_t len,
int timeout = -1);
240 ssize_t
recvfrom(
int sock_n, uint8_t* data,
size_t len,
WizIp& dst_ip,
241 uint16_t& dst_port,
int timeout = -1);
249 void close(
int sock_n,
int timeout = -1);
252 static constexpr int NUM_THREAD_WAIT_INFOS = 16;
253 static constexpr int NUM_SOCKETS = 8;
255 miosix::TimedWaitResult waitForINTn(miosix::Lock<miosix::FastMutex>& l,
257 int waitForSocketIrq(miosix::Lock<miosix::FastMutex>& l,
int sock_n,
258 uint8_t irq_mask,
long long until);
260 miosix::TimedWaitResult runInterruptServiceRoutine(
261 miosix::Lock<miosix::FastMutex>& l,
long long until);
263 void spiRead(uint8_t block, uint16_t address, uint8_t* data,
size_t len);
264 void spiWrite(uint8_t block, uint16_t address,
const uint8_t* data,
267 uint8_t spiRead8(uint8_t block, uint16_t address);
268 uint16_t spiRead16(uint8_t block, uint16_t address);
269 WizIp spiReadIp(uint8_t block, uint16_t address);
273 void spiWrite8(uint8_t block, uint16_t address, uint8_t data);
274 void spiWrite16(uint8_t block, uint16_t address, uint16_t data);
275 void spiWriteIp(uint8_t block, uint16_t address,
WizIp data);
276 void spiWriteMac(uint8_t block, uint16_t address,
WizMac data);
279 miosix::Thread* interrupt_service_thread =
nullptr;
281 miosix::Thread* intn_thread =
nullptr;
283 struct ThreadWaitInfo
288 miosix::Thread* thread;
291 enum class SocketMode
304 SocketInfo socket_infos[NUM_SOCKETS];
305 ThreadWaitInfo wait_infos[NUM_THREAD_WAIT_INFOS];
310 miosix::GpioPin intn;
311 miosix::FastMutex mutex;
321 auto old_flags = os.flags(os.dec);
322 os << (int)ip.a <<
"." << (
int)ip.b <<
"." << (int)ip.c <<
"." << (
int)ip.d;
329 auto old_flags = os.flags(os.hex);
330 os << (int)mac.a <<
":" << (
int)mac.b <<
":" << (int)mac.c <<
":"
331 << (
int)mac.d <<
":" << (int)mac.e <<
":" << (
int)mac.f;
Driver for STM32 low level SPI peripheral.
Driver for the WizNet W5500 ethernet.
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).
std::function< void()> OnIpConflictCb
void setSourceIp(WizIp ip)
Set the device IP address.
bool openUdp(int sock_n, uint16_t src_port, WizIp dst_ip, uint16_t dst_port, int timeout=-1)
Open a simple UDP socket.
void setSourceMac(WizMac mac)
Set the device MAC address.
void setOnIpConflict(OnIpConflictCb cb)
Sets the callback to be invoked when the device detects an IP. conflict.
std::function< void(WizIp, uint16_t)> OnDestUnreachableCb
bool checkVersion()
Checks the VERSION register. Can be used to detect device presence.
void setGatewayIp(WizIp ip)
Set global gateway ip.
void reset()
Resets the device. Performs a software resets, resetting all registers and closing all sockets.
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.
void handleINTn()
Handle an interrupt from INTn.
Wiz5500(SPIBus &bus, miosix::GpioPin cs, miosix::GpioPin intn, SPI::ClockDivider clock_divider)
Build an instance of the driver.
ssize_t recv(int sock_n, uint8_t *data, size_t len, int timeout=-1)
Receive data from the socket (works only in TCP).
void setSubnetMask(WizIp mask)
Set global subnet mask.
void setOnDestUnreachable(OnDestUnreachableCb cb)
Sets the callback to be invoked when the device detects an unreachable host.
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).
PhyState getPhyState()
Get current PHY state, can be used to poll link status, and wait for link up.
void close(int sock_n, int timeout=-1)
Close a socket.
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.
ClockDivider
SPI Clock divider.
This file includes all the types the logdecoder script will decode.
ostream & operator<<(ostream &os, const Boardcore::WizIp &ip)
Class representing an IPv4 ip.
Class representing an ethernet MAC address.