Documentation
¶
Overview ¶
Package w5500 implements a driver for the W5500 Ethernet controller.
The driver supports basic network functionality including TCP and UDP sockets. It currently does not use the IRQ or RST pins.
Datasheet: https://docs.wiznet.io/img/products/w5500/W5500_ds_v110e.pdf Product Page: https://wiznet.io/products/ethernet-chips/w5500
Index ¶
- type Config
- type Device
- func (d *Device) Accept(sockfd int) (int, netip.AddrPort, error)
- func (d *Device) Addr() (netip.Addr, error)
- func (d *Device) Bind(sockfd int, ip netip.AddrPort) error
- func (d *Device) Close(sockfd int) error
- func (d *Device) Configure(cfg Config) error
- func (d *Device) Connect(sockfd int, host string, ip netip.AddrPort) error
- func (d *Device) GetHardwareAddr() (net.HardwareAddr, error)
- func (d *Device) GetHostByName(name string) (netip.Addr, error)
- func (d *Device) LinkInfo() string
- func (d *Device) LinkStatus() LinkStatus
- func (d *Device) Listen(sockfd int, _ int) error
- func (d *Device) Recv(sockfd int, buf []byte, _ int, deadline time.Time) (int, error)
- func (d *Device) Reset()
- func (d *Device) Send(sockfd int, buf []byte, _ int, deadline time.Time) (int, error)
- func (d *Device) SetAddr(ip netip.Addr) error
- func (d *Device) SetGateway(gateway netip.Addr) error
- func (d *Device) SetSockOpt(int, int, int, any) error
- func (d *Device) SetSubnetMask(mask netip.Addr) error
- func (d *Device) Socket(domain int, stype int, protocol int) (int, error)
- type LinkStatus
- type Resolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DNS Resolver
MAC net.HardwareAddr
IP netip.Addr
SubnetMask netip.Addr
Gateway netip.Addr
// Optional, default is 8.
MaxSockets int
}
Config is the configuration for the device.
The SPI bus must be fully configured.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a driver for the W5500 Ethernet controller.
func (*Device) Accept ¶
Accept waits for an incoming connection on the specified socket file descriptor.
func (*Device) Configure ¶
Configure sets up the device.
MAC address must be provided. The other fields are optional.
func (*Device) Connect ¶
Connect establishes a connection to the specified host and port or ip and port.
If the host is an empty string, it will use the provided ip address and port, otherwise it will resolve the host name to an IP address.
func (*Device) GetHardwareAddr ¶
func (d *Device) GetHardwareAddr() (net.HardwareAddr, error)
GetHardwareAddr returns the hardware address of the device.
func (*Device) GetHostByName ¶
GetHostByName resolves the given host name to an IP address.
func (*Device) LinkStatus ¶
func (d *Device) LinkStatus() LinkStatus
LinkStatus returns the current link status of the device.
func (*Device) Listen ¶
Listen sets the socket to listen for incoming connections on the specified socket file descriptor.
The backlog parameter is ignored, as the W5500 does not support it.
func (*Device) Recv ¶
Recv reads data from the socket with the given file descriptor into the provided buffer. It blocks until data is available or the deadline is reached.
func (*Device) Send ¶
Send sends data to the socket with the given file descriptor. It blocks until all data is sent or the deadline is reached.
func (*Device) SetAddr ¶
SetAddr sets the IP address of the device.
The IP address must be a valid IPv4 address.
func (*Device) SetGateway ¶
SetGateway sets the gateway address of the device.
The gateway must be a valid IPv4 address. It is not checked if the gateway is in the same subnet as the device.
func (*Device) SetSockOpt ¶
SetSockOpt sets the socket option for the given socket file descriptor. It is not supported by the W5500, so it always returns an error.
func (*Device) SetSubnetMask ¶
SetSubnetMask sets the subnet mask of the device.
The subnet mask must be a valid IPv4 address. It is not checked if the subnet mask is valid for the device's IP address.
type LinkStatus ¶
type LinkStatus = uint8
LinkStatus is the link status of the device.
const ( LinkStatusDown LinkStatus = iota LinkStatusUp )
LinkStatus values.