Atmel ATSAM3X8E microcontroller Atmel AT86RF231 2.4GHz radio transceiver Atmel proprietary Lightweight Mesh software stack 10/100Mbps Ethernet



Similar documents
How To Use An Atmel Atmel Avr32848 Demo For Android (32Bit) With A Microcontroller (32B) And An Android Accessory (32D) On A Microcontroller (32Gb) On An Android Phone Or

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AT04389: Connecting SAMD20E to the AT86RF233 Transceiver. Atmel SAMD20. Description. Features

APPLICATION NOTE. Atmel AT02985: User s Guide for USB-CAN Demo on SAM4E-EK. Atmel AVR 32-bit Microcontroller. Features. Description.

USER GUIDE. ZigBit USB Stick User Guide. Introduction

Introducing a platform to facilitate reliable and highly productive embedded developments

Application Note. Atmel CryptoAuthentication Product Uses. Atmel ATSHA204. Abstract. Overview

APPLICATION NOTE Atmel AT02509: In House Unit with Bluetooth Low Energy Module Hardware User Guide 8-bit Atmel Microcontroller Features Description

Application Note. Atmel ATSHA204 Authentication Modes. Prerequisites. Overview. Introduction

APPLICATION NOTE. Atmel LF-RFID Kits Overview. Atmel LF-RFID Kit. LF-RFID Kit Introduction

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

AT91SAM ARM-based Flash MCU. Application Note

APPLICATION NOTE. AVR2130: Lightweight Mesh Developer Guide. Atmel MCU Wireless. Features. Description

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

APPLICATION NOTE. AT16268: JD Smart Cloud Based Smart Plug Getting. Started Guide ATSAMW25. Introduction. Features

USER GUIDE EDBG. Description

How To Design An Ism Band Antenna For 915Mhz/2.4Ghz Ism Bands On A Pbbb (Bcm) Board

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

APPLICATION NOTE. AT17284: Proximetry Cloud Based Smart Plug User Guide. SMART ARM-based Microcontrollers. Introduction. Features

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AT12181: ATWINC1500 Wi-Fi Network Controller - AP Provision Mode. Introduction. Features. Atmel SmartConnect APPLICATION NOTE

SMARTCARD XPRO. Preface. SMART ARM-based Microcontrollers USER GUIDE

Software Prerequisites Linux Ubuntu LTS. Estimated completion time: 15min. The goal of this hands-on is to:

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

APPLICATION NOTE. Atmel AT02607: Wireless Product Development Using Atmel Studio and ASF. Atmel MCU Wireless. Description.

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

APPLICATION NOTE. Atmel AT01095: Joystick Game Controller Reference Design. 8-/16-bit Atmel Microcontrollers. Features.

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

APPLICATION NOTE. Atmel AVR600: STK600 Expansion, Routing and Socket Boards. Atmel Microcontrollers. Introduction

AT88CK490 Evaluation Kit

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Section 1 Introduction to the AT91SAMD20 and the Development Environment

APPLICATION NOTE. Atmel AVR2033: SAM-ICE Adapter Hardware User Manual. 8-bit Atmel Microcontrollers. Features. Introduction

Atmel AT32UC3A3256 microcontroller 64MBit SDRAM Analog input (to ADC) Temperature sensor RC filter

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

MODFLEX MINI GATEWAY ETHERNET USER S GUIDE

PePWave Surf Series PePWave Surf Indoor Series: Surf 200, AP 200, AP 400

Atmel AVR ATxmega384C3 microcontroller OLED display with pixels resolution Analog sensors. Ambient light sensor Temperature sensor

Application Note. 1. Introduction. 2. Associated Documentation. 3. Gigabit Ethernet Implementation on SAMA5D3 Series. AT91SAM ARM-based Embedded MPU

AVR151: Setup and Use of the SPI. Introduction. Features. Atmel AVR 8-bit Microcontroller APPLICATION NOTE

APPLICATION NOTE. Atmel AT01180: Barcode and QR code scanner User Guide. Atmel 32-bit Microcontroller. Features. Introduction

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

