Rapid Prototyping Solutions Add Ethernet to your Embedded Application Craig Honegger President, Embedded Access Inc. TM Freescale, the Freescale logo, AltiVec, C-5, CodeTest, CodeWarrior, ColdFire, C-Ware, mobileGT, PowerQUICC, StarCore, and Symphony are trademarks of Freescale Semiconductor, Inc., Reg. U.S. Pat. & Tm. Off. BeeKit, BeeStack, CoreNet, the Energy Efficient Solutions Logo, Flexis, MXC, Platform in a Package, Processor Expert, QorIQ, QUICC Engine, SmartMOS, TurboLink and VortiQa are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. Module Objectives ► The objective of this module is: • Introduce networking concepts • Provide an overview of MQX network capabilities • Implement a simple Web server Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 2 Module Agenda ► Introduction to RTCS RTCS Sockets Application protocols HTTP server ► Hands-on Exercise – Build Your Own Embedded Web Server ► Additional Resources Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 3 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 4 TCP/IP Protocols RPC XDR SSH* Telnet XML* SMTP* POP3* SNMP FTP Sockets ICMP TFTP SSL* BootP DHCP TCP UDP NAT** IP IP-E IPCP ARP Ethernet HTTP DNS SNTP RIP IGMP PAP CHAP CCP LCP PPP Serial Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. PPPoE** HDLC TM 5 UDP vs. TCP UDP (RFC 768) ► 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 timedependent data (voice) Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TCP (RFC 793) ► 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) TM 6 RTCS Overview Application Task Application Task HTTP Server FTP Server FTP Client Telnet SNMP Server Agent SNTP DHCP Client Server RTCS API Application Task TCP UDP ICMP IGMP IP IP-E ARP Serial ADC Telnet Client I2 C Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. Enet TCP/IP Task RTCS MQX TM 7 RTCS Initialization Sequence ► Create RTCS ► Initialize interface(s) ► Bind RTCS to interface ► Initialize RTCS applications RTCS Apps TCP/IP Task RTCS Enet MQX Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 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.) TCP/IP Task RTCS Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 9 Interface Initialization ► Initialize device driver ► Assign MAC address ► Assign IP address, subnet, gateway ► Bind interface to stack TCP/IP Task RTCS Enet MQX Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 10 Sample Code Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 11 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 12 Using sockets Unbound Bound to datagram (UDP) Bound to stream (TCP) socket() recvfrom() bind() listen() connect() accept() send() recv() sendto() select() getsockopt() Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. setsockopt() shutdown () TM 13 Establishing a TCP Connection - Server Socket() Ground Bind () Bound Listen() Connect() Accept() Connected Listening Send(), Recv() Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 14 Establishing a TCP Connection - Client Socket() Ground Bind () Bound Listen() Connect() Accept() Connected Listening Send(), Recv() Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 15 Sample Code Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 16 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 17 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 19 Application Layer Protocols Telnet Server FTP Server TFTP Server DHCP Server HTTP Server Telnet Client FTP Client TFTP Client DHCP Client DNS Resolver SNMP Agent SNTP Client RTCS API TCP/IP Task RTCS MQX Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 20 Application protocols Clients: Servers: ► Use arbitrary port number ► Use ► Active connection ► Passive connection ► Connect to one server ► Connect with many clients standard port number Telnet Client Telnet Client Telnet Client Telnet Server Telnet Client Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 22 HTTP Server 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. Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 24 Sample Code Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 25 Module Agenda ► Introduction to RTCS RTCS Sockets Application protocols HTTP Server ► Hands-on exercise – build your own embedded Web server ► Additional resources Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 26 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 27 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) Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 28 Lab 2: Simple Application Server ► Objectives: • Create a simple TCP server framework • Test with Telnet Client Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 29 Module Agenda ► Introduction to RTCS RTCS Sockets Application protocols HTTP Server ► Hands-on exercise – build your own embedded Web server ► Additional resources Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 30 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 32 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) Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 33 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 Freescale™ and the Freescale logo are trademarks of Freescale Semiconductor, Inc. All other product or service names are the property of their respective owners. © Freescale Semiconductor, Inc. 2010. TM 34 TM