GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54...

54
GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 – 2016-06-07

Transcript of GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54...

Page 1: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 – 2016-06-07

Page 2: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 2 of 54 2016-06-07

NOTICE

COPYRIGHTS

COMPUTER SOFTWARE COPYRIGHTS

SPECIFICATIONS ARE SUBJECT TO CHANGE WITHOUT NOTICE

While reasonable efforts have been made to assure the accuracy of this document, Telit assumes no liability resulting from any inaccuracies or omissions in this document, or from use of the information obtained herein. The information in this document has been carefully checked and is believed to be reliable. However, no responsibility is assumed for inaccuracies or omissions. Telit reserves the right to make changes to any products described herein and reserves the right to revise this document and to make changes from time to time in content hereof with no obligation to notify any person of revisions or changes. Telit does not assume any liability arising out of the application or use of any product, software, or circuit described herein; neither does it convey license under its patent rights or the rights of others.

It is possible that this publication may contain references to, or information about Telit products (machines and programs), programming, or services that are not announced in your country. Such references or information must not be construed to mean that Telit intends to announce such Telit products, programming, or services in your country.

This instruction manual and the Telit products described in this instruction manual may be, include or describe copyrighted Telit material, such as computer programs stored in semiconductor memories or other media. Laws in the Italy and other countries preserve for Telit and its licensors certain exclusive rights for copyrighted material, including the exclusive right to copy, reproduce in any form, distribute and make derivative works of the copyrighted material. Accordingly, any copyrighted material of Telit and its licensors contained herein or in the Telit products described in this instruction manual may not be copied, reproduced, distributed, merged or modified in any manner without the express written permission of Telit. Furthermore, the purchase of Telit products shall not be deemed to grant either directly or by implication, estoppel, or otherwise, any license under the copyrights, patents or patent applications of Telit, as arises by operation of law in the sale of a product.

The Telit and 3rd Party supplied Software (SW) products described in this instruction manual may include copyrighted Telit and other 3rd Party supplied computer programs stored in semiconductor memories or other media. Laws in the Italy and other countries preserve for Telit and other 3rd Party supplied SW certain exclusive rights for copyrighted computer programs, including the exclusive right to copy or reproduce in any form the copyrighted computer program. Accordingly, any copyrighted Telit or other 3rd Party supplied SW computer programs contained in the Telit products described in this instruction manual may not be copied (reverse engineered) or reproduced in any manner without the express written permission of Telit or the 3rd Party SW supplier. Furthermore, the purchase of Telit products shall not be deemed to grant either directly or by implication, estoppel, or otherwise, any license under the copyrights, patents or patent applications of Telit or other 3rd Party supplied SW, except for the normal non-exclusive, royalty free license to use that arises by operation of law in the sale of a product.

Page 3: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 3 of 54 2016-06-07

USAGE AND DISCLOSURE RESTRICTIONS

I. License Agreements

II. Copyrighted Materials

III. High Risk Materials

IV. Trademarks

V. Third Party Rights

The software described in this document is the property of Telit and its licensors. It is furnished by express license agreement only and may be used only in accordance with the terms of such an agreement.

Software and documentation are copyrighted materials. Making unauthorized copies is prohibited by law. No part of the software or documentation may be reproduced, transmitted, transcribed, stored in a retrieval system, or translated into any language or computer language, in any form or by any means, without prior written permission of Telit