APPLICATION NOTE. Atmel AT02845: Coexistence between ZigBee and Other 2.4GHz Products. Atmel MCU Wireless. Description. Features

Application Note: AN00121 Using XMOS TCP/IP Library for UDP-based Networking

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Atmel AVR4950: ASF - USB Host Stack. 8-bit Atmel Microcontrollers. Application Note. Features. 1 Introduction

User Manual. Page 2 of 38

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

UG103.8 APPLICATION DEVELOPMENT FUNDAMENTALS: TOOLS

APPLICATION NOTE. Atmel AT03188: Performance Test EVK with External FEM. Atmel MCU Wireless. Features. Description

User Manual. PePWave Surf / Surf AP Indoor Series: Surf 200, E200, AP 200, AP 400. PePWave Mesh Connector Indoor Series: MC 200, E200, 400

Virtual KNX/EIB devices in IP networks

CryptoAuth Xplained Pro

AN4108 Application note

AT09333: USB Host Interface (UHI) for Communication Class Device (CDC) Introduction. Atmel Microcontrollers APPLICATION NOTE

Mini Gateway Ethernet for ModFLEX Wireless Networks

Two mechanical buttons Two user LEDs Four expansion headers. Board controller with USB interface. One power LED and one status LED

Ethernet Interface Manual Thermal / Label Printer. Rev Metapace T-1. Metapace T-2 Metapace L-1 Metapace L-2

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AT89C5131A Starter Kit... Software User Guide

Interfacing an HTML Form to the ez80f91 MCU

APPLICATION NOTE. Atmel AT02971: Use of Ethernet on SAM4E-EK. Atmel 32-bit Microcontroller. Features. Introduction

Cisco TelePresence VCR MSE 8220

AN655 R ANGE TEST APPLICATION FOR EZRADIO AND EZRADIOPRO. 1. Introduction. 2. Supported Radio Types

lwip TCP/IP APIs lwip memory management lwip GMAC network interface driver lwip demo for IAR 6.5 Raw HTTP basic example Netconn HTTP stats example

Follow these steps to prepare the module and evaluation board for testing.

What is VLAN Routing?

Atmel AVR1017: XMEGA - USB Hardware Design Recommendations. 8-bit Atmel Microcontrollers. Application Note. Features.

Crow Limited Warranty. Print Version 017

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

Ethernet Radio Configuration Guide

DSA-1000 / PRT-1000 Device Server / Thermal Printer

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

QSG105 GETTING STARTED WITH SILICON LABS WIRELESS NETWORKING SOFTWARE

APPLICATION NOTE. AT05558: Wireless Manufacturing Test Kit. Atmel ATmega256RFR2. Description. Features

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

Quick Start Guide. MRB-KW01 Development Platform Radio Utility Application Demo MODULAR REFERENCE BOARD

Atmel AVR4029: Atmel Software Framework User Guide. Atmel Microcontrollers. Application Note. Features. 1 Introduction

NMS300 Network Management System

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Hands-on MESH Network Exercise Workbook

DME-N Network Driver Installation Guide for LS9

Procedure: You can find the problem sheet on Drive D: of the lab PCs. Part 1: Router & Switch

Cyberoam Multi link Implementation Guide Version 9

Installation Guide Wireless 4-Port USB Sharing Station. GUWIP204 Part No. M1172-a

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Dell Statistica Statistica Enterprise Installation Instructions

Chapter 6 Using Network Monitoring Tools

Transcription:

APPLICATION NOTE Atmel AT02744: Lightweight Mesh to Ethernet Gateway with SAM3X - Software User s Guide Features Atmel 32-bit Microcontroller Atmel ATSAM3X8E microcontroller Atmel AT86RF231 2.4GHz radio transceiver Atmel proprietary Lightweight Mesh software stack 10/100Mbps Ethernet LwIP TCP/IP stack support TCP/IP client Single MCU gateway solution Preprogrammed firmware of wireless lighting control via PC software Introduction This application note mainly describes the software architecture and the application programming interfaces (API) of Lightweight Mesh to Ethernet Gateway reference design (hereafter the Gateway). A getting started guide at the end of this document gives details about the setup and operation of preprogrammed firmware. Figure 1. Lightweight Mesh to Ethernet Gateway. The Gateway is based on Atmel ATSAM3X8E microcontroller and Atmel AT86RF231 2.4GHz radio transceiver. For gateway hardware design details, refer to Atmel AT2200: ZigBee to Ethernet and Wi-Fi Gateway with SAM3X - Hardware User's Guide.

