Rapid Prototyping Solutions Add Ethernet to your Embedded Application Craig Honegger President, Embedded Access Inc.
The objective of this module is: Module Objectives The objective of this module is: Introduce networking concepts Provide an overview of MQX network capabilities Implement a simple Web server
Hands-on Exercise – Build Your Own Embedded Web Server Module Agenda Introduction to RTCS RTCS Sockets Application protocols HTTP server Hands-on Exercise – Build Your Own Embedded Web Server Additional Resources
RTCS Designed for embedded processors Uses standard socket interface Scalable at compile and/or run-time Only used protocols are included Data requirements tunable Protocol behavior controllable TCP/IP aware Debugger Integration Integrated with 3rd party packages 4 4 4 4
TCP/IP Protocols RPC XDR Telnet HTTP FTP POP3* SMTP* DNS SNMP SNTP SSL* IP-E IPCP PAP CHAP CCP PPP ARP Ethernet Serial PPPoE** TFTP SSH* XML* BootP DHCP RIP Sockets ICMP TCP UDP IGMP NAT** IP HDLC LCP ->Picture that builds up protocols slowly Includes a number of Application Layer Protocols Telnet Server and Client FTP Server and Client TFTP Server and Client SNMP Agent Echo Server EDS Server (Winsock) SNTP Client DNS Resolver DHCP Server and Client Quote of the day service 5 5 5 5
UDP vs. TCP UDP (RFC 768) TCP (RFC 793) Data sent in packets Simple layer on top of IP Connectionless (mail) Unreliable No buffering Packets can be lost Small code size High maximum data rate Used to transfer time-dependent data (voice) Data sent in streams Complex protocol Connection based (phone) Reliable (re-transmission) Buffered data transfer No packets are lost Large code size Lower maximum data rate Used to transfer accuracy critical data (files) 6
RTCS Overview Application Task RTCS MQX Serial ADC I2C Enet TCP/IP RTCS API FTP Server ARP ICMP TCP UDP IGMP IP IP-E HTTP Telnet Client SNMP Agent DHCP SNTP RTCS core runs as a separate task under MQX A number of application protocols included with RTCS run as a separate task (eg DHCP, TFP, SNMP, etc) Chip / board specific ethernet controller driver is part of the MQX release. -> Picture of “MQX”, “Drivers” and “Tasks” showing RTCS as a task, how tasks communicate with RTCS, and how RTCS communicates to driver. 7 7 7 7
RTCS Initialization Sequence Create RTCS Initialize interface(s) Bind RTCS to interface Initialize RTCS applications RTCS RTCS Apps TCP/IP Task MQX Enet Switch to explorer and create new folder Switch to CW and create new MQX project 8 8 8 8
RTCS Initialization RTCS is started by calling RTCS_create() Prototype is in <rtcs.h> Creates one TCP/IP task Creates internal data structures (PCBs, IP routing table, etc.) RTCS TCP/IP Task Switch to explorer and create new folder Switch to CW and create new MQX project 9 9 9 9
Interface Initialization Initialize device driver Assign MAC address Assign IP address, subnet, gateway Bind interface to stack RTCS TCP/IP Task MQX Enet
Sample Code
Sockets Data transfer is done with sockets A socket is one end-point of a two-way communication link Socket defines: Protocol Local IP-address and port # Remote IP-address and port # TCP and UDP sockets supported 12
Using sockets recvfrom() sendto() bind() connect() getsockopt() listen() accept() recv() Unbound Bound to datagram (UDP) socket() send() select() setsockopt() shutdown () Bound to stream (TCP) 13
Establishing a TCP Connection - Server Socket() Ground Bind () Bound Connect() Listen() Accept() Connected Listening Send(), Recv() 14
Establishing a TCP Connection - Client Socket() Ground Bind () Bound Connect() Listen() Accept() Connected Listening Send(), Recv() 15
Sample Code
Socket Options Socket options can be set to override default socket behavior using setsockopt(): Options include: Window sizes Various timeouts Blocking vs. non-blocking mode Send and receive push flags
Compile Time Configuration Close to 100 compile time configuration settings Each protocol can be individually enabled/disabled Protocol statistics can be individually enabled/disabled Level of error checking performed is configurable 18 18 18 18
Run-Time Configuration Allows dynamic control of RTCS, including: RTCS task priority and stack size RTCS memory allocation (where, how much) Enabled protocols and protocol behavior Socket behavior 19 19 19 19
Application Layer Protocols RTCS MQX TCP/IP Task RTCS API FTP Server HTTP Telnet Client SNMP Agent DHCP SNTP TFTP Server TFTP Client DHCP Client DNS Resolver 20 20 20 20
Application protocols Clients: Use arbitrary port number Active connection Connect to one server Servers: Use standard port number Passive connection Connect with many clients Telnet Client Telnet Client Telnet Server Telnet Client Telnet Client 21
HTTP Server HTTP 1.1 with persistent connections PUT and GET methods Form decoding Support for multiple virtual WEB folders Static file-system content: pages, images, multimedia, Java archives Dynamic page content, suitable for AJAX applications CGI-like dynamic content pages ASP-like in-page placeholders Basic authentication 22
HTTP Server Web pages may be: From memory (flash or RAM) using TFS CGI Table HTTP Client HTTP Server CGI CGI Web pages may be: From memory (flash or RAM) using TFS From internal or external file system storage (e.g., MFS/USB) Dynamically created via CGI functions MQX I/O Subsystem TFS MFS Others USB CF SD Etc. 23 23 23 23
HTTP Server Initialization Install file-system Initialize HTTP server, specify root directory and home page Register CGI table and function callback table, if required Start server
Sample Code
Module Agenda Introduction to RTCS RTCS Sockets Application protocols HTTP Server Hands-on exercise – build your own embedded Web server Additional resources
Instructions Lab Handout provides: Directions on assembling Tower System and connecting cables Three separate labs: Web server Simple application server FTP & Telnet servers Each Lab is independent; Labs can be done in any order
Lab 1: Web Server Objectives: Add a Web server to your project Customize look of the Web server Add form input for controlling Tower System hardware (LEDs) Add CGI for obtaining Tower System inputs (switches)
Lab 2: Simple Application Server Objectives: Create a simple TCP server framework Test with Telnet Client
Hands-on exercise – build your own embedded Web server Module Agenda Introduction to RTCS RTCS Sockets Application protocols HTTP Server Hands-on exercise – build your own embedded Web server Additional resources
*MCF51CN demos only, ** MPC5125 demo only More Information Demos Telnet Server Web server SNTP* SMTP with sockets* DNS Resolution* DHCP Client* Digital Sign** Web HVAC *MCF51CN demos only, ** MPC5125 demo only 31
Freescale MQX™ Documentation MQXUG User Guide MQXRM Reference Manual MQXUSBHOSTAPIRM USB Host API Reference Manual MQXUSBDEVAPI USB Device API Reference MQXUSBHOSTUG USB Host User Guide MQXRTCSUG RTCS User Guide MQXMFSUG File System User Guide MQXIOUG I/O Drivers User Guide MQXFS Software Solutions Fact Sheets All of these files are in the docs directory in the MQX source code and on freescale.com/mqx
Further Reading and Training TWR-MCF51CN-KIT Lab Document MCF5225x – Lab Document MQX Release Notes MQX User’s Guide Writing First MQX Application (AN3905) Using MQX: RTCS, USB, and MFS (AN3907) How to Develop I/O Drivers for MQX (AN3902) All of these documents can be found at freescale.com/mqx and are a sampling of some that you might find the most useful in getting started with MQX
Further Reading and Training (Cont.) Videos: www.freescale.com/mqx MCF5225x and Freescale MQX introduction Getting started with MCF5225x and Freescale MQX Lab Demos And more…. vFTF technical session videos: www.freescale.com/vftf Introducing a modular system, Serial-to-Ethernet V1 ColdFire® MCU and Complimentary MQX™ RTOS Writing First MQX Application Implementing Ethernet Connectivity with the Complimentary Freescale MQX™ RTOS All of these documents can be found at freescale.com/mqx and are a sampling of some that you might find the most useful in getting started with MQX