COSA
An Object-Oriented Platform for Arduino Programming
W5500 Class Reference

#include <W5500.hh>

Inheritance diagram for W5500:
Inheritance graph
Collaboration diagram for W5500:
Collaboration graph

Classes

struct  CommonRegister
 
class  Driver
 
struct  SocketRegister
 

Public Member Functions

 W5500 (const uint8_t *mac=NULL, Board::DigitalPin csn=Board::D10)
 
void addr (uint8_t ip[4], uint8_t subnet[4])
 
void dns_addr (uint8_t ip[4])
 
bool begin_P (const char *hostname, uint16_t timeout=500)
 
bool begin_P (str_P hostname, uint16_t timeout=500)
 
bool begin (uint8_t ip[4]=NULL, uint8_t subnet[4]=NULL, uint16_t timeout=500)
 
int bind (uint8_t ip[4], uint8_t subnet[4], uint8_t gateway[4]=NULL)
 
Socketsocket (Socket::Protocol proto, uint16_t port=0, uint8_t flag=0)
 
bool end ()
 

Static Public Attributes

static const uint8_t MAC [6]
 

Protected Types

enum  {
  MR_RST = 0x80, MR_WOL = 0x20, MR_PB = 0x10, MR_PPPoE = 0x08,
  MR_FARP = 0x02
}
 
enum  { IR_CONFLICT = 0x80, IR_UNREACH = 0x40, IR_PPPoE = 0x20, IR_MP = 0x10 }
 
enum  { IMR_CONFLICT = 0x80, IMR_UNREACH = 0x40, IMR_PPPoE = 0x20, IMR_MP = 0x10 }
 
enum  {
  SIR_S7_INT = 0x80, SIR_S6_INT = 0x40, SIR_S5_INT = 0x20, SIR_S4_INT = 0x10,
  SIR_S3_INT = 0x08, SIR_S2_INT = 0x04, SIR_S1_INT = 0x02, SIR_S0_INT = 0x01
}
 
enum  {
  SIMR_S7_INT = 0x80, SIMR_S6_INT = 0x40, SIMR_S5_INT = 0x20, SIMR_S4_INT = 0x10,
  SIMR_S3_INT = 0x08, SIMR_S2_INT = 0x04, SIMR_S1_INT = 0x02, SIMR_S0_INT = 0x01
}
 
enum  {
  MEM_SIZE_00K = 0x00, MEM_SIZE_01K = 0x01, MEM_SIZE_02K = 0x02, MEM_SIZE_04K = 0x04,
  MEM_SIZE_08K = 0x08, MEM_SIZE_16K = 0x10
}
 
enum  {
  MR_FLAG_MASK = 0xe0, MR_MULTIMF = 0x80, MR_BCASTB = 0x40, MR_NDMCMMB = 0x20,
  MR_UCASTB = 0x10, MR_PROTO_MASK = 0x0f, MR_PROTO_CLOSED = 0x00, MR_PROTO_TCP = 0x01,
  MR_PROTO_UDP = 0x02, MR_PROTO_IPRAW = 0x03, MR_PROTO_MACRAW = 0x04
}
 
enum  {
  CR_OPEN = 0x01, CR_LISTEN = 0x02, CR_CONNECT = 0x04, CR_DISCON = 0x08,
  CR_CLOSE = 0x10, CR_SEND = 0x20, CR_SEND_MAC = 0x21, CR_SEND_KEEP = 0x22,
  CR_RECV = 0x40
}
 
enum  {
  IR_SEND_OK = 0x10, IR_TIMEOUT = 0x08, IR_RECV = 0x04, IR_DISCON = 0x02,
  IR_CON = 0x01
}
 
