Once connected to a network, W5100 can communicate with other devices on that network. It can also access to the Internet through a Gateway (or Router) which connects to Internet Service Provider.
There are two operation modes, client and server. As a server, W5100 wait for a client to connect, receive requests and respond to the client. When operating as a client, W5100 connect to a server, which could be on the same network or the Internet, then send requests and receive response.
The library handles interface between Ansteron Board and W5100 as well as two basic network protocols which are DHCP (Dynamic Host Configuration Protocol) and DNS (Domain Name System). Both server and client mode can run concurrently, up to user program.
DHCP allows Ansteron Board to automatically set up network settings such as IP, net mask, Gateway and DNS server addresses. Most networks that have a Router/Gateway and connected to the Internet can use this feature. Network settings can also be set manually.
DNS protocol allows translation from domain name (like www.ansteron.com) into IP address. For internet applications, this should be used to avoid unexpected IP address changes.
All functions of the library has prefix "ENET_" which stands for Ethernet. Before communication can work, the interface must be set up. DHCP routine will then run to retrieve addresses or they must be manually entered. When that is done, the interface is ready.
All IP addresses given or returned from functions of the library are long type (32 bit integer), except some set up functions. Notation 192.168.1.1 is corresponding to value 0xC0A80101 but that cannot be used in the program.
The default MAC address is 00:1D:A4:01:12:2F. If other MAC address is used, they must be enter right after function
setup_ENET(), using function
Setup the interface with W5100. Input
cs_pin is the pin that connects to /CS signal of W5100 (
PIN_Dx). It can be any pin on Ansteron Board except pin B3, B4 and B5. The function returns 1 if succeeded, 0 if failed.
SPI interface between Ansteron Board and W5100 works at 4 MHz by default
Automatically retrieve and setup network information. Function returns 1 if succeeded, 0 if failed. The process should only take a second or two in most cases but it could wait up to 10 seconds for DHCP response. This function should be call once on start-up and cannot be used while server mode is running.
Resolve a domain name into IP address. The function returns IP address of the domain name in form of 32 bit
long integer value. If the domain name was not found or an error occurred, 0 will be returned. This function cannot work while server mode is running. Input domain is a zero-terminated string (ex. "www.ansteron.com"). Time-out value is in second.
Manually set up network information. If DHCP was not used, these functions must be called to set up the network before other functions can work.
b3..b0 are components of IP address, number values range from 0 to 255. For MAC function, input is a pointer to a
char array of 6 bytes MAC address.
Read current network settings. These functions returns IP addresses and netmask as
Open server on given port number. Function returns 1 if succeeded, 0 if failed. When a port is successfully opened, client can connect using server IP address and the same port number.
Close any opening port.
Return the IP address of connected client. If there is no client, zero will be returned.
This function return 1 if client has disconnected, zero otherwise.
Disconnect from connecting client and reopen the port. This can be called when server has finished responding to a request and would like to disconnect to serve the next client. Be informed that server can only serve one client at a time. It will be unreachable to other clients when one is being connected.
Read data or request received from connected client. Input
buffer is a pointer to location where data will be placed. Input
max_length is the size of given buffer. Function returns number of bytes read if succeeded, zero if there is no data received (without waiting).
Send data in buffer to connected client. Function will not return until all data has been lined up for sending. It does not return any value.
Send a string to connected client. The string is zero terminated and function returns number of bytes sent. Ending zero of the string will not be sent.
Connect to a server at given IP address and port number. Returned value from function
ENET_resolve() can be passed directly to this function. Value 1 is returned if function succeeded and connection is ready, 0 if failed. Time-out value is in second
Close any opening connection.
The function returns 1 if server has disconnected, 0 if connection is still active.
Send data or request to server. Function will not return until all given data is lined up for sending. It does not return any value.
Read data/response from server. Data will be written into buffer, up to
max_size number of bytes. Function returns number of bytes read, zero if there is no data. It returns zero immediately if no data was received.
In UDP mode, the first 8 bytes is UDP header. User program should discard if the header is not use.
Send a string to server. The string is zero-terminated. Function returns number of bytes sent. Ending zero of the string will not be sent.
UDP is a connectionless data transfer method. The function will initialize client mode to send UDP packets instead of regular TCP protocol. Functions
ENET_client_print() can be used to send and receive UDP packets.
Even though UDP shares the same functions with client mode, the term client does not have a meaning in this context.