For this reference design, the hardware design files (schematic, BOM and PCB Gerber) and software source code can be downloaded from Atmel website. The provided hardware documentation can be used with no limitations to manufacture the reference hardware solution for the design. 2

Table of Contents 1. Overview... 4 2. Development Tools... 4 3. Software Architecture... 4 3.1 Atmel Lightweight Mesh Software Stack... 5 3.2 LwIP TCP/IP Stack... 6 3.3 PC software... 6 4. Inside the Gateway Application... 8 4.1 Gateway Application Layer Structure... 8 4.2 Lightweight Mesh Task... 8 4.3 LwIP Task... 10 5. Main API Introduction... 11 5.1 Lightweight Mesh Software Stack API... 11 5.2 LwIP API Introduction... 12 6. Software Package Content... 13 7. Footprint... 16 8. Getting Started Guide... 17 8.1 Programming the Gateway... 17 8.2 Connecting to Ethernet... 18 8.3 8.2.1 Step-by-step guide... 18 PC software Menu... 20 Appendix A. Additional Information... 21 A.1 Lightweight Mesh Configuration... 21 A.2 LwIP Configuration... 21 Appendix B. Revision History... 22 3

1. Overview The Lightweight Mesh to Ethernet Gateway is designed to interface Lightweight Mesh network to Ethernet network. Through the Gateway, the user can control and monitor any nodes in Lightweight Mesh network remotely via Ethernet. A typical application scenario is shown in Figure 1-1. Figure 1-1. Typical Gateway Application Scenario. In the preprogrammed firmware, a wireless lighting control and monitor network is established. The lights in Lightweight Mesh network can be controlled and monitored via PC software remotely. 2. Development Tools To download or debug the preprogrammed firmware, the following development toolchain is needed: Atmel Studio 6. Version: 6.1.2674 with Service Pack 1 or above Atmel ARM GNU Toolchain. Version: 4.7.3.158 - GCC 4.7.3 or above Atmel Software Framework. Version: 3.9.1 or above Programming and debugging device: Atmel SAM-ICE SAM-ICE Adaptor: a minimized (1.27mm pitch 10-pin header) adaptor for Atmel SAM-ICE. For more details refer to Atmel AVR2033: SAM-ICE Adapter - Hardware User Manual 3. Software Architecture The software for the Gateway is composed of two main parts: Atmel Lightweight Mesh Software Stack LwIP TCP/IP Stack Besides the Gateway itself, PC software named TCP server is also provided as a simple graphic user interface (GUI). 4

The Gateway application is designed based on Atmel Software Framework (ASF). In fact, except the Lightweight Mesh Software Stack, other modules are from ASF. The Gateway exchanges data between Lightweight Mesh network and Ethernet network. The Lightweight Mesh network data is collected by the Gateway and transferred into Ethernet network, and finally displayed in PC software. The user input in PC software is also sent back to Lightweight Mesh network via the Gateway. The software block diagram of the Gateway is given in Figure 3-1. Figure 3-1. The Gateway Software Block Diagram. 3.1 Atmel Lightweight Mesh Software Stack Atmel Lightweight Mesh is the easy-to-use proprietary low power wireless mesh network protocol from Atmel. It is designed to work with all Atmel IEEE 802.15.4 transceivers and SoCs. To find more detailed information about the Lightweight Mesh architecture and application development process, refer to Atmel AVR2130: Lightweight Mesh Developer Guide. Atmel Lightweight Mesh software stack features: Simplicity of configuration and use Up to 65535 nodes in one network (theoretical limit) Up to 65535 separate PANs on one channel Up to 15 independent application endpoints No dedicated node is required to start a network No periodic service traffic occupying bandwidth Two distinct types of nodes: Routing (network address < 0x8000) Non-routing (network address >= 0x8000) Once powered on, the node is ready to send and receive data; no special joining procedure is required No child-parent relationship between the nodes Non-routing nodes can send and receive data to/from any other node (including non-routing nodes), but they will never be used for routing purposes Route discovery happens automatically if route to the destination is not known Routing table is updated automatically based on the data from the received and transmitted frames Duplicate frames (broadcast or multipath unicast) are rejected Small footprint (less than 8kB of Flash and 4kB of RAM for a typical application) 5

