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

#include <W5100.hh>

Inheritance diagram for W5100:
Inheritance graph
Collaboration diagram for W5100:
Collaboration graph

Classes

struct  CommonRegister
 
class  Driver
 
struct  SocketRegister
 

Public Member Functions

 W5100 (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_PB = 0x10, MR_PPPoE = 0x08, MR_AI = 0x02,
  MR_IND = 0x01
}
 
enum  {
  IR_CONFLICT = 0x80, IR_UNREACH = 0x40, IR_PPPoE = 0x20, IR_S3_INT = 0x08,
  IR_S2_INT = 0x04, IR_S1_INT = 0x02, IR_S0_INT = 0x01
}
 
enum  {
  IMR_CONFLICT = 0x80, IMR_UNREACH = 0x40, IMR_PPPoE = 0x20, IMR_S3_INT = 0x08,
  IMR_S2_INT = 0x04, IMR_S1_INT = 0x02, IMR_S0_INT = 0x01
}
 
enum  { RMSR_S3_POS = 6, RMSR_S2_POS = 4, RMSR_S1_POS = 2, RMSR_S0_POS = 0 }
 
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 = 0xf0, OP_READ = 0x0f }
 

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 = 0x0400
 
static const uint16_t SOCKET_REGISTER_SIZE = sizeof(SocketRegister)
 
static const uint16_t TX_MEMORY_BASE = 0x4000
 
static const uint16_t TX_MEMORY_MAX = 0x2000
 
static const uint16_t RX_MEMORY_BASE = 0x6000
 
static const uint16_t RX_MEMORY_MAX = 0x2000
 
static const size_t BUF_MAX = 2048
 
static const uint16_t BUF_MASK = 0x07ff
 
static const uint8_t TX_MEMORY_SIZE = 0x55
 
static const uint8_t RX_MEMORY_SIZE = 0x55
 
static const size_t MSG_MAX = BUF_MAX / 2
 
static const uint8_t SOCK_MAX = 4
 
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 W5100 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

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

References

  1. W5100 Datasheet Version 1.2.7, July 19, 2016, http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Document/W5100_Datasheet_v1.2.7.pdf
  2. W3150A+/W5100 Errata Sheet 2.6, October 5, 2015, http://www.wiznet.co.kr/wp-content/uploads/wiznethome/Chip/W5100/Document/3150Aplus_5100_ES_V260E.pdf

Definition at line 57 of file W5100.hh.

Member Enumeration Documentation

anonymous enum
protected

Mode Register bitfields, pp. 20.

Enumerator
MR_RST 

S/W Reset.

MR_PB 

Ping Block Mode.

MR_PPPoE 

PPPoE Mode.

MR_AI 

Address Auto-Increment.

MR_IND 

Indirect Bus I/F mode.

Definition at line 160 of file W5100.hh.

anonymous enum
protected

Interrupt Register bitfields, pp. 22.

Enumerator
IR_CONFLICT 

IP Conflict.

IR_UNREACH 

Destination unreachable.

IR_PPPoE 

PPPoE Connection Close.

IR_S3_INT 

Occurrence of Socket 3 Interrupt.

IR_S2_INT 

Occurrence of Socket 2 Interrupt.

IR_S1_INT 

Occurrence of Socket 1 Interrupt.

IR_S0_INT 

Occurrence of Socket 0 Interrupt.

Definition at line 171 of file W5100.hh.

anonymous enum
protected

Interrupt Mask Register bitfields, pp. 23.

Enumerator
IMR_CONFLICT 

Mask IP Conflict.

IMR_UNREACH 

Mask Destination unreachable.

IMR_PPPoE 

Mask PPPoE Connection Close.

IMR_S3_INT 

Mask occurrence of Socket 3 Interrupt.

IMR_S2_INT 

Mask occurrence of Socket 2 Interrupt.

IMR_S1_INT 

Mask occurrence of Socket 1 Interrupt.

IMR_S0_INT 

Mask occurrence of Socket 0 Interrupt.

Definition at line 184 of file W5100.hh.

anonymous enum
protected

RX Memory Size Register value, pp. 24.

Enumerator
RMSR_S3_POS 

Socket 3 memory size position.

