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

#include <W5200.hh>

Inheritance diagram for W5200:
Inheritance graph
Collaboration diagram for W5200:
Collaboration graph

Classes

struct  CommonRegister
 
class  Driver
 
struct  SocketRegister
 

Public Member Functions

 W5200 (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 }
 
enum  { IR_CONFLICT = 0x80, IR_PPPoE = 0x20 }
 
enum  { IMR_CONFLICT = 0x80, IMR_PPPoE = 0x20 }
 
enum  {
  IR2_S7_INT = 0x80, IR2_S6_INT = 0x40, IR2_S5_INT = 0x20, IR2_S4_INT = 0x10,
  IR2_S3_INT = 0x08, IR2_S2_INT = 0x04, IR2_S1_INT = 0x02, IR2_S0_INT = 0x01
}
 
enum  {
  IMR2_S7_INT = 0x80, IMR2_S6_INT = 0x40, IMR2_S5_INT = 0x20, IMR2_S4_INT = 0x10,
  IMR2_S3_INT = 0x08, IMR2_S2_INT = 0x04, IMR2_S1_INT = 0x02, IMR2_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_MULTI = 0x80, MR_MF = 0x40, MR_ND = 0x20,
  MR_MC = 0x20, MR_PROTO_MASK = 0x0f, MR_PROTO_CLOSED = 0x00, MR_PROTO_TCP = 0x01,
  MR_PROTO_UDP = 0x02, MR_PROTO_IPRAW = 0x03, MR_PROTO_MACRAW = 0x04, MR_PROTO_PPPoE = 0x05
}
 
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  { OP_WRITE = 0x80, OP_READ = 0x00 }
 

Protected Member Functions

void write (uint16_t addr, uint8_t data)
 
void write (uint16_t addr, const void *buf, size_t len, bool progmem=false)
 
void write_P (uint16_t addr, const void *buf, size_t len)
 
uint8_t read (uint16_t addr)
 
void read (uint16_t addr, void *buf, size_t len)
 