Currently the public release version of Lightweight Mesh software stack works with AVR -based MCUs, but given its extreme portability and low resource requirements, it can be run on almost any Atmel MCU. In the Gateway, it runs on ATSAM3X8E MCU. The Lightweight Mesh software stack version is v1.0.0. Note that at time of writing this application note, the Atmel Lightweight Mesh Software Stack is not integrated into ASF. In this reference design, the files in hal folder of Lightweight Mesh Software Stack are modified to reuse the low level drivers from ASF. 3.2 LwIP TCP/IP Stack The Lightweight TCP/IP stack is designed for embedded systems. The focus of the LwIP TCP/IP implementation is to reduce resource usage while still having a full scale TCP. LwIP features: IP (Internet Protocol) including packet forwarding over multiple network interfaces ICMP (Internet Control Message Protocol) for network maintenance and debugging UDP (User Datagram Protocol) including experimental UDP-lite extensions TCP (Transmission Control Protocol) with congestion control, RTT estimation and fast recovery/fast retransmit Specialized raw API for enhanced performance Optional Berkeley-alike socket API DHCP (Dynamic Host Configuration Protocol) PPP (Point-to-Point Protocol) ARP (Address Resolution Protocol) for Ethernet For more detailed information about the LwIP, refer to LwIP Wiki: http://lwip.wikia.com/wiki/lwip_wiki or the Atmel AVR32817: Getting Started with the 32-bit AVR UC3 Software Framework LwIP TCP/IP Stack application note. In the Gateway, only TCP/IP client is implemented. The LwIP version is 1.4.0. 3.3 PC software PC software named TCPServer is provided to control and monitor devices in Lightweight Mesh network. The following information is displayed in the TCPServer main window. Device: End device or Router Address: Device short address in Lightweight Mesh network Status: Device in network or not Channel: Working channel PAN ID: Lightweight Mesh network PAN ID LQI: Link quality Indicator of the last data transfer RSSI: Received Signal Strength Indication of the last data transfer TSensor: Dummy sensor data sent from devices in Lightweight Mesh network LED status: LED on / off status When clicking on a specific device in main window, the selected device can be controlled and monitored in the TCPServer control window. The LED status will be displayed. Red stands for ON, and blank indicates OFF The LED can be turned on or off by selecting ON or OFF and clicking Submit 6

The following information is displayed in the status bar: The server status Client IP address Port number Number of devices in Lightweight Mesh network Received data pack A screenshot of the PC software is shown in Figure 3-2. For details of the PC software operation, check Chapter 8. Figure 3-2. The Gateway PC Software TCPServer. Main Window Control Window Status Bar 7