RMSR_S2_POS 
RMSR_S1_POS 
RMSR_S0_POS 

Socket 0 memory size position.

Definition at line 197 of file W5100.hh.

anonymous enum
protected

Socket Mode Register bitfields, pp. 26.

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 237 of file W5100.hh.

anonymous enum
protected

Socket Command Register values, pp. 27-28.

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 255 of file W5100.hh.

anonymous enum
protected

Socket Interrupt Register bitfields, pp. 28-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 270 of file W5100.hh.

anonymous enum
protected

Socket Status Register values, pp. 29-31.

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 281 of file W5100.hh.

anonymous enum
protected

SPI Command codes. Format: [Command 8b] [Address 16b] [data 8b].

Enumerator
OP_WRITE 
OP_READ 

Definition at line 612 of file W5100.hh.

Constructor & Destructor Documentation

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

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

Get the current network address and subnet mask.

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

Initiate W5100 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 75 of file W5100.cpp.

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

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

Definition at line 90 of file W5100.hh.

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

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

Parameters
[in,out]ipnetwork address.

Definition at line 79 of file W5100.hh.

bool W5100::end ( )

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

void W5100::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 W5100::read ( uint16_t  addr)
protected

Read byte from given address.

Parameters
[in]addraddress on device.
void W5100::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 55 of file W5100.cpp.

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

Write byte to given address.

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

Definition at line 622 of file W5100.hh.

void W5100::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 W5100.cpp.

void W5100::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 643 of file W5100.hh.

Member Data Documentation

const uint16_t W5100::BUF_MASK = 0x07ff
staticprotected

Definition at line 314 of file W5100.hh.

const size_t W5100::BUF_MAX = 2048
staticprotected

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

Definition at line 313 of file W5100.hh.

const uint16_t W5100::COMMON_REGISTER_BASE = 0x0000
staticprotected

Common Register Base Address.

Definition at line 205 of file W5100.hh.

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

Definition at line 206 of file W5100.hh.

const uint8_t W5100::DNS_RETRY_MAX = 4
staticprotected

Maximum number of DNS request retries.

Definition at line 325 of file W5100.hh.

CommonRegister* W5100::m_creg
protected

Pointer to common registers; symbolic field calculation.

Definition at line 600 of file W5100.hh.

uint8_t W5100::m_dns[4]
protected

DNS server network address (provided by DHCP).

Definition at line 609 of file W5100.hh.

uint16_t W5100::m_local
protected

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

Definition at line 603 of file W5100.hh.

const uint8_t* W5100::m_mac
protected

Hardware address (in program memory).

Definition at line 606 of file W5100.hh.

Driver W5100::m_sock[SOCK_MAX]
protected

Sockets on device.

Definition at line 597 of file W5100.hh.

const uint8_t W5100::MAC[6]
static

Default hardware network address.

Definition at line 593 of file W5100.hh.

const size_t W5100::MSG_MAX = BUF_MAX / 2
staticprotected

TX Message Size; internal buffer size for flush threshold.

Definition at line 319 of file W5100.hh.

const uint16_t W5100::RX_MEMORY_BASE = 0x6000
staticprotected

RX Memory Address.

Definition at line 309 of file W5100.hh.

const uint16_t W5100::RX_MEMORY_MAX = 0x2000
staticprotected

Definition at line 310 of file W5100.hh.

const uint8_t W5100::RX_MEMORY_SIZE = 0x55
staticprotected

Definition at line 316 of file W5100.hh.

const uint8_t W5100::SOCK_MAX = 4
staticprotected

Maximum number of sockets on device.

Definition at line 322 of file W5100.hh.

const uint16_t W5100::SOCKET_REGISTER_BASE = 0x0400
staticprotected

Socket Registers Base Address.

Definition at line 301 of file W5100.hh.

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

Definition at line 302 of file W5100.hh.

const uint16_t W5100::TX_MEMORY_BASE = 0x4000
staticprotected

TX Memory Address.

Definition at line 305 of file W5100.hh.

const uint16_t W5100::TX_MEMORY_MAX = 0x2000
staticprotected

Definition at line 306 of file W5100.hh.

const uint8_t W5100::TX_MEMORY_SIZE = 0x55
staticprotected

Definition at line 315 of file W5100.hh.


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