Components, units, or third-party products used in the product described herein are NOT fault-tolerant and are NOT designed, manufactured, or intended for use as on-line control equipment in the following hazardous environments requiring fail-safe controls: the operation of Nuclear Facilities, Aircraft Navigation or Aircraft Communication Systems, Air Traffic Control, Life Support, or Weapons Systems (High Risk Activities"). Telit and its supplier(s) specifically disclaim any expressed or implied warranty of fitness for such High Risk Activities.

TELIT and the Stylized T Logo are registered in Trademark Office. All other product or service names are the property of their respective owners.

The software may include Third Party Right software. In this case you agree to comply with all terms and conditions imposed on you in respect of such separate software. In addition to Third Party Terms, the disclaimer of warranty and limitation of liability provisions in this License shall apply to the Third Party Right software.

TELIT HEREBY DISCLAIMS ANY AND ALL WARRANTIES EXPRESS OR IMPLIED FROM ANY THIRD PARTIES REGARDING ANY SEPARATE FILES, ANY THIRD PARTY MATERIALS INCLUDED IN THE SOFTWARE, ANY THIRD PARTY MATERIALS FROM WHICH THE SOFTWARE IS DERIVED (COLLECTIVELY “OTHER CODE”), AND THE USE OF ANY OR ALL THE OTHER CODE IN CONNECTION WITH THE SOFTWARE, INCLUDING (WITHOUT LIMITATION) ANY WARRANTIES OF SATISFACTORY QUALITY OR FITNESS FOR A PARTICULAR PURPOSE.

NO THIRD PARTY LICENSORS OF OTHER CODE SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND WHETHER MADE UNDER CONTRACT, TORT OR OTHER LEGAL THEORY, ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE OTHER CODE OR THE EXERCISE OF ANY RIGHTS GRANTED UNDER EITHER OR BOTH THIS LICENSE AND THE LEGAL TERMS APPLICABLE TO ANY SEPARATE FILES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Page 4: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 4 of 54 2016-06-07

APPLICABILITY TABLE

Note: The features described in the present document are provided by the products equipped with the software versions equal or higher than the versions shown in the table. See also the Document History chapter.

PRODUCT

GS 2K based Modules

SW Version

5.2.x onwards

Page 5: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 5 of 54 2016-06-07

Revision History

Version Date Remarks

1.0 June, 2016 Initial release

Page 6: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 6 of 54 2016-06-07

Table of Contents NOTICE………. ............................................................................................................................ 2

COPYRIGHTS.. ............................................................................................................................ 2

COMPUTER SOFTWARE COPYRIGHTS .................................................................................. 2

USAGE AND DISCLOSURE RESTRICTIONS ........................................................................... 3

APPLICABILITY TABLE ............................................................................................................. 4

CHAPTER 1. INTRODUCTION .................................................................................................. 9

1.1 SCOPE .............................................................................................................................9 1.2 OVERVIEW........................................................................................................................9 1.3 TERMINOLOGY ................................................................................................................10 1.4 STANDARDS AND CONCEPTS ...........................................................................................11

CHAPTER 2. FEATURES AND CAPABILITIES ..................................................................... 12

CHAPTER 3. THEORY OF OPERATION ................................................................................ 13

CHAPTER 4. ARCHITECTURE ............................................................................................... 14

4.1 COMPONENTS ................................................................................................................15 4.1.1 Hardware ............................................................................................................ 15 4.1.2 Software ............................................................................................................. 16

4.2 TASKS ............................................................................................................................17 CHAPTER 5. EMBEDDED APPLICATION EXECUTION SEQUENCE ................................. 20

5.1 GS TLS APPLICATION BOOT UP ......................................................................................20 5.1.1 Startup Code (GsnStartup_Main) ...................................................................... 20 5.1.2 Application Initialization (App_Main) .................................................................. 22 5.1.3 Application Boot Process (APP_Bootprocess) .................................................. 22 5.1.4 Application Main Clock Initialization (AppMainCtx_Init) .................................... 24

5.2 STARTING WEB SERVER (HTTPD) ..................................................................................27 5.3 SERVICE DISCOVERY USING MDNS/DNS-SD ..................................................................27 5.4 TLS DATA HANDLING......................................................................................................29

5.4.1 Provisioning ........................................................................................................ 32 5.4.2 OTAFU ............................................................................................................... 33 5.4.3 REST HTTP TLS API ......................................................................................... 34

5.5 XML FORMAT OF TLS DATA ...........................................................................................35 5.6 AUTO CACHE FEATURE ON HOSTLESS TLS APPLICATION ................................................36

CHAPTER 6. NATIVE APPLICATION OR WEBPAGE EXECUTION SEQUENCE .............. 37

6.1 TLS APPLICATION WEBPAGE ..........................................................................................37 6.2 SCREENSHOTS OF IOS APPLICATION ..............................................................................38 6.3 SCREENSHOTS OF ANDROID APPLICATION ......................................................................38

APPENDIX A REFERENCE CODE.......................................................................................... 40

A.1 TLS ADK REFERENCE CODE FLOW ................................................................................40 A.2 AUTO CACHE REFERENCE CODE FLOW...........................................................................42 A.2.1 APPLICATION START-UP (APP_STARTUP.C) ..................................................................42 A.2.2 APPLICATION MAIN THREAD (APP_MAIN_THREAD.C) ....................................................48 A.2.3 APPLICATION NETWORK SERVICE (APP_NETWORK_SERVICE.C) ...................................49 A.2.4 APPLICATION FLASH FETCH AUTOCACHE (APP_FLASHFETCH_AUTOCACHE.ICF) ...........50

Page 7: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 7 of 54 2016-06-07

List of Figures

Figure 1: Limited AP mode ......................................................................................................... 14

Figure 2: Client mode ................................................................................................................. 14

Figure 3: TLS ADK Component ................................................................................................. 15

Figure 4: Task Interface Architecture ......................................................................................... 18

Figure 5: Interface Architecture .................................................................................................. 19

Figure 6: GS2011MIE/Z EVB UART0 Debug Prints .................................................................. 20

Figure 7: HTTP GET Request/Response Flow Diagram ........................................................... 29

Figure 8: AUTO Cache Mapping ................................................................................................ 36

Figure 9: tls.html page access from web browser ..................................................................... 37

Figure 10: iOS APP TLS Resource Discovery and Sensor Data Update.................................. 38

Page 8: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 8 of 54 2016-06-07

List of Tables

Table 1: Glossary of Terms ........................................................................................................ 10

Table 2: Hardware Components ................................................................................................ 15

Table 3: Software Components .................................................................................................. 16

Page 9: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07

Chapter 1. Introduction

1.1 SCOPE

This document provides an overview about the GS2000 based TLS Application Development Kit (ADK) and describes the software and hardware architecture, network topology, functional features, API’s, Application execution sequence of the Embedded and Mobile applications. The TLS ADK provides a complete sensor reference design that allows users to read the Temperature and Light sensors from GS2K EVB using ADC and update to the iOS or Android based smartphones or web browser.

This GainSpan Temperature and Light Sensor (TLS) application provides a graphical interface used for viewing sensor node data on an iOS® or Android® based Smart Phone/devices. This embedded application is an mDNS based method to discover sensor devices and services available on the wireless network.

This document reviews the architecture of the TLS ADK and provides with necessary information required to understand the TLS ADK. This document assumes that the reader is generally familiar with GainSpan SoC products, Internet Protocol (IP) networks and the operation of 802.11 wireless devices.

1.2 OVERVIEW

GainSpan TLS ADK is a development platform enabling customers to build HOSTLESS SENSOR applications. By integrating the major hardware and software components for Wi-Fi Temperature and Light solution, this platform facilitates fast time to market for customer projects. It serves as a base reference application for customers developing HOSTLESS applications.

Targeted applications for this platform include Wi-Fi Hostless sensor based applications such as Door Locks, healthcare sensor devices and variety of other systems where the customers can add sensor based functionality in GS2K module.

NOTE: GainSpan SDK is mandatory for any development on TLS ADK.

Page 10: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 10 of 54 2016-06-07

1.3 TERMINOLOGY

Below table lists the different terminologies used in this document.

Term Explanation

AP Access Point

API Application Programmer’s Interface

ADC Analog-to-Digital converter

XML Extensible Markup Language

UART Universal Asynchronous Receiver/Transmitter

HTTP Hypertext Transfer Protocol

DNS Domain Name System

mDNS multicast Domain Name System

DNS-SD DNS Service Discovery

Table 1: Glossary of Terms

NOTE:

The term ‘Task’ also means thread in this document.

Page 11: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 11 of 54 2016-06-07

1.4 STANDARDS AND CONCEPTS

Standards

Generic

• HTTP

• mSNS/DNS-SD

ADK Specific

• TLS XML data format

Concepts

TLS ADK uses XML data format across the Application Development Kit.

Page 12: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 12 of 54 2016-06-07

Chapter 2. Features and Capabilities

This section provides the features and capabilities of GainSpan TLS ADK:

Features

• Provisioning

• OTAFU

• Temperature and Light Sensor

o Temperature

o Light

o Signal Strength (RSSI of last received packet)

o Battery Voltage (or line voltage if line powered)

• Limited AP and Station mode

Capabilities

• JTAG for debugging on GS2011MIE/MIZ EVB

Page 13: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 13 of 54 2016-06-07

Chapter 3. Theory of Operation

TLS ADK demonstrates sensor data update on android/iOS/web applications. Here GainSpan runs HTTP server and when the application request sensor data using HTTP GET, the module reads the sensor data via ADC and responds to the request.

TLS ADK is based on REST style HTTP APIs. TLS resource is represented as a URI and interaction with it is performed using HTTP GET/POST method and represented in XML.

Once TLS ADK board (GS2011M EVB) is powered up for the first time, it comes up in Limited- AP (SSID: GS_PROV_TLS_xxxxxx) with WPA2 security (password being GS_xxxxxx, where "xxxxxx" is last 6 digit of Limited-AP MAC address which is 1 more than STA interface MAC address mentioned on the module). TLS ADK Server also starts HTTP server and uses mDNS to announce the TLS resources. Stations such as Smartphone/tablets/laptops, and so on connect to the TLS ADK Limited-AP. The native android/iOS TLS application is launched on stations to discover mDNS TLS resource. Native applications send the HTTP GET request periodically to the GS TLS application on HTTP URI “/gainspan/profile/tls”. TLS HTTP server processes the HTTP GET request, reads temperature and light sensor using ADCs, formulates XML data response, and sends to the iOS/Android.

Page 14: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 14 of 54 2016-06-07

Chapter 4. Architecture

TLS ADK architecture consists of GS module working in Limited-AP/client mode. It fetches the temperature and light data from the temperature and light sensors connected with 12 bit SAR ADC pins (ADC_SAR_0_B and ADC_SAR_1_B) and sends it over HTTP GET RESPONSE in XML format.

The GainSpan module works in two modes:

• Limited-AP mode

• Client mode

Limited-AP Mode

Figure 1: Limited AP mode

On powering up the application board, the GainSpan Wi-Fi module establishes itself as a Limited AP broadcasting default SSID (GS_PROV_TLS_xxxxxx) with WPA2 security (password being GS_xxxxxx, where "xxxxxx" is last 6 digit of Limited-AP MAC address which is 1 more than STA interface MAC address mentioned on the module). It also starts as an HTTP server, which is a TCP based protocol that establishes the communication channel. Client (smartphones) browses through the list of available wireless networks, and connects to the default SSID having WPA2 Security. The TLS mobile application discovers profiles and services provided by the TLS embedded firmware application using mDNS. Client launches the TLS application to initiate HTTP communication and acts as an HTTP client in this process.

Client Mode

Figure 2: Client mode

On powering up the application board, the GainSpan Wi-Fi module establishes itself as an STA, connects to provisioned AP, and starts the HTTP Server. Clients (smartphones/Tablet) connects to same AP and discovers the available profiles and services using mDNS. Client launches the TLS application to initiate HTTP communication and acts as an HTTP client in this process.

Page 15: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 15 of 54 2016-06-07

4.1 COMPONENTS

The TLS ADK consists of the following hardware and software components.

Figure 3: TLS ADK Component

4.1.1 Hardware

The GainSpan EVB uses GS2011M Wi-Fi module based Temperature & Light sensor board that consists of the following hardware components.

Component Description

GS2011M EVB GS2011M module transmits TLS data over Wi-Fi using HTTP.

LEDs Indicates Power On, Operation mode (Limited AP or Client) and Run or Program mode

RT1 NCP21XV103J03RA Temperature sensor on GS2011M EVB

Q10 ALS-PT19-315C_L177_TR8 Light sensor on GS2011M EVB Table 2: Hardware Components

Page 16: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 16 of 54 2016-06-07

4.1.2 Software

The GainSpan TLS ADK uses the following software components.

Component Description

Embedded Firmware Application An embedded application that runs on the GainSpan EVB board which is the source of the Temperature and Light sensor that runs the HTTP server.

Native applications on iOS and Android

TLS application running HTTP client for reading the TLS data.

Webpage TLS webpage is used to view the TLS data in web browsers. Table 3: Software Components

Page 17: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 17 of 54 2016-06-07

4.2 TASKS

GEPS System Threads:

1) Soft timer: Thread priority of the soft timer is 1.

• The soft timer module provides multiple timers using a single hardware timer.

• It generates interrupts only when a soft timer expires.

2) Host Interface: Thread priority of the HIRecv is 2.

• It handles the mailbox communication between App and WLAN.

• It receives control/data messages from WLAN.

3) System Control: Thread priority of the SystemControl is 3.

• It handles the system messages exchanged between WLAN and app.

• It processes the system control messages such as battery check, file system read/write requests from WLAN.

4) WDD (Wireless Device Driver): Thread priority of the WDD is 4.

• It handles the WPA Supplicant packets. EAPOL messages and timeouts are handled in WDD task

5) DHCP Client: Thread priority of the DHCP Client is 3.

• It creates the DHCP Client thread to handle DHCP procedure after the L2 completion.

6) IP: Thread priority of the IP is 11.

• Network interface IP thread processes the IP packets and packet timeouts

TLS Application Threads:

1) Main: Thread priority of the main thread is 15.

a. It is the Application Main thread created after the boot Rom code is executed and performs the following.

b. Handles System/Network Events

c. Initializes clk control/Wif message system/soft timer/file system/wdd/network stack/WPA Supplicant

d. Sends boot request to the WLAN for initialization.

2) Web Server: Thread Priority of the webserver is 16.

• HTTPd server thread listens for incoming connections and handles the http client requests.

3) Network Receive: Thread Priority of the network receive is 5.

• It receives data from WDD task.

Page 18: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 18 of 54 2016-06-07

Figure 4: Task Interface Architecture

• The Main task creates Application main thread, HTTPd web server, performs all the system initializations, and gives WLAN boot request.

