Light-Weight IP (LwIP)
Support Across The Board ™
LwIP Module Outline
• A brief primer on TCP/IP and the BF536/7 EMAC
• What is LwIP?
• How to use LwIP in VisualDSP++ and VDK configuration
• How to trace and improve performance
• Summary
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
A Brief Primer on the OSI, TCP/IP
and BF537 EMAC
Application
Web Server, Ogg Vorbis,
Contiki, Theora etc.
HTTP, FTP, Telnet etc.
Layers 3, 4, 5 and 6
(Network, Transport,
Session & Presentation)
Protocol
TCP/IP Stack
lwIP, 3rd Party
Layer 2
EMAC Device Driver
Layer 7
(Application)
(Data Link)
EMAC core is provided
BF536/7 EMAC
Layer 1
(Physical)
Copyright © Avnet, Inc., Analog Devices, Inc.
PHY Transceiver
All rights reserved.
SMSC LAN83C185,
Realtek RTL8201, etc.
CONFIDENTIAL
Data Encapsulation
TCP/IP Stack Header Structure
DATA
application layer
Application runs
on top of the
TCP/IP Stack
--------------------------------------------------------------------------------------------------------------------
respectively
TCP-Header
DATA
UDP-Header
DATA
transport layer
-------------------------------------------------------------------------------------------------------------------IP Header
TCP/UDP-Header
DATA
network layer
-------------------------------------------------------------------------------------------------------------------MAC Header
IP Header
TCP/UDP-Header
DATA
TCP/IP Stack
supports the transport
and network layer
Trailer
data link layer
ADSP-BF536/7
Ethernet MAC
peripheral supports the
data link layer
header structure
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Layer 1 - Physical
• Consists of the physical and electrical interface to the
network: PHY Transceiver, 10BASE-T connector,
100BASE-TX, switches, and routers
• PHY transceiver performs electrical signal conditioning for
transmission over the medium: RJ45 cable
• 4-wire MII and 2-wire RMII Management Interface allows
layer 2 devices such as the BF536/7 EMAC to monitor
and control PHY operation.
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Blackfin Ethernet System Overview
ETxCLK
ETxD[3:0]
ETxEN
MDI
COL
TPO+
TPOTPI+
TPI-
Magnetics
RJ45
CRS
MII
ERxCLK
ERxD[3:0]
ERxDV
ERxER
25MHz
MDIO
MDC
YINT
ADSP-BF537
Copyright © Avnet, Inc., Analog Devices, Inc.
PHY
All rights reserved.
CONFIDENTIAL
Layer 2 – Data Link
• Enables functional and procedural aspects of
network data transfer as well as physical layer
error checking
• Two sub-layers on BF536/7 Blackfin processors
– EMAC peripheral is Media Access Control (MAC)
– EMAC device driver is Logical Link Control (LLC)
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Layer 2 – Data Link – EMAC Device Driver
• Configures / monitors the EMAC peripheral and
DMA engine to handle the flow of Ethernet
frames between memory buffers and the PHY
• Oversees the following core functions:
–Ethernet address and frame filtering
–Chained DMA transfers
–Interrupt management
–Collision detection
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Layers 3-6 – TCP/IP
• LwIP is included free with VisualDSP++
• LwIP – The ‘Light-weight IP’ stack is a multithreaded TCP/IP implementation using VDK
• Compliant with the system services model
• Built into VisualDSP++
• See www.sics.se/~adam/lwip/ for further information
• Additional implementations are available from 3rd
parties
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Layer 7 – Application
• Contains the session protocol, high-level
software application and user interface
• LwIP provides an API based on BSD sockets and
runs under VDK
• Example applications running on the ADSPBF537 EZ-KIT Lite:
–HTTP server
–HTTP client for streaming audio (Ogg Vorbis)
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
LwIP Stack - Overall Structure
• Consists of three major
components
– TCP/IP library itself
Application
– Interface library to the kernel
that is being used
LwIP TCP/IP Stack
– Driver library to connect the
stack to the Ethernet
controller
Kernel Interface
Library
VDK
Ethernet
Library
BF537 EMAC
• LwIP protocol suite runs under
VDK
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Folder Structure In VisualDSP++
TCP/IP STACK
Driver for ADSP-BF537
Documentation based on html
Examples for ADSP-BF537
Host programs and Source Code for the examples
Source Code of the TCP/IP Stack
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
LwIP Project Wizard
• Generates VDK-based
application which uses the
stack
• Can generate an application
for the BF537 EZ-Kit
• Provides code needed to
initialize and start the stack
operating
• If DHCP is being used, it will
also wait until the IP address
is obtained
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plug-In - General Tab
• Displays the name of the
associated configuration
file
• Allows you to specify the
protocols to be supported
by the build stack
• Eliminating a protocol will
reduce the size of the stack
• Controls the level of
statistical data that the
stack will accumulate
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plug-In - IP Tab
• IP Forward allows forwarding of IP
packets across network interfaces
• IP options allows for optional IP
payload data
• IP Fragmentation allows for
segmenting of packets.
• IP Reassembly enables re-assembling
of fragmented packets
• Support for multiple networks
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plug-In - Network Tab
• Optional Static IP support for
non-DHCP environment
• Configurable number of buffers
to match expected loading on
adapter
• Separate configurations for
multiple netowrks
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plug-In - TCP/UDP/ARP Tab
• Configurable number of UDP and
TCP connections
• Configurable number of open
socket connections
• Configurable maximum size of
TCP segment supported
• Configurable maximum TCP
receive window supported
• Configurable maximum number
of address resolution mapping
entries supported
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plugin - Debug Tab
• Specify the level of
debug checking and
reporting the stack
should provide
• Specify which events
the stack should
provide
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Configuration Plugin - Memory Tab
• Configurable pool sizes
– Each frame stored in a linked list
of pool buffers
– Setting pool buffer size too low
increases processor overheads
– Setting pool buffer size too high
increases memory overheads
• Configurable memory heap
size used by stack for non-pool
buffer memory requests
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
BSD Sockets Under LwIP
• Good introduction to sockets is Beej's Guide to Network
Programming
–http://www.ecst.csuchico.edu/~beej/guide/net/
• Core BSD Sockets functions
socket() - get socket descriptor
bind()
- associate socket with a port on the local machine
connect() - connect to a remote machine
listen()
- wait for someone to connect to the local machine
accept() - acknowledge remote connection attempt and
create a new descriptor
send()
- send data to remote machine
recv()
- receive data from remote machine
close()
- close opened socket
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Automatically Generated LwIP Application Template
• Default boot thread that initializes LwIP stack and underlying Ethernet MAC
and PHY drivers is in lwip_sysboot_threadtype.c (generated by the wizard)
void
lwip_sysboot_threadtype_RunFunction(void **inPtr)
{
.
.
.
// stack initialization
.
.
.
/**
* Add Application Code here
**/
}
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Example Application
• Retrieving data from an HTTP server is as easy as on a UNIX workstation
#define DEST_PORT 80
#define DEST_IP “192.168.0.2”
char in_buffer[100];
int socket_fd;
struct sockaddr_in dest_addr;
char http_request[] = "GET /index.html\r\n\r\n";
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(DEST_PORT);
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP);
socket_fd = socket(AF_INET, SOCK_STREAM, 0); // open a socket
connect(socket_fd, (struct sockaddr*)&dest_addr, sizeof(struct sockaddr);
send(socket_fd, http_request, sizeof(http_request), 0); // send a GET request
recv(socket_fd, (void *)(in_buffer), sizeof(in_buffer), 0); // get 100 bytes into
// in_buffer
close(fd);
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Tracing of TCP/IP Stack Activity
• Windows application provided
to capture and display tracing
information
• Configurable number of
events to be saved in a
circular buffer
• Events displayed in real time
unless display is paused
• Contents of trace buffer can
be saved to a file or all events
can be written to a file in real
time
• Tracing currently only shows
sent and received packets
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL
Support for File I/O Over TCP Connections
• Sample application showing how to redirect standard C/C++ I/O over TCP
connections
• Provides source for a STDIO device
driver to route I/O requests over TCP
connections
• Windows server application is also
provided to service requests
• Console output displayed in text box
• No user authentication supported
• File access can be restricted to part of
the host system
Copyright © Avnet, Inc., Analog Devices, Inc.
All rights reserved.
CONFIDENTIAL