4. Inside the Gateway Application In this chapter, the overall Gateway application layer structure is explained. And by different functions, the main application tasks in the Gateway are introduced in two parts: Lightweight Mesh, LwIP task. 4.1 Gateway Application Layer Structure As the Gateway is based on WSNDemo example from Lightweight Mesh Software Stack, it has similar structure in main(). The main() function of the Gateway is shown below: int main(void) { sysclk_init(); board_init(); init_ethernet(); /* This is the main polling loop */ while (1) { /* LwMesh task handler */ SYS_TaskHandler(); HAL_UartTaskHandler(); APP_TaskHandler();... ethernet_task(); } } sysclk_init() and board_init() are two functions to initialize clock and board from ASF. The Lightweight Mesh Software Stack hardware initializations are also put in board_init(). init_ethernet() is to initialize Ethernet. The task handlers in the while loop handles application tasks. They are introduced in the following sections. By following this structure, more functions can be added into main() to enrich the Gateway features. Several macro switches are defined in conf_board.h to give different application options. Here are some examples. #define LWMESH_USED #define ETH_USED 1 // Enable LWMESH PHY 1 // Enable Ethernet To run the Gateway with default features, don t not change the macro switches unless you know what it changes clearly. 4.2 Lightweight Mesh Task In the Gateway, Lightweight Mesh task is based on WSNDemo example from Lightweight Mesh Software Stack. The SYS_TaskHandler() and APP_TaskHandler() are the two APIs of Lightweight Mesh task. They should be called as frequently as possible. The Lightweight Mesh stack low layer tasks are handled by calling SYS_TaskHandler(). The application layer is handled in APP_TaskHandler(). The Gateway is a node in Ethernet network. It sends data to Ethernet by calling appsenddata() from APP_TaskHandler() at a predefined interval. The Gateway acts as Coordinator in Lightweight Mesh network. It receives data from other Lightweight Mesh devices from callback function appdataind() and sends data back to Lightweight Mesh network by filling the Acknowledgment command frame in this function. 8

Figure 4-1. Lightweight Mesh Task Flow. APP_STATE_INITIAL appinit(); APP_STATE_SEND appsenddata(); APP_STATE_SEND APP_STATE_SENDING_DONE appdatasendingtimerhandler(); SYS_TimerStart(); APP_STATE_WAIT_SEND_TIMER Data received appdataind(); ACK Control field filled 9

4.3 LwIP Task The Gateway is configured as TCP client when LwIP network connection is initialized. The LwIP task uses the ethernet_task() function to read data packet and run periodical tasks. This function should be called periodically. If Ethernet is used, the Gateway tries to connect to TCP server on a port specified in firmware. After successful connection, the Gateway is informed of incoming data through callback function tcp_client_received(). The data is sent to LwIP by calling appsendmessagetolwip(). Figure 4-2. LwIP Task Flow. lwip_init ethernet_configure_interface ethernet_task Data received? No No Yes IP packet? No ARP packet? ip_input Yes Yes etharp_arp_input TCP protocol? Yes No tcp_input Other protocol handler tcp_client_received appsendmessagetolwip tcp_write tcp_output 10

5. Main API Introduction The main API s introduction will be divided into two parts: Lightweight Mesh Software Stack API, LwIP Stack API driver API. Each part will be introduced respectively in the following sections. Note the APIs described here are focusing on application layer. For complete API descriptions, refer to the stacks and their documents mentioned in Chapter 3. 5.1 Lightweight Mesh Software Stack API As the Lightweight Mesh task is based on WSNDemo example, similar APIs in WSNDemo are used in the Gateway. Most of the Lightweight Mesh APIs used in Gateway are in WSNDemo.c. The main APIs are as below. SYS_Init() It initializes Lightweight Mesh HAL, PHY, NWK layer and system timer. It s called from board_init(). SYS_TaskHandler() It s the core API of Lightweight Mesh. The PHY, NWK and system timer task handlers are called in this API. APP_TaskHandler() It s the application layer task handler of Lightweight Mesh. The main purpose of using Lightweight Mesh on Gateway is to exchange data. Here are some APIs for sending and receiving data. appdataind() The call back function registered by NWK_OpenEndpoint() in appinit(). It s called when valid data received from Lightweight Mesh low level layer. It also fills the Acknowledgment command frame control field by calling NWK_SetAckControl(). Thus the data sent back to Lightweight Mesh network is implemented in a very simple manner. The limit here is the control field is only one byte. If large amount of data needs to be transmitted, a dedicated API and structure should be used. Refer to the none-coordinator code in WSNDemo.c for example. appsenddata() It s called by a predefined interval from APP_TaskHandler(). appsendmessagetolwip()and appsendmessage()are called in this function to send data to LwIP Tx buffer respectively. The timer API is used to generate fix interval through call back function. Here is the timer call back function in application layer. appdatasendingtimerhandler() It is registered by SYS_TimerStart() and called at predefined interval. As the Gateway acts as Coordinator in Lightweight Mesh network, some APIs from the stack are not used. For more details about other APIs in Lightweight Mesh, refer to the software package and documents inside. The latest Lightweight Mesh Software Stack package can be downloaded from http://www.atmel.com/tools/lightweight_mesh.aspx. 11

