weAut_01 / weAutSys    R 2.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Defines | Variables
uIP device driver functions
+ + uIP -- Adam Dunkels' TCP/IP stack + +

Overview

These functions are used by a network device driver for interacting with uIP.

Defines

#define uip_conn_active(conn)
 Check if a connection identified by its number is active.
#define uip_input()
 Process an incoming packet.
#define uip_periodic(conn)
 Periodic processing for a connection identified by its number.
#define uip_periodic_conn(conn)
 Perform periodic processing for a connection identified by pointer.
#define uip_poll_conn(conn)
 Request that a particular connection should be polled.

Variables

uint8_t uip_buf []
 The uIP packet buffer.
char * uip_buf_alias
 alias to uip_buf

Define Documentation

#define uip_input ( )

Process an incoming packet.

This function should be called when the device driver has received a packet from the network. The packet from the device driver must be present in the uip_buf buffer, and the length of the packet should be placed in the uip_len variable.

When the function returns, there may be an outbound packet placed in the uip_buf packet buffer. If so, the uip_len variable is set to the length of the packet. If no packet is to be sent out, the uip_len variable is set to 0.

The usual way of calling the function is presented by the source code below.

  uip_len = devicedriver_poll();
  if(uip_len > 0) {
    uip_input();
    if(uip_len > 0) {
      devicedriver_send();
    }
  }
Note:
If you are writing a uIP device driver that needs ARP (Address Resolution Protocol), e.g., when running uIP over Ethernet, you will need to call the uIP ARP code before calling this function:
  #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
  uip_len = ethernet_devicedrver_poll();
  if(uip_len > 0) {
    if(BUF->type == HTONS(UIP_ETHTYPE_IP)) {
      uip_arp_ipin();
      uip_input();
      if(uip_len > 0) {
        uip_arp_out();
   ethernet_devicedriver_send();
      }
    } else if(BUF->type == HTONS(UIP_ETHTYPE_ARP)) {
      uip_arp_arpin();
      if(uip_len > 0) {
   ethernet_devicedriver_send();
      }
    }
#define uip_periodic (   conn)

Periodic processing for a connection identified by its number.

This function does the necessary periodic processing (timers, polling) for a uIP TCP connection, and should be called when the periodic uIP timer goes off. It should be called for every connection, regardless of whether they are open or closed.

When the function returns, it may have an outbound packet waiting for service in the uIP packet buffer, and if so the uip_len variable is set to a value larger than zero. The device driver should hence be called to send out the packet.

The usual way of calling the function is through a for() loop like this:

  for(i = 0; i < UIP_CONNS; ++i) {
    uip_periodic(i);
    if(uip_len > 0) {
      devicedriver_send();
    }
  }
Note:
If you are writing a uIP device driver that needs ARP (Address Resolution Protocol), e.g., when running uIP over Ethernet, you will need to call the uip_arp_out() function before calling the device driver:
  for(i = 0; i < UIP_CONNS; ++i) {
    uip_periodic(i);
    if(uip_len > 0) {
      uip_arp_out();
      ethernet_devicedriver_send();
    }
  }
Parameters:
connnumber of the connection which is to be periodically polled
See also:
uip_conn_active
#define uip_periodic_conn (   conn)

Perform periodic processing for a connection identified by pointer.

Same as uip_periodic() but takes a pointer to the actual uip_conn struct instead of its number. This function can be used to force periodic processing of a specific connection.

  See also:   uip_periodic

Parameters:
connA pointer to the uip_conn struct of the connection
#define uip_poll_conn (   conn)

Request that a particular connection should be polled.

Similar to uip_periodic_conn() but does not perform any timer processing. The application is polled for new data.

Parameters:
connA pointer to the uip_conn struct for the connection to be processed.

Variable Documentation

uint8_t uip_buf[]

The uIP packet buffer.

The uip_buf array is used to hold incoming and outgoing packets. The device driver should place incoming data into this buffer. When sending data, the device driver should read the link level headers and the TCP/IP headers from this buffer. The size of the link level headers is configured by the UIP_LLH_LEN define.

Note:
The application data need not be placed in this buffer, so the device driver must read it from the place pointed to by the uip_appdata pointer as illustrated by the following example:
 void
 devicedriver_send(void)
 {
    hwsend(&uip_buf[0], UIP_LLH_LEN);
    if(uip_len <= UIP_LLH_LEN + UIP_TCPIP_HLEN) {
      hwsend(&uip_buf[UIP_LLH_LEN], uip_len - UIP_LLH_LEN);
    } else {
      hwsend(&uip_buf[UIP_LLH_LEN], UIP_TCPIP_HLEN);
      hwsend(uip_appdata, uip_len - UIP_TCPIP_HLEN - UIP_LLH_LEN);
    }
 }