Ethernet Library

The internal Ethernet Controller consists of a fully integrated media access controller (MAC) and network physical (PHY) interface (Stellaris M3 family only). The Ethernet Controller conforms to IEEE 802.3 specifications and fully supports 10BASE-T and 100BASE-TX standards.

The internal Ethernet library supports :

  Important :

Library Routines

Ethernet_Intern_Init

Prototype // for Stellaris MCUs

procedure Ethernet_Intern_Init(var mac : array[6] of byte; var ip : array[4] of byte; configuration : dword);

// for ST MCUs

function Ethernet_Intern_Init(var mac : array[6] of byte; var ip : array[4] of byte; config : byte; module : ^const Module_Struct) : byte;

// for Kinetis MCUs

function Ethernet_Intern_Init(var mac : array[6] of byte; var ip : array[4] of byte; module : ^const Module_Struct) : byte;

Returns
  • 1 - if error occured.
  • 0 - if there was no error.
Description

This is MAC module routine. It initializes Ethernet controller. This function is internaly splited into 2 parts to help linker when coming short of memory.

Ethernet controller settings (parameters not mentioned here are set to default):

  • RAM buffer read/write pointers in auto-increment mode.
  • receive filters set to default: CRC + MAC Unicast + MAC Broadcast in OR mode.
  • flow control with TX and RX pause frames in full duplex mode.
  • maximum packet size is set to 1536.
  • Back-to-Back Inter-Packet Gap: 0x15 in full duplex mode; 0x12 in half duplex mode.
  • Non-Back-to-Back Inter-Packet Gap: 0x0012 in full duplex mode; 0x0C12 in half duplex mode.
  • half duplex loopback disabled.
  • LED configuration: default (LEDA-link status, LEDB-link activity).

Parameters:

  • mac: RAM buffer containing valid MAC address.
  • ip: RAM buffer containing valid IP address.
  • configuration: ethernet duplex mode switch. Valid values:
    • _ETHERNET_HALFDUPLEX
    • _ETHERNET_FULLDUPLEX
    • _ETHERNET_SPD10
    • _ETHERNET_SPD100
    • _ETHERNET_AUTO_NEGOTIATION
    • _ETHERNET_MANUAL_NEGOTIATION
  • module: appropriate module pinout. Use Code Assistant to list available module pinouts by typing _GPIO_MODULE_ETH and pressing Ctrl + Space.
  Note : If a DHCP server is to be used, IP address should be set to 0.0.0.0.
Requires Nothing.
Example
var 
  myMacAddr : array[6] of byte; // my MAC address	
  myIpAddr  : array[4] of byte; // my IP addr
  ...
  myMacAddr[0] := 0x00;
  myMacAddr[1] := 0x14;
  myMacAddr[2] := 0xA5;
  myMacAddr[3] := 0x76;
  myMacAddr[4] := 0x19;
  myMacAddr[5] := 0x3F;

  myIpAddr[0]  := 192;
  myIpAddr[1]  := 168;
  myIpAddr[2]  := 20;
  myIpAddr[3]  := 60;
  
  Ethernet_Intern_Init(myMacAddr, myIpAddr, _ETHERNET_AUTO_NEGOTIATION);

Ethernet_Intern_Enable

Prototype

procedure Ethernet_Intern_Enable(enFlt : word);

Returns

Nothing.

Description

This is MAC module routine. This routine enables appropriate network traffic on the MCU's internal Ethernet module by the means of it's receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be enabled if a corresponding bit of this routine's input parameter is set. Therefore, more than one type of network traffic can be enabled at the same time. For this purpose, predefined library constants (see the table below) can be ORed to form appropriate input value.

Parameters:

  • enFlt: network traffic/receive filter flags. Each bit corresponds to the appropriate network traffic/receive filter:
  • Bit Mask Description Predefined library const
    0 0x01 MAC Multicast traffic/receive filter flag. When set, MAC multicast traffic will be enabled. _ETHERNET_MULTICAST
    1 0x02 CRC check flag. When set, packets with invalid CRC field will be discarded. _ETHERNET_CRC
    2 0x04 not used none
    3 0x08 not used none
    4 0x10 not used none
    5 0x20 not used none
    6 0x40 not used none
    7 0x80 not used none

      Note :
    • Advanced filtering available in the MCU's internal Ethernet module such as Pattern Match, Magic Packet and Hash Table can not be enabled by this routine.
      Additionaly, all filters, except CRC, enabled with this routine will work in OR mode, which means that packet will be received if any of the enabled filters accepts it.
    • This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the MCU's internal Ethernet module.
      The MCU's internal Ethernet module should be properly cofigured by the means of Ethernet_Intern_Init routine.
    • This routine is valid only for Stellaris devices.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