enum  {
  SR_CLOSED = 0x00, SR_ARP = 0x01, SR_INIT = 0x13, SR_LISTEN = 0x14,
  SR_SYNSENT = 0x15, SR_SYNRECV = 0x16, SR_ESTABLISHED = 0x17, SR_FIN_WAIT = 0x18,
  SR_CLOSING = 0x1A, SR_TIME_WAIT = 0x1B, SR_CLOSE_WAIT = 0x1C, SR_LAST_ACK = 0x1D,
  SR_UDP = 0x22, SR_IPRAW = 0x32, SR_MACRAW = 0x42, SR_PPPoE = 0x5F
}
 
enum  {
  SPI_CP_BSB_CR = 0x00, SPI_CP_BSB_SR = 0x08, SPI_CP_BSB_TX = 0x10, SPI_CP_BSB_RX = 0x18,
  SPI_CP_RWB_RS = 0x00, SPI_CP_RWB_WS = 0x04, SPI_CP_OM_VDM = 0x00, SPI_CP_OM_FD1 = 0x01,
  SPI_CP_OM_FD2 = 0x02, SPI_CP_OM_FD4 = 0x03
}
 

Protected Member Functions

void write (uint16_t addr, uint8_t ctl, uint8_t data)
 
void write (uint16_t addr, uint8_t ctl, const void *buf, size_t len, bool progmem=false)
 
void write_P (uint16_t addr, uint8_t ctl, const void *buf, size_t len)
 
uint8_t read (uint16_t addr, uint8_t ctl)
 
void read (uint16_t addr, uint8_t ctl, void *buf, size_t len)
 
void issue (uint16_t addr, uint8_t ctl, uint8_t cmd)
 

Protected Attributes

Driver m_sock [SOCK_MAX]
 
CommonRegisterm_creg
 
uint16_t m_local
 
const uint8_t * m_mac
 
uint8_t m_dns [4]
 

Static Protected Attributes

static const size_t BUF_MAX = 2048
 
static const size_t MSG_MAX = BUF_MAX / 2
 
static const uint8_t SOCK_MAX = 8
 
static const uint8_t DNS_RETRY_MAX = 4
 

Private Member Functions

void set_clock (Clock rate)
 
void set_clock (uint32_t freq)
 

Static Private Member Functions

static Clock clock (uint32_t freq)
 
static Clock cycle (uint16_t ns)
 

Private Attributes

Driverm_next
 List of drivers. More...
 
Interrupt::Handlerm_irq
 Interrupt handler. More...
 
OutputPin m_cs
 Device chip select pin. More...
 
Pulse m_pulse
 Chip select pulse width. More...
 
uint8_t m_spcr
 SPI/SPCR hardware control register setting. More...
 
uint8_t m_spsr
 SPI/SPSR hardware status register. More...
 

Detailed Description

Cosa WIZnet W5500 device driver class. Provides an implementation of the Cosa Socket and Cosa IOStream::Device classes. A socket may be bound directly to a Cosa IOStream. The device internal transmitter buffer is used. The buffer is sent on flush (TCP/UDP) or when full (TCP). Integrated with Cosa INET/DHCP so that the ethernet controller may obtain a network address and information from a DHCP server.

Circuit

+------------+
(D10)--------------29-|CSN |
(D11)--------------28-|MOSI |
(D12)--------------27-|MISO |
(D13)--------------30-|SCK |
(D2)-----[ ]-------56-|IRQ |
+------------+

References

  1. W5500 Datasheet Version 1.0.6, December 30, 2014, http://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_ds_v106e_141230.pdf
  2. W5500 Application Note 1.1 April 09, 2014, http://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_ap_ipraw_v110e.pdf

Definition at line 57 of file W5500.hh.

Member Enumeration Documentation

anonymous enum
protected

Mode Register bitfields, pp. 33-34.

Enumerator
MR_RST 

S/W Reset.

MR_WOL 

Wake on LAN.

MR_PB 

Ping Block Mode.

MR_PPPoE 

PPPoE Mode.

MR_FARP 

Force ARP.

Definition at line 164 of file W5500.hh.

anonymous enum
protected

Interrupt Register bitfields, pp. 36.