• HTTPd server thread listens for incoming connections and handles the http client requests.

• Application's URI handle “/gainspan/profile/tls” and callback AppTls_HttpApiCb is registered.

• AppTls_HttpApiCb handles the HTTP GET requests. It calls the API AppTls_CreateXmlResp() to get the XML format of the sensor values such temp, light, RSSI and battery values.

Page 19: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 19 of 54 2016-06-07

A generic interface concept on GS2000 platform is as follows:

Figure 5: Interface Architecture

Page 20: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 20 of 54 2016-06-07

Chapter 5. Embedded Application Execution Sequence

The sequence of execution starts as soon as the GainSpan module boots up which is as explained in the following sections.

5.1 GS TLS APPLICATION BOOT UP

TLS application execution starts once boot ROM code execution is completed and code is copied from Flash. GsnStartup_Main API allocates the RAM for application, copies the code from flash to the SRAM, creates BYTE POOLs and gives control to TLS application App_Main().

On boot up, debug prints are displayed on GainSpan UART0 (115200) interface as shown in the following figure. At this point of time, Main task initialization has been done from main function call. By default, GS node comes up as Limited-AP (SSID: GS_PROV_TLS_xxxxxx) with WPA2 security (password being GS_xxxxxx, where "xxxxxx" is last 6 digit of Limited-AP MAC address which is 1 more than STA interface MAC address mentioned on the module). The configuration information is present in the file “app_default_cfg.h” which can be modified according to the customer’s requirement, if SDK is purchased.

Figure 6: GS2011MIE/Z EVB UART0 Debug Prints

5.1.1 Startup Code (GsnStartup_Main)

1. Enables all four banks of RTC

2. Copies ‘.data’ section

3. Copies FPT in to 0x20004000 (@16KB)

4. Copies code (.txt and. rodata) in to ‘0x20040000’ (@256KB)

5. Initializes. bssdata section to ‘0’

Page 21: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 21 of 54 2016-06-07

6. Initializes heap-0

7. Initializes heap-1

8. Calls application entry (App_Main)

9. Triggers idle handler thread that transitions the system into deepsleep if idle

Page 22: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 22 of 54 2016-06-07

5.1.2 Application Initialization (App_Main)

It performs the configuration of RTC by checking the type of RESET and calls APP Main Task.

Code Ref:

App_Main()

{

APP_BootProcess();

/* Create APP main task */

AppMainCtx_Init();

return 0;

}

5.1.3 Application Boot Process (APP_Bootprocess )

1. If reset is due to POR (Power On Reset)

a. Enables clock source

b. Enables RTC-Bank-1

c. Sets time between DCDC assertion and reset release to the core as 1.25ms

d. Enables the threshold of brown out circuitry as 1.4V

e. Initializes RTC memory

f. Sets the boot reason as ‘First Boot’ in RTC latch memory (system reserved RTC area)

2. If reset is due to timer, configures the boot reason as ‘normal boot’ and boot info as

‘RTC’

3. If reset is due to alarm, performs actions based on the alarm:

1. Standby

­ Boot reason: normal boot

­ Boot info: alarm

2. Hibernate

­ Boot reason: First Boot

3. Watchdog boot

­ Update the boot reason accordingly

4. Debug Boot

­ Update the boot reason accordingly

5. Crypto Boot

­ Update the boot reason accordingly

6. Brownout boot

­ Update the boot reason accordingly

7. Software reset boot

­ Update the boot reason accordingly

8. Firmware update boot

­ Update the boot reason accordingly

9. External reset boot.

­ Update the boot reason accordingly

Page 23: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 23 of 54 2016-06-07

Call AppMainCtx_Init

Code Ref:

APP_BootProcess()

{

if(GsnRtc_IsPorEvent())

{

/* Enable RTC SRAM Bank 0*/

GsnRtc_RtcSramBankEn(GSN_RTC_SRAM_BANK0);

/*set time between DCDC assertion and reset release to the

core. 1.25ms */

GsnRtc_DcDcTmrValSet(APP_CFG_DCDC_TMR_VAL);

/* Enable pulldown for rtc gpio */

GsnRtc_GpioPullDownEn(0xF);

/* Enable BrownOut circuit*/

GsnRtc_BrownOutEn(GSN_BROWNOUT_THRESHOLD_1_4V);

/* Enable BrownOut reset */

RTC_RRH_CBO_CTL_REQ_SET(RTC);

APP_RtcInit(1);

/* Initial Boot */

GSN_BOOTINFO_SET(GSN_WIF_SYS_BOOT_FIRST_BOOT, 0);

GsnRtc_PorEventClr();

}

else

{

if (GSN_IS_RTC_RSVD_INFO_VALID())

{

}

Else

{

/*Enable RTC SRAM Bank 0*/

GsnRtc_RtcSramBankEn(GSN_RTC_SRAM_BANK0);

/*set time between DCDC assertion and reset release to

the core. 1.25ms */

GsnRtc_DcDcTmrValSet(APP_CFG_DCDC_TMR_VAL);

GsnRtc_GpioPullDownEn(0xF); //Enable

pulldown for rtc gpio

/* Enable BrownOut */

GsnRtc_BrownOutEn(GSN_BROWNOUT_THRESHOLD_1_4V);

/* Enable BrownOut reset */

RTC_RRH_CBO_CTL_REQ_SET(RTC);

APP_RtcInit(1);

/* Initial Boot */

GSN_BOOTINFO_SET(GSN_WIF_SYS_BOOT_FIRST_BOOT, 0);

}

}

}

Page 24: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 24 of 54 2016-06-07

5.1.4 Application Main Clock Initialization (AppMainCtx_Init )

1. Initializes Power management module

2. Initializes Clock

­ If first Boot, do the HS-RC calibration as well

­ Uncalibrated RC generates 40MHz, and post calibration it clocks at 80MHz

3. Initializes exception handler

4. Configures RTC

5. Initializes the UART to support Debug prints with 115200 Baud Rate

6. Initializes HI (host interface) for mailbox communication between app and WLAN

­ Registers queues for data and control messages

7. Initializes the system control message handler

­ Battery indication

­ Boot indication

­ OTP write, read

­ Temp read/write

­ ... (refer gsn_wif_api.h)

8. Enables WLAN Watchdog

9. Initializes soft timer module

­ Starts 100ms timer for system (thread-x)

10. Initializes Sys-Qual (software watchdog)

11. Mounts file system 0 (dynamic) & 1 (static)

12. Initializes OTP

13. Provides Boot request to WLAN (and wait for maximum of 10seconds).

­ Application continues to initialize further

14. Initializes Default configuration

15. Initializes WDD message handler thread

16. Initializes network stack

17. Initializes hardware crypto

18. Initializes supplicant module

19. Initializes BSD layer

20. Waits for WLAN to complete the boot process

Page 25: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 25 of 54 2016-06-07

Code Ref:

AppMainCtx_Init ()

{

msgSizeInWords =

GsnOsal_QueueMsgSizeInWords(sizeof(APP_MAINTASK_MSG_T));

/**< Creating the Mailbox to receive messages */

GsnOsal_QueueCreate( &appMainThreadMsgQueue, msgSizeInWords,

( UINT8*

)appMainThreadMsgQueueBuf,

sizeof(

appMainThreadMsgQueueBuf ));

GsnOsal_ThreadCreate(AppMainCtx_ThreadEntry, &appCtx,

&appMainCtxThread,

"App Main Ctx", APP_CFG_MAIN_THREAD_PRIORITY, (UINT8

*)appMainCtxThreadStack,

sizeof(appMainCtxThreadStack), GSN_OSAL_THREAD_INITIAL_READY);

}

AppMainCtx_ThreadEntry(UINT32 ctx)

{

GsnClkCtl_Init(&gsnBrClkCtlCtx1);

GsnExcpHdlr_Init();

App_RtcCfg();

/* Initiailize the UART early to support prints */

AppUart_Init();

AppDbg_Printf("Boot Reason = %d\r\n", GSN_BOOT_REASON_GET());

/*Initialise wif message system*/

App_HiInit(pAppCtx);

/*Initialise wif System Control message Handler */

App_SysCtlInit(pAppCtx);

/*Watch Dog init */

GsnActlWwdog_Enable();

/*Initialise Soft Timer */

App_SoftTimerInit(pAppCtx);

/*Initialise SysQual*/

App_SysQualInit();

/* Give boot request */

App_WlanBootReq(pAppCtx);

/*Initialise Default configuration*/

AppConfig_DefaultInit(&pAppCtx->config);

/*Initialise Wdd Message Handler */

AppInit_WddMsgHdlrInit(pAppCtx);

/*Initialize Nw statck. This is a one time initialisation*/

App_NwStackInit(pAppCtx);

/* Initialise Wpa Suppliacnt*/

App_WpaSupplicantInit(pAppCtx);

App_Init(pAppCtx);

#ifdef ADK_PROV_WPS_ENABLE

App_WpsGPIOInit(pAppCtx);

#endif

/**< Handle events forever */

while( TRUE )

{

/**< wait on message queue */

GsnOsal_QueueGet( &appMainThreadMsgQueue, ( UINT8* )&msg,

GSN_OSAL_WAIT_FOREVER );

Page 26: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 26 of 54 2016-06-07

/**< Process the message */

GsnSq_TaskMonitorStart(APP_CFG_SQ_MAIN_TASK_ID, msg.msgId);

AppSm_MsgProcess(pAppCtx, msg);

GsnSq_TaskMonitorStop(APP_CFG_SQ_MAIN_TASK_ID);

}

}