Ethernet_Intern_Enable(_Ethernet_Intern_CRC or _Ethernet_Intern_MULTICAST); // enable CRC checking and Multicast traffic

Ethernet_Intern_Disable

Prototype

procedure Ethernet_Intern_Disable(disFlt : word);

Returns

Nothing.

Description

This is MAC module routine. This routine disables appropriate network traffic on the MCU's internal Ethernet module by the means of it's receive filters (unicast, multicast, broadcast, crc). Specific type of network traffic will be disabled if a corresponding bit of this routine's input parameter is set. Therefore, more than one type of network traffic can be disabled at the same time. For this purpose, predefined library constants (see the table below) can be ORed to form appropriate input value.

Parameters:

  • disFlt: network traffic/receive filter flags. Each bit corresponds to the appropriate network traffic/receive filter:
  • Bit Mask Description Predefined library const
    0 0x01 MAC Multicast traffic/receive filter flag. When set, MAC multicast traffic will be enabled. _ETHERNET_MULTICAST
    1 0x02 CRC check flag. When set, packets with invalid CRC field will be discarded. _ETHERNET_CRC
    2 0x04 not used none
    3 0x08 not used none
    4 0x10 not used none
    5 0x20 not used none
    6 0x40 not used none
    7 0x80 not used none

      Note :
    • Advance filtering available in the MCU's internal Ethernet module such as Pattern Match, Magic Packet and Hash Table can not be disabled by this routine.
    • This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the MCU's internal Ethernet module.
    • The MCU's internal Ethernet module should be properly cofigured by the means of Ethernet_Intern_Init routine.
    • This routine is valid only for Stellaris devices.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
Ethernet_Intern_Disable(_Ethernet_Intern_CRC or _Ethernet_Intern_MULTICAST); // disable CRC checking and Multicast traffic

Ethernet_Intern_confFilter

Prototype

procedure Ethernet_Intern_confFilter(cfg : dword)

Returns

Nothing.

Description

This routine enables/disables appropriate network traffic on the MCU's internal Ethernet module by the means of it's receive filters (unicast, multicast, broadcast, crc).
Specific type of network traffic will be enabled if a corresponding bit of this routine's input parameter is set.

Parameters:

  • cfg: network traffic/receive filter flags. Each bit corresponds to the appropriate network traffic/receive filter:
    • _ETHERNET_FILTER_RECEIVE_ALL_EN: All received frames are passed.
    • _ETHERNET_FILTER_RECEIVE_ALL_DIS: Only filtered frames are passed. Filters are constructed by OR-ing filter constants below.
    • _ETHERNET_FILTER_MULTICAST_RECEIVE_ALL: All received frames with a multicast destination address (first bit in the destination address field is '1') are passed.
    • _ETHERNET_FILTER_MULTICAST_FILTER_PERFECT: MAC performs a perfect destination address filtering for multicast frames, that is, it compares the DA field with the values programmed in DA registers.
    • _ETHERNET_FILTER_MULTICAST_FILTER_HASH_TABLE: only frames that match the Hash filter are passed.
    • _ETHERNET_FILTER_MULTICAST_FILTER_PERFECT_HASH_TABLE: the address filter passes frames that match either the perfect filtering or the hash filtering
    • _ETHERNET_FILTER_UNICAST_HASH_TABLE: MAC performs destination address filtering of unicast frames according to the hash table.
    • _ETHERNET_FILTER_MULTICAST_FILTER_PERFECT_HASH_TABLE: the address filter passes frames that match either the perfect filtering or the hash filtering
      Note :
    • Advanced filtering available in the MCU's internal Ethernet module such as Pattern Match, Magic Packet and Hash Table can not be enabled by this routine.
      Additionaly, all filters, except CRC, enabled with this routine will work in OR mode, which means that packet will be received if any of the enabled filters accepts it.
    • This routine will change receive filter configuration on-the-fly. It will not, in any way, mess with enabling/disabling receive/transmit logic or any other part of the MCU's internal Ethernet module.
      The MCU's internal Ethernet module should be properly cofigured by the means of Ethernet_Intern_Init routine.
    • This routine is valid only for ST devices.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