5.2 LwIP API Introduction As no operating system is running, LwIP raw API has been used in the Gateway. And the Gateway is set as TCP client. Most of the LwIP APIs are in ethernet_sam.c. The main APIs of LwIP are as below: init_ethernet() It initializes LwIP Ethernet interface and related hardware. ethernet_task() The LwIP Ethernet task handler. It polls the Ethernet tasks periodically. The specific application codes are implemented in several call back functions. tcp_client_init() It initializes the Gateway as TCP client. By default, static IP is assigned to Gateway and a port number is bound. In this function, it tries to connect to TCP server with the default parameters. appsendmessagetolwip() This function sends data from Lightweight Mesh to LwIP. It fills the data buffer to be transferred. tcp_write() and tcp_ouput() are the actual functions sends data in LwIP. Here is the list of callback functions used in the Gateway. tcp_client_received() It s the callback function invoked whenever a data packet is received from LwIP. For Gateway, it stores data received from TCP server in a buffer. tcp_client_connected() It s the callback function invoked when a TCP connection is established. It sends a string to TCP server after successful connection and set TCP client in receive state by registering a callback function tcp_client_received() in tcp_recv(). tcp_err_handler() It s the callback function for TCP error handler. It re-initializes Gateway to TCP client if connection aborted or connection reset occurs in LwIP. status_callback() It s the callback function for a status change in default network interface. It initializes the Gateway as TCP client by calling tcp_client_init(). For more details about LwIP APIs, refer to LwIP stack. 12

6. Software Package Content As mentioned before, the Gateway is developed based on ASF. The directory structure of the software package integrates ASF structure and Lightweight Mesh Software Stack structure. For details of the structure of ASF, refer to Atmel AVR4029: Atmel Software Framework - Getting Started. For the structure of Lightweight Mesh, refer to Atmel AVR2130: Lightweight Mesh Developer Guide. The Gateway directory structure is shown as below: Figure 6-1. The Gateway Directory Structure. 13

The directory details are described below: apps: WSNDemo The Gateway application layer code. The main() is in WSNDemo.c. asf: common boards This directory contains the various board definitions shared between multiple architectures. As the Gateway is not a standard Atmel Kit, it s defined as USER_BOARD. And the board details are defined user_board.h and conf_board.h. services ASF common services. utils ASF common utilities. sam components Components supported by sam. Here the Gateway Ethernet PHY chip is supported by ASF. drivers ASF sam drivers. It contains the low level drivers of sam peripherals. utils ASF sam utilities. thirdparty CMSIS ARM Cortex Microcontroller Software Interface Standard folder. lwip LwIP stack folder. config: conf_board.h The ASF config file of board. The Gateway board settings and macros are placed in this file. conf_clock.h The ASF config file of clock. The Gateway clock settings can be configured here. conf_eth.h The ASF config file of EMAC. The Gateway Ethernet hardware, MAC address and IP address (if static IP if used) etc. are defined in this file. conf_spi_master.h The ASF config file of SPI in master mode. conf_uart_serial.h The ASF config file of UART port. It s for debug purpose in the Gateway. config.h The config file of Lightweight Mesh Software Stack. The device type and working channel are defined in this file. lwipopts.h The config file of LwIP stack. 14

stack: hal atsam3x8e Hardware abstraction layer of Lightweight Mesh Software Stack. In the Gateway, it reuses the low level drivers from ASF. nwk Network layer of Lightweight Mesh Software Stack. phy at86rf231 The radio PHY chip supported by the Gateway. Services The Lightweight Mesh application services. OTA service is provided, but it s not used in the Gateway. It can be removed from the project folder with no harm. It s kept there for not breaking Lightweight Mesh Software Stack original structure. Sys The Lightweight Mesh system services. 15