Page 27: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 27 of 54 2016-06-07

5.2 STARTING WEB SERVER (HTTPD)

1. Once system initialization is completed from main task, APP_EVENT_NW_CONNECT_DONE event is posted to main task after L2 is successfully completed.

2. Main task performs DHCP for IP assignment. DHCP server is created for Limited AP mode and IP is fetched for Station mode.

3. Once L2 and L3 are completed, HTTP server thread is created and initialized.

5.3 SERVICE DISCOVERY USING MDNS/DNS-SD

Once HTTP server is started, TLS embedded application initializes the mDNS and broadcasts the below services:

• TLS application - “TLS_gs2k-xxxxxx_TLS”

• Provisioning - “TLS_gs2k-xxxxxx_Prov”

• TLS application - “TLS_gs2k-xxxxxx_Otafu”

Code Ref:

AppSm_MsgProcess(APP_MAIN_CTX_T *pAppCtx, APP_MAINTASK_MSG_T msg )

{

switch ( msg.msgId )

{

case APP_EVENT_NW_START_NCM:

App_NcmStart(pAppCtx, &pAppCtx->if0);

break;

case APP_EVENT_NW_CONNECT_DONE:/*GSN_NCM_CTX_L3CONNECTED*/

AppSm_ConnectSuccessProcess(pAppCtx);

}

}

AppSm_ConnectSuccessProcess(APP_MAIN_CTX_T *pAppCtx)

{

UINT32 wlanNwType;

wlanNwType = pAppCtx->if0.macIfType;

if(GSN_WIF_WLAN_NW_TYPE_AP == wlanNwType)

{

GsnDhcpSrvr_Start();

}

/*In both AP and client case, start the web server*/

App_NetworkServicesStart(pAppCtx);

}

App_NetworkServicesStart(APP_MAIN_CTX_T *pAppCtx)

{

/* get the ip information by calling geps API */

GsnNwIf_IpConfigGet(&pAppCtx->if0.nwifCtx, &s_nwParams);

/* Start HTTP Server */

App_HttpdStart(pAppCtx);

/* Start MDNS */

#ifdef APP_MDNS_ENABLE

App_MdnsInit(pAppCtx);

#endif

}

/*

Page 28: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 28 of 54 2016-06-07

* MDNS Init : Initialize values (host name and service names) used when

registering mDNS/DNS-SD service names and records

App_MdnsHostName – TLS_gs2k-xxxxxx

#define APP_NAME_SUFFIX "_TLS"

MDNS resource name for TLS : “TLS_gs2k-xxxxxx_TLS”

MDNS resource name for Prov : “TLS_gs2k-xxxxxx_Prov”

MDNS resource name for OTAFU : “TLS_gs2k-xxxxxx_Otafu”

*/

void App_MdnsInitValues(APP_MAIN_CTX_T *pAppCtx)

{

strcpy((char*)App_MdnsHostName, (void*)pAppCtx-

>config.sysIdConfig.name);

sprintf(App_MdnsAppSvcSrv, "%s" APP_NAME_SUFFIX, App_MdnsHostName);

#ifdef ADK_PROV_ENABLE

sprintf(App_MdnsProvSrv, "%s_Prov", App_MdnsHostName);

#endif

#ifdef ADK_OTAFU_ENABLE

sprintf(App_MdnsFwupSrv, "%s_Otafu", App_MdnsHostName);

#endif

}

Page 29: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 29 of 54 2016-06-07

5.4 TLS DATA HANDLING

1. HTTPD server starts the web server thread at port 80 with Thread Priority 16.

2. Registers the /gainspan/profile/tls URI for HTTP request handling.

3. AppTls_HttpApiCb API handles the HTTP GET request. Once HTTP GET request is received, XML format of the sensor values is created and sent in HTTP GET RESPONSE.

4. Temperature and Light sensors are connected to 12bit SAR ADC pins ADC_SAR_0_B and ADC_SAR_1_B.

5. Temperature and light sensors are read using ADC APIs.

6. Following diagram shows the HTTP GET REQUEST from client applications and embedded software sends the sensor data with HTTP GET RESPONSE.

Figure 7: HTTP GET Request/Response Flow Diagram

Page 30: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 30 of 54 2016-06-07

7. Wireless sniffer logs to highlight HTTP GET REQUEST and RESPONSE.

Code Ref:

AppTls_HttpApiCb(ttHttpdUserEvent event, const char* uri, ttHttpdUserConHandle

conHandle)

{

switch (event)

{

case TM_HTTPD_EVENT_BODY_RECV:

// receives and process the HTTP body buffer and parses for led status to take

appropriate action for LED ON/OFF.

bufferLen = GSN_HTTPD_BUF_SIZE;

//Get a buffer from the received HTTP request message body.

tfHttpdUserGetRequestBody(conHandle,(char *)buffer,(INT32

*)&bufferLen,0);

pPostBody = buffer;

pPostBody[bufferLen]=0;

pPostBody = (INT8 *)strstr((char const *)buffer, "<leds>");

pPostBody += strlen("<leds>");

if('o'== pPostBody[0] && 'n'== pPostBody[1])

{

App_LedStatusSet(1);

}

else

{

App_LedStatusSet(0);

}

break;

case TM_HTTPD_EVENT_SEND_READY:

// Ready to send response data. Reads the Temp/Light ADC and forms the XML buffer

to send the sensor data.

respLen = AppTls_CreateXmlResp(pAppCtx, buffer, conHandle);

GsnHttpd_SendBufferAndLastChunk(conHandle, buffer, respLen,

TM_BLOCKING_ON,

&errorCode);

break;

}

if(NULL != buffer)

{

GsnHttpd_ReleaseBuffer(buffer);

}

return GSN_HTTPD_SUCCESS;

}

AppTls_CreateXmlResp(APP_MAIN_CTX_T *pAppCtx, INT8* buffer, ttHttpdUserConHandle

conHandle)

{

#if ! defined (GS2100MS_EVB) && ! defined (GS2100M_EVB)

AppTls_TempOrLightGet( TLSdata ); // call this only for GS2011M_EVB

#endif

GsnWdd_RSSIGet(&pAppCtx->if0.wddCtx, (INT8*) &wRssi, sizeof(wRssi));

Page 31: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 31 of 54 2016-06-07

AppBatt_LatestBattValGet(&pAppCtx->appBattCtx, &battery);

LEDStatus = App_GetLedStatus();

LEDstsPtr = (UINT8 *)(LEDStatus==1?"on":"off");

sprintf((char *)buffer, "<tls><version>%s</version><lux>%d</lux><temp>%d</temp>"

"<battery>%d</battery><rssi>%d</rssi><leds>%s</leds></tls>",

TLS_HTTP_API_VERSION, TLSdata[1], TLSdata[0], battery, (signed

char)wRssi.rssi, LEDstsPtr );

#endif

GsnHttpd_SendBufferAndLastChunk(conHandle, buffer, strlen((char const

*)buffer), TM_BLOCKING_ON, &errorCode);

return 0;

}

AppTls_TempOrLightGet(UINT32* tlsTempSensorData)

{

GsnADC_Open(&adchandle,&adcconfig);

channel = GSN_ADC_SOURCE_CH_0 | (GSN_ADC_SOURCE_CH_1 << 4) |

(GSN_ADC_SOURCE_CH_END << 8);

GsnADC_PollRead(&adchandle,GSN_ADC_MODE_SINGLE,

channel,&adcrw,GSN_ADC_REF_EXTERNAL);

GsnADC_Close(&adchandle);

return GSN_SUCCESS;

}

Page 32: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 32 of 54 2016-06-07

5.4.1 Provisioning

Gainspan’s provisioning solution allows configuration of both Limited AP and Station modes of operation. Further, provisioning of the device can be performed with the device operating as either a Limited AP or a client. Limited AP mode is more suitable for initial device provisioning. Provisioning makes use of following URIs.

1 /gainspan/system/prov/scan_params

2 /gainspan/system/prov/ap_list 3 /gainspan/system/config/network

4 /gainspan/system/config/httpd

Code Ref:

App_httpd.c:

App_HttpdStart(APP_MAIN_CTX_T *pAppCtx)

{

#ifdef ADK_PROV_ENABLE

/* System Configuration URI Handler */

GsnHttpdApi_ConfigInit(App_ConfigCb);

#ifdef ADK_PROV_WPS_ENABLE

provConfig.pWpsCbFn = (GSN_HTTPD_PROV_WPS_CB_FN_T) AppWps_CbFn;

#endif /* ADK_PROV_WPS_ENABLE */

GsnHttpdApi_ProvInit(&provConfig);

#endif /* ADK_PROV_ENABLE */

/* API Configuration URI Handler */

GsnHttpdApi_ApiInit();

}