Ethernet_Intern_confFilter(_ETHERNET_FILTER_RECEIVE_ALL_EN or _ETHERNET_FILTER_MULTICAST_RECEIVE_ALL); // enable CRC checking and Multicast traffic

Ethernet_Intern_doPacket

Prototype

function Ethernet_Intern_doPacket() : byte;

Returns

  • 0 - upon successful packet processing (zero packets received or received packet processed successfully).
  • 1 - upon reception error or receive buffer corruption. Ethernet controller needs to be restarted.
  • 2 - received packet was not sent to us (not our IP, nor IP broadcast address).
  • 3 - received IP packet was not IPv4.
  • 4 - received packet was of type unknown to the library.

Description

This is MAC module routine. It processes next received packet if such exists. Packets are processed in the following manner:

  Note : Ethernet_Intern_doPacket must be called as often as possible in user's code.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
while true do
  begin
    ...
    Ethernet_Intern_doPacket(); // process received packets
    ...
  end;

Ethernet_Intern_writePayloadByte

Prototype

procedure Ethernet_Intern_writePayloadByte(dat : byte; offset : word);

Returns

Nothing.

Description

It writes one byte in the TCP payload.

Parameters:

  • dat: data to store.
  • offset: offset from the beginning of the TCP payload. Considering that the size of the Ethernet buffer is 1480 bytes including the TCP header (which occupies 20 bytes without the option fields),
    the maximal value for the offset parameter is 1460.

This routine is called either from the Ethernet_Intern_UserTCP or Ethernet_Intern_UserUDP.

This routine is valid only for Stellaris devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var data_ : byte;
...
Ethernet_Intern_writePayloadByte(data_,0); // put a byte at the beginning of the TCP payload

Ethernet_Intern_writePayloadBytes

Prototype

procedure Ethernet_Intern_writePayloadBytes(dat : ^byte; offset : word; numOfBytes : word);

Returns

Nothing.

Description

It writes a requested number of bytes into TCP payload.

Parameters:

  • dat: RAM buffer containing bytes to be written into the TCP payload.
  • offset: offset from the beginning of the TCP payload. Considering that the size of the Ethernet buffer is 1480 bytes including the TCP header (which occupies 20 bytes without the option fields),
    the maximal value for the offset parameter is 1460.
  • n: number of bytes to be written.

This routine is called either from the Ethernet_Intern_UserTCP or Ethernet_Intern_UserUDP.

This routine is valid only for Stellaris devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var buffer : array[17] of byte;	 
  ...
buffer := 'mikroElektronika';	 
Ethernet_Intern_writePayloadBytes(@buffer, 0, 16); // put an RAM array into TCP payload

Ethernet_Intern_writePayloadString

Prototype

function Ethernet_Intern_writePayloadString(dat : ^byte; offset : word) : word;

Returns

Number of bytes written into the TCP payload.

Description

This is MAC module routine. It stores whole string (excluding null termination) into RAM at current write location.

Parameters:

  • dat: RAM buffer containing string to be written into the TCP payload.
  • offset: offset from the beginning of the TCP payload. Considering that the size of the Ethernet buffer is 1480 bytes including the TCP header (which occupies 20 bytes without the option fields),
    the maximal value for the offset parameter is 1460.

This routine is called either from the Ethernet_Intern_UserTCP or Ethernet_Intern_UserUDP.

This routine is valid only for Stellaris devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var buffer : array[17] of byte;	 
  ...
buffer := 'mikroElektronika';	 
Ethernet_Intern_writePayloadBytes(@buffer, 0); // put an RAM array into TCP payload

Ethernet_Intern_readPayloadByte

Prototype

function Ethernet_Intern_readPayloadByte(offset : word) : byte;

Returns

Byte read from TCP payload.

Description

It fetches a byte from the TCP payload, from the position detemined by the offset parameter.

Parameters:

  • offset: offset from the beginning of the TCP payload. Considering that the size of the Ethernet buffer is 1480 bytes including the TCP header (which occupies 20 bytes without the option fields),
    the maximal value for the offset parameter is 1460.

