weAut_01 / weAutSys    R 2.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Files | Data Structures | Defines | Typedefs | Functions | Variables
LAN / Ethernet communication
+ + System services (threading, time keeping, communication) + +

Overview

weAutSys provides Ethernet / LAN communication based on

These are the basic functions for all application (support) layers weAutSys supports. There upon application software may implement further protocols and networking applications.

Files

file  network.h
 

weAutSys' (low level) system calls, services and types for LAN / Ethernet communication


Data Structures

struct  ipConf_t
 The IP configuration. More...

Defines

#define BUF2EH
 The uip buffer cast to Ethernet header.
#define DHCP_MSK
 Mask for DHCP (use / set by) bit.
#define DNS1_MSK
 Mask for DNS server 1 set bit.
#define DNS2_MSK
 Mask for DNS server 2 set bit.
#define DNS_CLIENT_MSK
 Mask for be DNS client bit.
#define DNS_MSK
 Mask for DNS servers (set / use if set) bits.
#define ECHO_PORT   7
 The well known Echo port.
#define ENC_HWP
 Mask for the ENC HW problem bit in networkNotReady.
#define ENC_MSK
 Mask for the ENC bits in networkNotReady.
#define ENC_NRD
 Mask for the ENC not ready bit in networkNotReady.
#define ENC_PWS
 Mask for the ENC powersave bit in networkNotReady.
#define IP_ADD(addr0, addr1, addr2, addr3)
 Initializer of an IP (V4) address from four byte values.
#define IPBUF
 The uip buffer cast to Ethernet IP header.
#define LNC_IDN
 Mask for the link is down (at last status request) in networkNotReady.
#define LNC_WDN
 Mask for the link was down (before last status request) in networkNotReady.
#define MODBUS_PORT   502
 The well known Modbus port.
#define NTP1_MSK
 Mask for NTP server 1 set bit.
#define NTP2_MSK
 Mask for NTP server 2 set bit.
#define NTP_CLIENT_MSK
 Mask for be NTP client bit.
#define NTP_MSK
 Mask for NTP server bits.
#define NTP_SERVERT_MSK
 Mask for be NTP server bit.
#define STC_MSK
 Mask for the stack bits in networkNotReady.
#define STC_NST
 Mask for the stack' IP not set bit in networkNotReady.
#define TELNET_PORT   23
 The well known Telnet port.

Typedefs

typedef struct uip_eth_addr eth_addr_t
 Representation of a 48-bit Ethernet address / MAC address.

Functions

uint16_t deviceDriverPoll (void)
 Hand over received packages.
void deviceDriverSend (void)
 Send the actual uIP buffer.
struct uip_eth_addrgetMACforIPaddr (uip_ipaddr_t ipAddr)
 Get the MAC address for an IP address.
uint8_t linkState (void)
 Check the link state.
void networkPolling (void)
 Receive and then perhaps send the actual uIP buffer.
ptfnct_t outEncLanInfoThreadF (hierThr_data_t *threadD, FILE *toStream)
 Output Ethernet and driver (ENC28J60) state info, the thread function.
void setMACadd (eth_addr_t *mac)
 Set the IP stack's MAC address.
void setMACaddP (const eth_addr_t *mac)
 Set the stack's MAC address.
void udpAppcall (void)
 The uIP udp event function for the application software.
void uipAppcall (void)
 The uIP event function for the application software.
void uipGetAddresses (ipConf_t *ipConf)
 Get the addresses from the uIP stack.
void uipSetAddresses (ipConf_t *ipConf)
 Set the addresses in the uIP stack.

Variables

uint8_t arpTickPeriod
 The period of the ARP timeout tick in seconds.
uint8_t arpTimeOut
 The ARP timeout counter in seconds.
ipConf_t curIpConf
 The actual IP configuration.
uint8_t networkNotReady
 Network not ready.

Define Documentation

#define IP_ADD (   addr0,
  addr1,
  addr2,
  addr3 
)

Initializer of an IP (V4) address from four byte values.

This function constructs an {embraced} initialiser for an uip_ipaddr_t (array) type.

Example:

 uip_ipaddr_t defaultIPaddr = IPADD(192, 168, 89, 31);

will result in the correct array initialisation in network byte order (big endian).

Parameters:
addr0The first octet of the IP address
addr1The second octet
addr2The third octet
addr3The forth octet
Examples:
individEEP.c.
#define DHCP_MSK

Mask for DHCP (use / set by) bit.

See also:
ipConf_t
Examples:
individEEP.c, and main.c.
#define DNS1_MSK

Mask for DNS server 1 set bit.