// GsnHttpdApi_ConfigInit registers "/gainspan/system/config" URI

GsnHttpdApi_ConfigInit(GSN_HTTPD_API_CONFIG_CB_FN cb_fn)

{

GsnHttpd_UriHandlerConfig("/gainspan/system/config",

GSN_HTTPD_URI_METHOD_GET_POST,

"Network Configuration", config_network_cb,

GSN_HTTPD_CONTENT_APP_XML);

}

// GsnHttpdApi_ConfigInit registers "/ gainspan/system/prov" URI

void GsnHttpdApi_ProvInit(GSN_HTTPD_PROV_CONFIG_T *pConfig)

{

GsnHttpd_UriHandlerConfig("/gainspan/system/prov",

GSN_HTTPD_URI_METHOD_GET_POST, "Provisioning API",

GsnHttpdApi_cb, GSN_HTTPD_CONTENT_APP_XML);

}

Page 33: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 33 of 54 2016-06-07

5.4.2 OTAFU

GainSpan Over the Air firmware update solution can be used to update the GS firmware images on module flash. OTAFU feature uses “/gainspan/system/fwuploc” HTTP URI for firmware upgrade service.

Code Ref:

App_HttpdStart(APP_MAIN_CTX_T *pAppCtx)

{

#ifdef ADK_OTAFU_ENABLE

AppOtafu_Init(pAppCtx);

#endif…

}

PUBLIC VOID AppOtafu_Init(APP_MAIN_CTX_T* pAppCtx)

{

GsnOtafu_Init(&otafuCtx);

}

#define GSN_HTTP_OTAFU_API_PATH "/gainspan/system/fwuploc"

GsnOtafu_Init(GSN_OTAFU_CTX_T* pCtx)

{

GsnHttpd_FileApiConfig(GSN_HTTP_OTAFU_API_PATH, GsnOtafu_Cb,

GSN_HTTPD_URI_METHOD_POST);

}

Page 34: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 34 of 54 2016-06-07

5.4.3 REST HTTP TLS API

GainSpan’s ADK model is based on REST style HTTP APIs. TLS resource is represented as a URI and interaction with it is performed using HTTP GET method. As there are no parameters to modify, HTTP POST is done for switching ON the LED. The state is represented in XML.

Resource URI Methods TLS

TLS (Temperature

and

Light Sensor)

/gainspan/profile/tls HTTP GET Retrieves a representation of the current state of the resource in XML format. The state comprises of the following:

• API version (version)

• Ambient light (lux)

• Temperature (temp)

• Battery voltage (battery)

• RSSI – Signal strength (rssi)

Note: XML tag is shown in brackets.

LED /gainspan/profile/tls HTTP POST Receives LED ON and OFF status resource in XML format.

Page 35: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 35 of 54 2016-06-07

5.5 XML FORMAT OF TLS DATA

A formula needs to be applied to each of the individual elements to get the values in standard units (Lux, Celcius, Volts).

<tls>

<version>0.8.1</version>

<lux>653</lux>

<temp>634</temp>

<battery>3300</battery>

<rssi>-100</rssi>

<leds>off</leds>

</tls>

Page 36: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 36 of 54 2016-06-07

5.6 AUTO CACHE FEATURE ON HOSTLESS TLS APPLICATION

Auto cache feature is where 128K of flash memory is mapped to 16K of SRAM memory thus saving SRAM space. In our GEPS platform we have around 121KB of patch code which used to occupy the SRAM and thus the heap space used to be reduced by that amount. To overcome this, the Auto Cache feature is implemented where the entire patch code is put in the auto cache section of flash and 16KB is allocated in SRAM to bring the patch code to SRAM as and when required. This is done entirely by the hardware.

In this case, the hardware loads the code in the Auto Cache area of the flash in 256 bytes segments into SRAM Auto Patch Area. This is completely hardware driven. Sections of 128K of flash code is brought into 16K of SRAM on demand with page swapping done when entire 16K RAM is filled.

This is by default present in TLS 5.2.x code.

Figure 8: AUTO Cache Mapping

Auto Patch

Control Block 2

FPT-Function Pointer Table

Data init Section Const Code

SRAM

Auto Cache Flash

16k

8k

128k

Module FLASH

Page 37: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 37 of 54 2016-06-07

Chapter 6. Native Application or Webpage Execution Sequence

This section provides the native application/webpage execution sequence.

6.1 TLS APPLICATION WEBPAGE

When TLS ADK boots up, it comes up in Limited-AP mode. Client (laptop) associates with GainSpan limited AP and when the browser is opened with the URL <IP address of Limited AP> /TLS.html,sensor values are displayed as follows:

Figure 9: tls.html page access from web browser

Page 38: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 38 of 54 2016-06-07

6.2 SCREENSHOTS OF IOS APPLICATION

When TLS ADK boots up, it comes up in Limited-AP mode. Client (iOS) associates with GainSpan limited AP and when the iOS based TLS Mobile Application tls_xx.ipa is opened the following screens are displayed:

Figure 10: iOS APP TLS Resource Discovery and Sensor Data Update.

6.3 SCREENSHOTS OF ANDROID APPLICATION

When TLS ADK boots up, it comes up in Limited-AP mode. Client (Android based phones/tab) associates with GainSpan limited AP and when the Android based TLS Mobile Application tls_xx.ipa is opened following screens are displayed.

Page 39: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 39 of 54 2016-06-07

All HTTP GET and POST requests are handled by the AppTls_HttpApiCb which is registered as part of AppTls_HttpApiInit where AppTls_HttpApiInit is called from App_HttpdStart. HTTP POST is handled via TM_HTTPD_EVENT_BODY_RECV and HTTP GET is handled via

TM_HTTPD_EVENT_SEND_READY

*********************************************************************************

*****************

AppTls_HttpApiCb(ttHttpdUserEvent event, const char* uri, ttHttpdUserConHandle

conHandle)

{

case TM_HTTPD_EVENT_BODY_RECV:

bufferLen = GSN_HTTPD_BUF_SIZE;

tfHttpdUserGetRequestBody(conHandle,(char *)buffer,(INT32

*)&bufferLen,0);

pPostBody = buffer;

pPostBody[bufferLen]=0;

pPostBody = (INT8 *)strstr((char const *)buffer, "<leds>");

pPostBody += strlen("<leds>");

if('o'== pPostBody[0] && 'n'== pPostBody[1])

{

App_LedStatusSet(1);

}

else

{

App_LedStatusSet(0);

}

break;

case TM_HTTPD_EVENT_SEND_READY:

respLen = AppTls_CreateXmlResp(pAppCtx, buffer, conHandle);

GsnHttpd_SendBufferAndLastChunk(conHandle, buffer, respLen,

TM_BLOCKING_ON,

&errorCode);

break;

}

*********************************************************************************

*****

Page 40: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 40 of 54 2016-06-07

Appendix A Reference Code

A.1 TLS ADK REFERENCE CODE FLOW

Page 41: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 41 of 54 2016-06-07

Page 42: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 42 of 54 2016-06-07

A.2 AUTO CACHE REFERENCE CODE FLOW

A.2.1 APPLICATION START-UP (APP_STARTUP.C)

#pragma section = "BSS_SECTION" /* Points to the BSS segment of

FLASH code */

#pragma section = "DATA_SECTION" /* Points to the DATA section of

FLASH code */

#pragma section = "APP_READWRITE_SECTION" /* Points to the readwrite

section of FLASH code */

#pragma section = "DATA_INIT_SECTION" /* Points to the DATA INIT section

of FLASH code */

#pragma section = "ROM_PATCH_FPT_SECTION" /* Points to the ROM PATCH FPT

section in FLASH code */

#pragma section = "APP_CODE_SECTION" /* Points to the APP CODE section in

FLASH code */

#pragma section = "ROM_PATCH_AUTO" /* Points to the ROM PATCH section in

FLASH code */

#pragma section = "FREE_MEM" /* Points to the ROM PATCH section in FLASH

code */

#else /*Store code in to FLASH. prefetch/flash cache during run time*/

/**********************************************************************

*FLASH FETCH

extern GSN_BYTE_POOL_LINK_T *pGsnBytePoolHead;

extern UINT32 romFwImageFlashAddr;/* This holds the starting address of

the App Fw*/

extern INT32 App_Main( void );

UINT32 GsnStartup_ClosestPowerOf2( unsigned int value );

BOOL

App_FlashIfFlashCheckAndConfigure();

/*************************************************************************

****

*Private definitions

**************************************************************************

**/

//sachin....This section is used when AUTO CACHE not defined....

#ifndef AUTO_CACHE

#define APP_STARTUP_COPY_PROG( dst, src, len) GsnFlashCache_BlkFetch( src,

dst, len, NULL );

#define CB1_RESERVED_SIZE 0x1000

#define FPT_RESERVED_SIZE 0x2000

#define GSN_STARTUP_RESERVED_SIZE 0x800

#define SRAM_START_ADDR 0x20000000

#define SRAM_END_ADDR 0x2007FFFF /* 512 */

#define FPT_LOCATION 0x20004000 /* 0x20004000

Location in RAM where the ROM

function pointers has to be

copied */