This routine is called either from the Ethernet_Intern_UserTCP or Ethernet_Intern_UserUDP.

This routine is valid only for Stellaris devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var buffer : byte; 
  ...
buffer := Ethernet_Intern_readPayloadByte(0); // read a byte from TCP payload

Ethernet_Intern_readPayloadBytes

Prototype

procedure Ethernet_Intern_readPayloadBytes(dat : ^byte; offset : word; numOfBytes : word);

Returns

Nothing.

Description

It fetches requested number of bytes from the TCP payload.

Parameters:

  • dat: buffer for storing bytes read from the TCP payload.
  • offset: offset from the beginning of the TCP payload. Considering that the size of the Ethernet buffer is 1480 bytes including the TCP header (which occupies 20 bytes without the option fields),
    the maximal value for the offset parameter is 1460.
  • numOfBytes: number of bytes to be read.

This routine is called either from the Ethernet_Intern_UserTCP or Ethernet_Intern_UserUDP.

This routine is valid only for Stellaris devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var buffer : array[17] of byte;	 
...
Ethernet_Intern_readPayloadBytes(@buffer, 0, 16); // read an array from TCP payload

Ethernet_Intern_putByte

Prototype

procedure Ethernet_Intern_putByte(v : byte);

Returns

Nothing.

Description

This is MAC module routine. It stores one byte to address pointed by the current Ethernet controller's write pointer.

Parameters:

  • v: value to store.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  data : byte;
  ...
  Ethernet_Intern_putByte(data);  // put an byte into ethernet buffer

Ethernet_Intern_putBytes

Prototype

procedure Ethernet_Intern_putBytes(ptr : ^byte; n : word);

Returns

Nothing.

Description

This is MAC module routine. It stores requested number of bytes into Ethernet controller's RAM starting from current Ethernet controller's write pointer location.

Parameters:

  • ptr: RAM buffer containing bytes to be written into Ethernet controller's RAM.
  • n: number of bytes to be written.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  buffer : array[17] of byte;	 
  ...
  buffer := 'mikroElektronika';	 
  ...
  Ethernet_Intern_putBytes(buffer, 16); // put an RAM array into ethernet buffer

Ethernet_Intern_putConstBytes

Prototype

procedure Ethernet_Intern_putConstBytes(const ptr : ^byte; n : word);

Returns

Nothing.

Description

This is MAC module routine. It stores requested number of const bytes into Ethernet controller's RAM starting from current Ethernet controller's write pointer location.

Parameters:

  • ptr: const buffer containing bytes to be written into Ethernet controller's RAM.
  • n: number of bytes to be written.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
const 
  buffer : array[17] of byte;	 
  ...
  buffer := 'mikroElektronika';	 
  ...
  Ethernet_Intern_putConstBytes(buffer, 16); // put a const array into ethernet buffer

Ethernet_Intern_putString

Prototype

function Ethernet_Intern_putString(ptr : ^byte) : word;

Returns

Number of bytes written into Ethernet controller's RAM.

Description

This is MAC module routine. It stores whole string (excluding null termination) into Ethernet controller's RAM starting from current Ethernet controller's write pointer location.

Parameters:

  • ptr: string to be written into Ethernet controller's RAM.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  buffer : string[16];	 
  ...
  buffer := 'mikroElektronika';	 
  ...
  Ethernet_Intern_putString(buffer); // put a RAM string into ethernet buffer

Ethernet_Intern_putConstString

Prototype

function Ethernet_Intern_putConstString(const ptr : ^byte) : word;

Returns

Number of bytes written into Ethernet controller's RAM.

Description

This is MAC module routine. It stores whole const string (excluding null termination) into Ethernet controller's RAM starting from current Ethernet controller's write pointer location.

Parameters:

  • ptr: const string to be written into Ethernet controller's RAM.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
const 
  buffer : string[16];	 
  ...
  buffer := 'mikroElektronika';	 
  ...
  Ethernet_Intern_putConstString(buffer); // put a const string into ethernet buffer

Ethernet_Intern_getByte

Prototype

function Ethernet_Intern_getByte() : byte;

Returns

Byte read from Ethernet controller's RAM.

Description

This is MAC module routine. It fetches a byte from address pointed to by current Ethernet controller's read pointer.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  buffer : byte; 
  ...
  buffer := Ethernet_Intern_getByte(); // read a byte from ethernet buffer