Enumerator
IR_CONFLICT 

IP Conflict.

IR_UNREACH 

Destination Unreachable.

IR_PPPoE 

PPPoE Connection Close.

IR_MP 

Magic Packet.

Definition at line 175 of file W5500.hh.

anonymous enum
protected
Enumerator
IMR_CONFLICT 
IMR_UNREACH 

Destination Unreachable.

IMR_PPPoE 

PPPoE Connection Close.

IMR_MP 

Magic Packet.

Definition at line 185 of file W5500.hh.

anonymous enum
protected

Socket Interrupt Register bitfields, pp. 38.

Enumerator
SIR_S7_INT 

Occurrence of Socket 7 Interrupt.

SIR_S6_INT 

Occurrence of Socket 6 Interrupt.

SIR_S5_INT 

Occurrence of Socket 5 Interrupt.

SIR_S4_INT 

Occurrence of Socket 4 Interrupt.

SIR_S3_INT 

Occurrence of Socket 3 Interrupt.

SIR_S2_INT 

Occurrence of Socket 2 Interrupt.

SIR_S1_INT 

Occurrence of Socket 1 Interrupt.

SIR_S0_INT 

Occurrence of Socket 0 Interrupt.

Definition at line 195 of file W5500.hh.

anonymous enum
protected

Socket Interrupt Mask Register bitfields, pp. 38.

Enumerator
SIMR_S7_INT 

Mask occurrence of Socket 7 Interrupt.

SIMR_S6_INT 

Mask occurrence of Socket 6 Interrupt.

SIMR_S5_INT 

Mask occurrence of Socket 5 Interrupt.

SIMR_S4_INT 

Mask occurrence of Socket 4 Interrupt.

SIMR_S3_INT 

Mask occurrence of Socket 3 Interrupt.

SIMR_S2_INT 

Mask occurrence of Socket 2 Interrupt.

SIMR_S1_INT 

Mask occurrence of Socket 1 Interrupt.

SIMR_S0_INT 

Mask occurrence of Socket 0 Interrupt.

Definition at line 209 of file W5500.hh.

anonymous enum
protected

RX/TX Socket Memory Size bitfield pp. 54-55.

Enumerator
MEM_SIZE_00K 

0KB

MEM_SIZE_01K 

1KB

MEM_SIZE_02K 

2KB

MEM_SIZE_04K 

4KB

MEM_SIZE_08K 

8KB

MEM_SIZE_16K 

16KB

Definition at line 223 of file W5500.hh.

anonymous enum
protected

Socket Mode Register bitfields, pp 45-46.

Enumerator
MR_FLAG_MASK 

Flag mask.

MR_MULTIMF 

Multicast(UDP) MAC Filter(MACRAW).

MR_BCASTB 

Broadcast Block(UDP & MACRAW)

MR_NDMCMMB 

No Delayed ACK(TCP) Multicast IGMP version(UDP) Multicast Block(MACRAW).

MR_UCASTB 

Unicast Block(UDP) IPv6 Block(MACRAW)

MR_PROTO_MASK 

Protocol mask.

MR_PROTO_CLOSED 

Closed.

MR_PROTO_TCP 

TCP.

MR_PROTO_UDP 

UDP.

MR_PROTO_IPRAW 

RAW IP. See W5500 Application Note doc.

MR_PROTO_MACRAW 

RAW MAC.

Definition at line 265 of file W5500.hh.

anonymous enum
protected

Socket Command Register values, pp. 47-49

Enumerator
CR_OPEN 

Initiate socket according to MR.

CR_LISTEN 

TCP: Initiate server mode.

CR_CONNECT 

TCP: Initiate client mode.

CR_DISCON 

TCP: Disconnect server/client.

CR_CLOSE 

Close socket.

CR_SEND 

Transmit data according to TX_WR.

CR_SEND_MAC 

UDP: Transmit data.

CR_SEND_KEEP 

TCP: Check connection status.