#define APP_CODE_SRAM_BLOCK1_ADDR 0x20040000 /* at 256KB */

#define APP_CODE_SRAM_BLOCK1_SIZE 0x40000 /* 256KB */

Page 43: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 43 of 54 2016-06-07

#define APP_CODE_SRAM_BLOCK2_ADDR 0x20080000 /* at 512KB */

#define APP_CODE_SRAM_BLOCK2_SIZE 0x10000 /* 16KB */

GSN_BYTE_POOL_LINK_T heapBytePool[4];/* create up to 4 byte poola to be

used as heap*/

#define WORD_ALIGNED_ADDR(a) (((a) & (~0x3)) + 0x4)

typedef struct HEAP_INFO

{

UINT32 start;

UINT32 size;

}HEAP_INFO_T;

extern APP_MAIN_CTX_T appCtx;

VOID

AppSm_GotoStandby(APP_MAIN_CTX_T *pAppCtx);

VOID

App_IdleHandler();

/*************************************************************************

****

*Function definitions

**************************************************************************

**/

void GsnStartup_Main( void )

{

UINT32 appFwImageFlashAddr;

UINT32 sectionFlshAddr,sectionSize;

HEAP_INFO_T heap[4] = {0};

UINT32 appCodeSize, appCodeSramEnd;

GSN_FLASHCACHE_BLK_REMAP_T remap;

UINT32 remapIndx = 1;

/* Program address space - Address assigned in icf file*/

UINT32 *autoPatchStart = __section_begin("ROM_PATCH_AUTO");

UINT32 *autoPatchEnd = __section_end("ROM_PATCH_AUTO");

UINT32 *fptStart = __section_begin("ROM_PATCH_FPT_SECTION");

UINT32 *fptEnd = __section_end("ROM_PATCH_FPT_SECTION");

UINT32 *bssStart = __section_begin("BSS_SECTION");

UINT32 *bssEnd = __section_end("BSS_SECTION");

UINT32 *dataStart = __section_begin("DATA_SECTION");

/*UINT32 *dataEnd = __section_end("DATA_SECTION");*/

UINT32 *appCodeStart = __section_begin("APP_CODE_SECTION");

UINT32 *appCodeEnd = __section_end("APP_CODE_SECTION");

UINT32 *dataInitStart = __section_begin("DATA_INIT_SECTION");

UINT32 *dataInitEnd = __section_end("DATA_INIT_SECTION");

UINT32 *freeMemStart = __section_begin("FREE_MEM");

//App_FlashIfFlashCheckAndConfigure();

appFwImageFlashAddr = romFwImageFlashAddr;

/* Copy data init section. "dataStart" gives absolute SRAM

location*/

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

((UINT32)autoPatchEnd -

(UINT32)autoPatchStart ) +

FPT_RESERVED_SIZE +

GSN_STARTUP_RESERVED_SIZE +

((UINT32)dataInitStart -

(UINT32)appCodeStart);

sectionSize = (UINT32)dataInitEnd - (UINT32)dataInitStart;

APP_STARTUP_COPY_PROG((UINT32)dataStart, sectionFlshAddr,

sectionSize);

/* Copy Function Pointer Table (FPT)*/

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

Page 44: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 44 of 54 2016-06-07

((UINT32)autoPatchEnd -

(UINT32)autoPatchStart );

sectionSize = (UINT32)fptEnd - (UINT32)fptStart;

APP_STARTUP_COPY_PROG((UINT32)FPT_LOCATION, sectionFlshAddr,

sectionSize);

/*Copy App code*/

appCodeSize = sectionSize = (UINT32)appCodeEnd -

(UINT32)appCodeStart;

if(appCodeSize > APP_CODE_SRAM_BLOCK1_SIZE) sectionSize =

APP_CODE_SRAM_BLOCK1_SIZE;

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

((UINT32)autoPatchEnd -

(UINT32)autoPatchStart ) +

FPT_RESERVED_SIZE +

GSN_STARTUP_RESERVED_SIZE;

APP_STARTUP_COPY_PROG((UINT32)APP_CODE_SRAM_BLOCK1_ADDR,

sectionFlshAddr, sectionSize);

/*remap*/

remap.codeAddr = (UINT32)appCodeStart + 1;

remap.remapIndex = remapIndx++;

remap.remapSize = APP_CODE_SRAM_BLOCK1_SIZE;

remap.sramAddr = APP_CODE_SRAM_BLOCK1_ADDR;

GsnFlashCache_BlkRemapSet(&remap);

appCodeStart += (sectionSize >> 2); /* devide the size by 4 as the

pointer is of type "UINT32 *" */

sectionFlshAddr += sectionSize;

appCodeSramEnd = APP_CODE_SRAM_BLOCK1_ADDR + sectionSize;/* Used to

calculate the heapat the end*/

if(appCodeStart < appCodeEnd)

{

appCodeSize = sectionSize = (UINT32)appCodeEnd -

(UINT32)appCodeStart;

if(appCodeSize > APP_CODE_SRAM_BLOCK2_SIZE) sectionSize =

APP_CODE_SRAM_BLOCK2_SIZE;

appCodeSramEnd += sectionSize + 1024;

APP_STARTUP_COPY_PROG((UINT32)APP_CODE_SRAM_BLOCK2_ADDR,

sectionFlshAddr, sectionSize);

/*remap*/

remap.codeAddr = (UINT32)appCodeStart + 1;

remap.remapIndex = remapIndx++;

remap.remapSize = APP_CODE_SRAM_BLOCK2_SIZE;

remap.sramAddr = APP_CODE_SRAM_BLOCK2_ADDR;

GsnFlashCache_BlkRemapSet(&remap);

}

/* Set uninitialised data section to zero*/

memset((void *)bssStart, 0, ((UINT32)bssEnd- (UINT32)bssStart));

/* Calculate the heap */

heap[0].start = (((UINT32)freeMemStart & ~3 ) + 8 );

heap[0].size = APP_CODE_SRAM_BLOCK1_ADDR - heap[0].start;

tx_byte_pool_create(&heapBytePool[0].bPool, NULL,

(void*)heap[0].start,

(UINT32)heap[0].size);

appCodeSramEnd = ( appCodeSramEnd & ~3 ) + 8;

heap[1].start = appCodeSramEnd;

heap[1].size = SRAM_END_ADDR - heap[1].start;

tx_byte_pool_create(&heapBytePool[1].bPool, NULL,

(void*)heap[1].start,

(UINT32)heap[1].size);

Page 45: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 45 of 54 2016-06-07

pGsnBytePoolHead = ( heap[1].size >= heap[0].size) ?

&heapBytePool[1] : &heapBytePool[0];

pGsnBytePoolHead->pNext = ( heap[1].size >= heap[0].size) ?

&heapBytePool[0] : &heapBytePool[1];

/* 3 blocks of 64K SRAM is released to wlan - Temporary*/

*((volatile UINT32 *)(0x40080008)) = (UINT32)0x1c;

/* Call APP MAIN */

App_Main();

/* This is the idle loop */

App_IdleHandler();

}

//sachin ....This is for Auto Flash.....Directly copied from S2W

#else

#define APP_STARTUP_COPY_PROG( dst, src, len) GsnFlashCache_BlkFetch( src,

dst, len, NULL );

#define CB1_RESERVED_SIZE 0xD000 //(64k - 8k FPT - 4k

startup) //0x1000

#define FPT_RESERVED_SIZE 0x2000

#define GSN_STARTUP_RESERVED_SIZE 0x1000

#define SRAM_START_ADDR 0x20000000

#define SRAM_END_ADDR 0x2007FFFF /* 512 */

#define FPT_LOCATION 0x20004000 /* 0x20004000

Location in RAM where the ROM

function pointers has to be

copied */

#define APP_CODE_SRAM_BLOCK1_ADDR 0x20040000 /* at 256KB */

#define APP_CODE_SRAM_BLOCK1_SIZE 0x40000 /* 256KB */

#define APP_CODE_SRAM_BLOCK2_ADDR 0x20080000 /* at 512KB */

#define APP_CODE_SRAM_BLOCK2_SIZE 0x10000 /* 16KB */

#define APP_AUTO_CACHE_SRAM_ADDR SRAM_START_ADDR

GSN_BYTE_POOL_LINK_T heapBytePool[4];/* create up to 4 byte poola to be

used as heap*/

#define WORD_ALIGNED_ADDR(a) (((a) & (~0x3)) + 0x4)

typedef struct HEAP_INFO

{

UINT32 start;

UINT32 size;

}HEAP_INFO_T;

void Cplusplus_Startup( unsigned int *sramAddr );

extern APP_MAIN_CTX_T appCtx;

VOID

AppSm_GotoStandby(APP_MAIN_CTX_T *pAppCtx);

VOID

App_IdleHandler();

/*************************************************************************

****

*Function definitions

**************************************************************************

**/

void GsnStartup_Main( void )

