44 constexpr WizIp(uint8_t
a, uint8_t
b, uint8_t
c, uint8_t
d)
49 constexpr explicit WizIp(uint32_t ip)
50 :
a{static_cast<uint8_t>((ip >> 24) & 0xFF)},
51 b{static_cast<uint8_t>((ip >> 16) & 0xFF)},
52 c{static_cast<uint8_t>((ip >> 8) & 0xFF)},
53 d{static_cast<uint8_t>(ip & 0xFF)}
57 constexpr explicit operator uint32_t()
const
59 return a << 24 |
b << 16 |
c << 8 |
d;
96 Wiz5500(
SPIBus& bus, miosix::GpioPin cs, miosix::GpioPin intn,
195 uint16_t dst_port,
int timeout = -1);
209 uint16_t& dst_port,
int timeout = -1);
222 bool openUdp(
int sock_n, uint16_t src_port,
WizIp dst_ip, uint16_t dst_port,
235 bool send(
int sock_n,
const uint8_t* data,
size_t len,
int timeout = -1);
247 ssize_t
recv(
int sock_n, uint8_t* data,
size_t len,
int timeout = -1);
261 ssize_t
recvfrom(
int sock_n, uint8_t* data,
size_t len,
WizIp& dst_ip,
262 uint16_t& dst_port,
int timeout = -1);
270 void close(
int sock_n,
int timeout = -1);
273 static constexpr int NUM_THREAD_WAIT_INFOS = 16;
274 static constexpr int NUM_SOCKETS = 8;
276 miosix::TimedWaitResult waitForINTn(miosix::Lock<miosix::FastMutex>& l,
278 int waitForSocketIrq(miosix::Lock<miosix::FastMutex>& l,
int sock_n,
279 uint8_t irq_mask,
long long until);
281 miosix::TimedWaitResult runInterruptServiceRoutine(
282 miosix::Lock<miosix::FastMutex>& l,
long long until);
284 void spiRead(uint8_t block, uint16_t address, uint8_t* data,
size_t len);
285 void spiWrite(uint8_t block, uint16_t address,
const uint8_t* data,
288 uint8_t spiRead8(uint8_t block, uint16_t address);
289 uint16_t spiRead16(uint8_t block, uint16_t address);
290 WizIp spiReadIp(uint8_t block, uint16_t address);
294 void spiWrite8(uint8_t block, uint16_t address, uint8_t data);
295 void spiWrite16(uint8_t block, uint16_t address, uint16_t data);
296 void spiWriteIp(uint8_t block, uint16_t address,
WizIp data);
297 void spiWriteMac(uint8_t block, uint16_t address,
WizMac data);
300 miosix::Thread* interrupt_service_thread =
nullptr;
302 miosix::Thread* intn_thread =
nullptr;
304 struct ThreadWaitInfo
309 miosix::Thread* thread;
312 enum class SocketMode
325 SocketInfo socket_infos[NUM_SOCKETS];
326 ThreadWaitInfo wait_infos[NUM_THREAD_WAIT_INFOS];
331 miosix::GpioPin intn;
332 miosix::FastMutex mutex;
342 auto old_flags = os.flags(os.dec);
343 os << (int)ip.
a <<
"." << (
int)ip.
b <<
"." << (int)ip.
c <<
"." << (
int)ip.
d;
350 auto old_flags = os.flags(os.hex);
351 auto old_fill = os.fill(
'0');
352 os << std::setw(2) << (int)mac.
a <<
":" << std::setw(2) << (int)mac.
b <<
":"
353 << std::setw(2) << (int)mac.
c <<
":" << std::setw(2) << (int)mac.
d <<
":"
354 << std::setw(2) << (int)mac.
e <<
":" << std::setw(2) << (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.
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.
Driver for the VN100S IMU.
ostream & operator<<(ostream &os, const Boardcore::WizIp &ip)
Class representing an IPv4 ip.
constexpr WizIp(uint32_t ip)
constexpr WizIp(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
Class representing an ethernet MAC address.