Ethernet_Intern_getBytes

Prototype

procedure Ethernet_Intern_getBytes(ptr : ^byte; addr : word; n : word);

Returns

Nothing.

Description

This is MAC module routine. It fetches equested number of bytes from Ethernet controller's RAM starting from given address. If value of 0xFFFF is passed as the address parameter, the reading will start from current Ethernet controller's read pointer location.

Parameters:

  • ptr: buffer for storing bytes read from Ethernet controller's RAM.
  • addr: Ethernet controller's RAM start address. Valid values: 0..8192.
  • n: number of bytes to be read.

This routine is valid for ST and Kinetis devices.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  buffer: array[16] of byte;	 
  ...
  Ethernet_Intern_getBytes(buffer, 0x100, 16); // read 16 bytes, starting from address 0x100

Ethernet_Intern_UserTCP

Prototype

function Ethernet_Intern_UserTCP(var remoteHost : array[4] of byte; remotePort, localPort, reqLength : word; var flags: TEthInternPktFlags) : word;

Returns

  • 0 - there should not be a reply to the request.
  • Length of TCP/HTTP reply data field - otherwise.

Description

This is TCP module routine. It is internally called by the library. The user accesses to the TCP/HTTP request by using some of the Ethernet_Intern_get routines. The user puts data in the transmit buffer by using some of the Ethernet_Intern_put routines. The function must return the length in bytes of the TCP/HTTP reply, or 0 if there is nothing to transmit. If there is no need to reply to the TCP/HTTP requests, just define this function with return(0) as a single statement.

Parameters:

  • remoteHost: client's IP address.
  • remotePort: client's TCP port.
  • localPort: port to which the request is sent.
  • reqLength: TCP/HTTP request data field length.
  • flags: record consisted of two fields :
    type TEthInternPktFlags = record
      canCloseTCP: boolean;  // flag which closes socket
      isBroadcast: boolean;  // flag which denotes that the IP package has been received via subnet broadcast address
    end;
    
  Note : The function source code is provided with appropriate example projects. The code should be adjusted by the user to achieve desired reply.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example

This function is internally called by the library and should not be called by the user's code.

Ethernet_Intern_UserUDP

Prototype

function Ethernet_Intern_UserUDP(var remoteHost : array[4] of byte; remotePort, destPort, reqLength : word; var flags: TEthInternPktFlags) : word;

Returns

  • 0 - there should not be a reply to the request.
  • Length of UDP reply data field - otherwise.

Description

This is UDP module routine. It is internally called by the library. The user accesses to the UDP request by using some of the Ethernet_Intern_get routines. The user puts data in the transmit buffer by using some of the Ethernet_Intern_put routines. The function must return the length in bytes of the UDP reply, or 0 if nothing to transmit. If you don't need to reply to the UDP requests, just define this function with a return(0) as single statement.

Parameters:

  • remoteHost: client's IP address.
  • remotePort: client's port.
  • destPort: port to which the request is sent.
  • flags: record consisted of two fields :
    type TEthInternPktFlags = record
      canCloseTCP: boolean;  // flag which closes socket (not relevant to UDP)
      isBroadcast: boolean;  // flag which denotes that the IP package has been received via subnet broadcast address
    end;
    
      Note : The function source code is provided with appropriate example projects. The code should be adjusted by the user to achieve desired reply.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example

This function is internally called by the library and should not be called by the user's code.

Ethernet_Intern_getIpAddress

Prototype

function Ethernet_Intern_getIpAddress() : ^byte;

Returns Pointer to the global variable holding IP address.
Description

This routine should be used when DHCP server is present on the network to fetch assigned IP address.

  Note : User should always copy the IP address from the RAM location returned by this routine into it's own IP address buffer. These locations should not be altered by the user in any case!
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  ipAddr : array[4] of byte;  // user IP address buffer
  ...	
  memcpy(ipAddr, Ethernet_Intern_getIpAddress(), 4); // fetch IP address

Ethernet_Intern_getGwIpAddress

Prototype

function Ethernet_Intern_getGwIpAddress() : ^byte;

Returns Pointer to the global variable holding gateway IP address.
Description