{

UINT32 appFwImageFlashAddr;

UINT32 sectionFlshAddr,sectionSize;

Page 46: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 46 of 54 2016-06-07

HEAP_INFO_T heap[4] = {0};

UINT32 appCodeSize, appCodeSramEnd;

GSN_FLASHCACHE_BLK_REMAP_T remap;

UINT32 remapIndx = 1;

/* Program address space - Address assigned in icf file*/

UINT32 *autoPatchStart = __section_begin("ROM_PATCH_AUTO");

UINT32 *autoPatchEnd = __section_end("ROM_PATCH_AUTO");

UINT32 *fptStart = __section_begin("ROM_PATCH_FPT_SECTION");

UINT32 *fptEnd = __section_end("ROM_PATCH_FPT_SECTION");

UINT32 *bssStart = __section_begin("BSS_SECTION");

UINT32 *bssEnd = __section_end("BSS_SECTION");

UINT32 *dataStart = __section_begin("DATA_SECTION");

/*UINT32 *dataEnd = __section_end("DATA_SECTION");*/

UINT32 *appCodeStart = __section_begin("APP_CODE_SECTION");

UINT32 *appCodeEnd = __section_end("APP_CODE_SECTION");

UINT32 *dataInitStart = __section_begin("DATA_INIT_SECTION");

UINT32 *dataInitEnd = __section_end("DATA_INIT_SECTION");

UINT32 *freeMemStart = __section_begin("FREE_MEM");

#if 0

volatile UINT32 flag = 1;

while(flag);

#endif

UINT32 *appCodeStartCopy = appCodeStart;

//App_FlashIfFlashCheckAndConfigure();

appFwImageFlashAddr = romFwImageFlashAddr;

/* Copy data init section. "dataStart" gives absolute SRAM

location*/

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

((UINT32)autoPatchEnd -

(UINT32)autoPatchStart ) +

FPT_RESERVED_SIZE +

GSN_STARTUP_RESERVED_SIZE +

((UINT32)dataInitStart -

(UINT32)appCodeStart);

sectionSize = (UINT32)dataInitEnd - (UINT32)dataInitStart;

APP_STARTUP_COPY_PROG( (UINT32)dataStart, sectionFlshAddr,

sectionSize);

/* Copy Function Pointer Table (FPT)*/

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE;

sectionSize = (UINT32)fptEnd - (UINT32)fptStart;

APP_STARTUP_COPY_PROG( (UINT32)FPT_LOCATION, sectionFlshAddr,

sectionSize);

/* Set Flasf Auto cache (Auto Patching )*/

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

FPT_RESERVED_SIZE + GSN_STARTUP_RESERVED_SIZE;

GsnFlashCache_PatchCtlSet(sectionFlshAddr, (UINT32) autoPatchStart,

APP_AUTO_CACHE_SRAM_ADDR);

/*Copy App code*/

sectionSize = (UINT32)appCodeEnd - (UINT32)appCodeStart;

sectionFlshAddr = appFwImageFlashAddr + CB1_RESERVED_SIZE +

((UINT32)autoPatchEnd -

(UINT32)autoPatchStart ) +

FPT_RESERVED_SIZE +

GSN_STARTUP_RESERVED_SIZE;

APP_STARTUP_COPY_PROG((UINT32)APP_CODE_SRAM_BLOCK1_ADDR,

sectionFlshAddr, sectionSize);

/*remap*/

remap.codeAddr = (UINT32)appCodeStart + 1;

remap.remapIndex = remapIndx++;

Page 47: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 47 of 54 2016-06-07

remap.remapSize = APP_CODE_SRAM_BLOCK1_SIZE;

remap.sramAddr = APP_CODE_SRAM_BLOCK1_ADDR;

GsnFlashCache_BlkRemapSet(&remap);

appCodeSramEnd = APP_CODE_SRAM_BLOCK1_ADDR + sectionSize;/* Used to

calculate the heapat the end*/

/* Set uninitialised data section to zero*/

memset((void *)bssStart, 0, ((UINT32)bssEnd- (UINT32)bssStart));

/* Calculate the heap */

// heap[0].start = WORD_ALIGNED_ADDR(freeMemStart) ;//freeMemStart ;

heap[0].start = ((((UINT32)freeMemStart) & (~0x3)) +

0x4);//freeMemStart ;

heap[0].size = APP_CODE_SRAM_BLOCK1_ADDR - heap[0].start;

tx_byte_pool_create(&heapBytePool[0].bPool, NULL,

(void*)heap[0].start,

(UINT32)heap[0].size);

heap[1].start = WORD_ALIGNED_ADDR(appCodeSramEnd);//appCodeSramEnd;

heap[1].size = SRAM_END_ADDR - heap[1].start;

tx_byte_pool_create(&heapBytePool[1].bPool, NULL,

(void*)heap[1].start,

(UINT32)heap[1].size);

pGsnBytePoolHead = ( heap[1].size >= heap[0].size) ?

&heapBytePool[1] :

&heapBytePool[0];

pGsnBytePoolHead->pNext = ( heap[1].size >= heap[0].size) ?

&heapBytePool[0] :

&heapBytePool[1];

pGsnBytePoolHead->pNext->pNext = NULL;

/* 3 blocks of 64K SRAM is released to wlan - Temporary*/

*((volatile UINT32 *)(0x40080008)) = (UINT32)0x1c;

// Cplusplus_Startup( (unsigned int *)0x180000 );

//Cplusplus_Startup( appCodeStartCopy );

/* Call APP MAIN */

App_Main();

/* This is the idle loop */

App_IdleHandler();

}

#endif

#endif/*NO_FLASH_FETCH*/

Page 48: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 48 of 54 2016-06-07

A.2.2 APPLICATION MAIN THREAD (APP_MAIN_THREAD.C)

………………………………………………………………………….

………………………………………………………………………..

PUBLIC VOID AppMainCtx_Init(VOID)