See also:
ipConf_t
Examples:
individEEP.c, and main.c.
#define DNS2_MSK

Mask for DNS server 2 set bit.

See also:
ipConf_t
#define DNS_MSK

Mask for DNS servers (set / use if set) bits.

See also:
ipConf_t
#define DNS_CLIENT_MSK

Mask for be DNS client bit.

See also:
ipConf_t
#define NTP1_MSK

Mask for NTP server 1 set bit.

See also:
ipConf_t
#define NTP2_MSK

Mask for NTP server 2 set bit.

See also:
ipConf_t
#define NTP_MSK

Mask for NTP server bits.

See also:
ipConf_t
#define NTP_CLIENT_MSK

Mask for be NTP client bit.

See also:
ipConf_t
Examples:
main.c.
#define NTP_SERVERT_MSK

Mask for be NTP server bit.

See also:
ipConf_t
#define BUF2EH

The uip buffer cast to Ethernet header.

This macro provides the buffer uip_buf as type uip_eth_hdr .

#define IPBUF

The uip buffer cast to Ethernet IP header.

This macro provides the buffer uip_buf as type ethip_hdr .


Typedef Documentation

typedef struct uip_eth_addr eth_addr_t

Representation of a 48-bit Ethernet address / MAC address.

This is uIP's type uip_eth_addr defined in uip.h holding an array uint8_t addr[6] in the end.

addr[0] would be octet [1] of the MAC address defining
Bit 0 = 0: unicast / = 1: multi/broadcast address
Bit 1 = 0: manufacturer / =1: locally assigned address


Function Documentation

void setMACadd ( eth_addr_t mac)

Set the IP stack's MAC address.

This sets the the Ethernet stack's i.e. uIP's MAC address but not the driver's ( ENC28J60).

Of course, the driver's MAC setting has to be same. This is done by encSetMacAdd(), encInit() or networkInit().

See also:
uip_setethaddr
actMACadd
encSetMacAdd
Parameters:
macpointer to a structure (in RAM) holding the new MAC address
void setMACaddP ( const eth_addr_t mac)

Set the stack's MAC address.

This is the same as setMACadd except for the new MAC address structure held in program (flash) memory

Parameters:
macpointer to a structure (in flash) holding the new MAC address
void uipSetAddresses ( ipConf_t ipConf)

Set the addresses in the uIP stack.

This function takes the fields ipAddr, netMask, defaultRouter and dnsAddr and makes the appropriate settings in the uIP stack. The bit 4 ("stack's IP is not yet set") is cleared in networkNotReady.

ipConf's cFlags is irrelevant: the settings are made even if the flag says "use DHCP". Hence ipConf must not be null and it must have correct entries for ipAddr, netMask and defaultRouter.

See also:
uip_sethostaddr
uip_setnetmask
uip_setdraddr
resolv_conf
Parameters:
ipConfpointer to the source of the addresses and masks
void uipGetAddresses ( ipConf_t ipConf)

Get the addresses from the uIP stack.

This function fills the fields ipAddr, netMask, defaultRouter and dnsAddr from the respective settings in the uIP stack.

ipConf's cFlags is left unchanged.

See also:
uipSetAddresses
Parameters:
ipConfpointer to the destination of the addresses and masks
void deviceDriverSend ( void  )

Send the actual uIP buffer.

See function devicedriver_send respectively ethernetdevicedriver_send in uIP documentation.

This function does nothing if the NIC's transmit logic is not (yet) idle. In case of weAut_01 the NIC is an ENC28J60.

void networkPolling ( void  )

Receive and then perhaps send the actual uIP buffer.

This is standard control structure around calling uip_input as described in the uIP documentation in one function.

To have all this in one block by calling this function may be questionable. It will be put in (pieces in) appropriate threads. And as of this writing this function was not used yet.

uint16_t deviceDriverPoll ( void  )

Hand over received packages.

This function checks if the network driver IC (NIC), an ENC28J60 in case of weAut_01, has received a package. If so it is copied to uIP's uip_buf and the number of bytes is returned.

See function devicedriver_poll respectively ethernetdevicedrver_poll in uIP documentation.

Returns:
the length of the (new) package or 0 if there was none
ptfnct_t outEncLanInfoThreadF ( hierThr_data_t threadD,
FILE *  toStream 
)

Output Ethernet and driver (ENC28J60) state info, the thread function.

This thread will output some info on Ethernet and driver configuration and state to toStream (as standard output).

This thread function acts on threadD's secondary thread and secondary flag. flag2's bits signal which informations are to be output:
Bit 0 : MAC
Bit 1 : current IP setting
Bit 2 : default IP setting
Bit 3 : ARP
Bit 4 : Link state
Bit 5 : DHCP state