CR_RECV 

Receiving packet to RX_RD.

Definition at line 282 of file W5500.hh.

anonymous enum
protected

Socket Interrupt Register bitfields, pp. 49.

Enumerator
IR_SEND_OK 

Send operation is completed.

IR_TIMEOUT 

Timeout occured.

IR_RECV 

Received data.

IR_DISCON 

Connection termination.

IR_CON 

Connection established.

Definition at line 297 of file W5500.hh.

anonymous enum
protected

Socket Status Register values, pp. 50-51.

Enumerator
SR_CLOSED 
SR_ARP 

Undocumented ????

SR_INIT 
SR_LISTEN 
SR_SYNSENT 
SR_SYNRECV 
SR_ESTABLISHED 
SR_FIN_WAIT 
SR_CLOSING 
SR_TIME_WAIT 
SR_CLOSE_WAIT 
SR_LAST_ACK 
SR_UDP 
SR_IPRAW 
SR_MACRAW 
SR_PPPoE 

Undocumented ????

Definition at line 308 of file W5500.hh.

anonymous enum
protected

SPI Control Phase bits and masks, pp. 16-17. CP byte made up of (BSB & RWB & OM & (SN << 5)) For BSB selecting control register no socket number should ever be given.

Enumerator
SPI_CP_BSB_CR 

Control Register.

SPI_CP_BSB_SR 

Socket Register.

SPI_CP_BSB_TX 

Socket TX Buffer.

SPI_CP_BSB_RX 

Socket RX Buffer.

SPI_CP_RWB_RS 

Read Access Select.

SPI_CP_RWB_WS 

Write Access Select.

SPI_CP_OM_VDM 

Operation, variable date mode.

SPI_CP_OM_FD1 

Operation, fixed data 1 byte mode.

SPI_CP_OM_FD2 

Operation, fixed data 2 byte mode.

SPI_CP_OM_FD4 

Operation, fixed data 3 byte mode.

Definition at line 332 of file W5500.hh.

Constructor & Destructor Documentation

W5500::W5500 ( const uint8_t *  mac = NULL,
Board::DigitalPin  csn = Board::D10 
)

Construct W5500 device driver with given hardware address, and chip select.

Parameters
[in]machardware address (in program memory, default NULL).
[in]csnchip selection pin (Default D10).

Member Function Documentation

void W5500::addr ( uint8_t  ip[4],
uint8_t  subnet[4] 
)

Get the current network address and subnet mask.

Parameters
[in]ipnetwork address.
[in]subnetmask.
bool W5500::begin ( uint8_t  ip[4] = NULL,
uint8_t  subnet[4] = NULL,
uint16_t  timeout = 500 
)

Initiate W5500 device driver with given network address and subnet mask. Returns true if successful otherwise false.

Parameters
[in]ipnetwork address (Default NULL, 0.0.0.0).
[in]subnetmask (Default NULL, 0.0.0.0).
[in]timeoutretry timeout period (Default 500 ms).
Returns
bool.

Definition at line 72 of file W5500.cpp.

bool W5500::begin_P ( const char *  hostname,
uint16_t  timeout = 500 
)

Initiate W5500 device driver with given hostname. Network address, subnet mask and gateway should be obtained from DHCP. Returns true if successful otherwise false.

Parameters
[in]hostnamestring in program memory.
[in]timeoutretry timeout period (Default 500 ms).
Returns
bool.
bool W5500::begin_P ( str_P  hostname,
uint16_t  timeout = 500 
)
inline

Definition at line 90 of file W5500.hh.

int W5500::bind ( uint8_t  ip[4],
uint8_t  subnet[4],
uint8_t  gateway[4] = NULL 
)

Bind to the given network address and subnet mask. Returns zero if successful otherwise negative error code.

Parameters
[in]ipnetwork address.
[in]subnetmask.
[in]gatewaynetwork address (Default NULL).
Returns
zero if successful otherwise negative error code.
void W5500::dns_addr ( uint8_t  ip[4])
inline