7. Footprint Figure 7-1 and Figure 7-2 illustrate the CODE and RAM spaces that each module used in the software of the Gateway. Figure 7-1. Lightweight Mesh to Ethernet Gateway CODE Footprint [KB]. Toochain lib; 5.312 ASF; 5.142 LwMesh; 5.848 LwIP; 19.358 Application; 1.504 Figure 7-2. Lightweight Mesh to Ethernet Gateway RAM Footprint [KB]. LwIP; 8.156 emac buffer; 14.192 LwMesh; 3.012 Application; 0.312 stack size; 8.196 ASF; 0.392 Toolchain lib; 2.196 The Lightweight Mesh and LwIP stack RAM usage should be configured in their corresponding configuration file according to real application. 16

8. Getting Started Guide In this chapter, it gives step-by-step guide to setup the Gateway and run the preprogrammed firmware. 8.1 Programming the Gateway Along with this document, two hex files are provided. One is for the Gateway (LwMesh_Gateway.hex) and the other is for Lightweight Mesh devices connecting to the Gateway (LwMesh_RCB128RFA1.hex). To program the Gateway hex file, SAM-ICE adaptor mentioned in Chapter 2 is needed. The steps are as below. 1. Connect SAM-ICE to the SAM-ICE adapter. 2. Connect SAM-ICE adapter to the Gateway programming header J2. 3. Power the Gateway via the USB cable. 4. Open Atmel Studio and select menu Tools -> Device Programming. 5. Choose SAM-ICE for Tool, ATSAM3X8E for Device and JTAG for Interface, and then click Apply button. 6. Click the Device signature Read button to check if the connection is correct. 7. Select the Memories tab and then select the pre-built image for the Gateway from in Flash section. 8. Click Program. If the pre-built image is downloaded to the board, message Verifying Flash OK appears. Figure 8-2. Programming the Gateway. The hex file for Lightweight Mesh devices is running on RCB128RFA1. It acts as End Device in the network. LED (D4) on RCB128RFA1 can be monitored and controlled through the Gateway. Refer to Atmel AVR2131: Lightweight Mesh Getting Started Guide for the setup and programming the RCB128RFA1 Radio Control Board. 17

8.2 Connecting to Ethernet In the preprogrammed firmware, the Gateway Ethernet is configured as below. TCP client Server IP: 192.168.1.105. Port: 8840 Gateway static IP: 192.168.1.101. Sub net mask: 255.255.255.0. Default Gateway: 192.168.1.1 The parameters can be changed in the Gateway firmware, but the PC software TCPServer provided with this document is designed to work with the settings above. 8.2.1 Step-by-step guide To directly connect the Gateway to PC via Ethernet, follow the steps below. 1. Configure PC IP address to 192.168.1.105, Sub net mask: 255.255.255.0, Default Gateway: 192.168.1.1 as shown in Figure 8-1. Figure 8-1. PC IP address configuration. 2. Connect Ethernet cable between Gateway and PC. 3. Power on Gateway by connecting USB cable. Ethernet connection status is indicated by LED D2, D3 and D4 on Gateway. The red color of bi-color LED D7 on Gateway will be on when Lightweight Mesh network ready. 4. Open TCPServer in PC. If the Gateway and PC are setup correctly, TCPServer will report Connected, Client IP and Port in the status bar as shown in Figure 8-2. 18

Figure 8-2. The Gateway connected to TCPServer. 5. Power on the other Lightweight Mesh devices. If the Lightweight Mesh devices are setup correctly, the device information will be displayed in the main window of TCPServer as shown in Figure 8-3. The green color of bicolor LED D7 on Gateway will toggle each time it receives data from connected devices. Figure 8-3. Lightweight Mesh devices connected via Ethernet. 6. Click on one device in main window. The LED status on selected device is displayed in control window. Select ON or OFF and then click Submit, the LED on the device can be controlled accordingly. 19