As secondary thread it will usually be started as the primary threads child.

Parameters:
threadDthe thread state data (pointer to; not NULL)
toStreamstreams to switch the standard streams to (if not MULL)
Returns:
PT_YIELDED if waiting for conditions that may become automatically true; PT_WAITING if blocked by conditions that other's action may set true; PT_EXITED if stopped by conditions that never will become true (sorry, not all work done and never will; PT_ENDED if ready with all work
uint8_t linkState ( void  )

Check the link state.

This function checks the actual link state and sets the relevant bits (LNC_IDN and LNC_WDN) in networkNotReady.

Returns:
0: link is down; 1: link is and was up since last call; 2: link is up, but was down since last call
struct uip_eth_addr* getMACforIPaddr ( uip_ipaddr_t  ipAddr) [read]

Get the MAC address for an IP address.

This function checks the ARP table for an entry about ipAddr and returns the (pointer to its) MAC address.

The caller must not manipulate the returned MAC.

Parameters:
ipAddrIP address the MAC is to be determined for
Returns:
pointer to MAC if determinable or NULL else
void udpAppcall ( void  )

The uIP udp event function for the application software.

The reason for being called will be in the uip_udp_conn structure, especially in the ports.

This function will be called for events, ports etc. not handled by system software (like NTP or DHCP e.g.).
If no extra protocols are implemented by user / application software the implementation should do nothing (but return; ).

Otherwise it is best to use (at least) the remote port to distribute to different protocol handling functions (best being protothreads). Client example:

void udpAppcall(void){

   if(uip_udp_conn->rport == HTONS(MTP_PORT)) {  // MTP protocol
     mtpAppcall(); // protothread function / state machine handling MTP
     return;
   }  // MTP protocol

   if(uip_udp_conn->rport == HTONS(THCPC_SERVER_PORT)) {  // THCP protocol
      thcpc_appcall(); // protothread function / state machine handling THCP
      return;
   } // THCP protocol (client)

   // add further protocols here

} //  udpAppcall()
See also:
udp_appcall
Examples:
main.c.
void uipAppcall ( void  )

The uIP event function for the application software.

The reason for being called will be in uip_flags.

This function will be called for events, ports etc. not handled by system software.
If no extra protocols are implemented by user / application software the implementation should do nothing (but return; ).

Otherwise it is best to use (at least) the local port to distribute to different protocol handlers. The handlers would best be implemented as protothread functions using appropriate appstate fields in the uip_conn as state.
The server example is simplified (i.e. stateless):

void uipAppcall(void){

   // for state use something
   // like : struct cliThr_data_t *s = (cliThr_data_t *)&(uip_conn->appstate);

   if(uip_conn->lport == HTONS(7)   // Echo protocol .. and
         && (uip_newdata() || uip_acked())) { // new (or ack'ed) data
      uip_send(uip_appdata, uip_datalen());
      return;
   } // echo server (new data only)

   // add further handling and protocols here

} // uipAppcall()
See also:
uip_appcall
Examples:
main.c.

Variable Documentation

The actual IP configuration.

See also:
defaultConfData defaultConfData.ipConf
Examples:
main.c.
uint8_t arpTickPeriod

The period of the ARP timeout tick in seconds.

The standard / default value is 10. User / application software might set a higher value to reduce ARP µController load.

See also:
UIP_ARP_MAXAGE
arpTimeOut
uint8_t arpTimeOut

The ARP timeout counter in seconds.

This counter is decremented every second. At 0 it is reset to arpTickPeriod and uip_arp_timer() is called. The latter uIP function handles the aging of ARP entries.

See also:
UIP_ARP_MAXAGE
arparpTickPeriod
uint8_t networkNotReady

Network not ready.

If this state flag 0x00 means the network is ready.
One of the lower four bits stands for a network state or problem that impedes communication.
The upper four bits do the same for the hardware driver, which in the case of weAut_01 it is an ENC28J60.

Bit 7 : ENC is not initialised yet / was reset (mask ENC_NRD)
Bit 6 : ENC has hardware (CLKRDY) trouble (mask ENC_HWP)
Bit 5 : ENC is in power save (PWRSV) mode (mask ENC_PWS)

Bit 3 : stack's IP is not yet set / determined (by DHCP e.g., mask STC_NST)
Bit 2 : link is down (status of last last request by e.g. linkState(), mask LNC_IDN)
Bit 1 : link was down (status before last last request by e.g. linkState(), mask LNC_WDN)