This routine should be used when DHCP server is present on the network to fetch assigned gateway IP address.

  Note : User should always copy the IP address from the RAM location returned by this routine into it's own gateway IP address buffer. These locations should not be altered by the user in any case!
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  gwIpAddr : array[4] of byte;  // user gateway IP address buffer
  ...	
  memcpy(gwIpAddr, Ethernet_Intern_getGwIpAddress(), 4); // fetch gateway IP address 

Ethernet_Intern_getDnsIpAddress

Prototype

function Ethernet_Intern_getDnsIpAddress() : ^byte;

Returns Pointer to the global variable holding DNS IP address.
Description

This routine should be used when DHCP server is present on the network to fetch assigned DNS IP address.

  Note : User should always copy the IP address from the RAM location returned by this routine into it's own DNS IP address buffer. These locations should not be altered by the user in any case!
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
 var dnsIpAddr : 
        array[4] of byte;  // user DNS IP address buffer ...	
        memcpy(dnsIpAddr, Ethernet_Intern_getDnsIpAddress(), 4); // fetch DNS 
        server address  

Ethernet_Intern_getIpMask

Prototype

function Ethernet_Intern_getIpMask() : ^byte;

Returns Pointer to the global variable holding IP subnet mask.
Description

This routine should be used when DHCP server is present on the network to fetch assigned IP subnet mask.

  Note : User should always copy the IP address from the RAM location returned by this routine into it's own IP subnet mask buffer. These locations should not be altered by the user in any case!
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  IpMask : array[4] of byte;  // user IP subnet mask buffer
  ...	
  memcpy(IpMask, Ethernet_Intern_getIpMask(), 4); // fetch IP subnet mask

Ethernet_Intern_confNetwork

Prototype

procedure Ethernet_Intern_confNetwork(var ipMask, gwIpAddr, dnsIpAddr : array[4] of byte);

Returns Nothing.
Description

Configures network parameters (IP subnet mask, gateway IP address, DNS IP address) when DHCP is not used.

Parameters:

  • ipMask: IP subnet mask.
  • gwIpAddr gateway IP address.
  • dnsIpAddr: DNS IP address.
  Note : The above mentioned network parameters should be set by this routine only if DHCP module is not used. Otherwise DHCP will override these settings.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  ipMask    : array[4] of byte;  // network mask (for example : 255.255.255.0)
  gwIpAddr  : array[4] of byte;  // gateway (router) IP address
  dnsIpAddr : array[4] of byte;  // DNS server IP address
  ...	
  gwIpAddr[0]  := 192;
  gwIpAddr[1]  := 168;
  gwIpAddr[2]  := 20;
  gwIpAddr[3]  := 6;

  dnsIpAddr[0] := 192;
  dnsIpAddr[1] := 168;
  dnsIpAddr[2] := 20;
  dnsIpAddr[3] := 100;

  ipMask[0]    := 255;
  ipMask[1]    := 255;
  ipMask[2]    := 255;
  ipMask[3]    := 0;
  ...
  Ethernet_Intern_confNetwork(ipMask, gwIpAddr, dnsIpAddr); // set network configuration parameters

Ethernet_Intern_arpResolve

Prototype

function Ethernet_Intern_arpResolve(var ip : array[4] of byte; tmax : byte) : ^byte;

Returns

If successful, returns MAC address, NULL otherwise.

Description

This is ARP module routine. It sends an ARP request for given IP address and waits for ARP reply. If the requested IP address was resolved, an ARP cash entry is used for storing the configuration. ARP cash can store up to 3 entries. For ARP cash structure refer to "__Ethernet_Intern_Private.mpas" file in the compiler's Uses folder.

Parameters:

  • ip: IP address to be resolved.
  • tmax: time in seconds to wait for an reply.
  Note : The Ethernet services are not stopped while this routine waits for ARP reply. The incoming packets will be processed normaly during this time.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  IpAddr : array[4] of byte;  // IP address
  ...	
  IpAddr[0] := 192;
  IpAddr[0] := 168;
  IpAddr[0] := 1;
  IpAddr[0] := 1;
  ...
  Ethernet_Intern_arpResolve(IpAddr, 5); // get MAC address behind the above IP address, wait 5 secs for the response

Ethernet_Intern_sendUDP

Prototype

function Ethernet_Intern_sendUDP(var destIP : array[4] of byte; sourcePort, destPort : word; pkt : ^byte; pktLen : word) : byte;