{

UINT32 msgSizeInWords;

memset((INT8 *)&appCtx, 0, sizeof(appCtx));// REVERT REMOVE

globalAppCtxPtr = &appCtx;

msgSizeInWords = GsnOsal_QueueMsgSizeInWords(sizeof(APP_MAINTASK_MSG_T));

/**< Creating the Mailbox to receive messages */

GsnOsal_QueueCreate( &appMainThreadMsgQueue, msgSizeInWords,

( UINT8*

)appMainThreadMsgQueueBuf,

sizeof( appMainThreadMsgQueueBuf

));

/**< Create the main Application Thread */

#ifdef GSN_DBG_STACK_PATTERN_FILL /* Only for debug */

memset(appMainCtxThreadStack, 0x5a, sizeof(appMainCtxThreadStack));

#endif

GsnPwrMgmt_Init(&appCtx.pwrMgmtCtx);

#ifdef APP_OPT_PS_IN_PSPOLL

GsnPwrMgmt_StdbyDisable(&appCtx.pwrMgmtCtx);

#endif

#ifdef AUTO_CACHE

GsnOsal_ThreadCreate(AppMainCtx_ThreadEntry, &appCtx, &appMainCtxThread,

"App Main Ctx", APP_CFG_MAIN_THREAD_PRIORITY, (UINT8

*)appMainCtxThreadStack,

sizeof(appMainCtxThreadStack), GSN_OSAL_THREAD_INITIAL_SUSPENDED);

#else

GsnOsal_ThreadCreate(AppMainCtx_ThreadEntry, &appCtx, &appMainCtxThread,

"App Main Ctx", APP_CFG_MAIN_THREAD_PRIORITY, (UINT8

*)appMainCtxThreadStack,

sizeof(appMainCtxThreadStack), GSN_OSAL_THREAD_INITIAL_READY);

#endif

/* Define the test threads. */

PRIVATE VOID

AppMainCtx_ThreadEntry(UINT32 ctx)

{

……………………………….

………………………………

/* Initialise Wpa Suppliacnt*/

App_WpaSupplicantInit(pAppCtx);

App_RandomNumGenInit();

APP_BsdLayerInit(pAppCtx, &pAppCtx->if0);

/*initialise an interface on device Index 0 of Wlan Nw type STA*/

App_DefaultIfInit(pAppCtx, &pAppCtx->if0);

//sachin

#ifndef AUTO_CACHE

App_WaitOnLock();

#endif

if(GSN_WIF_SYS_BOOT_NORMAL_BOOT != GSN_BOOT_REASON_GET())

{

/*Open the interface. Need to open the interface after wdd and nwif

initialisations?*/

App_InterfaceStart(pAppCtx, &pAppCtx->if0);

}

App_DfltWlanCfgSet(pAppCtx, &pAppCtx->if0);

}

……………………………………………….

………………………………………………..

Page 49: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 49 of 54 2016-06-07

PRIVATE GSN_STATUS

App_WlanBootReq(APP_MAIN_CTX_T *pAppCtx)

{

…………………………………….

……………………………………

wlanRespTimeoutTmrHndl = GsnSoftTmr_Start(&wlanRespTimeoutTmr,

GSN_SOFT_TMR_ONESHOT, 0,

SEC_TO_SYSTIME(10),

App_WlanRespTimeoutTmrCb, NULL);

GsnSysCtl_BootReq_Patch(&pAppCtx->sysCtlCtx, &bootReqParm,

App_WlanBootIndCb, pAppCtx);

AppDbg_Printf("BootReq %d %d\r\n", bootReqParm.bootReason,

bootReqParm.bootSubreason);

/*Wait for Boot indication*/

//sachin

#ifdef AUTO_CACHE

App_WaitOnLock();

#endif

return GSN_SUCCESS;

}

A.2.3 APPLICATION NETWORK SERVICE (APP_NETWORK_SERVICE.C)

………………………………………………………………………….

PUBLIC VOID HeapAvailable()

{

ULONG heap1Size = heapBytePool[0].bPool.tx_byte_pool_size;

ULONG heap2Size = heapBytePool[1].bPool.tx_byte_pool_size;

ULONG heap1Available = heapBytePool[0].bPool.tx_byte_pool_available;

ULONG heap2Available = heapBytePool[1].bPool.tx_byte_pool_available;

ULONG heap1Fragments = heapBytePool[0].bPool.tx_byte_pool_fragments;

ULONG heap2Fragments = heapBytePool[1].bPool.tx_byte_pool_fragments;

AppDbg_Printf("\r\n****************************\r\n");

AppDbg_Printf("heap1Size = %u, heap2Size = %u, totalHeapSize = %u\r\n",

heap1Size, heap2Size, heap1Size+heap2Size);

AppDbg_Printf("heap1Available = %u, heap2Available = %u,

totalHeapAvailable = %u\r\n", heap1Available, heap2Available,

heap1Available+heap2Available);

AppDbg_Printf("heap1Fragments = %u, heap2Fragments = %u\r\n",

heap1Fragments, heap2Fragments);

AppDbg_Printf("****************************\r\n");

}

………………………………………………………………………..

Page 50: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 50 of 54 2016-06-07

A.2.4 APPLICATION FLASH FETCH AUTOCACHE

(APP_FLASHFETCH_AUTOCACHE.ICF)

/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */

/*

ROM :

---------------------------------------------0x00000000

| |

| ROM (512K) |

| |

| |

---------------------------------------------0x0007FFFF

SRAM :

_________________________________________ 0x20000000

| |

| 16KB reserved for ROM PATCH AUTO |

| |

|---------------------------------------|

| |

| 8KB reserved for ROM PATCH FPT |

| |

|---------------------------------------|

| |

| 8KB reserved for predefined heap |

| ( Heap 1) |

|---------------------------------------|

| |

| |

| |

| |

| |

|---------------------------------------| 0x2007FFFF

Dual Port RAM:

---------------------------------------------0x20200000

| |

| Dual Port RAM (64K) |

| |

| |

---------------------------------------------0x2020FFFF

*/

define symbol _APP_RAM_START_ = 0x200121c8;/* First 192HB 0x20000000 -

0x2002FFFF is used by ROM. As defined in rom.icf*/

define symbol _APP_CODE_SRAM_STRAT = 0x20040000; /* Code is placed at 256

KB*/

define symbol _APP_RAM_END_ = 0x2007FFFF;

/*-Specials-*/

/* Max size that can be assigned to this is the limitation of RAM size

and it has to be power of 2 */

define symbol __APP_CODE_SIZE__ = 0x00080000; /* 512 KB*/

Page 51: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 51 of 54 2016-06-07

/* Should be 128KB. DONT MODIFIY THIS */

define symbol __ROM_AUTO_PATCH_SIZE_IN_FLASH__ = 0x00020000;

/* It is 16KB. DONT MODIFIY THIS */

define symbol __ROM_AUTO_PATCH_SIZE_IN_SRAM___ = 0x00004000;

/* Should be 8KB. DONT MODIFIY THIS */

define symbol __ROM_PATCH_FPT_SIZE__ = 0x00002000;

/* Should be 2KB. DONT MODIFIY THIS */

define symbol __APP_STARTUP_CODE_SIZE__ = 0x00000800;

/*- Memory Regions for readonly section -*/

define symbol __ICFEDIT_region_ROM_AUTO_PATCH_start__ = 0x00100000;

define symbol __ICFEDIT_region_ROM_AUTO_PATCH_end__ =

__ICFEDIT_region_ROM_AUTO_PATCH_start__ +

__ROM_AUTO_PATCH_SIZE_IN_FLASH__ - 1;

define symbol __ICFEDIT_region_ROM_PATCH_FPT_start__ =

__ICFEDIT_region_ROM_AUTO_PATCH_end__ + 1;

define symbol __ICFEDIT_region_ROM_PATCH_FPT_end__ =

__ICFEDIT_region_ROM_PATCH_FPT_start__

+

__ROM_PATCH_FPT_SIZE__ - 1;

define symbol __ICFEDIT_region_APP_FLASH_STARTUP_start__ =

__ICFEDIT_region_ROM_PATCH_FPT_end__ + 1;

define symbol __ICFEDIT_region_APP_FLASH_STARTUP_end__ =

__ICFEDIT_region_APP_FLASH_STARTUP_start__ +

__APP_STARTUP_CODE_SIZE__ - 1;

/* The start address is made aligned to __APP_CODE_SIZE__ */

define symbol __ICFEDIT_region_APP_code_start__ =

(__ICFEDIT_region_APP_FLASH_STARTUP_end__ + 1 + __APP_CODE_SIZE__ - 1) &

~(__APP_CODE_SIZE__ - 1 );

define symbol __ICFEDIT_region_APP_Code_end__ =

__ICFEDIT_region_APP_code_start__ + __APP_CODE_SIZE__ - 1;

/*-Memory Regions for readwrite section - */

define symbol __ICFEDIT_region_APP_RAM_start__ = _APP_RAM_START_;

define symbol __ICFEDIT_region_APP_RAM_end__ = _APP_CODE_SRAM_STRAT - 1;

/**** End of ICF editor section. ###ICF###*/

define memory mem with size = 4G;

define region APP_FLASH_STARTUP_region =

mem:[from __ICFEDIT_region_APP_FLASH_STARTUP_start__ to

__ICFEDIT_region_APP_FLASH_STARTUP_end__];

define region ROM_AUTO_PATCH_region =

mem:[from __ICFEDIT_region_ROM_AUTO_PATCH_start__ to

__ICFEDIT_region_ROM_AUTO_PATCH_end__];

define region ROM_PATCH_FPT_region =

mem:[from __ICFEDIT_region_ROM_PATCH_FPT_start__ to

__ICFEDIT_region_ROM_PATCH_FPT_end__];

/*App code and the data init section*/

define region APP_CODE_region =

mem:[from __ICFEDIT_region_APP_code_start__ to

__ICFEDIT_region_APP_Code_end__];

Page 52: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 52 of 54 2016-06-07

/* App read wirite region */

define region APP_RAM_region =

mem:[from __ICFEDIT_region_APP_RAM_start__ to

__ICFEDIT_region_APP_RAM_end__ ];

/* Contains both initialized and uninitialized data */

define block BSS_SECTION

{

section .bss

};

/* Contains only initailized data section */

define block DATA_SECTION

{

section .data

};

/* Conatins the initial values for initialized data segment */

define block DATA_INIT_SECTION

{

section .data_init

};

define block ROM_PATCH_AUTO

{

readonly object rom_patch_auto.a, section .text object rom_patch_app.a,

section .rodata object rom_patch_app.a,

};

/* APP code section except the data init section, readonly secions of

rom_patch_fpt, rom_patch_auto library. This contains the readonly section of

geps_prefetch library

*/

define block APP_CODE_SECTION

{

section .text, section .rodata, readonly

}

except

{

section __DLIB_PERTHREAD, section .data_init, readonly object

rom_patch_fpt.a,

readonly object rom_patch_auto.a, readonly object app_startup.o,

section .text object rom_patch_app.a, section .rodata object

rom_patch_app.a

};

define block ROM_PATCH_FPT_SECTION

{

readonly object rom_patch_fpt.a

};

define block FREE_MEM with size = 0x04, alignment = 4 { };

initialize manually { readwrite };

initialize by copy with packing = none { section __DLIB_PERTHREAD }; /*

Required in a multi-threaded application */

do not initialize { section .noinit, readwrite };

place in ROM_AUTO_PATCH_region { block ROM_PATCH_AUTO };

place in ROM_PATCH_FPT_region { block ROM_PATCH_FPT_SECTION };

place in APP_FLASH_STARTUP_region { readonly object app_startup.o };

place in APP_CODE_region { block APP_CODE_SECTION, block

DATA_INIT_SECTION, };

place in APP_RAM_region { block BSS_SECTION, readwrite, section

__DLIB_PERTHREAD, block DATA_SECTION };

Page 53: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview

GS2K TLS ADK Application Note

80560NT11587A Rev. 1.0 Page 53 of 54 2016-06-07

/* The _tx_initialize_low_level function inside of tx_initialize_low_level.s

also determines

the first available address for use by the application, which is supplied as

the sole input parameter to your application definition function,

tx_application_define. To accomplish this, a section is created in

tx_initialize_low_level.s called FREE_MEM.

!!!!

*/place in APP_RAM_region {block FREE_MEM };

NOTE: This section must be located after all other RAM sections in memory

Page 54: GS2K TLS ADK Application Note · GS2K TLS ADK Application Note 80560NT11587A Rev. 1.0 Page 9 of 54 2016-06-07 Chapter 1. Introduction 1.1 SCOPE This document provides an overview