void issue (uint16_t addr, 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 uint16_t COMMON_REGISTER_BASE = 0x0000
 
static const uint16_t COMMON_REGISTER_SIZE = sizeof(CommonRegister)
 
static const uint16_t SOCKET_REGISTER_BASE = 0x4000
 
static const uint16_t SOCKET_REGISTER_SIZE = sizeof(SocketRegister)
 
static const uint16_t TX_MEMORY_BASE = 0x8000
 
static const uint16_t TX_MEMORY_MAX = 0x4000
 
static const uint16_t RX_MEMORY_BASE = 0xC000
 
static const uint16_t RX_MEMORY_MAX = 0x4000
 
static const size_t BUF_MAX = 2048
 
static const uint16_t BUF_MASK = 0x07ff
 
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 W5200 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

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

References

  1. W5200 Datasheet Version 1.4.0, November 10, 2014, http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5200/Documents/W5200_DS_V140E.pdf
  2. W5200 Errata Sheet 1.0.6, July 07, 2014, http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5200/Documents/W5200_ES_V106E.pdf

Definition at line 57 of file W5200.hh.

Member Enumeration Documentation

anonymous enum
protected

Mode Register bitfields, pp. 17.

Enumerator
MR_RST 

S/W Reset.

MR_WOL 

Wake on LAN.

MR_PB 

Ping Block Mode.

MR_PPPoE 

PPPoE Mode.

Definition at line 165 of file W5200.hh.

anonymous enum
protected

Interrupt Register bitfields, pp. 18.

Enumerator
IR_CONFLICT 

IP Conflict.

IR_PPPoE 

PPPoE Connection Close.

Definition at line 175 of file W5200.hh.

anonymous enum
protected

Interrupt Mask Register bitfields, pp. 23.

Enumerator
IMR_CONFLICT 

Mask IP Conflict.

IMR_PPPoE 

Mask PPPoE Connection Close.

Definition at line 183 of file W5200.hh.

anonymous enum
protected

Socket Interrupt Register (IR2) bitfields, pp. 22.

Enumerator
IR2_S7_INT 

Occurrence of Socket 7 Interrupt.

IR2_S6_INT 

Occurrence of Socket 6 Interrupt.

IR2_S5_INT 

Occurrence of Socket 5 Interrupt.

IR2_S4_INT 

Occurrence of Socket 4 Interrupt.

IR2_S3_INT 

Occurrence of Socket 3 Interrupt.

IR2_S2_INT 

Occurrence of Socket 2 Interrupt.

IR2_S1_INT 

Occurrence of Socket 1 Interrupt.

IR2_S0_INT 

Occurrence of Socket 0 Interrupt.

Definition at line 191 of file W5200.hh.

anonymous enum
protected

Interrupt Mask Register (IR2) bitfields, pp. 19.

Enumerator
IMR2_S7_INT 

Mask occurrence of Socket 7 Interrupt.

IMR2_S6_INT 

Mask occurrence of Socket 6 Interrupt.

IMR2_S5_INT 

Mask occurrence of Socket 5 Interrupt.

IMR2_S4_INT 

Mask occurrence of Socket 4 Interrupt.

IMR2_S3_INT 

Mask occurrence of Socket 3 Interrupt.

IMR2_S2_INT 

Mask occurrence of Socket 2 Interrupt.

IMR2_S1_INT 

Mask occurrence of Socket 1 Interrupt.

IMR2_S0_INT 

Mask occurrence of Socket 0 Interrupt.

Definition at line 205 of file W5200.hh.

anonymous enum
protected

RX/TX Socket Memory Size bitfield pp. 37.

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 219 of file W5200.hh.

anonymous enum
protected

Socket Mode Register bitfields, pp. 24-25.

Enumerator
MR_FLAG_MASK 

Flag mask.

MR_MULTI 

Multicasting.

MR_MF 

MAC Filter.

MR_ND 

Use No Delay ACK.

MR_MC 

Multicast version.

MR_PROTO_MASK 

Protocol.

MR_PROTO_CLOSED 

Closed.

MR_PROTO_TCP 

TCP.

MR_PROTO_UDP 

UDP.

MR_PROTO_IPRAW 

RAW IP.

MR_PROTO_MACRAW 

RAW MAC.

MR_PROTO_PPPoE 

PPPoE.

Definition at line 265 of file W5200.hh.

anonymous enum
protected

Socket Command Register values, pp. 26-27.

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 283 of file W5200.hh.

anonymous enum
protected

Socket Interrupt Register bitfields, pp. 29.

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 305 of file W5200.hh.

anonymous enum
protected

Socket Status Register values, pp. 30-32.

Enumerator
SR_CLOSED 
SR_ARP 
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 

Definition at line 321 of file W5200.hh.

anonymous enum
protected

SPI Command codes; or'ed with MSB of length.

Enumerator
OP_WRITE 
OP_READ 

Definition at line 650 of file W5200.hh.

Constructor & Destructor Documentation

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

Construct W5200 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 W5200::addr ( uint8_t  ip[4],
uint8_t  subnet[4] 
)

Get the current network address and subnet mask.

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

Initiate W5200 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 71 of file W5200.cpp.

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

Initiate W5200 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 W5200::begin_P ( str_P  hostname,
uint16_t  timeout = 500 
)
inline

Definition at line 90 of file W5200.hh.

int W5200::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 W5200::dns_addr ( uint8_t  ip[4])
inline

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

Parameters
[in,out]ipnetwork address.

Definition at line 79 of file W5200.hh.

bool W5200::end ( )

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

void W5200::issue ( uint16_t  addr,
uint8_t  cmd 
)
protected

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

Parameters
[in]addraddress on device.
[in]cmdcommand to issue.
uint8_t W5200::read ( uint16_t  addr)
protected

Read byte from given address.

Parameters
[in]addraddress on device.
void W5200::read ( uint16_t  addr,
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]bufpointer to buffer.
[in]lennumber of bytes to read.

Definition at line 53 of file W5200.cpp.

Socket* W5200::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 W5200::write ( uint16_t  addr,
uint8_t  data 
)
inlineprotected

Write byte to given address.

Parameters
[in]addraddress on device.
[in]datato write.

Definition at line 660 of file W5200.hh.

void W5200::write ( uint16_t  addr,
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]bufpointer to buffer.
[in]lennumber of bytes to write.
[in]progmemprogram memory pointer flag.

Definition at line 35 of file W5200.cpp.

void W5200::write_P ( uint16_t  addr,
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]bufpointer to buffer in program memory.
[in]lennumber of bytes to write.

Definition at line 681 of file W5200.hh.

Member Data Documentation

const uint16_t W5200::BUF_MASK = 0x07ff
staticprotected

Definition at line 354 of file W5200.hh.

const size_t W5200::BUF_MAX = 2048
staticprotected

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

Definition at line 353 of file W5200.hh.

const uint16_t W5200::COMMON_REGISTER_BASE = 0x0000
staticprotected

Common Register Base Address.

Definition at line 229 of file W5200.hh.

const uint16_t W5200::COMMON_REGISTER_SIZE = sizeof(CommonRegister)
staticprotected

Definition at line 230 of file W5200.hh.

const uint8_t W5200::DNS_RETRY_MAX = 4
staticprotected

Maximum number of DNS request retries.

Definition at line 363 of file W5200.hh.

CommonRegister* W5200::m_creg
protected

Pointer to common registers; symbolic field calculation.

Definition at line 638 of file W5200.hh.

uint8_t W5200::m_dns[4]
protected

DNS server network address (provided by DHCP).

Definition at line 647 of file W5200.hh.

uint16_t W5200::m_local
protected

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

Definition at line 641 of file W5200.hh.

const uint8_t* W5200::m_mac
protected

Hardware address (in program memory).

Definition at line 644 of file W5200.hh.

Driver W5200::m_sock[SOCK_MAX]
protected

Sockets on device.

Definition at line 635 of file W5200.hh.

const uint8_t W5200::MAC[6]
static

Default hardware network address.

Definition at line 631 of file W5200.hh.

const size_t W5200::MSG_MAX = BUF_MAX / 2
staticprotected

TX Message Size; internal buffer size for flush threshold.

Definition at line 357 of file W5200.hh.

const uint16_t W5200::RX_MEMORY_BASE = 0xC000
staticprotected

RX Memory Address.

Definition at line 349 of file W5200.hh.

const uint16_t W5200::RX_MEMORY_MAX = 0x4000
staticprotected

Definition at line 350 of file W5200.hh.

const uint8_t W5200::SOCK_MAX = 8
staticprotected

Maximum number of sockets on device.

Definition at line 360 of file W5200.hh.

const uint16_t W5200::SOCKET_REGISTER_BASE = 0x4000
staticprotected

Socket Registers Base Address.

Definition at line 341 of file W5200.hh.

const uint16_t W5200::SOCKET_REGISTER_SIZE = sizeof(SocketRegister)
staticprotected

Definition at line 342 of file W5200.hh.

const uint16_t W5200::TX_MEMORY_BASE = 0x8000
staticprotected

TX Memory Address.

Definition at line 345 of file W5200.hh.

const uint16_t W5200::TX_MEMORY_MAX = 0x4000
staticprotected

Definition at line 346 of file W5200.hh.


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