Returns
  • 1 - UDP packet was sent successfully.
  • 0 - otherwise.
Description

This is UDP module routine. It sends an UDP packet on the network.

Parameters:

  • destIP: remote host IP address.
  • sourcePort: local UDP source port number.
  • destPort: destination UDP port number.
  • pkt: packet to transmit.
  • pktLen: length in bytes of packet to transmit.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  IpAddr : array[4] of byte;  // remote IP address
  ...	
  IpAddr[0] := 192;
  IpAddr[0] := 168;
  IpAddr[0] := 1;
  IpAddr[0] := 1;
  ...
  Ethernet_Intern_sendUDP(IpAddr, 10001, 10001, 'Hello', 5); // send Hello message to the above IP address, from UDP port 10001 to UDP port 10001 

Ethernet_Intern_dnsResolve

Prototype

function Ethernet_Intern_dnsResolve(var host : string; tmax : byte) : ^byte;

Returns
  • pointer to the location holding the IP address - the requested host name was resolved.
  • 0 - otherwise.
Description

This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply. If the requested host name was resolved, it's IP address is stored in library global variable and a pointer containing this address is returned by the routine. UDP port 53 is used as DNS port.

Parameters:

  • host: host name to be resolved.
  • tmax: time in seconds to wait for an reply.

The above mentioned network parameters should be set by this routine only if DHCP module is not used. Otherwise DHCP will override these settings.

  Note :
  • The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will be processed normaly during this time.
  • User should always copy the IP address from the RAM location returned by this routine into it's own resolved host IP address buffer. These locations should not be altered by the user in any case!
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
var 
  remoteHostIpAddr : array[4] of byte;	// user host IP address buffer
  ...
  // SNTP server:
  // Zurich, Switzerland: Integrated Systems Lab, Swiss Fed. Inst. of Technology
  // 129.132.2.21: swisstime.ethz.ch
  // Service Area: Switzerland and Europe	
  memcpy(remoteHostIpAddr, Ethernet_Intern_dnsResolve('swisstime.ethz.ch', 5), 4);

Ethernet_Intern_initDHCP

Prototype

function Ethernet_Intern_initDHCP(tmax : byte) : byte;

Returns
  • 1 - network parameters were obtained successfully.
  • 0 - otherwise.
Description

This is DHCP module routine. It sends an DHCP request for network parameters (IP, gateway, DNS addresses and IP subnet mask) and waits for DHCP reply. If the requested parameters were obtained successfully, their values are stored into the library global variables.

These parameters can be fetched by using appropriate library IP get routines:

UDP port 68 is used as DHCP client port and UDP port 67 is used as DHCP server port.

Parameters:

  • tmax: time in seconds to wait for an reply.
  Note :
  • The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will be processed normaly during this time.
  • When DHCP module is used, global library variable Ethernet_Intern_userTimerSec is used to keep track of time. It is user responsibility to increment this variable each second in it's code.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
  ...	
  Ethernet_Intern_initDHCP(5); // get network configuration from DHCP server, wait 5 sec for the response 
  ...

Ethernet_Intern_doDHCPLeaseTime

Prototype

function Ethernet_Intern_doDHCPLeaseTime() : byte;

Returns
  • 0 - lease time has not expired yet.
  • 1 - lease time has expired, it's time to renew it.
Description

This is DHCP module routine. It takes care of IP address lease time by decrementing the global lease time library counter. When this time expires, it's time to contact DHCP server and renew the lease.

Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
while true do
  if(Ethernet_Intern_doDHCPLeaseTime() <> 0) then
   ...// it's time to renew the IP address lease

Ethernet_Intern_renewDHCP

Prototype

function Ethernet_Intern_renewDHCP(tmax : byte) : byte;

Returns
  • 1 - upon success (lease time was renewed).
  • 0 - otherwise (renewal request timed out).
Description

This is DHCP module routine. It sends IP address lease time renewal request to DHCP server.

Parameters:

  • tmax: time in seconds to wait for an reply.
Requires

Ethernet module has to be initialized. See Ethernet_Intern_Init.

Example
while true do
  begin 
    ...
    if(Ethernet_Intern_doDHCPLeaseTime() <> 0) then
      begin
        Ethernet_Intern_renewDHCP(5); <i> // it's time to renew the IP address lease, with 5 secs for a reply</i>
      end;  
    ...  
  end;