Get DNS network address if W5500 device driver was initiated with hostname and obtained network address from DHCP.

Parameters
[in,out]ipnetwork address.

Definition at line 79 of file W5500.hh.

bool W5500::end ( )

Terminate W5500 device driver. Closes all active sockets. Return true if successful otherwise false.

void W5500::issue ( uint16_t  addr,
uint8_t  ctl,
uint8_t  cmd 
)
protected

Issue given command to register with given address and await completion.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
[in]cmdcommand to issue.
uint8_t W5500::read ( uint16_t  addr,
uint8_t  ctl 
)
protected

Read byte from given address.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
void W5500::read ( uint16_t  addr,
uint8_t  ctl,
void *  buf,
size_t  len 
)
protected

Read data from given address on device to given buffer with given number of bytes.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
[in]bufpointer to buffer.
[in]lennumber of bytes to read.

Definition at line 54 of file W5500.cpp.

Socket* W5500::socket ( Socket::Protocol  proto,
uint16_t  port = 0,
uint8_t  flag = 0 
)

Allocate socket with the given protocol, port and flags. Returns pointer to socket. The socket is deallocated with Socket::close().

Parameters
[in]protosocket protocol.
[in]portnumber (Default 0).
[in]flag(Default 0).
Returns
socket pointer or NULL.
void W5500::write ( uint16_t  addr,
uint8_t  ctl,
uint8_t  data 
)
inlineprotected

Write byte to given address.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
[in]datato write.

Definition at line 644 of file W5500.hh.

void W5500::write ( uint16_t  addr,
uint8_t  ctl,
const void *  buf,
size_t  len,
bool  progmem = false 
)
protected

Write data from given buffer with given number of bytes to address.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
[in]bufpointer to buffer.
[in]lennumber of bytes to write.
[in]progmemprogram memory pointer flag.

Definition at line 36 of file W5500.cpp.

void W5500::write_P ( uint16_t  addr,
uint8_t  ctl,
const void *  buf,
size_t  len 
)
inlineprotected

Write data from given program memory buffer with given number of bytes to address.

Parameters
[in]addraddress on device.
[in]ctlbyte specifiying what block of memory to access, BSB of Control Phase byte
[in]bufpointer to buffer in program memory.
[in]lennumber of bytes to write.

Definition at line 667 of file W5500.hh.

Member Data Documentation

const size_t W5500::BUF_MAX = 2048
staticprotected

Socket Buffer Size; 2 Kbyte TX/RX per socket.

Definition at line 346 of file W5500.hh.

const uint8_t W5500::DNS_RETRY_MAX = 4
staticprotected

Maximum number of DNS request retries.

Definition at line 355 of file W5500.hh.

CommonRegister* W5500::m_creg
protected

Pointer to common registers; symbolic field calculation.

Definition at line 627 of file W5500.hh.

uint8_t W5500::m_dns[4]
protected

DNS server network address (provided by DHCP).

Definition at line 636 of file W5500.hh.

uint16_t W5500::m_local
protected

Next local port number; DYNAMIC_PORT(49152)-UINT16_MAX(65535).

Definition at line 630 of file W5500.hh.

const uint8_t* W5500::m_mac
protected

Hardware address (in program memory).

Definition at line 633 of file W5500.hh.

Driver W5500::m_sock[SOCK_MAX]
protected

Sockets on device.

Definition at line 624 of file W5500.hh.

const uint8_t W5500::MAC[6]
static

Default hardware network address.

Definition at line 620 of file W5500.hh.

const size_t W5500::MSG_MAX = BUF_MAX / 2
staticprotected

TX Message Size; internal buffer size for flush threshold.

Definition at line 349 of file W5500.hh.

const uint8_t W5500::SOCK_MAX = 8
staticprotected

Maximum number of sockets on device.

Definition at line 352 of file W5500.hh.


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