8.3 PC software Menu The TCPServer provided with this document is a simple GUI to demonstrate the Gateway reference design. In a real application, a more complicated GUI may be used. For an overview of the PC software features refer to Section 3.3. The menu of TCPServer is simple. Only the menu items under Action are implemented. They are described as below. Refresh List: Refresh the device list manually Start Listening: Start listening on the default server port 8840 Stop Listening: Stop listening on the default server port 8840 Whenever the device list is not updated or showing Not Found in main window as in Figure 8-4, the TCPServer can restart working by selecting Stop Listening and Start Listening. Figure 8-4. Device Not Found in TCPSerever. 20

Appendix A. Additional Information A.1 Lightweight Mesh Configuration Table A-1 lists the Lightweight Mesh Software Stack configuration used in this reference design and this configuration can be modified in src/config/config.h. Table A-1. Lightweight Mesh Options. Option Value Description APP_ADDR 0 - Coordinator Node network address. It should be 0 for the Gateway APP_CHANNEL 0x18 Radio transceiver channel. Valid range for 2.4GHz radios is 11 26 (0x0b 0x1a) APP_PAN_ID 0x1234 Network identifier APP_ENDPOINT 1 Application main data communication endpoint NWK_BUFFERS_AMOUNT 10 Number of buffers reserved for stack operation HAL_UART_RX_FIFO_SIZE 4 UART RX buffer size A.2 LwIP Configuration Table A-2 lists the LwIP stack configuration in this reference design, and these configurations can be modified in src/config/lwipopts.h. Table A-2. LwIP Options. Option Value Description MEM_SIZE 3*1024 The size of the heap memory MEMP_NUM_PBUF 12 The number of memp struct pbufs MEMP_NUM_TCP_PCB 2 The number of simultaneously active TCP connections MEMP_NUM_TCP_PCB_LISTEN 1 The number of listening TCP connections MEMP_NUM_TCP_SEG 9 The number of simultaneously queued TCP segments PBUF_POOL_SIZE 6 The number of buffers in the pbuf pool PBUF_POOL_BUFSIZE 512 The size of each pbuf in the pbuf pool LWIP_TCP 1 Turn on TCP TCP_WND 1500 The size of a TCP window TCP_MSS 1500 TCP Maximum segment size TCP_SND_BUF 2150 TCP sender buffer space TCP_SND_QUEUELEN (6 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS) TCP sender buffer space 21

Appendix B. Revision History Doc. Rev. Date Comments 42165A 11/2013 Initial document release 22

Atmel Corporation 1600 Technology Drive San Jose, CA 95110 USA Tel: (+1)(408) 441-0311 Fax: (+1)(408) 487-2600 www.atmel.com Atmel Asia Limited Unit 01-5 & 16, 19F BEA Tower, Millennium City 5 418 Kwun Tong Road Kwun Tong, Kowloon HONG KONG Tel: (+852) 2245-6100 Fax: (+852) 2722-1369 Atmel Munich GmbH Business Campus Parkring 4 D-85748 Garching b. Munich GERMANY Tel: (+49) 89-31970-0 Fax: (+49) 89-3194621 Atmel Japan G.K. 16F Shin-Osaki Kangyo Building 1-6-4 Osaki, Shinagawa-ku Tokyo 141-0032 JAPAN Tel: (+81)(3) 6417-0300 Fax: (+81)(3) 6417-0370 2013 Atmel Corporation. All rights reserved. / Rev.: Atmel, Atmel logo and combinations thereof, Enabling Unlimited Possibilities, AVR, and others are registered trademarks or trademarks of Atmel Corporation or its subsidiaries. ARM and Cortex are registered trademarks or trademarks of ARM Ltd. Other terms and product names may be trademarks of others. Disclaimer: The information in this document is provided in connection with Atmel products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Atmel products. EXCEPT AS SET FORTH IN THE ATMEL TERMS AND CONDITIONS OF SALES LOCATED ON THE ATMEL WEBSITE, ATMEL ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS AND PROFITS, BUSINESS INTERRUPTION, OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF ATMEL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Atmel makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and products descriptions at any time without notice. Atmel does not make any commitment to update the information contained herein. Unless specifically provided otherwise, Atmel products are not suitable for, and shall not be used in, automotive applications. Atmel products are not intended, authorized, or warranted for use as components in applications intended to support or sustain life.