AirPrime - Open AT Tutorial - Rev1.0 PDF
AirPrime - Open AT Tutorial - Rev1.0 PDF
AirPrime - Open AT Tutorial - Rev1.0 PDF
Preface
2
Open AT® TUTORIAL
Preface
PREFACE
Welcome to the programming guide to Open AT, the operating system dedicated to wireless
Machine-to-Machine (M2M) development.
About M2M
Simply said, M2M includes all businesses, technologies and services whose primary purpose is to
create a data link exchange between machines, and not between individuals. Typical examples
are remotely reading and managing power consumption (metering), in-vehicle diagnostic,
assistance and emergency systems (fleet and automotive), remote patient monitoring
(healthcare), home & industrial alarms (security) and many more.
The objective of Open AT is to provide a complete software and tool suite to facilitate the
creation, deployment and management of such applications in small and constrained embedded
environments.
Open AT was created in 1998, a couple of years after Wavecom (now Sierra Wireless) created the
first cellular wireless module, named WISMO 1A. At that time, it was a 40mm by 64mm, dual-
sided 900 MHz GSM device, and was running on an ARM6 processor. It was an impressive
industrial achievement at the time, even if its features pale in comparison to the todayr’s WISMO
228: as small as 25mm by 25mm, single sided, GSM/GPRS, 4 bands, with powerful ARM926
processor running at hundreds of MHz.
In these early days of GSM technology, we were selling most of these devices to handset
manufacturers. But these small modules were already running much more than a proprietary
Protocol Stack as the whole User Interface was also sharing the modest ARM5 processor.
Wavecom was providing a simple SDK to create a sophisticated UI, although at this time the
concept of color screen and multimedia graphical devices was not very common.
3
Open AT® TUTORIAL
Preface
Alongside with the handset business, Wavecom was an early believer in M2M and the very same
WISMO 1A device had a specific software version that would enable it to be driven through AT
commands, similar to a regular PSTN modem. GPRS did not exist at the time, but CSD (Circuit-
Switched Data), Fax and SMS were used for M2M.
The usual architecture was to have a micro-controller or processor running a user application
(early Telemetry, Fleet management or even Wireless Local Loop) that would control the WISMO
1A device through these AT commands.
Of course, a natural parallel with the handset architecture model was immediately to allow the
same capability to run the application software directly on the module instead of an external
processor, as in many cases an M2M application was less demanding than a handset UI. But it was
not a simple development cycle and the flexibility requirements were (and still are) very different:
A handset UI is often a bigger effort, hence it made sense for customers to allocate a fair
amount of time and efforts to understand a SDK – it is worth the investment, even if the SDK
is complex
Change of features, updates, improvement happen quite often in M2M, so a rapid design
cycle for small application was needed where, to the contrary, UI changes after a handset
commercial launch are rare
Handset suppliers can afford the burden of doing an extensive certification process thanks to
the high volume and the small amount of software version per model. M2M customers
cannot.
Embedded developers are very familiar with C and they like it, despite (or because of) its very
“unsafe” nature
The interest of using our module as an application processor is a mix of cost, size and
availability of SDK (pre-existing libraries). But any sort of interpreted language has a large
memory footprint that would at least partly void the cost interest
A lot of applications, even if they are small, do require some sort of real time capability, to
drive IO or peripherals, so at least one language “close to the metal” was needed.
4
Open AT® TUTORIAL
Preface
Finally, using C as the main programming language was the best compromise, with a decent
isolation and protection between user space and kernel space. Thus the module was delivered
with pre-loaded firmware and the possibility to download a user application without linking both.
Another consideration taken into account was the possibility to provide an easy transition from
using an external processor connected to a modem through AT commands to sharing the same
CPU. Obviously, allowing the user application to send the same AT commands, but directly from
within the module provided this smooth transition - “Open AT” was born.
Many years and millions of devices later, Open AT’s simple AT command mode has been
improved with a complete API to facilitate application development. This is the ‘adl’ interface
which allows application to do native calls to the kernel, instead of sending and receiving AT
commands. This is faster, easier, organized by family of services and a good basis to add
extensions, or plug-ins (like GPS, TCP/IP, Security and more). Nevertheless, the built-in capability
to send and receive AT commands has been and will be maintained.
What might be surprising while discovering this system is the choice of an event-driven
programming paradigm, which is not so usual in the embedded space. Although it requires a
slightly different way to build a program, this brings multiple benefits, including:
Tools are also a very important topic that all developers pay great attention to - in fact, many
surveys show that this is a primary concern. A few years ago, we decided to base our entire IDE on
the well-recognized, open Eclipse™ suite. The free Developer Studio now includes all modern
features of a fully integrated environment and there is continued focus to deliver a very polished
development and debugging experience.
One last word regarding programming paradigm and languages: the initial development language
chosen for Open AT is C, for the benefit of speed (real time) and efficiency. But it is also
understood that different needs require different languages. Instead of opposing C and scripting,
both are provided to be able to write the low layer, HW-connected drivers in C for data extraction
and be able to benefit from the ease and speed of development of 4G languages for data
manipulation.
5
Open AT® TUTORIAL
Preface
Open AT does not impose only one language and Lua has been added as an open source, free to
use Language and Virtual Machine. It also offers very easy integration with what is written in C, all
with the minimum penalty for a VM and a 4G language. To take full benefit of such a system, a
complete 4G modeling environment named Developer Suite is available and we plan to bring
more on languages and tools soon.
Sierra Wireless hopes this guide will serve well in discovering and using Open AT. Don’t hesitate to
join our forum and exchange with developers at https://forum.sierrawireless.com/.
Philippe Guillemette
Chief Technology Officer
6
Open AT® TUTORIAL
Table of Contents
Contents
TABLE OF CONTENTS
CHAPTER 1 29
About this Training Courseware ................................................................................................................ 29
1. Objective .................................................................................................................................... 29
2. Audience .................................................................................................................................... 29
3. Pre-requisites ............................................................................................................................. 29
CHAPTER 2 31
Introduction to Open AT®.......................................................................................................................... 31
1. Objective .................................................................................................................................... 31
2. What is Open AT? ...................................................................................................................... 31
3. Areas of Application................................................................................................................... 32
4. Advantages of using Open AT .................................................................................................... 33
CHAPTER 3 35
Embedded Software Architecture ............................................................................................................. 35
1. Objective .................................................................................................................................... 35
2. Embedded Software Architecture ............................................................................................. 35
3. ADL Interfaces ............................................................................................................................ 36
4. Mandatory Embedded Application Code .................................................................................. 37
5. Open AT OS Memory Resources ................................................................................................ 38
6. Open AT Application Running Modes ........................................................................................ 38
6.1. Target Mode .............................................................................................................................. 38
6.2. Remote Mode ............................................................................................................................ 38
CHAPTER 4 41
Software Installation ................................................................................................................................ 41
1. Objective .................................................................................................................................... 41
2. What is Sierra Wireless Software Suite?.................................................................................... 41
3. System Requirements ................................................................................................................ 41
4. Hardware Requirements............................................................................................................ 41
5. Installing Sierra Wireless Software Suite ................................................................................... 42
7
Open AT® TUTORIAL
Table of Contents
CHAPTER 5 51
Open AT Project Development.................................................................................................................. 51
1. Objective .................................................................................................................................... 51
2. Creating an Open AT Application Project using Developer Studio ............................................ 51
2.1. Using Developer Studio to create Open AT Application ............................................................ 51
2.2. Compiling and executing the project ......................................................................................... 55
2.2.1. Target Mode .............................................................................................................................. 55
2.2.2. Remote Mode ............................................................................................................................ 57
2.3. Debugging Open AT Application in Remote mode .................................................................... 59
CHAPTER 6 63
Running Open AT® Application and Using Developer Studio ...................................................................... 63
1. Objective .................................................................................................................................... 63
2. Developer Studio ....................................................................................................................... 63
2.1. Target Management Perspective............................................................................................... 64
2.2. Open AT Perspective.................................................................................................................. 68
2.3. Debug Perspective ..................................................................................................................... 68
3. Open AT Application .................................................................................................................. 68
3.1. ARM ELF GCC ............................................................................................................................. 68
3.2. ARM EABI GCC ........................................................................................................................... 69
3.3. RVDS .......................................................................................................................................... 69
3.4. MINGW ...................................................................................................................................... 69
3.5. Comparison between the types of compilers ............................................................................ 70
3.6. Limitations of Compilers ............................................................................................................ 70
4. Open AT Application Execution ................................................................................................. 70
4.1. Target Application Execution ..................................................................................................... 70
4.2. Remote Application Execution .................................................................................................. 71
5. Introduction to GDB................................................................................................................... 71
6. Introduction to JTAG .................................................................................................................. 72
6.1. Need for JTAG ............................................................................................................................ 72
6.2. JTAG in Sierra board .................................................................................................................. 72
6.3. AirPrime WMP Series Settings ................................................................................................... 73
6.3.1. Enabling JTAG Debug mode: +WCFM ........................................................................................ 73
6.3.2. Activation JTAG Debug Mode: +WDEBUG ................................................................................. 74
6.3.3. Resetting the AirPrime WMP Series .......................................................................................... 74
7. Functioning Modes .................................................................................................................... 74
7.1. Standalone External Application................................................................................................ 75
7.2. Embedded Application in Standalone Mode ............................................................................. 76
7.3. Cooperative Mode ..................................................................................................................... 76
8
Open AT® TUTORIAL
Table of Contents
CHAPTER 7 79
AT Commands and Responses .................................................................................................................. 79
1. Objective .................................................................................................................................... 79
2. Responses .................................................................................................................................. 79
3. Classification of Responses ........................................................................................................ 80
3.1. Terminal Response .................................................................................................................... 80
3.2. Unsolicited Response................................................................................................................. 80
3.3. Intermediate Response.............................................................................................................. 80
4. Subscribing to Unsolicited Responses ....................................................................................... 80
5. Unsubscribing from Responses.................................................................................................. 82
6. Sample Code .............................................................................................................................. 83
7. Sending Responses from the Open AT Application ................................................................... 83
7.1. adl_atSendResponse API ........................................................................................................... 84
7.2. adl_atSendResponseSpe API ..................................................................................................... 85
7.3. adl_atSendStdResponse API ...................................................................................................... 86
7.4. adl_atSendStdResponseSpe API ................................................................................................ 87
7.5. adl_atSendStdResponseExt API ................................................................................................. 88
7.6. adl_atSendStdResponseExtSpe API ........................................................................................... 89
7.7. adl_atSendStdResponseExtStr API............................................................................................. 90
7.8. adl_atSendUnsoResponse API ................................................................................................... 91
7.9. adl_atSendResponsePort () macro ............................................................................................ 92
7.10. adl_atSendStdResponsePort() macro ........................................................................................ 92
7.11. adl_atSendStdResponseExtPort () macro ................................................................................. 93
7.12. Sample Code .............................................................................................................................. 94
8. Sending Standard AT Commands from the Open AT Application.............................................. 94
8.1. adl_atCmdCreate API ................................................................................................................. 94
8.2. adl_atCmdSend () API ................................................................................................................ 97
8.3. adl_atCmdSendExt () API ........................................................................................................... 97
8.4. adl_atCmdSendText () API ......................................................................................................... 98
8.5. Sample Code .............................................................................................................................. 99
8.6. Sample Code ............................................................................................................................ 100
8.7. Creating Custom AT Commands .............................................................................................. 101
8.8. Unsubscribing AT Commands .................................................................................................. 104
8.9. Setting Quiet Mode ................................................................................................................. 104
8.10. Sample Code ............................................................................................................................ 105
CHAPTER 8 107
AT Services ..............................................................................................................................................107
1. Objective .................................................................................................................................. 107
2. AT Standard String Set ............................................................................................................. 107
3. APIs .......................................................................................................................................... 108
3.1. Getting a String Response ID ................................................................................................... 108
3.2. Getting an ID along with an Optional Response Argument ..................................................... 108
3.3. Checking for the Last Response String ..................................................................................... 109
9
Open AT® TUTORIAL
Table of Contents
CHAPTER 9 113
Timer Service ..........................................................................................................................................113
1. Objective .................................................................................................................................. 113
2. Timers ...................................................................................................................................... 113
3. Types of Timers ........................................................................................................................ 113
3.1. Cyclic Timers ............................................................................................................................ 114
3.2. Non-Cyclic Timers .................................................................................................................... 114
4. Using Timers in Open AT Applications ..................................................................................... 114
4.1. Subscribing and Starting a Timer ............................................................................................. 114
4.2. Unsubscribing a Timer ............................................................................................................. 116
5. Sample Code ............................................................................................................................ 117
5.1. Subscribing to a non-cyclic timer ............................................................................................. 117
5.2. Subscribing to a cyclic timer .................................................................................................... 118
CHAPTER 10 119
Error Management Service ......................................................................................................................119
1. Objective .................................................................................................................................. 119
2. Introduction ............................................................................................................................. 119
3. Error Management APIs........................................................................................................... 119
3.1. Subscribing to the Error Management Service ........................................................................ 119
3.2. Unsubscribing from the Error Management Service ............................................................... 120
3.3. Handling an Error ..................................................................................................................... 121
3.4. Start Backtrace analysis ........................................................................................................... 121
3.5. Retrieve next Backtrace ........................................................................................................... 121
3.6. Erase all backtraces ................................................................................................................. 122
3.7. Get the current analysis state .................................................................................................. 122
4. Sample Code ............................................................................................................................ 123
CHAPTER 11 125
Memory Management.............................................................................................................................125
1. Objective .................................................................................................................................. 125
2. Sections in RAM ....................................................................................................................... 125
3. Open AT OS RAM ..................................................................................................................... 125
4. Memory Management in Open AT OS ..................................................................................... 125
5. Allocating Memory .................................................................................................................. 126
6. Releasing Memory ................................................................................................................... 127
6.1. The adl_memRelease macro ................................................................................................... 127
6.2. The adl_memRelease Function................................................................................................ 127
10
Open AT® TUTORIAL
Table of Contents
CHAPTER 12 131
Debug Traces...........................................................................................................................................131
1. Objective .................................................................................................................................. 131
2. Debug Traces in an Open AT Application................................................................................. 131
3. Build Configuration Macros ..................................................................................................... 131
3.1. Debug Configuration ................................................................................................................ 131
3.2. Full Debug Configuration ......................................................................................................... 131
3.3. Release Configuration .............................................................................................................. 131
3.4. TRACE macro............................................................................................................................ 132
3.5. DUMP macro............................................................................................................................ 132
3.6. FULL TRACE macro ................................................................................................................... 132
3.7. FULL DUMP macro ................................................................................................................... 132
4. Displaying the Debug Trace ..................................................................................................... 132
5. Dumping the buffer ................................................................................................................. 133
6. Sample Code ............................................................................................................................ 135
CHAPTER 13 137
Flash Memory .........................................................................................................................................137
1. Objective .................................................................................................................................. 137
2. Flash Memory .......................................................................................................................... 137
3. Flash APIs ................................................................................................................................. 138
3.1. Subscribing to Flash Objects .................................................................................................... 138
3.2. Flash Object Exist Function ...................................................................................................... 139
3.3. Erasing the Flash Memory ....................................................................................................... 139
3.4. Writing Objects to the Flash Memory ..................................................................................... 140
3.5. Reading from the Flash Memory ............................................................................................. 141
3.6. Remaining Flash Memory ........................................................................................................ 142
3.7. Handle ID Count ....................................................................................................................... 142
3.8. Handle Memory Size ................................................................................................................ 142
4. Sample Code ............................................................................................................................ 143
CHAPTER 14 147
Application and Data Storage Service ......................................................................................................147
1. Objective .................................................................................................................................. 147
2. Application and Data Storage Memory ................................................................................... 147
3. Uses of A&D Storage................................................................................................................ 148
4. Subscribing to A&D Storage Services ....................................................................................... 148
11
Open AT® TUTORIAL
Table of Contents
CHAPTER 15 167
Secured Data Storage Service ..................................................................................................................167
1. Objective .................................................................................................................................. 167
2. Introduction ............................................................................................................................. 167
3. Configuring Security Feature in Embedded module ................................................................ 167
4. Secured Data Storage APIs....................................................................................................... 168
4.1. Retrieving Information about the Secured Data Storage ........................................................ 168
4.2. Storing Secured Data ............................................................................................................... 169
4.3. Reading Secured Data .............................................................................................................. 169
4.4. Retrieving Secured Data Entry Size .......................................................................................... 170
4.5. Deleting Secured Data Entry .................................................................................................... 171
4.6. Updating Cryptographic Keys .................................................................................................. 171
5. Sample Code ............................................................................................................................ 172
CHAPTER 16 175
Flow Control Management ......................................................................................................................175
1. Objective .................................................................................................................................. 175
2. Flow Control Manager ............................................................................................................. 175
2.1. V24 Serial ................................................................................................................................. 176
2.2. GSM and GPRS Flows ............................................................................................................... 176
3. Flow Control Architecture ....................................................................................................... 176
3.1. V24/USB Serial Flow in Data Mode from/to an Open AT Application ..................................... 177
3.2. V24/USB Serial Link Switched in the AT Mode ........................................................................ 177
12
Open AT® TUTORIAL
Table of Contents
3.3. GSM and GPRS Data Flow from an Open AT Application ........................................................ 178
4. FCM Service Provided by ADL Library ...................................................................................... 179
4.1. FCM Flows and Subscription .................................................................................................... 179
4.2. Unsubscribing FCM Flow ......................................................................................................... 182
4.3. Releasing FCM Credits ............................................................................................................. 183
4.4. Switching Serial Link State ....................................................................................................... 184
4.5. Sending Data on the Requested FCM Flow ............................................................................. 184
4.6. Sending Unprocessed Data on the FCM FLOW ........................................................................ 185
4.7. Get Buffer State ....................................................................................................................... 186
4.8. adl_fcmIsAvailable function..................................................................................................... 187
5. Sample Code ............................................................................................................................ 187
CHAPTER 17 189
Open UART .............................................................................................................................................189
1. Objective .................................................................................................................................. 189
2. Understanding UART Signals ................................................................................................... 190
2.1. RTS (Request To Send) ............................................................................................................. 190
2.2. CTS (Clear To Send) .................................................................................................................. 191
2.3. DTR (Data Terminal Ready) ...................................................................................................... 191
2.4. DSR (Data Set Ready) ............................................................................................................... 191
2.5. RI (Ring Indicator) .................................................................................................................... 191
2.6. DCD (Data Carrier Detect)........................................................................................................ 191
3. Open UART Interface ............................................................................................................... 191
4. Open UART Operations............................................................................................................ 192
4.1. Open Function ......................................................................................................................... 193
4.2. Read Function .......................................................................................................................... 194
4.3. The Write Request ................................................................................................................... 198
4.4. The io_control Request............................................................................................................ 200
4.5. The Close Request ................................................................................................................... 200
4.6. The On TX Complete notification handler ............................................................................... 201
4.7. The On TX Empty notification handler..................................................................................... 202
4.8. The On Rx Complete notification handler ............................................................................... 202
4.9. The On Rx Data Available notification handler ........................................................................ 203
4.10. The On Signal State Change notification handler .................................................................... 203
4.11. The On Error notification handler............................................................................................ 204
5. Benefits of Open UART ............................................................................................................ 205
6. Overhead of Open UART over FCM ......................................................................................... 205
CHAPTER 18 207
General Purpose Input Output .................................................................................................................207
1. Objective .................................................................................................................................. 207
2. General Purpose Input Output ................................................................................................ 207
3. Availability of GPIOs................................................................................................................. 207
13
Open AT® TUTORIAL
Table of Contents
CHAPTER 19 221
Bus Service ..............................................................................................................................................221
1. Objective .................................................................................................................................. 221
2. Bus Description ........................................................................................................................ 221
2.1. SPI Bus ..................................................................................................................................... 221
2.2. I2C Bus ..................................................................................................................................... 223
2.3. Parallel Bus .............................................................................................................................. 223
3. Bus APIs ................................................................................................................................... 223
3.1. Subscribing to Bus Service ....................................................................................................... 223
3.2. Unsubscribing from the Bus Service ........................................................................................ 228
3.3. Modifying the Configuration of the Subscribed Bus ................................................................ 229
3.4. Reading Data from the Subscribed Bus (SPI and I2C) .............................................................. 230
3.5. Reading Data from the Subscribed Parallel Bus ...................................................................... 231
3.6. Writing Data to the Subscribed Bus (SPI and I2C).................................................................... 232
3.7. Writing Data to the Subscribed PARALLEL Bus ........................................................................ 233
4. Sample Code for writing to SPI bus.......................................................................................... 233
CHAPTER 20 237
Watchdog................................................................................................................................................237
1. Objective .................................................................................................................................. 237
2. Watchdog Timer ...................................................................................................................... 237
2.1. Hardware Watchdog Timer ..................................................................................................... 237
2.2. Software Watchdog Timer ....................................................................................................... 238
3. Advantages of Watchdog Timer .............................................................................................. 238
4. Restrictions & Limitations of Watchdog Timer ........................................................................ 239
5. Watchdog Timer APIs .............................................................................................................. 239
5.1. Deactivation of Hardware Watchdog ...................................................................................... 239
14
Open AT® TUTORIAL
Table of Contents
CHAPTER 21 245
SIM Service .............................................................................................................................................245
1. Objective .................................................................................................................................. 245
2. Overview of the SIM Service .................................................................................................... 245
3. Events Related to the SIM and PIN .......................................................................................... 245
4. SIM States ................................................................................................................................ 246
5. API Related to the SIM Service ................................................................................................ 247
5.1. Subscription to SIM service ..................................................................................................... 247
5.2. Unsubscribe from the SIM Service........................................................................................... 248
5.3. Getting the SIM State .............................................................................................................. 248
5.4. Entering a new PIN code .......................................................................................................... 249
5.5. Entering PUK code ................................................................................................................... 249
5.6. Get the remaining attempts on PIN and PUK codes ................................................................ 250
6. Sample Code ............................................................................................................................ 250
CHAPTER 22 253
Short Message Service .............................................................................................................................253
1. Objective .................................................................................................................................. 253
2. What is SMS? ........................................................................................................................... 253
3. Basic Services ........................................................................................................................... 253
4. SMS Service Implementation ................................................................................................... 254
4.1. Subscribing to the SMS Service................................................................................................ 254
4.2. Sending a SMS ......................................................................................................................... 256
4.3. Unsubscribing from SMS service ............................................................................................. 257
5. Sample Code ............................................................................................................................ 258
CHAPTER 23 261
Call Service ..............................................................................................................................................261
1. Objective .................................................................................................................................. 261
2. Call Service Events ................................................................................................................... 261
3. Call Service APIs ....................................................................................................................... 263
3.1. Subscription to Call Service...................................................................................................... 263
3.2. Unsubscribe from the Call Service ........................................................................................... 265
3.3. Setup an outgoing call ............................................................................................................. 266
3.4. Hangup a call ........................................................................................................................... 267
3.5. Answer a call ............................................................................................................................ 267
15
Open AT® TUTORIAL
Table of Contents
CHAPTER 24 271
General Packet Radio Service...................................................................................................................271
1. Objective .................................................................................................................................. 271
2. Overview of GPRS .................................................................................................................... 271
3. GPRS-related Events ................................................................................................................ 272
4. GPRS-related APIs .................................................................................................................... 273
4.1. Subscribing to the GPRS Service .............................................................................................. 274
4.2. Unsubscribing from the GPRS Service ..................................................................................... 275
4.3. PDP Context Information ......................................................................................................... 275
4.4. Configuring the APN parameters and setting up GPRS Service ............................................... 276
4.5. The adl_gprsActExt () API......................................................................................................... 277
4.6. The adl_gprsDeactExt () API..................................................................................................... 278
4.7. The adl_gprsIsAnIPAddress () API ............................................................................................ 279
5. Sample Code ............................................................................................................................ 279
CHAPTER 25 283
Application Safe Mode Service ................................................................................................................283
1. Objective .................................................................................................................................. 283
2. Overview of the Application Safe Mode Service ..................................................................... 283
3. Events Related to the Application Safe Mode Service ............................................................. 283
4. Application Safe Mode Service APIs ........................................................................................ 285
4.1. Subscribing to Application Safe Mode Service ........................................................................ 285
4.2. Unsubscribing from the Application Safe Mode Service ......................................................... 286
4.3. adl_safeRunCommand function .............................................................................................. 286
5. Sample Code ............................................................................................................................ 287
CHAPTER 26 289
Open SIM Access (OSA) Service ................................................................................................................289
1. Objective .................................................................................................................................. 289
2. Required header file ................................................................................................................ 290
3. OSA Service APIs ...................................................................................................................... 290
3.1. The adl_osaSubscribe() API...................................................................................................... 290
3.2. The adl_osaSendResponse() API .............................................................................................. 291
3.3. The adl_osaUnsubscribe() API ................................................................................................. 292
4. Sample Code ............................................................................................................................ 292
CHAPTER 27 295
List Management.....................................................................................................................................295
1. Objective .................................................................................................................................. 295
16
Open AT® TUTORIAL
Table of Contents
CHAPTER 28 305
AT FCM/IO Port Service ...........................................................................................................................305
1. Objective .................................................................................................................................. 305
2. Introduction ............................................................................................................................. 305
3. AT FCM/IO service related events ........................................................................................... 305
4. AT FCM/IO service related enums ........................................................................................... 306
4.1. The adl_portSignal_e enum ..................................................................................................... 306
4.2. The adl_portEvent_e enum ..................................................................................................... 306
5. AT FCM/IO service related Macros .......................................................................................... 307
5.1. The ADL_PORT_GET_PHYSICAL_BASE macro .......................................................................... 307
5.2. The ADL_PORT_IS_A_SIGNAL_CHANGE_EVENT macro........................................................... 307
5.3. The ADL_PORT_IS_A_PHYSICAL_PORT macro ......................................................................... 308
5.4. The ADL_PORT_IS_A_PHYSICAL_OR_BT_PORT macro ............................................................ 308
5.5. The ADL_PORT_IS_AN_FCM_PORT macro .............................................................................. 308
5.6. The ADL_PORT_IS_AN_AT_PORT macro ................................................................................. 309
6. AT FCM/IO service related APIs ............................................................................................... 309
6.1. The adl_portSubscribe API....................................................................................................... 309
6.2. The adl_portUnsubscribe API .................................................................................................. 310
6.3. The adl_portIsAvailable API ..................................................................................................... 310
6.4. The adl_portGetSignalState API .............................................................................................. 311
6.5. The adl_portStartSignalPolling API .......................................................................................... 311
6.6. The adl_portStopSignalPolling API .......................................................................................... 312
7. Sample Code ............................................................................................................................ 312
CHAPTER 29 315
17
Open AT® TUTORIAL
Table of Contents
RTC Service..............................................................................................................................................315
1. Objective .................................................................................................................................. 315
2. Introduction ............................................................................................................................. 315
3. Macros and Constants ............................................................................................................. 315
4. RTC service related APIs .......................................................................................................... 316
4.1. Retreiving Second Fractional Part............................................................................................ 316
4.2. Retreving the Current RTC Time .............................................................................................. 316
4.3. Configuring the RTC Time ........................................................................................................ 317
4.4. Converting the RTC Time ......................................................................................................... 318
4.5. Finding the Difference between two UNIX based TimeStamps............................................... 319
5. Sample Code ............................................................................................................................ 320
CHAPTER 30 323
Real Time Operating System ....................................................................................................................323
1. Introduction to RTOS ............................................................................................................... 323
2. Open AT RTOS Architecture ..................................................................................................... 324
3. Scheduling policies................................................................................................................... 326
4. RTOS APIs ................................................................................................................................. 326
5. Task Management – Multitasking API’s ................................................................................... 327
5.1. Introduction ............................................................................................................................. 327
5.2. Structure to Define Tasks......................................................................................................... 328
5.3. Sample Code ............................................................................................................................ 328
6. Task Management - Context Service APIs ............................................................................... 329
6.1. Introduction ............................................................................................................................. 329
6.2. Get the Current Context .......................................................................................................... 329
6.3. Get the Current Task................................................................................................................ 330
6.4. Get the Current Tasks Count ................................................................................................... 331
6.5. Get the Diagnostic Information ............................................................................................... 331
6.6. Get the State of the Context .................................................................................................... 332
6.7. Suspend a Task ........................................................................................................................ 333
6.8. Suspend Multiple Tasks ........................................................................................................... 333
6.9. Resume a Task ......................................................................................................................... 334
6.10. Resume Multiple Tasks ............................................................................................................ 334
6.11. Sleep a Task ............................................................................................................................. 335
6.12. Sample Code ............................................................................................................................ 335
7. Inter-task Communication – Message Service APIs ................................................................. 336
7.1. Introduction ............................................................................................................................. 337
7.2. Header file ............................................................................................................................... 337
7.3. Subscribe to Message Service.................................................................................................. 337
7.4. Unsubscribe from Message Service ......................................................................................... 339
7.5. Sending Message to Task ......................................................................................................... 339
7.6. Sample Code ............................................................................................................................ 340
8. Synchronization – Semaphore APIs ......................................................................................... 341
8.1. Introduction ............................................................................................................................. 341
18
Open AT® TUTORIAL
Table of Contents
19
Open AT® TUTORIAL
Table of Contents
CHAPTER 31 381
Power Consumption Modes.....................................................................................................................381
1. Objective .................................................................................................................................. 381
2. Introduction ............................................................................................................................. 381
3. Types of low power modes ...................................................................................................... 381
3.1. Active mode with GSM stack ON ............................................................................................. 382
3.2. Active mode with GSM stack OFF ............................................................................................ 382
3.3. Sleep mode with GSM stack ON .............................................................................................. 382
3.4. Sleep mode with GSM stack OFF ............................................................................................. 382
3.5. Alarm mode ............................................................................................................................. 382
3.6. OFF mode................................................................................................................................. 383
4. Power Measurement ............................................................................................................... 383
5. Comparison of Low Power Modes ........................................................................................... 384
CHAPTER 32 385
Audio Service ..........................................................................................................................................385
1. Objective .................................................................................................................................. 385
2. Introduction ............................................................................................................................. 385
2.1. Single/Dual Tone ...................................................................................................................... 385
2.2. DTMF ....................................................................................................................................... 386
2.3. Melody ..................................................................................................................................... 386
2.4. Audio Stream ........................................................................................................................... 387
3. Header file ............................................................................................................................... 387
3.1. Subscribe to Audio Service ...................................................................................................... 387
3.2. Unsubscribe from Audio Service.............................................................................................. 389
3.3. Playing Single/Dual Tone ......................................................................................................... 389
3.4. Playing Single/Dual Tone with a High Precision Gain .............................................................. 390
3.5. Playing DTMF Tone .................................................................................................................. 391
3.6. Playing DTMF Tone with a High Precision Gain ....................................................................... 391
3.7. Playing Melody ........................................................................................................................ 392
3.8. Playing Melody with a High Precision Gain ............................................................................. 393
20
Open AT® TUTORIAL
Table of Contents
CHAPTER 33 409
VariSpeed................................................................................................................................................409
1. Objective .................................................................................................................................. 409
2. Introduction ............................................................................................................................. 409
3. Header file ............................................................................................................................... 410
3.1. Subscribe to VariSpeed Service ............................................................................................... 410
3.2. Unsubscribe from VariSpeed Service ....................................................................................... 410
3.3. Change the Processor Speed ................................................................................................... 410
4. Sample Code ............................................................................................................................ 411
CHAPTER 34 413
Internet Plug-in for Open AT ....................................................................................................................413
1. Introduction ............................................................................................................................. 413
2. Overview of TCP/IP .................................................................................................................. 413
3. Objective .................................................................................................................................. 414
4. Why TCP/IP on Sierra Wireless embedded module ................................................................ 414
5. TCP/IP software ....................................................................................................................... 415
6. Architecture of Internet Plug-In............................................................................................... 415
7. Internet Plug-In APIs without options ..................................................................................... 416
8. Internet Plug-In APIs with advanced configurable options ..................................................... 416
CHAPTER 35 417
IP Stack Initialization ...............................................................................................................................417
1. Objective .................................................................................................................................. 417
2. Initialization APIs ..................................................................................................................... 417
2.1. Initialization with default options ............................................................................................ 417
2.2. Initialization with configurable advanced options................................................................... 418
2.3. Release the resources allocated during initialization .............................................................. 418
2.4. Configuration of TCP/IP protocol options................................................................................ 419
21
Open AT® TUTORIAL
Table of Contents
2.5. Getting the current configuration of TCP/IP protocol options ................................................ 420
3. Sample Code ............................................................................................................................ 420
CHAPTER 36 423
IP Stack Bearer Management ...................................................................................................................423
1. Overview .................................................................................................................................. 423
2. APIs .......................................................................................................................................... 423
2.1. Attaching to bearer interface .................................................................................................. 423
2.2. Detaching from bearer interface ............................................................................................. 424
2.3. Configuration of bearer specific options ................................................................................. 424
2.4. Retrieving the configuration of bearer specific options .......................................................... 425
2.5. Establishing bearer connection ............................................................................................... 426
2.6. Accepting an incoming PPP connection................................................................................... 426
2.7. Starting a PPP server................................................................................................................ 427
2.8. Terminating the bearer connection ......................................................................................... 428
2.9. Retrieving the list of available bearers .................................................................................... 428
2.10. Freeing the list of available bearers......................................................................................... 429
3. Activation of TCP/IP connection .............................................................................................. 429
3.1. TCP/IP Connection Using GPRS ................................................................................................ 429
3.2. TCP/IP Connection Using PPP .................................................................................................. 430
3.3. Sierra Wireless embedded module acting as a PPP client ....................................................... 431
3.4. Sierra Wireless embedded module acting as a PPP server...................................................... 433
CHAPTER 37 437
IP Stack Channels ....................................................................................................................................437
1. Objective .................................................................................................................................. 437
2. Introduction ............................................................................................................................. 437
3. Architecture ............................................................................................................................. 437
4. Read/Write Events ................................................................................................................... 438
4.1. Read Events ............................................................................................................................. 438
4.2. Write Events ............................................................................................................................ 439
5. APIs .......................................................................................................................................... 440
5.1. Closing channel ........................................................................................................................ 440
5.2. Finalizers: ................................................................................................................................. 441
5.3. Changing the context of channel ............................................................................................. 441
5.4. Query the state of the channel ................................................................................................ 442
5.5. Reading data from channel without options ........................................................................... 442
5.6. Reading data from channel with options................................................................................. 443
5.7. Writing data to the channel ..................................................................................................... 444
5.8. Writing data to the channel without options .......................................................................... 444
5.9. Writing data to the channel with advanced options ............................................................... 444
5.10. Configuring the channel........................................................................................................... 445
5.11. Retrieving the configuration of a channel ............................................................................... 445
22
Open AT® TUTORIAL
Table of Contents
CHAPTER 38 447
TCP and UDP Socket Service ....................................................................................................................447
1. Objective .................................................................................................................................. 447
2. Introduction ............................................................................................................................. 447
3. Preliminary tasks to be performed before opening a TCP/UDP Socket .................................. 447
4. TCP sockets .............................................................................................................................. 447
5. Types of TCP sockets ................................................................................................................ 448
5.1. TCP server socket ..................................................................................................................... 448
5.2. TCP client socket ...................................................................................................................... 449
6. Include file ............................................................................................................................... 449
6.1. Creating a TCP server without options .................................................................................... 449
6.2. Starting TCP server with options ............................................................................................. 450
6.3. Sample Code for TCP Server .................................................................................................... 451
6.4. Creating a TCP client without options ..................................................................................... 453
6.5. Creating a TCP client with options ........................................................................................... 453
6.6. Sample Code for TCP Client ..................................................................................................... 455
6.7. Aborting a TCP socket .............................................................................................................. 456
6.8. Shutting TCP communication .................................................................................................. 457
7. UDP sockets ............................................................................................................................. 457
7.1. Creating a UDP socket without options ................................................................................... 458
7.2. Creating a UDP socket with options ........................................................................................ 459
7.3. Sample Code for UDP............................................................................................................... 460
CHAPTER 39 461
Management of IP Address Formats ........................................................................................................461
1. Objective .................................................................................................................................. 461
2. Internet protocol support API.................................................................................................. 461
3. Conversion from dot notation to unsigned format. ................................................................ 461
4. Conversion from unsigned format to dot notation. ................................................................ 462
5. Sample Code ............................................................................................................................ 462
CHAPTER 40 463
File API for IP services ..............................................................................................................................463
1. Objective .................................................................................................................................. 463
2. File APIs.................................................................................................................................... 463
2.1. Creating Data Channel Without Options for Downloading Data ............................................. 463
2.2. Creating Data Channel With Options for Downloading Data .................................................. 464
2.3. Creating Data Channel Without Options for Uploading Data .................................................. 465
2.4. Creating Data Channel With Options for Uploading Data ....................................................... 465
2.5. Changing the Working Directory ............................................................................................. 466
2.6. Creation of New Directory ....................................................................................................... 466
2.7. Deleting a File .......................................................................................................................... 467
2.8. Deleting a Directory ................................................................................................................. 467
23
Open AT® TUTORIAL
Table of Contents
CHAPTER 41 471
FTP Client ................................................................................................................................................471
1. Objective .................................................................................................................................. 471
2. Introduction to FTP .................................................................................................................. 471
3. FTP APIs ................................................................................................................................... 472
3.1. Creating of FTP Session Channel Without Options .................................................................. 472
3.2. Creating of FTP Session Channel With Options ....................................................................... 473
3.3. Configuring the FTP Session Channel....................................................................................... 474
3.4. Retrieving the Configuration of a FTP Session Channel ........................................................... 475
3.5. Creating FTP Data Channel Without Options for Downloading File ........................................ 476
3.6. Creating Data Channel With Options for Downloading File .................................................... 477
3.7. Creating Data Channel Without Options for Uploading File.................................................... 477
3.8. Creating Data Channel With Options for Uploading File ......................................................... 478
3.9. Reading Data From FTP Data Channel ..................................................................................... 479
3.10. Writing Data To The FTP Data Channel.................................................................................... 479
3.11. Shutting FTP Data Channel ...................................................................................................... 480
3.12. Closing FTP Session/Data Channel ........................................................................................... 480
4. Sample Code ............................................................................................................................ 481
CHAPTER 42 485
HTTP Client..............................................................................................................................................485
1. Objective .................................................................................................................................. 485
2. Introduction to HTTP ............................................................................................................... 485
3. HTTP Request-Response Model............................................................................................... 485
4. HTTP Request........................................................................................................................... 486
5. HTTP Response ........................................................................................................................ 487
6. HTTP Response Headers .......................................................................................................... 487
7. HTTP Methods ......................................................................................................................... 488
8. HTTP Versions .......................................................................................................................... 489
9. HTTP APIs ................................................................................................................................. 489
9.1. Creating of HTTP Session Channel Without Options ............................................................... 490
9.2. Creating of HTTP Session Channel With Options ..................................................................... 490
9.3. Creating HTTP Data Channel Without Options for Downloading URL Data ............................ 491
9.4. Creating HTTP Data Channel With Options for Downloading URL Data .................................. 492
9.5. Creating HTTP Data Channel Without Options for Uploading URL Data ................................. 493
9.6. Creating HTTP Data Channel With Options for Uploading URL Data ....................................... 493
9.7. Reading Data From HTTP Data Channel .................................................................................. 494
9.8. Writing Data To The HTTP Data Channel ................................................................................. 495
24
Open AT® TUTORIAL
Table of Contents
APPENDIX 503
25
Open AT® TUTORIAL
Table of Figures
TABLE OF FIGURES
Figure 1 –Without Open AT Application ............................................................................................................................. 31
Figure 2 - With Open AT Application .................................................................................................................................. 32
Figure 3 - Open AT Application with Custom Commands .................................................................................................. 32
Figure 4 - Open AT Application for Automotive ................................................................................................................. 33
Figure 5 – Embedded Software Architecture ..................................................................................................................... 36
Figure 6 – Sierra Wireless Software Suite Installation Wizard............................................................................................ 42
Figure 7 – Sierra Wireless Software Suite Installation Wizard............................................................................................ 43
Figure 8 – Sierra Wireless Software Suite Installation Wizard............................................................................................ 43
Figure 9 – Sierra Wireless Software Suite Installation Wizard............................................................................................ 44
Figure 10 – Sierra Wireless Software Suite Installation Wizard ......................................................................................... 44
Figure 11 - Sierra Wireless Software Suite Installation Wizard .......................................................................................... 45
Figure 12 – Developer Studio ............................................................................................................................................. 45
Figure 13 – Select Workspace for Developer Studio .......................................................................................................... 46
Figure 14 – Developer Studio Welcome Page .................................................................................................................... 46
Figure 15 – Open AT perspective ....................................................................................................................................... 47
Figure 16 – Packages Manager Perspective ....................................................................................................................... 48
Figure 17 – Install Packages Window ................................................................................................................................. 48
Figure 18 – Open AT perspective ....................................................................................................................................... 51
Figure 19 – Open AT perspective ....................................................................................................................................... 52
Figure 20 - Open AT project creation wizard ...................................................................................................................... 53
Figure 21 – Open AT perspective ....................................................................................................................................... 53
Figure 22 – Toolchains and Configurations window ........................................................................................................... 54
Figure 23 – Open AT perspective ....................................................................................................................................... 55
Figure 24 – Select Target Build Configuration .................................................................................................................... 56
Figure 25 – Open AT Target Run Configuration .................................................................................................................. 56
Figure 26 – Open AT Target Run Configuration error ......................................................................................................... 57
Figure 27 – Select Remote Build Configuration .................................................................................................................. 57
Figure 28 – Run Configuration ............................................................................................................................................ 58
Figure 29 – Open AT RTE Run Configuration Window ........................................................................................................ 58
Figure 30 – Remote Tasks Monitor .................................................................................................................................... 59
Figure 31 – Select Remote Debug Build Configuration ...................................................................................................... 59
Figure 32 – Insert break point ............................................................................................................................................ 60
Figure 33 – Enabled break point......................................................................................................................................... 60
Figure 34 – Disabled break point ........................................................................................................................................ 61
Figure 35 – Open AT RTE Debug Configuration .................................................................................................................. 61
Figure 36 – M2M Studio Debug Perspective ...................................................................................................................... 62
Figure 37 – Developer Studio Environment ....................................................................................................................... 63
Figure 38 – Change serial port settings .............................................................................................................................. 64
Figure 39 – Serial Port settings: COM 1 .............................................................................................................................. 65
Figure 40 – Open the selected port .................................................................................................................................... 65
Figure 41 – Show View Window ......................................................................................................................................... 66
Figure 42 – Infos pane (Target Information) ...................................................................................................................... 66
Figure 43 – Remote traces configuration ........................................................................................................................... 67
Figure 44 – Traces configuration ........................................................................................................................................ 67
Figure 45 – Console ............................................................................................................................................................ 68
Figure 46 - Remote Task Environment ............................................................................................................................... 71
Figure 47: Schematic for use of the Sierra Wireless debug interface on the AirPrime WMP100. ...................................... 72
Figure 48 - Standalone External Application ...................................................................................................................... 75
26
Open AT® TUTORIAL
Table of Figures
27
Open AT® TUTORIAL
Table of Figures
28
Open AT® TUTORIAL
CHAPTER 1
About this Training Courseware
1. Objective
This book will guide you through the working of Open AT with detailed step-by-step instructions. This book is also the
support of the Open AT training organized regularly by Sierra Wireless allowing developers discover easily the word of
Open AT.
The following features of this document will guide you through the installation, setup and working of Open AT:
If you need more information, please contact your Sierra Wireless distributor.
2. Audience
This training guide is addressed to all developers want to start M2M design application with Open AT.
3. Pre-requisites
These pre-requisites must be in place before starting Open AT training or before developing your first Open AT
application:
Sierra Wireless Development kit along with required power supplies and adaptors
SIM cards with the following features enabled according to your usage:
o Basic GSM features such as SMS and voice call
o PIN1, PIN2, PUK1 and PUK2 codes
o GPRS (if required)
o GSM data call (if required)
29
Open AT® TUTORIAL
Hardware Requirements: The main requirements for the PC to support the Developer Studio are:
o Pentium 300MHz (or higher) processor with at least 128 MB of RAM and 500 MB free hard disk space.
o A CD ROM drive (for software installation)
o At least one free COM (serial) port for the communication with the target product.
Software Requirements: Following is the list of software which is required to build the Open AT Application:
o Developer Studio (including GCC compiler)
o ARM compiler (if required)
System Requirements: To be able to install the Developer Studio, your system must support one of the following
operating systems:
o WINDOWS 98
o WINDOWS NT
o WINDOWS Me
o WINDOWS 2000
o WINDOWS XP
o WINDOWS 7
Sierra Wireless Software Suite from an USB Key or downloaded from www.sierrawireless.com
NOTE:
The GCC compiler provided within the Developer Studio installation setup can run only on Windows NT/2000/XP
systems. It is not supported on Windows 98/ME systems.
30
Open AT® TUTORIAL
CHAPTER 2
Introduction to Open AT®
1. Objective
The objective of this chapter is to introduce you the Open AT concept and the different modes to use it.
The following image depicts a microcontroller-based application without Open AT Application. In such a situation, all
the applications are external to the embedded module.
In such a scenario, without Open AT Application, you must have interfaces for the hardware, and also develop custom
applications that will be embedded in the external micro-controller to interact with embedded module and with the
external devices (by GPIO or BUS interface).
With Open AT Application, the external micro-controller is not required, and therefore the Open AT Application takes
control of the embedded module and interacts with the external devices. This is depicted in the following image.
31
Open AT® TUTORIAL
Raw Data
GPIO/
Keyboard Interface
Figure 2 - With Open AT Application
Open AT Application allows you more flexibility. Open AT Application allows you to modify the response to basic AT
commands and therefore customize according to the functionality required. In addition to the basic AT commands, you
can also develop custom commands and add to the available command set. The required functionality can be
implemented in these commands.
This provides more power to the wireless developer and eases the programming task. The following figure depicts this
advantage with a scenario in which custom commands are used.
GPIO/
Keyboard Interface
3. Areas of Application
Open AT OS can provide functionality in a wide variety of applications, such as:
Systems that use standard GSM, GPRS and EDGE services for status reporting
Systems that provide internet connectivity and access to Web services like FTP, HTTP, POP3, SMTP and PING
Systems that act as TCP/UDP client/server machines and provide services to other nodes
Systems that provide location information in automotive systems using GPS (Global Positioning System) services
Applications that send sensor information (read through GPIOs) to remote base locations
Applications that store sensor data or other vital information in flash (ROM) and help protect critical information
for state of the art information processing systems
Applications that provide WAP-related services
32
Open AT® TUTORIAL
Domains where Open AT Applications can be used include Automotive, Fleet Management, Remote Asset Monitoring,
Telemetry and Telematics etc.
The Application figure depicts an example of Open AT usage. In case of a motor accident, the sensors fitted in the
automobile send the information to the base server, which in turn informs the emergency helpline, prompting it to
send help to the accident site. The Open AT Application running on the handles this process of collecting and sending
the information to the base server.
Server Internet
Wireless Infrastructure
Sensor
(Data Source) Emergency Service
The Open AT helps reducing the development and testing time considerably. You can concentrate on the functionalities
of the application instead of the lower level technical details.
Open AT reduces the cost of the product. Without Open AT, a considerable amount of time is spent interfacing
hardware and creating drivers which are used to provide external stimuli (information) to the embedded module. But
Open AT OS provides APIs with which the power of the embedded module can be easily manipulated without any
external interfacing hardware or software.
Open AT Application is tightly integrated with the Firmware. As the Open AT OS (on which the application is built) is
extensively tested to work with the Firmware, the level of integration and reliability of the Open AT Application meets
user expectations. With Open AT OS (library) the Open AT Application can interact efficiently with the Firmware.
Open AT Application allows you more flexibility; in addition to the basic AT commands, you can also develop custom
commands which can add to the available command set. The required functionality can be provided in these
commands. Hence, the overall flexibility of programming can be increased.
Open AT can be used to create intelligent internet-enabled applications directly on the embedded module. This
shortens development time and reduce materials cost.
This Operating System allows defining multiple tasks which can run parallel. It provides RTOS features which:
33
Open AT® TUTORIAL
Summary
Without Open AT Application, all the applications are external to the embedded module. With Open AT
Application, the Open AT Application takes control of the embedded module, and interacts with the external
devices.
34
Open AT® TUTORIAL
CHAPTER 3
Embedded Software Architecture
1. Objective
This chapter describes the module embedded software components and architecture. It includes the minimum to know
about the Open AT OS: main ADL interfaces, memory resources and running modes of Open AT Application.
The Open AT OS APIs interacts directly with the Firmware. The Open AT Application is built on top of these APIs. The
Firmware is present in the embedded module as one binary file. The Open AT Application also compiles to a binary file
which lies above the Firmware. The software thus follows a dual binary architecture.
35
Open AT® TUTORIAL
The Open AT Application binary file is built by the Open AT developer. It is the Open AT developer source code compiled
and linked with the Open AT OS library and optionally with other plug-in libraries. This binary is downloaded into the
flash memory and runs concurrently with the Firmware, using the Open AT OS interface and managed by the same Real
Time OS. (For more details, refer to the chapter 13 flash memory and chapter 30 RTOS) In this way, self-reliant
applications can be created and programmed in the flash memory to run without any user intervention.
3. ADL Interfaces
The Open AT OS is a multitasking Operating System. This mode has the following features:
AT command APIs: Software interfaces that provide access to the Firmware functions.
OS API: Software interfaces that provide access to operating system functions.
36
Open AT® TUTORIAL
FCM API: Software interfaces that provide access to the Flow Control Manager functions (secure
access to V24 and Data IO flows). For more details, refer to the chapter on the flow control
manager.
GPIO API: Software interfaces that provide access to the GPIO services.
GPRS/EDGE API: Software interfaces that provide access to the GPRS/EDGE services (for
authentication and IPCP information).
BUS API: Software interfaces that provide control on bus devices (as SPI, Parallel or I2C bus).
List API: A set of list-processing functions.
DOTA I/II/III API: A set of APIs to enable Download Over The Air functionality.
Sound API: Software interfaces to control the playing of regular and DTMF tones.
Standard API: A standard set of C functions, in addition to some string processing functions.
RTOS API: A set of APIs that supports RTOS feature.
Registry API: A set of APIs that provides access to the platform registry.
Error Management API: A set of APIs for managing errors.
Secured Data API: A set of APIs for storing secured data.
To define the Open AT Application call stack size follow the prototype below:
Before Open AT OS 6.30, the entry point function that is called during the Open AT Application initialization was:
This entry point has been kept for backward compatibility. However currently Open AT OS allows to define multiple
tasks. Each task is defined by the following parameters:
The task entry point, called at the embedded module boot time, in the priority order
The task call stack size
The task priority level
The task name
typedef struct
{
void (* EntryPoint)(void);
u32 StackSize;
const ascii* Name;
u8 Priority;
} adl_InitTasks_t;
37
Open AT® TUTORIAL
Please refer the RTOS section in this book of the course material for more details on this feature.
The global variable, call stack and dynamic memory allocated are all part of the RAM allocated to the Open AT
Application. The RAM size used by the call stack is dependent on the Open AT Application. The call stack uses at least
1KB of RAM. In addition to that, 0.5KB of memory is used by internal variables of the library. Hence in case an Open AT
Application is developed on an embedded module with 128kbytes of RAM available to Open AT, then the RAM memory
is shared between Open AT Application and Open AT OS variables. The RAM memory will have
The Firmware and Open AT Application manages their own RAM area and any access from one of these programs into
the other will cause the embedded module to reboot. In case of illegal access of RAM, the Trace View screen displays
the message “ARM exception: 1 xxx” where xxx is the address of the location that the Open AT Application was trying to
access.
In case an Open AT Application uses more than the specified RAM or ROM area, then the behavior of the program
becomes erratic.
In the remote mode, the Open AT Application is executed on the development environment (PC) and uses its own
resources like memory and clock. This mode provides the facility of line-by-line debugging. This mode can be used to
38
Open AT® TUTORIAL
debug the Open AT Application by inserting various breakpoints and traces. Dynamic changes in the contents of the
memory can be viewed using Developer Studio.
Sierra Wireless provides the RTE (Remote Task Execution) tool to debug the Open AT Application in remote mode.
The following chapters of this document provide more information on the target and remote modes of Open AT
Application development.
Summary
The following points have been covered in this chapter:
The embedded Software Architecture includes the Firmware and the Open AT Application.
OASiS is the set of embedded software components provided by Sierra Wireless to build an Open AT application
The Download over the Air (DOTA I/II/III) service is provided by Open AT OS to upgrade the existing/running
Open AT Applications and Firmware dynamically over the air (using a GSM/GPRS link).
Open AT OS provides ADL Interface for Open AT Application development.
Based on the memory embedded module type of Sierra product, different sizes of Open AT Application can be
downloaded in the embedded module.
39
Open AT® TUTORIAL
40
Open AT® TUTORIAL
CHAPTER 4
Software Installation
1. Objective
This chapter guides you through the software installation needed to develop your Open AT application.
3. System Requirements
To be able to successfully install Developer Studio, your system must support one of the following Operating Systems:
WINDOWS XP
WINDOWS VISTA
WINDOWS 7
In countries with double-byte operating systems (CJK), Developer studio installation may require installation of Java
package. Please contact your Sierra Wireless distributor for more information.
NOTE:
CJK – Chinese Japanese Korean
4. Hardware Requirements
The main requirements for the PC to support the Developer Studio are:
41
Open AT® TUTORIAL
Pentium 1GHz (or higher) processor with at least 1 GB of RAM and 500 MB free hard disk space (Recommended:
dual core 2GHz processor or higher, RAM: 2GB or more).
At least, one free COM (serial) port for communication with the target product.
The steps listed below will guide you through the installation of all Sierra Wireless Software Suite including Developer
Studio, OASiS and drivers. Refer to the screenshots for references made to specific field labels.
1. Launch the executable file from the location of its storage (CD ROM or USB Flash drive). You will get this screen.
Click Next to continue.
2. The Product Selection screen is displayed. Select your Product Family and click Next to continue.
42
Open AT® TUTORIAL
3. Select the items to install in the Software Selection screen. Click Next to continue.
4. Select the destination directory where the Sierra Wireless Software Suite components will be installed.
Click on Browse to select the destination folder from the folders tree. It can also be entered manually. If the
destination folder does not exist, it will be created automatically before extraction.
43
Open AT® TUTORIAL
5. The License Agreement screen is displayed. Accept the agreement and click Install to continue.
6. The extraction is automatically started once you click Install and the following screen appears.
44
Open AT® TUTORIAL
7. Once the package is successfully extracted, the setup propose you to launch Developer Studio automatically and
you will be asked to choose a workspace folder.
Click on Browse to select the workspace folder where Open AT packages/projects should be stored. The
workspace selected here is applicable for the current session. In case you want to use this as the default
workspace for importing Software Suite packages and for creating Open AT Applications, then mark the
checkbox “Use this as default and do not ask again”.
45
Open AT® TUTORIAL
NOTE:
The workspace path shall not contain space character.
The workspace path length shall be less than 50 characters.
8. Once the workspace path is specified it automatically re-directs you to the Welcome Page of Developer studio
which means that the Developer studio is now ready to use.
To be able to use OASiS with Developer Studio, you will have to follow the below mentioned steps:
You will have to first install the OASiS package in Developer Studio either through the Sierra Wireless Software Suite
installation process or the Developer Studio Software Package Manager Installation process. This will extract the
contents of the packages in the Developer Studio workspace, making them available to the developer for the Open
AT Application.
The OASiS needs to be imported only once in Developer Studio. Next time when an Open AT Application is to be
created, you can use the previously imported package for the same. If a different version of OASiS is required, then
the same has to be imported in the Developer Studio workspace before using it for Open AT Application
development.
46
Open AT® TUTORIAL
If more than one OASiS has been installed, you can select the version to be used from the available list when
creating an Open AT Application.
After importing an OASiS, the Open AT perspective available in Developer Studio can be used to
create/execute/debug Open AT Applications.
The detailed process to be followed to do the above steps is explained in the following sections of this chapter.
1. Select Window > Open Perspective > Other > Packages Manager and then click OK.
2. In the Packages Manager perspective look for Available Packages window. Select the package you want to install,
right click and select “Install selected packages“.
47
Open AT® TUTORIAL
3. The Install Packages window is displayed. Click on Select all and then Install.
4. Once the installation is complete, you will be directed to the ‘Open AT Perspective’ in Developer Studio and an
Open AT Application can now be created using Developer Studio.
48
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter:
Sierra Wireless Software Suite includes an IDE named Developer Studio, the embedded Software components
named OASiS and drivers
The installation of Sierra Wireless Software Suite
The Software Package Manager allows to import OASiS or any third party plug-in into the Developer Studio
49
Open AT® TUTORIAL
50
Open AT® TUTORIAL
CHAPTER 5
Open AT Project Development
1. Objective
This chapter describes how to develop an Open AT project using Developer Studio.
Developer Studio is the IDE allowing you to develop your Open AT application. It supports you during these following
steps:
1. Select the ‘Open AT Perspective’ from the top right tabs in Developer Studio.
51
Open AT® TUTORIAL
2. Select File > New > Open AT Project from the Developer Studio menu. This will take you to the Open AT
project creation wizard.
3. By default, the new Open AT Application will be created in the workspace provided during the installation of
Developer Studio. If you wish to change the Open AT Application location, uncheck the box which says “Use
default location” and specify the location manually.
4. Provide the project name and select the project type. You can select either of the project type.
6. The Target Platform Configuration window will be displayed. In the package selection:
Select the appropriate Open AT Plug-in to be used in the Open AT Application under Plug-in tab. You can
select one or more depending on the project requirements.
Select the Open AT OS package that should be used to build the Open AT Application under OS tab.
Select the Open AT Firmware package that should be used under Firmware tab.
You can either press Finish to create a new empty template project, or Next to go to the sample
selection step.
The next step allows configuring the sample on which the project will be based.
52
Open AT® TUTORIAL
7. Sample selection window will be displayed, select a sample for the project creation. If no sample is selected, a
default template will be used.
8. Select the appropriate toolchain to be used. You can select one or more depending on the project
requirements. The Dependencies list allows adding references to already existing library projects in the
workspace. The Configuration group allows to set some Target related additional parameters:
The embedded Module, when using a Target Platform supporting several types
The Memory Type (for Open AT Application projects only), to configure the memory settings according
to the used target type
Click Finish to continue.
53
Open AT® TUTORIAL
NOTE:
A new compiler will be available in Toolchain for SDK Profile 2.34 and above, ARM EABI GCC. When an Open AT project
is created this compiler is selected by default, user can also select all other compilers as the previous compiler list will
still be available.
9. The Open AT Project is created and the screen is directed to the ‘Open AT perspective’. The Open AT Project is
displayed in the Project Explorer pane.
54
Open AT® TUTORIAL
Open AT project can be compiled and executed in either of the following modes:
Target mode
Remote mode
To run an Open AT Application in the target or download mode, you must build the Open AT Application in
Target mode and create a Run Configuration accordingly.
To compile and build the Open AT Application Developer Studio, follow the steps below:
1. To build an Open AT Application you will have to select the mode in which the Open AT Application
should be built. This can be done through Project > Build Configurations > Set Active and select either
Target Release or Target Debug configuration.
55
Open AT® TUTORIAL
2. The Target Release mode should be selected if no debug information is required from the Open AT
Application. When this mode is selected, the Traces used in the Open AT Application are not logged in
the Trace View window of Developer Studio.
3. The Target Debug mode should be selected when the debug information provided in the Open AT
Application is required. When this mode is selected, the Traces used in the Open AT Application are
logged in the Trace View window of Developer Studio.
4. After selecting the build mode, select Project > Build Project to build the project.
5. Create a Run Configuration to execute the Open AT Application. To do this, select the project root folder
in the Project Explorer pane and right click on it. Then select Run As > Run Configurations. This will open
a Run Configurations window.
To create a new Open AT Target configuration, double click on Open AT Target option on the left pane.
Notes:
A Run Configuration can be re-used for the same Open AT project. If a Run Configuration already exists for an Open AT
Application, there is no need to create a new Run Configuration every time you want to execute the Open AT
Application.
56
Open AT® TUTORIAL
6. Once the Run Configuration is created successfully, all the fields are filled automatically by Developer
Studio. In case of an error, an error message is displayed on the top left of the Run Configurations
window.
7. If the Run Configuration is successful, click on Run to execute the Open AT Application. In case of an
error, delete the incorrect configuration and check for the specified error before creating a new one.
8. After executing a successful Run Configuration, you can switch to the ‘Target Management’ perspective
and communicate with the embedded module.
In the remote mode, the Open AT Application can be compiled and executed in M2M Studio using the
following steps:
1. Set active the mode that should be used to build the Open AT Application. This can be done through
Project > Build Configurations > Set Active and selecting RTE Debug configuration. RTE debug
configuration should be selected if you want to debug the Open AT Application by putting break points.
3. Create a Run Configuration to execute the Open AT Application in RTE mode. To do this, select the
project root folder in the Project Explorer pane and right click on it. Then select Run As > Run
57
Open AT® TUTORIAL
Configurations. This will open a Run Configurations window. Create a new Open AT RTE configuration
by double clicking on Open AT RTE option on the left pane.
4. Once the Run Configuration is created successfully, all the fields are filled automatically by M2M Studio.
Click on Run to start executing the Open AT Application in RTE mode. This will open the Remote Task
Monitor window.
58
Open AT® TUTORIAL
5. Select the ADL traces from the drop down menu and check the required trace levels. Click on Start to
start executing the Open AT Application in Remote mode.
6. Once the Open AT Application execution is complete, click Stop to stop the Remote Task Monitor. This
option is enabled only if the Start option is disabled.
7. Click Safe target and Quit to exit the remote mode of the Open AT Application.
1. Set active RTE mode to be used to build the Open AT Application. This can be done through Project >
Build Configurations > Set Active and select RTE Debug configuration.
59
Open AT® TUTORIAL
3. To set breakpoint, right-click in the marker bar area on the left side of the editor beside the line where
the program to be suspended, then choose Toggle Breakpoint option. You can also double click on the
marker bar next to the source code line to put/remove a break point.
60
Open AT® TUTORIAL
6. Create a Debug Configuration to debug the Open AT Application in RTE mode. To do this, select the
project root folder in the Project Explorer pane and right click on it. Then select Debug As > Debug
Configurations. This will open a Debug Configurations window. Create a new Open AT RTE configuration
by double clicking on Open AT RTE option on the left pane.
61
Open AT® TUTORIAL
7. Once the Debug Configuration is created successfully, all the fields are filled automatically by M2M
Studio. Click on Debug to start executing the Open AT Application in RTE mode. This will open the
‘Debug Perspective’ in M2M Studio which can be used to control the flow of execution using break
points. It will also open the Remote Tasks Monitor.
8. Select the ADL traces from the drop down menu and check the required trace levels. Click on Start to
start executing the Open AT Application in Remote mode. Once the break point is hit, the execution of
the Open AT Application will be suspended.
9. You can use the debug options available in the ‘Debug perspective’ to debug the Open AT Application.
10. Once the Open AT Application debugging is complete, click Stop to stop the Remote Task Monitor. This
option is enabled only if the Start option is disabled.
11. Click Safe Modem and Quit to exit the remote mode of the Open AT Application.
Summary
The following points have been covered in this chapter:
Open AT Application can be compiled and executed in Target and Remote modes.
Run/Debug configurations are used to Execute/Debug an Open AT Application.
62
Open AT® TUTORIAL
CHAPTER 6
Running Open AT® Application
and Using Developer Studio
1. Objective
This chapter describes Developer Studio and its use for communicating with the embedded module and executing Open
AT Applications.
2. Developer Studio
Developer Studio comes with built-in plug-ins that can be used during Open AT Application development and to
communicate to the embedded module. Traces, Remote Shell, are some of the examples of the built-in plug-ins.
Developer Studio manages different functionalities with the help of different perspectives. The different perspectives
provided by Developer Studio are:
63
Open AT® TUTORIAL
The Target Management perspective is used to communicate with the embedded module over the COM port.
It has built-in plug-ins to
Displays the Open AT Application’s trace messages from the target or the Remote Application.
Send AT command and receive the corresponding response.
Retrieve Target information.
1. Switch on the embedded module. Ensure the target is not in the initialization stage.
2. Make sure that the selected COM port is not in use by any other application.
3. Select the corresponding COM port under Devices view and use the Change serial port settings option
to configure the COM port settings.
64
Open AT® TUTORIAL
4. Click on Open the selected port option under the Devices view to connect to the embedded module.
5. In case of any error while connecting, the corresponding error message will be displayed.
6. The Infos pane can be used to retrieve embedded module information. Click on the refresh button in the
Infos pane to retrieve the state of the embedded module and other values.
7. Infos pane can be viewed using Window->Show View->Other. In Show View window select Target
Management->Infos and then click OK.
65
Open AT® TUTORIAL
8. Trace View window can be viewed using Window->Show View->Other. In Show View window select
Target Management->Traces and then click OK. It displays the traces logged by Open AT Application. The
level of traces to be displayed can be selected by using the “Remote Traces configuration” option in the
Trace View toolbar.
66
Open AT® TUTORIAL
9. The traces logged by the Open AT Application will be displayed in the Traces window based on the Trace
levels selected.
10. Console window can be viewed using Window->Show View->Other. In Show View window select
General->Console and then click OK. The Console enables the user to enter AT commands and receive
the responses for the same.
67
Open AT® TUTORIAL
Figure 45 – Console
This perspective is used for debugging an Open AT Application in Remote Debug mode. The perspective is
automatically called once a breakpoint in the Open AT Application is hit. The perspective allows doing a step
by step debugging of an Open AT Application. The steps involved in debugging have been discussed in details
in chapter 5.
3. Open AT Application
The Open AT application can be compiled using the following compilers:
The GNU Compiler Collection (usually shortened to GCC) is a compiler system produced by the GNU Project
supporting various programming languages. GCC is often the compiler of choice for developing software that
is required to execute on a wide variety of hardware and/or operating systems.
68
Open AT® TUTORIAL
This toolchain requires some internal functions at the link stage as soon as C++ is used. These functions are
provided in a stub, which has to be added to every Open AT Application project compiled with the ARM EABI
GCC toolchain and which embeds C++ code. This compiler is selected by default, while creating an Open AT
Project in Developer Studio for OASIS 2.34 and above. List of other compilers will also be available, the user
can select all other compilers also.
3.3. RVDS
The ARM RealView Development Suite 4.0 Professional is a complete, end-to-end solution for software
development supporting all ARM processors and ARM CoreSight™ debug technology. This product enables
developers to begin software development, optimization and test ahead of silicon availability, significantly
reducing application time-to-market and ensuring the highest degree of software quality. RealView
Development Suite 4.0 Professional incorporates the best-in-class ARM Compiler and market-leading ARM
Profiler enabling applications to easily achieve both high performance and optimal code size.
Supported Platforms
RVDS 4.0 supports the following platforms and service packs:
3.4. MINGW
MinGW is a native Windows port of the GNU Compiler Collection (GCC), with freely distributable import
libraries and header files for building native Windows applications. MinGW is used to compile the Open AT
Application in remote i.e. RTE mode. It is actually integrated into the IDE itself and it uses the Windows C
runtime libraries.
69
Open AT® TUTORIAL
Maximum optimization level possible is –O3 in ARM ELF GCC and RVDS compilers.
The generated binary file (.dwl file) is downloaded to the embedded module by Developer Studio when a
Target Run Configuration is created in the Open AT perspective. After the download is complete, the
embedded module is restarted using the AT+CFUN=1 command. The newly created Open AT Application is
then started using the AT+WOPEN=1 command. All these commands are issued by the Developer Studio and
the user does not have to do anything.
The AT+WOPEN=0 command can be used to stop the embedded Open AT Application. The AT+WOPEN=4
command can be used to erase the embedded Open AT Application.
70
Open AT® TUTORIAL
The Open AT Application runs using the Real Time Execution Environment (RTE) which is integrated with
Developer Studio. This mode can be used to debug the Open AT Application by inserting various breakpoints
and traces. Moreover, dynamic changes in the contents of the memory can also be seen using the tools
available in Developer Studio. This mode can be used during the development of the Open AT Application
before releasing the product (which will be downloaded to the embedded module).
The RTE is used to send the instructions directly to the embedded module, which then executes these
instructions and performs the required operation. The Remote Task Execution (Remote Mode) image shows
a screenshot of the Remote Task Monitor which is displayed when the Open AT Application is running in the
remote mode.
Before starting the remote Open AT Application, set the appropriate ADL level traces from the Remote Task
Monitor.
5. Introduction to GDB
The GNU Debugger, usually called just GDB, is the standard debugger for the GNU software system. GDB, the GNU
Project debugger, allows you to see what is going on ‘inside’ a program while it executes or what a program was doing
at the moment it crashed.
GDB can do four main kinds of things (plus other things in support of these) to help you catch bugs in the act:
Start your program, specifying anything that might affect its behaviour.
Make your program stop on specified conditions.
Examine what has happened, when your program has stopped.
Change things in your program, so you can experiment with correcting the effects of one bug and go on to learn
about another.
71
Open AT® TUTORIAL
The program being debugged can be written in Ada, C, C++, Objective-C, Pascal (and many other languages). Those
programs might be executing on the same machine as GDB (native) or on another machine (remote). GDB can run on
most popular UNIX and Microsoft Windows variants.
6. Introduction to JTAG
JTAG (Joint Test Action Group) is an in-circuit debugging solution capable of tracking down issues which may occur in
routines but cannot be reproduced with the Remote Tasks Environment. Using a compliant debugger and the proper
configuration, Open AT customers can step through the code of their Open AT application on the AirPrime WMP Series.
Besides debugging, the second purpose of the JTAG interface is allowing device programmer hardware to
transfer data into internal non-volatile device memory. Some device programmers serve a double purpose
for programming as well as debugging the device.
Figure 47: Schematic for use of the Sierra Wireless debug interface on the AirPrime WMP100.
72
Open AT® TUTORIAL
Please refer to the AT commands Interface Guide for complete information regarding the commands in the
following subsections.
73
Open AT® TUTORIAL
Notes
The JTAG debug mode can be enabled with <mode>= 1 and the parameter <FtrMask>= 80 (Sierra debug
feature). The +WCFM command requires a password to enable JTAG Debug mode (and other modes as well).
Please contact your Sierra FAE if you do not readily have your password.
Activate the JTAG Debug mode by issuing the +WDEBUG command as follows:
AT+WDEBUG=1
Verify that the JTAG Debug mode is properly activated using the AT+WDEBUG? command and that an error
command was not issued. The response confirming that JTAG Debug mode is active is as follows:
+WDEBUG:1,1
OK
Reset the AirPrime WMP Series to complete setting up JTAG Debug mode. You can reset it via a soft reset by
issuing the +CFUN command as follows: AT:
AT+CFUN=1
Otherwise you can issue a hard reset by using the switch on the hardware itself. Please refer to the related
documentation if you are unsure how to perform a hard reset.
NOTES
When the +WDEBUG read command is issued after resetting the AirPrime WMP Series, it will display the
following response if the JTAG Debug mode is properly activated:
+WDEBUG:1,0
OK
For more details on how to use this JTAG interface, please refer to
WMP_Family_JTAG_Debug_Application_Note-001_002.pdf.
7. Functioning Modes
Open AT Application can work in any one of the following functioning modes:
74
Open AT® TUTORIAL
Open AT®
Embedded Binary
Open AT®
Application
Serial
External Application AT
Link
Send AT Command 1 2 3
6 5 4
Receive Response
In this mode of operation the commands are sent by the external application to the embedded module that
you want to process, and the response is sent back to the external application.
75
Open AT® TUTORIAL
Open AT®
Application
6 adl_atCmdCreate() 1
Serial
AT
Link
4 3
In this mode of operation the Open AT Application is downloaded over the embedded module and is run in
the target mode. The Open AT Application and the embedded module do not require any external interface
to drive the embedded module. The Open AT Application will drive the product by sending the command and
handling the response with the embedded module.
1. The embedded Open AT Application calls the adl_atCmdCreate function to send an AT command.
2. The Open AT OS calls the appropriate AT command from the Firmware.
3. The AT function processes the command.
4. The AT function sends the AT response to the embedded Open AT Application.
5. This response ID is dispatched by the Open AT OS which calls the event handler associated with
adl_atCmdCreate function of the Open AT Application.
6. The event handler processes the response.
In this case, various levels of subscription are available for the command and responses, depending on the
requirement.
76
Open AT® TUTORIAL
adl_atCmdSubscribe( )
5 6
Serial
External Application AT
Link
Send AT command
1 2
3
1. The embedded Open AT Application subscribes to the command by calling the adl_atCmdSubscribe
function.
2. The Open AT OS calls the appropriate function from the Firmware.
3. The AT function sets the subscription.
Summary
The following points have been covered in this section
Developer Studio provides different perspectives that can be used for different purpose:
o Open AT perspective to develop Open AT Application.
o Target Management perspective to communicate with the embedded module.
o Debug perspective to do a step by step debugging of Open AT Application.
Application execution modes:
o Remote Mode: Open AT Application utilizes the resources of development environment (PC) and utilizes
its resources (like memory and clock). Suitable for debugging purposes.
o Target Mode: Application actually downloaded in the embedded module and executed. Utilizes the
embedded module resources.
77
Open AT® TUTORIAL
78
Open AT® TUTORIAL
CHAPTER 7
AT Commands and Responses
1. Objective
The objective of this chapter is to help you build familiarity with the APIs that can be used to subscribe/unsubscribe to
the AT Commands and Responses. Open AT allows you to build and subscribe to custom (user-defined) commands. You
can define the functionality for these custom commands to enhance the usability of the Open AT Application.
2. Responses
All the AT commands and response-related APIs are declared in the adl_at.h header file. This file must be included in
the Open AT Application to use these APIs.
The embedded module executes the AT commands and generates possible responses. The response generated depends
on the type of command executed.
Errors generated during the execution of these AT commands could be due to the following reasons:
79
Open AT® TUTORIAL
In case of an error, the string ERROR or +CME ERROR: <error_no> responses are displayed.
The responses generated provide feedback about the success or failure of AT command execution, and also indicate the
occurrence of any new events.
3. Classification of Responses
There are three categories of responses:
Terminal Response
Unsolicited Response
Intermediate Response
Terminal responses are the final outcome of an AT command, and indicate the success or failure of the
command executed. Examples of this category are OK, +CMS ERROR: <error_no> and +CME ERROR:
<error_no>.
Unsolicited responses are sent without being requested for, and indicate occurrence of events like network
registration, new SMS or incoming call. These responses are not related to the execution of any command.
Intermediate responses indicate the progress of the execution of certain commands. For example, to send an
SMS, use the AT+CMGS command. After executing the AT+CMGS=”<dest_no>” command, an intermediate
response (“>”) is sent by the embedded module. This response prompts the entry of SMS text suffixed by a
Ctrl+Z character.
The Open AT Application can only subscribe to unsolicited responses, and not to terminal and intermediate
responses.
Prototype:
The API associates a call-back (handler) function to a specific unsolicited response. The call-back function is
executed whenever the unsolicited event is received. This function will contain your specific implementation.
80
Open AT® TUTORIAL
Parameters:
UnSostr: This parameter is the name of the unsolicited response to which you want to subscribe. For
instance, this parameter can contain the string “+WIND: 4”. It means that you are subscribing to the “+WIND:
4” unsolicited event.
There is a predefined set of response IDs which can be used by programmers. These responses include the
ADL_STR_NO_STRING, ADL_STR_OK values and others listed in the following table:
UnSohdl: The call-back function that will be called on receipt of the unsolicited event specified in UnSostr
(first parameter). This function should be declared as follows:
The call-back handler is invoked and information such as the Response ID or actual string response is passed.
The UnSohdl callback function must return TRUE if you want the unsolicited responses to be sent to the
external application (Terminal Emulator/HyperTerminal).
If the UnSohdl callback function returns FALSE, then the unsolicited response will not be sent to the external
application.
The parameter of this callback function is a structure of the adl_atUnsolicited_t type. This structure will hold
the unsolicited response to which you have subscribed. The structure is declared as follows:
typedef struct
81
Open AT® TUTORIAL
{
adl_strID_e RspID;
adl_atPort_e Dest;
u16 StrLength;
ascii StrData[1];
} adl_atUnsolicited_t;
If the response is a terminal response (member of adl_rsp_ID_e), then RspID contains the response ID.
The Dest member indicates the destination port to which unsolicited response will be sent.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES
The call-back function will be executed every time the unsolicited response is received. You should explicitly
unsubscribe from the unsolicited response to prevent the call-back function from being executed each time the
response is received.
An unsolicited response can be subscribed to several times in your Open AT Application. If you subscribe for an
unsolicited response and provide func1 () as the call-back function and then again subscribe for the same
response by providing func2 () as the call-back, both the functions (func1 () and func2 ()) will be executed on
receipt of that unsolicited response.
The Open AT Application can only subscribe to unsolicited responses, and not to terminal and intermediate
responses.
Prototype:
Parameters:
UnSostr: This parameter represents the unsolicited string from which you want to unsubscribe. This should
be the same string that was subscribed to using the adl_atUnSoSubscribe() API. Refer to the enumeration
adl_rspID_e for the values which can be assigned to this string.
82
Open AT® TUTORIAL
UnSohdl: This parameter indicates the call-back function that was associated with the subscribed unsolicited
response. This is the same function that was specified in the adl_atUnSoSubscribe () API. Refer to the section
on
UnSohdl for the description of this call-back function.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES
You can only unsubscribe from unsolicited responses to which you had subscribed.
After unsubscribing, the call-back function will not be called on receipt of same event.
6. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
adl_atSendResponse() API
adl_atSendResponseSpe() API
adl_atSendStdResponse() API
adl_atSendStdResponseSpe() API
adl_atSendStdResponseExt() API
83
Open AT® TUTORIAL
adl_atSendStdResponseExtSpe() API
adl_atSendStdResponseExtStr() API
adl_atSendUnsoResponse() API
adl_atSendResponsePort() API
adl_atSendStdResponsePort API
adl_atSendStdResponseExtPort API
This is the most commonly used API which allows you to send any type of responses from within your Open
AT Application to the external application. This API can be used to send text as various kinds of responses to
the external application. This gives you the flexibility to send the text as either a terminal, unsolicited or
intermediate response. The Type parameter determines the type of the response associated to the text
string.
Prototype:
Parameters:
Type: This parameter determines the type of the response which is associated to the text string that you
want to send and the port to which the string needs to be sent. This is done using the ADL_AT_PORT_TYPE
macro.
ADL_PORT_MAX = ADL_PORT_USB,
84
Open AT® TUTORIAL
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This
type of responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response
string. These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
String: This parameter is a pointer to the string which should be sent to the external application as a
response. The type of the response string depends on the Type parameter of the
adl_atSendResponse() API.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This API can be used to send specified text as various kinds of responses to the external application. This
gives you the flexibility to send the text as either a terminal, unsolicited or intermediate response. The Type
parameter determines the type of the response associated to the text. With the NI provided, the associated
command is found. If the command had subscribed to this response, then the response handler is called.
Otherwise, the response is sent to the port provided.
NOTES
NI parameter is to hold the Notification Identifier provided by the command initiating the response. This
parameter is helpful in identifying the command that subscribed for the response in the case of multiple
subscriptions.
This parameter is related to the adl_atCmdSendExt() API and hence please refer to the Note after 7.8.4 and
section 7.8.5 Sample Code to understand the usage of the notification identifier (NI).
85
Open AT® TUTORIAL
Prototype:
Parameters:
Type: This parameter is composed of the response type, and the destination port where to send the
response. The type and destination combination has to be done with the following macro:
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be displayed.
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This
type of responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response
string. These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This API can be used to send terminal responses to the external application. This API gives you the facility to
send only the standard responses defined as the elements of the adl_strID_e enumeration to the external
application. The Type parameter defines the type that must be associated with the response ID.
Prototype:
86
Open AT® TUTORIAL
Parameters:
Type: This parameter determines the type of the response which is associated to the text string that you
want to send and the port to which the string needs to be sent. This is done using the
ADL_AT_PORT_TYPE macro.
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be
displayed.
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This
type of responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response
string. These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
RspID: This parameter indicates the response string that must be sent.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This API can be used to send terminal responses to the external application. This API gives you the facility to
send only the standard responses defined as the elements of the adl_strID_e enumeration to the external
application. The Type parameter defines the type that must be associated with the response ID. With the NI
provided, the associated command is found. If the command had subscribed to this standard response, then
the response handler is called. Otherwise, the standard response is sent to the port provided.
Prototype:
Parameters:
Type: This parameter is composed of the response type, and the destination port where to send the
response. The type & destination combination has to be done with the following macro:
87
Open AT® TUTORIAL
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be
displayed.
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This
type of responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response
string. These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This API is an extension to the previous adl_atSendStdResponse() API. This is because it allows you to send
arguments along with various terminal responses. For example, using adl_atSendStdResponse() API, you can
send the +WIND: response (as defined in the adl_rspID_e enumeration). However, to send a +WIND: 4
response or +WIND: 7 response (that is, the +WIND response with the argument), you must use the
adl_atSendStdResponseExt() API.
Prototype:
Parameters:
Type: This parameter determines the type of the response which is associated to the text string that you
want to send and the port to which the string needs to be sent. This is done using the ADL_AT_PORT_TYPE
macro.
88
Open AT® TUTORIAL
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be displayed.
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This type of
responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
arg: This parameter represents the response argument. According to the RspID, this argument should be
an u32 integer, or an ascii * string. For example, an integer value should be assigned to this argument when it
is used with an RspID “ADL_STR_WIND”. For “ascii *” string, the pointer to the string should be type cast to
u32 and passed as a last parameter.
Returned values:
OK is returned if the response is sent successfully.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This function sends the provided standard response with an argument as a response, an unsolicited response
or an intermediate response, according to the requested type. With the NI provided, the associated
command is found. If the command had subscribed to this standard response with an argument, then the
response handler is called. Otherwise, the standard response with an argument is sent to the port provided.
Prototype:
s32 adl_atSendStdResponseExtSpe (u16 Type, adl_strID_e RspID, u32 arg, u16 NI)
Parameters:
Type: This parameter is composed of the response type, and the destination port where to send the
response. The type and destination combination has to be done with the following macro:
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be displayed.
89
Open AT® TUTORIAL
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This type of
responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
arg: This parameter represents the response argument. According to the RspID, this argument should be
an u32 integer, or an ascii * string. For example, an integer value should be assigned to this argument when
it is used with an RspID “ADL_STR_WIND”. For “ascii *” string, the pointer to the string should be type cast to
u32 and passed as a last parameter.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This function sends the provided standard response with an argument to the required port, as a response, an
unsolicited response or an intermediate response, according to the requested type.
Prototype:
Parameters:
Type: This parameter is composed of the response type, and the destination port where to send the
response. The type and destination combination has to be done with the following macro:
Parameters:
_port: This parameter is of adl_atPort_e type which specifies the port on which the text string
should be sent. Note that the port should be opened otherwise the response will not be displayed.
ADL_AT_RSP: This value indicates that the text should be sent as a final response string. These
responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used. When this type of
responses is sent, all the buffered unsolicited responses will be flushed on the required port.
90
Open AT® TUTORIAL
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response. These
responses will be sent to all the opened ports if ADL_AT_PORT_TYPE macro is not used. This type of
responses is buffered automatically till the terminal response is sent.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
These responses will be sent to UART1 if ADL_AT_PORT_TYPE macro is not used.
arg: This parameter represents the response argument. According to the RspID, this argument should be
an u32 integer, or an ascii * string. For example, an integer value should be assigned to this argument when
it is used with an RspID “ADL_STR_WIND”. For “ascii *” string, the pointer to the string should be type cast to
u32 and passed as a last parameter.
Returned values:
This function sends the provided standard response with an argument to the required port, as a response, an
unsolicited response or an intermediate response, according to the requested type.
Prototype:
Parameters:
NOTES
The RI pulse generation behaviour depends on "+WRIM" AT command parameter:
• If mode parameter of "+WRIM" AT command is set to 0, RI signal cannotbe pulsed by
adl_atSendUnsoResponse.
• RI pulse duration depends on pulse_width parameter of "+WRIM" ATcommand.
Returned values:
91
Open AT® TUTORIAL
This macro is used to send a custom response string to a specific port. The response string can be of the
following types:
Unsolicited
Terminal
Intermediate
Prototype:
Parameters:
_t: This parameter determines the type of the response which is associated to the text string that you want
to send. The values this parameter can take are:
ADL_AT_RSP: This value indicates that the text should be sent as a final response string.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
_p: This parameter is of adl_atPort_e type which specifies the port on which the text string should be sent.
Note that the port should be opened otherwise the response will not be displayed.
_r: This parameter is a pointer to the string which is sent to the specified port as a response. The type of the
response string depends on the _t parameter.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This macro can be used to send standard defined responses such as OK, ERROR
(unsolicited/terminal/intermediate) to a specific port.
Prototype:
Parameters:
_t: This parameter determines the type of the response which is associated to the text string that you want to
send. The values this parameter can take are:
92
Open AT® TUTORIAL
ADL_AT_RSP: This value indicates that the text should be sent as a final response string.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
_p: This parameter is of adl_atPort_e type which specifies the port on which the text string should be sent.
Note that the port should be opened otherwise the response will not be displayed.
_r: This parameter is a pointer to the string which is sent to the specified port as a response. The type of the
response string depends on the _t parameter.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This macro can be used to send a standard defined response with a parameter
(unsolicited/terminal/intermediate) on a specific port. For e.g. ‘+CME ERROR: 10” where “+CME ERROR” is a
standard defined response and “10” is a parameter for the response.
Prototype:
Parameters:
_t: This parameter determines the type of the response which is associated to the text string that you want to
send. The values this parameter can take are:
ADL_AT_RSP: This value indicates that the text should be sent as a final response string.
ADL_AT_UNS: This value indicates that the text should be sent as an unsolicited response.
ADL_AT_INT: This value indicates that the text should be sent as an intermediate response string.
_p: This parameter is of adl_atPort_e type which specifies the port on which the text string should be sent.
Note that the port should be opened otherwise the response will not be displayed.
_r: This parameter indicates the response ID that must be sent.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
93
Open AT® TUTORIAL
NOTES
adl_atSendResponseSpe, adl_atSendStdResponseSpe, adl_atSendStdResponseExtSpe are to be used with
adl_atCmdSendExt function.
adl_atCmdSendExt stacks command when call in a command handler to resend the command whereas
adl_atSendResponseSpe, adl_atSendStdResponseSpe, adl_atSendStdResponseExtSpe unstacks the command
and call the appropriate response handler (if any).
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
adl_atCmdCreate () API
adl_atCmdSend () API
adl_atCmdSendExt () API
adl_atCmdSendText() API
The following API allows you to send standard AT commands. The response of the executed command can be
captured in the associated callback function. You can also subscribe to various responses of the command to
be sent.
94
Open AT® TUTORIAL
Parameters:
Cmdstr: This parameter contains the command that you want to send (or execute). The command should be
an AT command. Refer to the AT command interface guide for the various commands and their formats.
Rspflag: This parameter determines whether or not the response and the intermediate response of the
command being created should be sent to the external application. It can have the following values:
TRUE: This indicates that the responses and the intermediate responses of the created command
(that are not subscribed) will be sent to the external application.
FALSE: This indicates that the responses and intermediate responses of the created command (that
are not subscribed) will not be sent to the external application.
This parameter can also be used to determine the port from which the command is to be created.
For instance, if you want a particular response to be created in such a way that it is emulated to be
created from UART1, then the RspFlag parameter can be used to define this behaviour. This is done
using the macro ADL_AT_PORT_TYPE. For instance,
Rsphdl: This parameter is the callback function associated with all the subscribed responses and
intermediate responses of the command being created and sent. This function will be called whenever the
subscribed responses of the command are received by the Open AT Application. This function has the
following prototype:
The argument of this function is of the adl_atResponse_t structure. This will hold the response to which you
have subscribed. This structure has the following definition:
typedef struct
{
adl_strID_e RspID; // Response ID // RspID
adl_port_e Dest; // Dest
u16 StrLength; //Length of unsolicited // Response length
void * Contxt; // Context
bool IsTerminal; // Terminal response flag
u8 NI; // Notification Identifier
u8 Type; // Type of the response
u8 Pad [1]; // Reserved for future use
ascii StrData [1]; //Unsolicited response. // Response address
} adl_atResponse_t;
95
Open AT® TUTORIAL
Description:
RspID:
Detected standard response ID if the received response is a standard one.
Dest:
Port on which the command has been executed; it is also the destination port where the
response will be forwarded if the handler returns TRUE.
StrLength:
Response string buffer length.
Contxt:
A context holding information gathered at the time the command is sent (if provided).
IsTerminal:
A boolean flag indicating if the received response is the terminal one (TRUE) or an intermediate
one (FALSE).
NI:
This parameter is to hold the Notification Identifier provided by the command initiating the
response.
Type:
Type of the response.
StrData[1]:
Response string buffer address.
< … > This parameter represents a list of standard and intermediate responses to which you want to
subscribe. When these responses are received, the callback function (Rsphdl) will be executed. To mark
the end of the list, the last element of this list should be NULL. If this list contains only two elements (“*”
and NULL), then all the responses of the command being sent will result in the invocation of the callback
function.
Returned values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES
You can specify which intermediate or terminal responses of the command being created should lead to the
execution of the callback function (Rsphdl). Specify the responses in the (…) variable list parameter of
adl_atCmdCreate () API.
If the variable list parameter (…) contains “*” and NULL, then any of the responses which the command will
generate result in the execution of the callback function.
96
Open AT® TUTORIAL
You also have the option of not specifying any callback function (Rsphdl) when the command is executed.
Specify NULL in place of the callback function. The adl_atCmdCreate() API should then be invoked as:
adl_atCmdCreate(“command”,TRUE,NULL,NULL);
This API functionality is same as adl_atCmdCreate without the rspflag argument and instead it sends the
command to the required command port stack, in order to be executed as soon this port is ready.
Prototype:
Parameters:
atstr: The string (name) of the command we want to send. Since this service only handles AT commands, this
string has to begin by the "AT" characters.
rsphdl: The response handler of the callback function associated to the command.
...: A list of strings of the response to subscribed to. This list has to be terminated by NULL.
Returned values:
OK is returned on success.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This function sends AT command with 2 added arguments compared to adl_atCmdCreate / adl_atCmdSend:
a NI (Notification Identifier) and a Context.
Prototype:
s8 adl_atCmdSendExt ( ascii * atstr,adl_atPort_e port,u16 NI,ascii * Contxt,adl_atRspHandler_t
rsphdl,... )
Parameters:
atstr: The string (name) of the command you want to send. Since this service only handles AT commands,
this string has to begin by the "AT" characters.
NI: This parameter is to hold the Notification Identifier provided by the command handler when re sending
the command already subscribed to solve any loop effect. The NI parameter can have the following values:
97
Open AT® TUTORIAL
0 (default value): the command is directly sent for execution (as when using adl_atCmdCreate or
adl_atCmdSend)
ADL_NI_LAUNCH: the searching handler process is launched:
If the command is subscribed the handler will be called
Else the command will be executed
Contxt: Context made to hold information gathered at the time the command wassent.
rsphdl: The response handler of the callback function associated to the command.
...: A list of strings of the response to subscribed to. This list has to be terminated by NULL.
Returned values:
OK is returned on success.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
This API is used to send intermediate text for a command which requires intermediate input text (For e.g.
AT+CMGS).
Prototype:
s8 adl_atCmdSendText (adl_port_e Port, ascii* Text )
Parameters:
Port: This parameter determines the port on which the text string should be sent. The port can be a
physical or virtual port. The values this parameter can take are defined in the adl_port_e enum.
Text: This parameter determines the text string to send to the specified port as intermediate text. If the text
doesn’t end with CTRL+Z character, it is added automatically by this API.
Returned values:
OK is returned if the response is sent successfully.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES:
dl_atCmdSendExt (with a NI parameter different from 0) finds out if the command has been subscribed. If
the command has been subscribed the handler is called otherwise the command is executed (as it is when
called with adl_atCmdSend or adl_atCmdCreate). If the command has multiple subscriptions, the last
handler subscribed is called. In order for any other handler to be called the last handler has to resend the
command with adl_atCmdSendExt API and the NI parameter provided so that the penultimate handler will
be called and so on.
98
Open AT® TUTORIAL
For any multiply subscribed command sent by an external application on one of the embedded modules ports
all handlers were called at the same time. Now there is a change of behaviour where only the last subscribed
handler is called (by resending the command using adl_atCmdSendExt API and the provided NI the
penultimate handler is called and so on ...).
If any Inner AT Command (as decribed in section 2.5 Inner AT Commands Configuration of ADL UGD) is
subscribed its handler has to resend the command with adl_atCmdSendExt API and the NI parameter
provided so that ADL internal handler is called. Otherwise as explained in section 2.5 of ADL UGD it may
affect ADL correct behaviour.
If a command is only subscribed once. Sending this command will call the handler. If the handler resends the
command with adl_atCmdSendExt API and the NI parameter provided the command will be sent for
execution. Likewise if a command is multiply subscribed. Sending this command with adl_atCmdSendExt API
and the NI parameter provided will call the last handler if at some point (after re-sending the command with
adl_atCmdSendExt API and the NI parameter provided) the first handler is called re-sending the command
with adl_atCmdSendExt API and the NI parameter provided will send the command for execution
99
Open AT® TUTORIAL
{
TRACE (( 1, "In ATI_CmdHandler2 - sending AT cmd for execution (no
more handlers)" ));
// sending ati command with adl_atCmdSendExt() and provided NI
// ati is not subscribed anymore (both subscribed handler have been
//called) hence the AT command is sent for execution
adl_atCmdSendExt( paras->StrData, paras->Port, paras->NI, NULL,
ATI_RspHandler3, "*", NULL );
}
void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, "Embedded Application : Main" ));
// ati is subscribed twice
// - first with ATI_CmdHandler2 command handler
// - then with ATI_CmdHandler1 command handler
adl_atCmdSubscribe("ati",ATI_CmdHandler2,ADL_CMD_TYPE_ACT);
adl_atCmdSubscribe("ati",ATI_CmdHandler1,ADL_CMD_TYPE_ACT);
}
100
Open AT® TUTORIAL
Open AT OS allows you to create and subscribe to your own custom AT commands. The following sections
describe the Open AT APIs that you can use to create new AT commands
The following API can be used to create a custom AT command:
Prototype:
This API allows you to subscribe (create) to a specific command along with an associated callback handler, so
that whenever this command is sent by the external application, the callback handler is executed. It should
be noted that the subscribed command can be a standard AT command or a new user defined AT command.
In this way, you can create new AT commands. However, these custom commands can be executed only
when the Open AT Application is running.
Parameters:
Cmdhdl: This parameter is the callback function which must be executed whenever the subscribed command
is sent by the external application. This function has the following prototype:
typedef void ( *adl_atCmdHandler_t) (adl_atCmdPreParser_t *)
The argument of this callback function is of the adl_atCmdPreParser_t type and holds the command and its
parameters to which you have subscribed. It has the following definition:
typedef struct
{
u16 Type; //Type of command
u8 NbPara; //No of valid parameters (different
//from “”)
adl_atPort_e Port; // Port
wm_lst_t ParaList; // Parameter list for the command
u16 StrLength; //Length of command
101
Open AT® TUTORIAL
Whenever the subscribed command is sent by the external application the callback function is called and the
elements of the adl_atCmdPreParser_t structure are filled with arguments provided to the command.
Parameters:
Type: This member indicates the type of command that is sent. The commands are also classified on the
basis of their operation and whether or not they provide any input (using arguments). The following types of
commands are defined.
Command Type Value Meaning Assigned
ADL_CMD_TYPE_PARA 0x0100 These types of commands allow arguments
to be passed. For example, the AT+CMD=x,y
command. However, the command must
have the correct format for the callback to
be executed.
ADL_CMD_TYPE_TEST 0x0200 These types of commands allow you to get
the values which can be set for its
parameter. For example, AT+CMD=?.
ADL_CMD_TYPE_READ 0x0400 This type of commands allows you to test
the value already set for the parameter. For
example, AT+CMD?.
ADL_CMD_TYPE_ACT 0x0800 This is the simple type of commands which
can be subscribed. For example, “AT+CMD”.
ADL_CMD_TYPE_ROOT 0x1000 This type allows you to subscribe to all the
commands starting with a particular string.
The callback handler will receive the whole
AT string.
ADL_CMD_TYPE_ROOT_EXT 0x2000 This parameter is same as
ADL_CMD_TYPE_ROOT in this version.
NbPara: This member contains the number of valid arguments (those parameters which are different from
“”) of the command. This is valid only in case the command is of the ADL_CMD_TYPE_PARA type as this is the
only command type which can have arguments.
Port: This member contains the port information on which the command is sent by the external application.
ParaList: This member contains the parameters which are passed to the command (in case the command is
of the ADL_CMD_TYPE_PARA) type. To retrieve the parameters, use the ADL_GET_PARAM (_P_,_i_) macro.
The first parameter (_P_) of this macro is a pointer to the adl_atCmdPreParser_t structure and the second
parameter (_i_) is the requested parameter index (starting from 0). This macro (ADL_GET_PARAM ()) returns
a pointer to the ASCII string which contain the arguments passed in the command.
102
Open AT® TUTORIAL
StrLength: This member contains the length of the command to which you have subscribed. Whenever, this
command is sent by the external application, the StrLength parameter will contain the complete length of
the string entered (which constitutes the command).
NI: This parameter is to hold the Notification Identifier provided by the command handler when re sending
the command already subscribed to solve any loop effect.
Context: This parameter contains the context information which is provided during the subscription.
StrData: This member is the pointer to the string of the command which is entered through the external
application.
Options:
This parameter is used to provide the command type (ADL_CMD_TYPE_PARA, ADL_CMD_TYPE_READ,
ADL_CMD_TYPE_ACT, ADL_CMD_TYPE_ROOT, and ADL_CMD_TYPE_TEST) information to the API. If the
command type is ADL_CMD_TYPE_PARA (which accepts parameter), then the Options parameter also
provide the maximum and minimum parameters which can be used with the command. This is done with the
logical OR of the following information:
The minimum number of arguments ‘a’ is stored in the least significant nibble (4 bits) as in 0x000a.
The maximum number of arguments ’b’ which can be provided to the command should be stored in the
second least significant nibble as in 0x00b0.
For example, if a command expects a maximum of 4 arguments and a minimum of 1 argument then this can
be specified in the Options parameter by giving ADL_CMD_TYPE_PARA|0x0041 as its value.
Context: This parameter holds context information that will be gathered during the command subscription.
Cmdport: This parameter defines the port on which the command is subscribed. This is defined by
ADL_CMD_SUBSCRIPTION_ONLY_EXTERNAL_PORT and ADL_CMD_SUBSCRIPTION_ALL_PORTS. Note that in
this version only ADL_CMD_SUBSCRIPTION_ONLY_EXTERNAL_PORT valid value for this option.
Returned Values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES
Only those commands which accept parameters (ADL_CMD_TYPE_PARA) should specify the maximum and
minimum number of arguments.
You can also subscribe to standard AT commands and provide new functionality to these commands (in the
callback function). In this way, your Open AT Application can become extremely flexible.
To prevent the callback function from being called every time the command is sent, unsubscribe from the
command.
If you subscribe to a command with a callback handler (for example func1()) and then subscribe the same
command with a callback handler (for example func2()), then whenever this command is issued, both the
handlers(func1() and func2()) will be invoked depending upon the subscription order
ADL internally can subscribe to few AT commands and these commands shouldn’t be subscribed by Open AT
103
Open AT® TUTORIAL
Application. Subscribing to these commands may result in undefined behaviour. These commands include:
AT+CPIN
ATD, ATA, ATH
AT+CGACT, AT+CGANS, AT+CGDATA
AT+WDWL, AT+WOPEN
ATO, ATQ, ATV, AT+WIND, AT+CMEE, AT&W, ATZ, AT&F, AT+CREG, AT+CGREG, AT+CRC, AT+CGEREP
Prototype:
After calling this API, the callback function associated with the subscribed command will not be executed
again.
Parameters:
Cmdstr: This parameter contains the string (name) of the command from which you want to unsubscribe.
This might contain a standard AT command, or a user-defined AT command.
Cmdhdl: This parameter is the callback function associated with the previously subscribed command.
Returned Values:
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTES:
Only the commands subscribed using adl_atCmdSubscribe () API can be unsubscribed using
adl_atCmdUnSubscribe ().
After unsubscribing the command, the callback function will not be called when the command is issued again
from the external application
Open AT OS provides the following API to set Quite mode. This mode has the behaviour similar to ATQ
command. In this mode, the terminal response will not be sent to external application.
Prototype:
void adl_atCmdSetQuietMode (bool IsQuiet )
104
Open AT® TUTORIAL
Parameters:
IsQuiet: This parameter sets the quiet mode. The quite mode will be enabled if this parameter is set to TRUE.
If it is set to FALSE then the quite mode will be disabled.
Returned Values:
None
105
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
Different types of responses: Terminal Responses, Intermediate Responses and Unsolicited Responses.
To subscribe and unsubscribe unsolicited responses use the adl_atUnSoSubscribe () and adl_atUnSoUnSubscribe
() APIs respectively.
To send responses from the Open AT Application use the adl_atSendResponse (), adl_atSendStdResponse () and
adl_atSendStdResponseExt () APIs.
To send standard AT commands use the adl_atCmdCreate ()/ adl_CmdSend ()/ adl_CmdSendExt ()/
adl_CmdSendText () API from within the Open AT Application.
To subscribe and unsubscribe AT commands use the adl_atCmdSubscribe ()/ adl_atCmdSubscribeExt () and
adl_atCmdUnSubscribe () APIs
106
Open AT® TUTORIAL
Chapter 8 – AT Services
CHAPTER 8
AT Services
1. Objective
This chapter introduces you to the AT strings service and the functions that you can use to process the strings.
typedef enum
{
ADL_STR_NO_STRING, // The string is unknown
ADL_STR_OK, // OK
ADL_STR_BUSY, // BUSY
ADL_STR_NO_ANSWER, // NO ANSWER
ADL_STR_NO_CARRIER, // NO CARRIER
ADL_STR_CONNECT, // CONNECT
ADL_STR_ERROR, // ERROR
ADL_STR_CME_ERROR, // +CME ERROR:
ADL_STR_ CMS_ERROR, // +CMSERROR:
ADL_STR_CPIN, // +CPIN:
ADL_STR_LAST_TERMINAL, //ALL TERMINAL RESPONSE ARE BEFORE THIS STRING
ADL_STR_RING= ADL_STR_LAST_TERMINAL, //RING
ADL_STR_WIND, //+WIND: INDICATION
ADL_STR_CRING, //+CRING: INDICATION
ADL_STR_CPINC, //+CPINC: INDICATION
ADL_STR_WSTR, //+WSTR: INDICATION
ADL_STR_CMEE, // "+CMEE:"
107
Open AT® TUTORIAL
Chapter 8 – AT Services
ADL_STR_CREG, // "+CREG:"
ADL_STR_CGREG, // "+CGREG:"
ADL_STR_CRC, // "+CRC:"
ADL_STR_CGEREP, // "+CGEREP:"
ADL_STR_LAST, //LAST STRING ID
} adl_strID_e;
3. APIs
3.1. Getting a String Response ID
The adl_strGetID () function can be used to get the string ID corresponding to a given response string. The ID
obtained can be used to make the programming logic simpler. For instance, while using a switch-case
statement, it is simpler to use an ID instead of an actual string.
Prototype:
Parameters:
Returned Values:
This function is used to get the ID of the provided response string along with an optional argument of the
response string. The function is defined below:
Prototype:
Parameters:
arg: This parameter takes the value of parsed argument of the string. For example, the
ADL_STR_CME_ERROR string when parsed, will return the string ID along with the CMEE error code. The arg
parameter will return the CMEE error code value. For example, if the response is +CME ERROR: 10, the arg
parameter is 10.
108
Open AT® TUTORIAL
Chapter 8 – AT Services
Returned Values:
The following function can be used to check whether a particular response string is the last string that was
received for a sent command. This function can be used to check for any of the terminal responses received
as well, and the return value can be used as a condition to implement a particular logic.
Prototype:
This function checks whether a particular response ID belongs to the last response.
Parameters:
Returned Values:
Given an ID, the adl_strGetResponse () function is used to get the AT response string corresponding to that
ID. The function is described below.
Prototype:
Parameters:
RspID: This parameter takes the ID corresponding for which the response string must be found.
109
Open AT® TUTORIAL
Chapter 8 – AT Services
Returned Values:
This function is used to retrieve the response string from a given ID, in cases where the string responses have
an optional argument.
Prototype:
Parameters:
RspID: This parameter takes the ID corresponding to which the response string is to be found.
arg: this parameter gives the response ID to be copied in the response string. According to response ID, this
argument should be an integer value, or an ascii *string.
Returned Values:
4. Sample Code
#include "adl_global.h"
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
/* Local variables */
ascii *arg;
u8 *argType;
bool Termresp=FALSE;
ascii * rsp="+WIND: 4";
ascii * rspArgStr="+CME ERROR: 10";
adl_strID_e Get_ID;
adl_strID_e StrIDArg;
u32 Get_String=2;
ascii * ResponseStr;
ascii * ResponseStrArg;
u32 argresp;
adl_tmr_t * timerHandle;
/* Function : adl_main */
110
Open AT® TUTORIAL
Chapter 8 – AT Services
/* Function to get response string ID and argument from a given response string */
StrIDArg = (adl_strID_e) adl_strGetIDExt (rspArgStr,arg , argType );
TRACE( ( 1, "String ID for '+CME ERROR: 10'= %d",StrIDArg ) );
TRACE( ( 1, "argument= %d",*arg) );
/* Function to get response string along with argument from a given response string ID*/
Summary
The following points have been covered in this chapter
Open AT OS provides APIs to process AT standard string responses. The need for AT strings service arises when
certain functionality must be implemented based on the AT responses received from various AT command.
To get an ID from a response string use adl_strGetID () function.
To get an ID from a response string containing an optional argument use adl_strGetIDExt ()function
To check whether or not the given string belongs to the last response use the
adl_strIsTerminalResponse()function.
To get a response string for a given response ID use the adl_strGetResponse()function.
To get a response string which has an optional argument, use the adl_strGetResponseExt function
111
Open AT® TUTORIAL
Chapter 8 – AT Services
112
Open AT® TUTORIAL
CHAPTER 9
Timer Service
1. Objective
The objective of this chapter is to introduce you to timers and their usage. Timers are extensively used in Open AT
Applications to introduce a time delay, execute a process or poll for events. This can prove to be handy in situations
where a time delay is necessary between subsequent instructions or network operations as depicted in the examples
that follow in this chapter.
2. Timers
Timers are indispensable components of the Open AT OS. Timers provide the following functionality:
Run a function/procedure after a specified period of time.
Automatically execute a task at periodic intervals.
Hence, timers can be used when:
A process needs to be executed repeatedly after a specific interval. For example, polling of an input pin, or sending
sensor data to the server every hour.
A delay is needed in the execution of statements. For instance, while dealing with network-related activities, a time
delay must be introduced so that the outcome of the first activity is available before the second activity is initiated. In
these cases, timers can provide the necessary delay.
3. Types of Timers
Two types of timers are available in Open AT OS: Cyclic and Non-Cyclic Timers.
113
Open AT® TUTORIAL
These timers can run a particular process repeatedly after a specified time interval. These have the following
advantages:
These timers are used to provide a one-time delay in executing a particular process, and are not scheduled to
run again.
For instance, an Open AT Application can be put on hold for sometime during its initialization to give the
network registration operations time to be completed before the Open AT Application starts other functions.
The following API is provided to subscribe to a timer (Cyclic/Non-Cyclic) and associate a process with it (callback
function):
Prototype:
This API starts a timer with an associated callback function. The callback function will be executed when the
timer interval expires. The statements which constitute the process to be scheduled should be placed in the
callback function so that they will be automatically executed after the time interval expires.
Prototype:
bCyclic: This Boolean parameter determines whether a cyclic or a non-cyclic timer must be started. If this
parameter is set to TRUE, a cyclic timer will be started. If this parameter is set to FALSE, then a Non-Cyclic
timer will be started.
CyclicOpt: This parameter determines whether a cyclic or a non-cylcic timer must be started. This is defined
by the following structure:
114
Open AT® TUTORIAL
typedef enum
{
ADL_TMR_CYCLIC_OPT_NONE,
ADL_TMR_CYCLIC_OPT_ON_EXPIRATION,
ADL_TMR_CYCLIC_OPT_ON_RECEIVE,
ADL_TMR_CYCLIC_OPT_LAST
} adl_tmrCyclicMode_e;
Parameters:
ADL_TMR_CYCLIC_OPT_NONE: The timer will be started in non-cyclic mode if this parameter is used for
setting the timer mode. The timer will be automatically unsubscribed as soon as the timer expiration event is
notified to the application.
ADL_TMR_CYCLIC_OPT_ON_EXPIRATION: The timer will be started in cyclic mode if this parameter is used
for setting the timer mode. The timer will be re-programmed before the timer expiration event is sent to the
application. Hence, there is no minimum time guaranteed between two timer events, since if the application
is pre-empted for some time, timer events will continue to be generated even if the application is not
notified.
ADL_TMR_CYCLIC_OPT_ON_RECEIVE: The timer will be started in cyclic mode if this parameter is used for
setting the timer mode. The timer will be re-programmed after the timer expiration event is sent to the
application. Hence, the duration between two events is guaranteed to be at least equal to the timer period.
TimerValue: This parameter indicates the period after which the timer expires. This parameter is dependent
on the TimerType parameter.
TimerType: This parameter represents the unit of TimerValue parameter. In other words, this parameter is
the unit of the timeout interval. The possible values which this parameter can take are:
ADL_TMR_TYPE_100MS: This value indicates that the TimerValue is in 100 milliseconds steps. The least
timeout value which can be set using the timer is 100 milliseconds. The TimerValue parameter will indicate
the steps of 100 milliseconds after which the timer expires. For example, if the TimerValue has a value of 2,
then the timer will expire after 200 milliseconds (2 * 100 milliseconds).
ADL_TMR_TYPE_TICK: This value indicates that the TimerValue is in 18.5 millisecond steps. Hence, the least
value which can be set using the timer will become 18.5 milliseconds. The TimerValue parameter indicates
the steps of 18.5 milliseconds after which the timeout occurs. For example, if TimerValue parameter has a
value of 2, then the timer will expire after 2 * 18.5 = 37 milliseconds.
Timerhdl: This parameter is the callback function which is called after timeout. For cyclic timers, this function
is called repeatedly after each timeout. For non-cyclic timers, this function is called only once after the
timeout occurs. This function has the following prototype:
115
Open AT® TUTORIAL
The argument received by this function will contain the timer ID and the Context. There can be a maximum
of 32 timers running simultaneously. The timer ID is an integer parameter that will differentiate a timer from
other timers. The maximum value of the Timer ID that can be received in the timer callback function is 31;
the minimum value is 0. The timer ID values are assigned in a circular fashion. That is, if a timer with a timer
ID of 1 is subscribed, the next subscription will yield a timer ID 2, irrespective of whether or not the previous
timer was subscribed. After the whole range (0-31) is used, the timer IDs will be reused.
The argument context is a pointer on the application context provided to adl_tmrSubscribeExt (). This will be
set to NULL if the timer is subscribed using adl_tmrSubscribe ().
Context: This is a pointer on an application defined context, which will be provided to the handler when the
timer event will occur. This parameter should be set to NULL if not used.
Returned Values:
If the API is successful, it returns the pointer to the timer which is started. This pointer is used to unsubscribe
the timer.
NULL is returned if the timer value is zero or if there is no more timer resource available.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
There can be a maximum of 32 timers running at a time. If a request is made for a new timer after subscribing
for all 32 timers, the adl_tmrSubscribe/adl_tmrSubscribeExt API returns NULL.
A single callback function can be associated with several timers.
The minimum delay which can be provided using a timer is 18.5 milliseconds.
Prototype:
This API stops and unsubscribes the timer and its handler. The call to this API is only meaningful for a cyclic
timer or a timer that hasn't expired yet. After execution of this API, the callback function of the timer will not
be called again.
Parameters:
tim: This parameter is the pointer to the timer from which you want to unsubscribe. This is received as a
return value of adl_tmrSubscribe API.
Timerhdl: This parameter is the callback function associated with the timer.
116
Open AT® TUTORIAL
TimerType: This parameter represents the unit of timeout interval. This parameter can have the following
values:
Returned Values:
If the API is successful, it returns the remaining time of the timer before the timeout occurs. (The unit will be
according to the TimerValue parameter).
ADL_RET_ERR_BAD_HDL is returned if the provided timer handle is unknown or not in accordance with the
handler.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
The call to adl_tmrUnSubscribe API is only meaningful for a cyclic timer or a timer that hasn't expired yet. A non-
cyclic timer automatically unsubscribes itself when the timer times out.
5. Sample Code
5.1. Subscribing to a non-cyclic timer
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
adl_tmr_t *timer_ptr;
u32 timeout_period = 5;
117
Open AT® TUTORIAL
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
adl_tmr_t *timer_ptr;
u16 timeout_period = 5;
static counter=0;
Summary
The following points have been covered in this chapter
Timers are tools which allow a function to be called at regular interval and induce a time delay in the execution
of statements.
There are two types of timers:
o Cyclic Timers: These timers can be used when periodic execution of task is required.
o Non-Cyclic Timers: These timers are used to provide a one time delay in executing a particular task.
To subscribe to a timer use adl_tmrSubscribe ()/ adl_tmrSubscribeExt() API.
To unsubscribe a timer use adl_tmrUnSubscribe () API
118
Open AT® TUTORIAL
CHAPTER 10
Error Management Service
1. Objective
This chapter describes how to manage error messages in the embedded module using the Open AT OS.
2. Introduction
Open AT OS uses a special area in flash to store the error description and call stack when an exception occurs. This area
is called backtraces and the data inside this area can be retrieved using Error Management service APIs.
The error management service also allows user to catch the error generated through the Open AT Application. This
service also allows raising the custom errors from the Open AT Application. When this error occurs, the embedded
module may reset.
Prototype:
s8 adl_errSubscribe( adl_errHdlr_f ErrorHandler )
119
Open AT® TUTORIAL
Parameters:
ErrorHandler: This Error handler is invoked when a error occurs; this function is declared thus:
An error is associated with the ID (ErrorID) and the corresponding text string (ErrorStr), sent as parameters to
the adl_errHalt API.
Returned Values:
FALSE: if the error is processed and filtered.
TRUE: will cause the embedded module to execute a fatal error reset and give a backtrace.
Returned Values:
OK is returned on successful subscription to the error management service.
NOTE :
ErrorID below 0x0100 are for internal purpose. So you must only use ErrorIDs above 0x0100.
You cannot subscribe to the error management service more than once at a time. You have to unsubscribe before
subscribing again
The following API should be used to unsubscribe from the error management service:
Prototype:
s8 adl_errUnsubscribe( adl_errHdlr_f ErrorHandler )
Parameters:
ErrorHandler: The same handler passed to the adl_errSubscribe API.
Returned Values:
OK is returned on successfully unsubscribing from the error management service.
120
Open AT® TUTORIAL
The following function causes an error that is defined by its ID and string:
Prototype:
void adl_errHalt( u16 ErrorID, const ascii * ErrorStr )
If an error handler is defined, it is invoked when this API is called, otherwise, the API will result in resetting
the embedded module.
Parameters:
ErrorID: ID of the error.
Returned Values:
None
This API is used to start the backtrace analysis process. This process has to be started before Open AT
Application can read the backtraces. When the embedded module is rebooted due to exception, this process
can be started to understand the cause of the exception.
Prototype:
s8 adl_errStartBacktraceAnalysis ( void )
Parameters:
None
Returned Values:
Positive or null handle is returned on success.
This API is used to retrieve the next backtrace stored in the non-volatile memory. The analysis process has to
be started before using this API.
Prototype:
s32 adl_errRetrieveNextBacktrace ( u8 Handle, u8 * BacktraceBuffer, u16 Size )
121
Open AT® TUTORIAL
Parameters:
Handle: Handle returned by adl_errStartBacktraceAnalysis () API.
BacktraceBuffer: Buffer where next retrieved backtrace will be copied. If mentioned NULL, this API will
return the required size for the next call to this API.
Returned Values:
OK is returned on success.
NOTE :
Back trace retrieved using adl_errRetrieveNextBacktrace () should be sent using FCM flow to the external
application. GPRS flow can also be used to send the traces to the remote system.
These backtraces are ciphered, so an Open AT Application can't interpret them.
This API is used to erase all the stored backtraces in the non-volatile memory. If the backtrace memory is
full, the backtraces are not over-written, hence it is very important to erase the backtraces using this API.
Prototype:
s32 adl_errEraseAllBacktraces ( void )
Parameters:
None
Returned Values:
OK is returned on success.
Prototype:
adl_errAnalysisState_e adl_errGetAnalysisState ( void )
122
Open AT® TUTORIAL
Parameters:
None
Returned Values:
Return the current analysis state. The values it can take are defined in the adl_errAnalysisState_e enum. This
enum is defined below:
typedef enum
{
ADL_ERR_ANALYSIS_STATE_IDLE, // No running analysis
ADL_ERR_ANALYSIS_STATE_RUNNING // A backtrace analysis is
// running
}adl_errAnalysisState_e
4. Sample Code
/* sample code implementing the error management functionality */
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
/* Timer handler */
void TimerHdlr( u8 ID, void *context)
{
static u8 count = 0;
count++;
if( count == 10 )
{
adl_tmrUnSubscribe(tmr_hdl,TimerHdlr,ADL_TMR_TYPE_100MS);
adl_errHalt(ADL_ERR_LEVEL_APP,"Error From Appl");
}
123
Open AT® TUTORIAL
/* Main function */
void adl_main ( adl_InitType_e InitType )
{
s8 ret;
TRACE((1,"Main function"));
ret = adl_errSubscribe(ErrHandler);
TRACE((1,"Return value of adl_errSubscribe=%d",ret));
tmr_hdl = adl_tmrSubscribe(TRUE, 30, ADL_TMR_TYPE_100MS, TimerHdlr);
}
Summary
The following points have been covered in this chapter
The APIs for error management are defined in the adl_error.h header file.
The adl_errSubscribe API should be used to subscribe to the error management service.
The adl_errUnsubscribe API should be used to unsubscribe from the error management service.
The adl_errHalt API should be used to control the embedded module behaviour when an error occurs. For fatal
error, a reset could be performed and for a non fatal error a trace could be performed.
The adl_errStartBacktraceAnalysis API should be used to start the backtrace analysis process.
The adl_errRetrieveNextBacktrace API used to retrieve the next backtrace stored in the non-volatile memory.
The adl_errEraseAllBacktraces used API to erase all the stored backtraces in the non-volatile memory.
The adl_errGetAnalysisState API used to get the current backtrace analysis state.
124
Open AT® TUTORIAL
CHAPTER 11
Memory Management
1. Objective
The objective of this chapter is to introduce the different sections of RAM available in the embedded module and the
usage of each in detail.
2. Sections in RAM
RAM available for the embedded module has two sections. They are:
Open AT OS RAM
Firmware RAM
Firmware RAM is managed by Real Time Kernel and Open AT RAM is the memory space available for Open AT
Application and is discussed in more detail in the following sections
3. Open AT OS RAM
The objective of this section is to introduce the usage of RAM memory in Open AT Application. Memory is always an
important and scarce resource in any embedded device. In Open AT Application memory could be allocated dynamically
(at runtime). It is essential that you release the memory once it has been used.
This chapter provides answers to the following queries:
Data (Global Variables): This area depends on number of global and static variables used in the application.
125
Open AT® TUTORIAL
The map file (file name: m) can be used to observe the size of different areas in RAM and Flash. This file is generated
during Open AT Application binary generation and is available in the “out” folder. Please find below the extract from the
map file generated for Hello World sample:
=================================================
Code RO Data RW Data ZI Data Debug
39036 1678 420 586 82152 Grand Totals
=================================================
Total RO Size(Code + RO Data) 40714 ( 39.76kB)
Total RW Size(RW Data + ZI Data) 1006 ( 0.98kB)
Total ROM Size(Code + RO Data + RW Data) 41134 ( 40.17kB)
=================================================
Here RAM allocated for global variables is 0.98 kB. This includes RW data of 420 bytes for uninitialized global variables
and ZI data of 586 bytes for zero initialized global variables.
The RO (Read Only) data is added to the Open AT Application binary which is later flashed to embedded module. The
RO data includes constant variables used in the Open AT Application.
5. Allocating Memory
Memory APIs are declared in the adl_memory.h header file. Hence, this file must be included in the Open AT
Application which requires memory to be allocated dynamically.
For allocating memory, Open AT OS finds the best block in heap memory and allocates to the customer. If the block is
unavailable, it returns an error.
The user should take care of fragmentation issues that could occur due to frequent allocation/release of memory. For
efficient use of heap memory, user can allocate heap memory of constant size. For e.g. user can define the memory size
as 128, 512, 1024 and so on. When the application needs memory of 100 bytes, it can allocate size of 128 bytes.
126
Open AT® TUTORIAL
The following API can be used to dynamically allocate memory of the requested size in Open AT Application’s RAM
memory:
Prototype:
Parameters:
Returned Values:
ADL_ERR_MEM_GET error in case the memory allocation fails, which is handled by the error service. If the
error handler filters and refuse this error, then the function returns NULL.
NOTE :
adl_memGet API throws an exception (ADL_ERR_MEM_GET) if there is a failure in memory allocation.
6. Releasing Memory
6.1. The adl_memRelease macro
This macro releases the allocated memory buffer designed by the supplied pointer.
Parameters:
_p_: A pointer on the allocated memory buffer.
Returned Values:
TRUE if the memory was correctly released. In this case, the provided pointer is set to NULL.
Internal memory release function, which should not be called directly. The adl_memRelease macro has to be
used in order to release memory buffer.
Prototype:
bool adl_memRelease (void **ptr);
This API releases the memory allocated to the supplied pointer and sets the pointer to NULL.
Parameters:
ptr: Pointer to the allocated memory buffer address.
127
Open AT® TUTORIAL
Returned Values:
Please refer to the adl_memRelease macro definition
NOTE :
If the memory release fails, one of the following exceptions is generated (these exception cannot be filtered by
the Error service, and systematically lead to a reset of the embedded module).
Exceptions:
RTK exception 155: The supplied address is out of the heap memory address range
RTK exception 161 or 166: The supplied buffer header or footer data is corrupted: a write overflow has
occurred on this block
RTK exception 159 or 172: The heap memory release process has failed due to a global memory corruption
in the heap area.
Prototype:
#define ADL_MEM_UNINIT ( _X ) _X __attribute__((section("UNINIT")));
Parameters:
_X: This parameters corresponds to global variable to define. The type and the name of the variable have to
be defined. Refer to Example below to get more information.
NOTE :
Rules on the syntax:
At the end of the variable declaration, there is no semicolon
Global variable cannot be initialized with a value when it is declared
Warning:
This macro is not functional in RTE mode; the global variable will be intialized to 0 at starting.
Example:
// Global variable definition
ADL_MEM_UNINIT( u32 MyGlobal )
void adl_main ( adl_InitType_e InitType )
{
...
MyGlobal = 500
...
}
128
Open AT® TUTORIAL
Prototype:
Parameters:
typedef struct
{
u32 TotalSize // Total RAM size for Open AT Application in bytes.
u32 StackSize // Open AT OS call stack area size in bytes.
u32 HeapSize // Open AT OS Heap area size in bytes.
u32 GlobalSize //Open AT OS Global variable area size in bytes.
} adl_memInfo_t
Returned values:
OK on success
7. Memory Limitations
The global variables, call stack and dynamic memory allocated are all part of the RAM allocated to Open AT Application.
When an Open AT Application is developed on a embedded module B-type (with 128Kb of RAM), the whole RAM
memory is not available for the Open AT Application as some of it is used by call stack and library ADL variables. The call
stack uses at least 1KB of RAM. In addition to that 0.5KB of memory is used by the internal variables of the library.
8. Sample Code
#include "adl_global.h"
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
void adl_main ( adl_InitType_e InitType )
{
ascii * buffer;
u32 total_allocation = 0;
u16 max_size = 500;
TRACE ((1, "Embedded Application: Main”));
adl_atSendResponse(ADL_AT_UNS,"\r\nInside adl_main\r\n");
129
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
The memory can be allocated using the void * adl_memGet(u32 size) API.
The adl_memGet API leads to an exception (memory error 0x10) if there is not enough RAM for the required
size).
The memory can be released using the bool adl_memRelease(void **ptr) API.
The memory should be released only if it has been allocated previously, otherwise it will lead to an exception
(RTK exception 155).
130
Open AT® TUTORIAL
CHAPTER 12
Debug Traces
1. Objective
This chapter introduces you to the concept of debug traces in an Open AT Application and describes the debug
configuration settings of the Open AT OS.
When the Debug configuration is selected in Developer Studio, the __DEBUG_APP__ compilation flag is
defined, and also the TRACE & DUMP macros. Traces & dumps declared with these macros will be embedded
at compilation time.
In this Debug configuration, the FULL_TRACE and FULL_DUMP macros are ignored (even if these are used in
the application source code, they will neither be compiled nor displayed on Target Monitoring Tool at
runtime).
When the Full Debug configuration is selected in the Developer Studio, both the __DEBUG_APP__ and
__DEBUG_FULL__ compilation flags are defined, and also the TRACE, FULL_TRACE, DUMP & FULL_DUMP
macros. Traces & dumps declared with these macros will be embedded at compilation time.
When the Release configuration is selected in the Developer Studio, neither the __DEBUG_APP__ nor
__DEBUG_FULL__ compilation flags are defined. The TRACE, FULL_TRACE, DUMP and FULL_DUMP macros
131
Open AT® TUTORIAL
are ignored (even if these ones are used in the application source code, they will neither be compiled, nor
displayed on Target Monitoring Tool at runtime).
This macro is a shortcut to the adl_trcPrint function. Traces declared with this macro are only embedded in
the application if it is compiled with in the Debug or Full Debug configuration, but not in the Release
configuration.
#define TRACE ( _X_ )
This macro is a shortcut to the adl_trcDump function. Dumps declared with this macro are only embedded in
the application if it is compiled with in the Debug or Full Debug configuration, but not in the Release
configuration.
#define DUMP ( _lvl_, _P_, _L_ )
This macro is a shortcut to the adl_trcPrint function. Traces declared with this macro are only embedded in
the application if it is compiled with in Full Debug configuration, but not in the Debug or Release
configuration.
#define FULL_TRACE ( _X_ )
This macro is a shortcut to the adl_trcDump function. Dumps declared with this macro are only embedded in
the application if it is compiled with in Full Debug configuration, but not in the Debug or Release
configuration.
#define FULL_DUMP ( _lvl_, _P_, _L_ )
for tasks: on the trace element name defined in the tasks declaration table
for Low Level Interrupt handlers: on the "LLH" trace element
for High Level Interrupt handlers: on the "HLH" trace element
In addition to the trace information, a embedded module local timestamp is also displayed in the tool.
Example1:
u8 I = 123;
TRACE (( 1, "Value of I: %d", I ));
132
Open AT® TUTORIAL
At runtime, this will display the following string on the CUS4 level 1 on the Target Monitoring Tool:
Value of I: 123
Prototype:
s8 adl_trcPrint ( u8 Level, const ascii* strFormat, ... )
Parameters:
Level: This defines the trace level. The trace level range is from 1 to 32. Traces are displayed on the ADL level
on the Trace View window of Developer Studio.
strFormat: This parameter is the trace string, which can use the standard C sprintf syntax. The maximum
displayed string length is 256 bytes. If this string is longer it will be truncated on display.
NOTE :
Direct use of the adl_trcPrint function is not recommended. The TRACE & FULL_TRACE macros should be used
instead, to take benefit of the build configurations features.
‘%s’ character, normally used to insert strings, is not supported by the the trace function.
The trace display should be limited to 255 bytes. If the trace string is longer, it will be truncated.
for tasks: on the trace element name defined in the tasks declaration table
In addition to the trace information, a embedded module local timestamp is also displayed in the tool.
Since the maximum length of a display line is 255 bytes, if the display length is greater than 80 (each byte is displayed
on 3 ASCII characters), the dump will be segmented on several lines. Each truncated 80-byte line will end with an ellipse
(…).
An example follows:
u8 buffer [200], i;
for (i=0;i<200;i++)
buffer[i] = i;
DUMP (1, buffer, 200);
At runtime this code sample will display the following three lines on the CUS4 level1 on the Trace View window of
Developer Studio:
133
Open AT® TUTORIAL
Prototype:
Parameters:
Level: This defines the trace level. The trace level range is from 1 to 32. Traces are displayed on the ADL
element on the Trace View window of Developer Studio.
NOTE :
Direct use of the adl_trcDump function is not recommended. The DUMP & FULL_DUMP macros should be used
instead, to take benefit of the build configurations features.
134
Open AT® TUTORIAL
6. Sample Code
#include "adl_global.h"
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
void adl_main ( adl_InitType_e InitType )
{
ascii * buffer;
u32 total_allocation = 0;
u16 max_size = 256;
Summary
The following points have been covered in this chapter
Debug trace service is used to display the software trace strings on the Trace View window of Developer Studio.
Debug traces are used in three configurations:
Debug configuration
Full debug configuration
Release configuration
The DUMP macro displays the contents of a buffer in a hexadecimal format on the Trace View window of
Developer Studio.
The TRACE macro is used to print the trace string using the standard C sprintf syntax.
135
Open AT® TUTORIAL
136
Open AT® TUTORIAL
CHAPTER 13
Flash Memory
1. Objective
This chapter describes the flash memory and its usage in the embedded module. Various APIs are used in the Open AT
OS to manage the flash memory. These API are used to subscribe, write, read, and erase the flash object in the flash
memory.
2. Flash Memory
Flash memory refers to a memory chip that holds its content even when the power is switched off. Flash memory is
derived from EEPROM, but it is less expensive and provides higher bit densities. In embedded module, the flash
memory consists if various logical regions as mentioned in the below figure:
A part of the flash memory is reserved for flash object. This area is called "flash" in the Open AT OS memory mapping.
The objects are associated with a user-defined string handle. Each object can be uniquely identified by a numeric ID.
The same is shown in the below mentioned figure:
137
Open AT® TUTORIAL
Flash Handle = "My Flash Area #1" Flash Handle = "My Flash Area #2"
Object #1 Header Object #1 Header
Object #2 Header Object #2 Header
Object #3 Header Object #3 Header
Object #4 Header Object #4 Header
…. ….
Object #N-1 Header Object #N-1 Header
Object #N Header Object #N Header
A single object can use up to 30 Kbytes and only 2000 object identifiers can exist in Open AT Application at any point in
time.
3. Flash APIs
This section describes the Open AT OS that you can use to manage the flash memory. These include APIs to create a
flash handle, read from flash, write to flash, find object count and so on.
Use the following API to subscribe to a set of objects that are identified by the handle.
Prototype:
Parameters:
Handle: This parameter is user-defined string used to identify a particular space on the flash memory. It is
used by the other flash APIs to read and write on the flash memory.
NbObjectRes: This parameter specifies the number of objects or IDs related to the given handle. It also
specifies that IDs are in the 0 to (NbObjectsRes-1) range.
Returned Values:
138
Open AT® TUTORIAL
NOTE :
It is sufficient to subscribe to the handle only once.
You cannot unsubscribe from a handle. To release the handle and object associated with it, you must issue the
AT+WOPEN=3 command. The flash object of the embedded Open AT Application will be erased.
The object IDs and the handle associated with the flash subscription are stored in the flash memory when you
subscribe to it.
Prototype:
Parameters:
Handle: This parameter is a user-defined string. It is used by the other flash APIs to read and write on the
flash memory.
ID: This parameter is the ID of the flash object that you want to check for in the flash memory.
Returned Values:
If successful, this function returns the length of the specified flash object.
Use the following API to erase the flash object of a given ID from the specified handle:
Prototype:
139
Open AT® TUTORIAL
Parameters:
Handle: This parameter gives the handle of the subscribed set of objects.
ID: This parameter gives the ID of the flash object that you want to erase.
Returned Values:
This function writes the flash object from the given Handle at the given Id for the length of the sting
provided. A single flash object can use up to 30 Kbytes.
Use the following API to write flash objects to the flash memory.
Prototype:
Parameters:
Handle: This parameter gives the handle of the subscribed set of objects.
ID: This parameter gives the ID of the flash object that you want to write to the flash memory.
Len: This parameter gives the length of the flash object that you want to write to the flash memory.
WriteData: This parameter gives the string that you want to write to the flash object.
Returned Values:
140
Open AT® TUTORIAL
NOTE :
A single object can use up to 30 Kbytes and only 2000 object identifiers can exist at the same time.
If the power is cut off during a flash write sequence, the data that the current operation was writing will be
lost. However, data that was previously written is retained and can be retrieved.
Use the following API to read the flash object from flash memory.
Prototype:
Parameters:
Handle: This parameter gives the handle of the subscribed set of objects.
ID: This parameter gives the ID of the flash object that you want to read.
Len: This parameter gives the length of the flash object that you want to read.
ReadData: This parameter gives the string allocated to store the read flash object.
Returned Values:
141
Open AT® TUTORIAL
Use the following API to get the size of remaining space in the flash memory.
Prototype:
Parameters:
None.
Returned Values:
This API returns the size of the free space flash memory in bytes.
Use the following API to get the ID count associated with the given handle. If the handle is set to NULL, then
this API lists the total ID count in the flash memory.
Prototype:
Parameters:
Handle: This parameter gives the handle of the subscribed set of objects.
Returned Values:
This API returns the ID count associated with the given handle on success. If the Handle parameter is set to
NULL, then this API returns the total ID count in the flash memory.
Use the following API to get the size of flash memory space used by the specified ID range and handle.
Prototype:
142
Open AT® TUTORIAL
Parameters:
Handle: This parameter gives the handle of the subscribed set of objects. If this parameter is set to NULL, the
total used size of the flash memory will be returned.
StartID: This parameter gives the starting ID of the range for which you want to find the size of the used
memory space. The value must not exceed the EndID value.
EndID: This parameter gives the last ID of the range for which you want to find the size of the used memory
space. This must be greater than the start ID.
Returned Values:
If this API is successful it returns the size of the used memory space associated with the given handle. If the
Handle is set to NULL, then this API returns the total size of the used flash memory.
4. Sample Code
/* sample code implementing the flash API */
#include "adl_global.h"
#include "adl_flash.h"
const u16 wm_apmCustomStackSize = 4096;
u8 *buffer_read;
/* Function to write data in Flash Memory*/
bool Flashwrite_Handler( adl_atCmdPreParser_t *paras )
{
s8 ret_val;
buffer_write = (u8 *) adl_memGet( BlockSize );
wm_memset( buffer_write, 'A', BlockSize-1 );
buffer_write[BlockSize]='\0';
TRACE( ( 1, "Inside Flashwrite_Handler" ) );
adl_atSendResponse(ADL_AT_RSP,"\r\nInside Flashwrite_Handler\n");
143
Open AT® TUTORIAL
144
Open AT® TUTORIAL
NOTE:
The handle needs to be subscribed only once.
The parameter which provides the length of the flash object (len) should exceed the actual length of the flash object
If the power is cut off during a flash write sequence, the data that the current operation was writing will be lost.
However, the data that was previously written is retained and can be retrieved.
145
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
Flash memory refers to a memory chip that holds its content without power.
Flash memory is derived from EEPROM, but it is less expensive and provides higher bit densities.
The flash APIs are declared in the adl_flash.h header file.
To subscribe to the flash service, use the adl_flhSubscribe API.
To check for the existence of the flash object, use the adl_flhExist API.
To erase the flash object, use the adl_flhErase API.
To write to the flash memory, use the adl_flhWrite API.
To read from the flash memory, use the adl_flhRead API.
To get the remaining flash memory size, use the adl_flhGetFreeMem API.
To get the ID count for the given handle, use the adl_flhGetIDCount API.
To get the size of the used memory space by a handle, use the adl_flhGetUsedSize API.
146
Open AT® TUTORIAL
CHAPTER 14
Application and Data Storage
Service
1. Objective
This chapter introduces you to the Application and Data Storage Volume (A&D) Services and explains the APIs which can
be used to manipulate this service. It also explains the concept behind the A&D storage memory and the process which
should be followed to use this service. This chapter answers the following questions:
These operations are done over the air using a GSM/GPRS link and this reduces the cost of upgrading the software as
the physical proximity with the embedded module is not required to upgrade/install an embedded Open AT
Application. You do not need to visit the installation site of the embedded module to upgrade the software. You only
need to implement the DOTA I/II/III functionality in your Open AT Application and send the new/ upgraded Open AT
Application to your embedded module over the GPRS/GSM data link. Moreover, as the A&D storage is a part of the
flash memory, the Open AT Application/ Firmware contents stored in this area are non-volatile. Hence, you can install
the new Open AT Application/ Firmware whenever you require it. You do not have to worry about the risk of losing the
contents of the new Open AT Application when the power to the embedded module is shut off.
Flash memory refers to a memory chip that holds its content even when the power is switched off. Flash memory is
derived from EEPROM, but it is less expensive and provides higher bit densities.
147
Open AT® TUTORIAL
A part of the flash memory is reserved for A&D storage space. This area is called "A&D space" in the Open AT OS
memory mapping.
A cell is a basic unit of A&D storage that it is allocated for data. The size of a cell can be specified during allocation. This
is a logical entity as compared to a sector, which is a physical unit.
A&D storage memory is a part of flash which can be used by the Open AT Application to store data objects or passive
applications. Data objects can be any piece of information which you want to be stored permanently. Passive
applications are inactive (not in execution) and are simply stored as raw data in the A&D storage. You can execute the
Open AT Application as and when you want by using the adl_adInstall API described later in this chapter.
In Firmware, the command AT+WOPEN=6 can be used to configure the amount of memory to be allocated for A&D. The
remaining memory will be available for Open AT Application binary. Please refer to the AT command interface guide for
more details on this command.
You can send a compiled Open AT Application (.dwl file) to the embedded module over an FTP connection or a
GPRS/GSM data connection. The embedded module can store the Open AT Application in the A&D storage. Hence, you
can update your old Open AT Application by sending new/updated applications to the embedded module. These Open
AT Application are stored in the A&D storage memory. When required, you can execute this new Open AT Application
by overwriting the old Open AT Application. In this way, you can update and execute the latest Open AT Application as
and when needed. This process is also known as DOTA I (Download Over The Air).
A&D storage are could be used to store a .dwl file (that it could be a new embedded Open AT Application binary file, or
an EEPROM configuration file, or an XModem downloader binary file). The dwl file stored can be installed whenever is
required.
You can download your Open AT Application to the A&D storage using the protocols like XModem
over data call or FTP over GPRS or any other protocol.
You can even download complete Firmware in the A&D storage cell also. The contents of the cell
can then be installed and hence, a firmware upgrade can also be performed. This is called DOTA-II.
You can even download delta of Firmware in the A&D storage cell also. The contents of the cell can
then be installed and hence, a firmware upgrade can also be performed. This is called DOTA-III.
NOTE :
When an Open AT Application downloaded in the A&D storage is installed, the older application (if any) is
erased, and the new application will take control when it is executed.
148
Open AT® TUTORIAL
In order to avail the A&D services, your Open AT Application must subscribe to the A&D services using the following
API:
Prototype:
Parameters:
CellID: Each A&D cell is identified by a particular identifier. This parameter holds the cell identifier of the
A&D space to which you want to subscribe. Here you can enter a cell ID which will uniquely identify the cell
that you want to use. This cell may already exist. In this case, the cell will continue to hold the previously
allocated space. However, in case, the cell does not exist, required cell is created and allotted the memory
size requested by the second parameter.
Size: This parameter holds the size of cell (in bytes) to which you want to subscribe. If the cell exists, this
parameter will be ignored. If you want a cell of variable size, then set this parameter to
ADL_AD_SIZE_UNDEF.
Returned Values:
A positive or null handle is returned if the API is successful. This handle will then be used in other operations
such as reading and writing in the subscribed cell.
ADL_RET_ERR_BAD_STATE is returned if another undefined size cell is already subscribed and not finalized.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
Prototype:
Parameters:
149
Open AT® TUTORIAL
Returned Values:
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
6. A&D events
This API is used to subscribe for all the events related to Application and data storage.
Prototype:
Parameters:
Handler: Call back function to notify all the event related to the application and data storage.
Prototype:
Parameter:
150
Open AT® TUTORIAL
Returned Values:
ADL_RET_ERR_NO_MORE_HANDLER is returned if A&D service has been subscribed for more than 128
times.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
Prototype:
Parameters:
EventHandle: Handle returned during the time of subscription.
Returned Values:
OK is returned on success.
ADL_RET_ERR_BAD_STATE is returned if the format or re-compaction process is running with the given
handle.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
151
Open AT® TUTORIAL
Parameters:
Handle: Handle returned by the earlier call to adl_adSubscribe () API.
Data: This is the pointer to the data to be written into the subscribed A&D storage cell.
Returned Values:
ADL_AD_RET_ERR_OVERFLOW is returned if the write operation exceeded the allocated cell size.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
You can get information related to a specified cell using the following API:
Prototype:
Parameters:
Handle: The A&D cell handle that is returned by the adl_adSubscribe () API.
Info: This is a pointer to a structure of type adl_adInfo_t which will contain the requested information
pertaining to the cell identified by the Handle (first parameter), after the call is complete.
152
Open AT® TUTORIAL
Returned Values:
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
Prototype:
Parameters:
Handle: Handle (value) returned by the earlier call to adl_adSubscribe () API.
Returned Values:
An OK is returned on successful finalization of the specified cell.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
Prototype:
153
Open AT® TUTORIAL
Parameters:
Handle: A&D cell handle that is returned by the earlier call to adl_adSubscribe () API.
Returned Values:
A successful installation will reset the embedded module. When the embedded module restarts, the
adl_InitType_e parameter of adl_main function is set to ADL_INIT_DOWNLOAD_SUCCESS. This acts as an
indication that the installation process was successful. After the product reset, the newly installed
application will start automatically.
ADL_RET_ERR_BAD_STATE is returned if the cell (from which the file must be installed) is not finalized.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
Prototype:
Parameters:
Handle: A&D cell handle that is returned by the adl_adSubscribe () API.
Returned Values:
An OK is returned on successful deletion of the specified storage cell.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from low level interrupt handler.
154
Open AT® TUTORIAL
Re-compaction is the process which releases the space and ID of deleted cells. After re-compaction, the
space and ID of deleted cells are made available for use again. This process is started automatically when the
deleted A&D Storage Space exceeds 50 percent of the total A&D storage space. Alternatively, you can initiate
this process by calling the following API:
Prototype:
Parameters:
EventHandle: This is the event handle that is previously returned by the adl_adEventSubscribe() API. The
event handler that is associated with the A&D event subscription will receive all the events that is related to
the re-compaction process.
Returned Values:
An OK is returned on successful completion of the recompaction process.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interruption handler.
Prototype:
Parameters:
155
Open AT® TUTORIAL
State: Pointer to the information structure for the A&D state. The values in this structure are filled by
adl_adGetState API. After calling this API, this structure will contain the values that will indicate the state
information of A&D storage.
typedef struct
{
u32 freemem; //Free memory space
u32 deletedmem; //Deleted memory size
u32 totalmem; //Total A&D storage space
u16 numobjects; //Number of allocated objects
u16 numdeleted; //Number of deleted objects
u8 pad; //This field is not used.
} adl_adState_t;
Returned Values:
An OK is returned when the data is retrieved successfully.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interruption handler.
Prototype:
Parameters:
CellList: A pointer to a list wm_lst_t variable. The adl_adGetCellList API updates this list with the identifiers of
the allocated cells.
Returned Values:
156
Open AT® TUTORIAL
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interruption handler.
NOTE :
The adl_adDelete () API marks the cell identified by its handle as ‘free’. The memory occupied by the cell, is
retrieved after the next recompaction process.
It is advisable to finalize a cell after writing to it. This is because, if you have subscribed to a cell of variable
size (ADL_AD_SIZE_UNDEF), and do a recompaction without finalizing it, it will not work.
Each subsequent write operation will append the data to the existing (written) data. You can have a sequence
of write operations and after you complete the write operation, you can finalize the cell using the
adl_adFinalise () API.
Prototype:
Parameters:
EventHandle: Event handle previously returned by the adl_adEventSubscribe function. The associated
handler will receive the format process events sequence.
Returned Values:
OK is returned on success
.
ADL_AD_RET_NOT_AVAILBLE is returned if no A&D space is available.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interruption handler.
157
Open AT® TUTORIAL
NOTE:
1. This API should be used before A&D cell subscription.
2. As whole A&D area needs to be formatted, this API might take some time for processing.
This API can be used to search for a cell ID between the 2 cell identifiers.
Prototype:
Parameters:
Returned Values:
OK is returned on success.
Prototype:
Parameters:
BrowseInfo: This parameter is the browse information returned by adl_adFindInit () API.
CellID: This parameter is the next cell ID found.
158
Open AT® TUTORIAL
Returned Values:
OK is returned on success.
Prototype:
Returned Values:
OK is returned on success.
Prototype:
Parameters:
typedef enum
{
ADL_FACTORY_CELL_SERIAL,
ADL_FACTORY_CELL_TX,
ADL_FACTORY_CELL_RX,
} adl_factoryCell_e;
159
Open AT® TUTORIAL
data: String read.This is an optional parameter, it could be set to NULL just to retrieve size of cell.
Returned Values:
8. Sample Code
#include "adl_global.h"
#include "adl_ad.h"
const u16 wm_apmCustomStackSize = 4096;
s32 sEventHandle;
u32 gCellId = 1;
s32 gCellHandle = -1;
void SubscribeCell( )
{
u8 * mData;
ascii Msg[250];
u16 mDataLen=10;
// Subscribe Cell
gCellHandle = adl_adSubscribe( gCellId, ADL_AD_SIZE_UNDEF );
// Verify Handle
if ( gCellHandle < 0 )
{
wm_sprintf( Msg, "\r\nERROR: adl_adSubscribe --> FAILED\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
return;
}
else
{
wm_sprintf( Msg, "\r\n adl_adSubscribe --> PASSED\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
160
Open AT® TUTORIAL
// Finalise Cell
if ( adl_adFinalise( gCellHandle ) != OK )
{
wm_sprintf( Msg, "\r\nERROR: adl_adFinalise --> FAILED\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
return;
}
else
{
wm_sprintf( Msg, "\r\n adl_adFinalise --> PASSED\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
// Delete Cell
if ( adl_adDelete( gCellHandle ) != OK )
{
wm_sprintf( Msg, "\r\nERROR: adl_adDelete --> FAILED\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
return;
}
else
{
161
Open AT® TUTORIAL
}
}
}
}
break;
case ADL_AD_EVENT_INSTALL:
TRACE (( 1, "ADL_AD_EVENT_INSTALL Event is received" ));
break;
}
}
162
Open AT® TUTORIAL
ascii Msg[250];
adl_atSendResponse ( ADL_AT_UNS, "\r\nRECOMPACT...\r\n" );
sRet=adl_adRecompact( sEventHandle );
if ( sRet != OK )
{
wm_sprintf( Msg, "\r\nERROR: adl_adRecompact --> FAILED returns %d\r\n", sRet );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
}
}
void Clean()
{
s32 sReturn;
s8 MyIndex;
ascii Msg[250];
u32 * CellID;
s32 CellHandle;
u16 mLstCount = 0;
u16 i;
wm_lst_t * mCellList = adl_memGet( sizeof( wm_lst_t ) );
adl_atSendResponse ( ADL_AT_UNS, "\r\nCLEAN...\r\n" );
163
Open AT® TUTORIAL
164
Open AT® TUTORIAL
}
else
{
wm_sprintf( Msg, "\r\nList ID %d Delete Cell Handle %x --> PASSED\r\n\r\n", i, CellHandle );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
}
}
}
adl_memRelease( mCellList );
}
sEventHandle = adl_adEventSubscribe(adEventHandler);
if ( sEventHandle<0)
{
wm_sprintf( Msg, "\r\nERROR: sEventHandle --> FAILED returns %d\r\n", sEventHandle);
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
return;
}
else
{
wm_sprintf( Msg, "\r\nsEventHandle is OK\r\n" );
TRACE (( 1, Msg ));
adl_atSendResponse ( ADL_AT_RSP, Msg );
}
Clean();
}
if (adl_adDelete (cell_handle)!=OK)
{
TRACE((1,"Cannot delete the cell"));
}
else
{
TRACE((1,"Cell deleted successfully"));
}
165
Open AT® TUTORIAL
if (adl_adRecompact(recompact_handler)!=OK) {
TRACE((1,"Cannot recompact"));
}
else
{
TRACE((1,"Recompaction request successful"));
}
}
Summary
The following points have been covered in this chapter
Open AT OS provides APIs to manage the A&D storage space. The A&D storage space can be used to store data
objects or Open AT Application binary files (.dwl) files.
You can install the Open AT Application stored in the A&D storage space. The previous application will be
deleted in this case and the new application will be executed.
The adl_adSubscribe () API can be used to subscribe to A&D storage services. Use the adl_adUnsubscribe () API
to unsubscribe from the A&D storage services.
To write to a specific cell use the adl_adWrite () API. To get the data stored in a particular cell, use the
adl_adInfo () API.
Data written to a cell should be finalized to make it read only. This can be done using the adl_adFinalise () API.
To delete a cell, use the adl_adDelete () API. However this API only marks the cell for deletion. The storage
space is freed only after the recompaction process.
To recompact the A&D storage space, use the adl_adRecompact () API. The recompaction process is also
automatically initiated if the deleted A&D Storage Space exceeds 50 percent of the total available A&D space.
The adl_adInstall () API can be used to install the contents of a cell that contains a .dwl file. After successful
installation, the embedded module will be restarted.
The adl_adGetState () API can be used to get information about the state of the A&D storage space. This
information includes information such as the total A&D memory space, free A&D memory space and the
number of objects. The adl_adInfo () API can be used to get the information pertaining to a particular cell.
The adl_adFindInit () and adl_adFindNext () are used for searching cell ID.
166
Open AT® TUTORIAL
CHAPTER 15
Secured Data Storage Service
1. Objective
This chapter describes the secured data storage service and its usage in the embedded module.
2. Introduction
The data which is stored in the flash of the embedded module can be read by any user. Hence it is not safe to store the
confidential information in the flash. To provide security for the data stored in the flash, secured data storage is
provided.
Secured data storage is a part of flash memory where the data will be stored in the ciphered format thus providing the
security for the data. This is useful in case of storing confidential information such as password, user name etc.
Using the dongle .wpk executable needs to be downloaded into the embedded module.
Set/Enable the security features Option will be popped up. If selected, this option allows the user to load a secured key
into the firmware (SDS Secured Data Storage).
Followed by this option, resizing of A&D storage and flash size, firmware download will be popped up. Select
accordingly and proceed further.
Once the configuration and the firmware download is complete “Process Successful” message will be seen in dwlwin.
User can exit from the dwlwin and can start using SDS feature.
For more details please refer to the pdf “AirPrime WMP100 Development kit - Software download tutorial -
2009-02-11[1].pdf”.
167
Open AT® TUTORIAL
NOTE : The maximum size for the secured data service can be configured by DWLWIN while initially configuring the
module (as stated in 15.3). Hence for a given module the “maximum SDS service size” is the size defined by the user
during initial configuration. This size would be part of the whole flash available to the module (the flash available to the
FW and not Open AT flash service).
The minimum to maximum size of the secured data varies from 0 to “maximum SDS service size”.
Read/write/query data stored in ciphered format in non volatile memory (embedded module Flash).
Update cryptographic keys to block replay/re-download attacks.
The APIs related to the secured data storage service is declared in the adl_sds.h header file.
Prototype:
Parameters:
Stats: This parameter is a pointer to a adl_sdsStats_t which stores information about the secured data
storage. The structure adl_sdsStats_t is defined as:
typedef struct
{
u32 MaxEntrySpace; //Maximum size of one secured entry
u32 FreeSpace; //Available space for secured entries
u32 TotalSpace ; //Total space allocated for secured entries
u16 MaxEntry ; //Maximum number of secured entries
u16 EntryCount ; //Total number of secured entries
}adl_sdsStats_t;
168
Open AT® TUTORIAL
Returned Values:
OK is returned on successful retrieval of secured data storage information.
This API is used to store data in a ciphered format with the specific numeric ID. Data is updated if ID is
already present otherwise new entry will be created. The updated data is ciphered before it is stored in the
non-volatile memory.
Prototype:
Parameters:
ID: This parameter is the numeric ID of the entry which ranges from 0 to maximum entry retrieved by
adl_sdsStats API.
Length: This parameter indicates the length of the data. The maximum length of the data can be retrieved by
adl_sdsStats API.
Returned Values:
169
Open AT® TUTORIAL
Prototype:
s32 adl_sdsRead (u32 ID, u32 offset, u32 Length, void* Destination)
Parameters:
ID: This parameter is the numeric ID of the entry which ranges from 0 to maximum entry retrieved by
adl_sdsStats API.
Offset: This parameter indicates the offset in the secured entry specified in terms of bytes. This parameter
allows retrieving part of the entry.
Length: This parameter indicates the length of the data. The maximum length of the required entry should
be retrieved by adl_sdsQuery API.
Destination: This parameter is the pointer to buffer where the retrieved data will be stored.
Returned Values:
OK is returned on successful retrieval of secured data storage information.
Prototype:
Parameters:
ID: This parameter is the numeric ID of the entry which ranges from 0 to maximum entry retrieved by
adl_sdsStats API.
Length: This is a pointer which holds the length of the entry. This parameter can be set to NULL.
Returned Values:
170
Open AT® TUTORIAL
Prototype:
Parameters:
ID: This parameter is the numeric ID of the entry which ranges from 0 to maximum entry retrieved by
adl_sdsStats API.
Returned Values:
OK is returned on successful retrieval of secured data storage information.
When the internal keys are updated, the data available in the flash memory is re-encrypted according to new
keys. Hence it affects the life span of non-volatile memory. The re-generation of keys should be done to
provide more security to data. For e.g. If someone is able to decode the key, it will cause a security issue to
the data if the key is not updated periodically.
Prototype:
171
Open AT® TUTORIAL
Parameters:
None.
Returned Values:
NOTE :
The above functions are available only if:
They are used with a compatible platform.
The Secured Data Storage feature is properly activated on the production line.
The objects are not erased; otherwise embedded module has to be returned in production line.
Otherwise, every function cited above will return the error code ADL_RET_ERR_NOT_SUPPORTED.
5. Sample Code
#include "adl_global.h"
#include "adl_sds.h"
const u16 wm_apmCustomStackSize = 4096;
adl_tmr_t *timer_ptr;
u16 timeout_period = 5;
static counter=0;
172
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
Open AT OS provides APIs for reading/writing secured data.
The adl_sdsStats API should be used to retrieve information about free space available for secured entries, total
space allocated for secured entries, total number of secured entries, maximum number of secured entries and
maximum size of one secured entry.
The adl_sdsWrite API should be used to store data in a ciphered format with the specific numeric ID.
The adl_sdsRead API should be used to read data from a secured entry.
The adl_sdsQuery API should be used to check whether the secured data entry exists or not.
The adl_sdsDelete API should be used to delete secured data entries.
The adl_sdsUpdateKeys API should be used to re-generate the internal cryptographic keys.
173
Open AT® TUTORIAL
174
Open AT® TUTORIAL
CHAPTER 16
Flow Control Management
1. Objective
This chapter introduces the Flow Control Manager (FCM). It explains the data and command flows in the embedded
module and how these can be managed from within the environment.
UART 2
GPRS
Wireless CPU ®
USB
Logical C -BT
CMUX
Ports
175
Open AT® TUTORIAL
Bluetooth port
These ports are independent of physical ports
These ports are created when Bluetooth stack in started using Open AT OS APIs.
Wireless CPU®
Open AT ®
Application
Open AT ® Bluetooth
Firmware
GPRS
V24
Serial
Link GSM Data
176
Open AT® TUTORIAL
An Open AT Application can subscribe to any flow (V24, GSM DATA or GPRS) to exchange data with the corresponding
flow points. For example, if the embedded Open AT Application subscribes to the V24 flow then all the data from the
V24 flow will be sent directly to the Open AT Application.
The different flow types that you can use are described in the sections that follow.
In this flow, the data is transmitted through the serial point (UART1, UART2) between the embedded Open
AT Application and the external application. This happens when the Open AT Application has subscribed for
the V24 flow and the serial link is switched in data mode. The flow of the data is shown in the Serial link
Switched in Data Mode image.
Wireless CPU®
Open AT ®
Application
Open AT ® Bluetooth
Firmware
GPRS
V24
Serial
Link GSM Data
177
Open AT® TUTORIAL
Wireless CPU®
Open AT ®
Application
Open AT ® Bluetooth
Firmware
GPRS
V24
Serial
Link
GSM Data
Wireless CPU®
Open AT ®
Application
Open AT ® Bluetooth
Firmware
GPRS
V24
Serial
Link
GSM Data
178
Open AT® TUTORIAL
The Open AT Application must subscribe to an IO flow, before the flow can be made available to the Open AT
Application. Use the adl_fcmSubscribe function to subscribe to a flow. This function takes the callback
handlers for control and data events as parameters and returns a handle which can be used in all further
FCM operations.
Outgoing data can be sent to the different flow points using the adl_fcmSendData function. Incoming data is
processed by the data handlers specified in the adl_fcmSubscribe command.
There are different flows that can be opened: GSM data flow, GPRS flow, v24 UART1 flow, v24 UART2 flow
and USB flow. Each flow is independent and it can be subscribed and unsubscribed separately.
The v24 flow can function in two different modes by switching the V24 serial link:
AT mode
Data mode
The AT mode is used to transmit AT commands to the embedded module. The Data mode is used to transfer
data from the external application to the Open AT Application. The adl_fcmSwitchV24State function can be
used to switch between these two modes.
The V24 flow can be made on UART1, UART2 or USB. A V24 Master flow subscription is used to manage the
V24 flow. Only a Master subscriber can switch modes. The corresponding data handler is then intimated of
mode switch events. The ADL_FCM_FLOW_V24_MASTER corresponds to ADL_FCM_FLOW_V24_UART1 and
ADL_FCM_FLOW_V24 corresponds to ADL_FCM_FLOW_V24_UART1 | ADL_FCM_FLOW_SLAVE.
When the data handlers are called, they can indicate that they have processed the data by returning TRUE.
This process is known as releasing credit. The data is then cleared in the V24 buffers so that the external
application can continue sending data. If the data handler returns FALSE (credit is not released), then the
buffers are not flushed. When the buffer is filled and can accept no more data, the V24 layer uses the
hardware flow controls to stop the external application from sending more data.
The adl_fcmSubscribe function is used for the subscription of the different IO flow points. This API is used for
the subscription of any of the IO flows. On successful subscription of a flow, the event
ADL_FCM_EVENT_FLOW_OPENNED is received in the control handler. The function returns a handler which
must be provided to other FCM service APIs. You can subscribe to the V24 flow multiple times, only after you
subscribe to the V24 Master flow. The first V24 flow is subscribed in master mode and the others V24 flows
are subscribed in slave mode.
The prototype of this API gives the definition of the API along with the parameters that need to be passed.
s8 adl_fcmSubscribe (adl_fcmFlow_e Flow, adl_fcmCtrlHdlr_f CtrlHandler, adl_fcmDataHdlr_f DataHandler)
179
Open AT® TUTORIAL
Parameters:
Flow: The flow parameter decides the type of flow that needs to be subscribed. The allowed values of the
flow are:
ADL_FCM_FLOW_GSM_DATA,
ADL_FCM_FLOW_GPRS,
ADL_FCM_FLOW_V24_UART1
ADL_FCM_FLOW_V24_UART2
ADL_FCM_FLOW_USB
For serial-link related flows (ADL_FCM_FLOW_V24_UART1 & 2), the corresponding UART has to be opened
first with the “AT+WMFM” command, otherwise the subscription will fail. By default, only the UART1 is
opened.
The following table lists the flow events and their descriptions:
FCM Events Description
ADL_FCM_EVENT_FLOW_OPENNED This event is generated when the subscribed
flow is opened.
ADL_FCM_EVENT_FLOW_CLOSED This event is generated when the subscribed
flow is closed.
ADL_FCM_EVENT_V24_DATA_MODE This event is generated when the V24
Master is subscribed and Data mode is
selected.
ADL_FCM_EVENT_V24_DATA_MODE_EXT This event is generated when the Data
mode switches from the external
application.
ADL_FCM_EVENT_V24_AT_MODE This event is generated when the V24
Master is subscribed and Data mode is
selected.
180
Open AT® TUTORIAL
NOTE :
The flow control is activated on the V24 serial link, in the command (offline) mode. Payload data is located
on the seven least significant bits (LSB) of every byte. So in every byte that is sent along the serial link, only
the least seven bits contain the actual data. The rest of the data can be ignored.
This handler receives data blocks from the associated flow. Once the data block is processed, the handler
must return TRUE to release the credit, or FALSE if the credit must not be released. In this case, all credits will
be released the next time the handler returns TRUE. On the V24 flow, all the subscribed data handlers are
notified with a data event, and the credit will be released only if all handlers return TRUE as the default
value.
If a credit is not released on the data block reception, it will be released the next time the data handler
returns TRUE. The adl_fcmReleaseCredits () should also be used to release credits outside of the data
handler.
Maximum size of each data packets to be received by the data handlers depends on the flow type:
On serial link flows (UART physical & logical based ports): 120 bytes;
On GSM CSD data port: 270 bytes;
On GPRS port: 1500 bytes;
If data size to be received by the Open AT application exceeds this maximum packet size, data will be
segmented by the Flow Control Manager, which will call several times the Data Handlers with the segmented
packets.
Please note that on GPRS flow, whole IP packets will always be received by the Open AT application.
When the serial link is in the Data mode, if the external application sends the sequence 1s delay; +++; 1s
delay, the serial link is switched to the AT mode, and the V24 Master handler is notified by the
ADL_FCM_EVENT_V24_AT_MODE_EXT event. The behavior then depends on the returned value. If it is
TRUE, then all the V24 handlers are also notified with this event. The V24 MASTER handle cannot be
unsubscribed in this state. If the returned value is FALSE, then the V24 handlers are not notified with this
event, and the serial link is switched back to the Data mode immediately. In the first case, after the
ADL_FCM_EVENT_V24_AT_MODE_EXT event, the V24 Master should switch the serial link to Data mode
with the adl_fcmSwitchV24State API, or wait for the ADL_FCM_EVENT_V24_DATA_MODE_EXT event. The
event is sent when the external application sends the ATO command; the serial link is switched to the Data
mode, and all the V24 clients are then notified.
181
Open AT® TUTORIAL
The following table lists the FCM flows and their descriptions:
FCM Flows Description
ADL_FCM_FLOW_GSM_DATA Subscribe to this flow to receive and send data via
GSM data flow.
ADL_FCM_FLOW_GPRS Subscribe to this flow to receive and send data via
GPRS.
ADL_FCM_FLOW_V24_UART1 Subscribe to this flow to receive and send data via
UART1. This is the same as
ADL_FCM_FLOW_V24_MASTER.
ADL_FCM_FLOW_V24_UART2 Subscribe to this flow to receive and send data via
UART2.
ADL_FCM_FLOW_USB Subscribe to USB flow to send/receive data. Subject
to availability
Returned Values:
A positive or null handle is returned on success. The Control handler will also receive a
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level Interrupt handler.
Prototype:
182
Open AT® TUTORIAL
Parameters:
Returned Values:
OK on successful subscription of the IO flow. The control handler will also receive
ADL_FCM_EVENT_FLOW_CLOSED event when flow is closed.
ADL_RET_ERR_BAD_STATE is returned if the serial link is not in the AT mode. A negative handle is returned
on failure.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
Prototype:
Parameters:
NbCredits: This indicates the number of credits to release for this flow. If this number is greater than the
number of previously received data blocks, all the credits are released. If an Open AT Application wants to
release all the received credits, it should call the adl_fcmReleaseCredits API with NbCredits parameter set to
0xFF.
Returned Values:
OK is returned on successful subscription of the IO flow.
183
Open AT® TUTORIAL
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Parameters:
Handle: Handle returned by the adl_fcmSubscribe function.
V24State: Serial link state to switch to. The allowed values are defined below:
ADL_FCM_V24_STATE_AT
ADL_FCM_V24_STATE_DATA
Returned Values:
OK is returned on successful subscription of the IO flow. The control handler will receive
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
Handle: Handle returned by the adl_fcmSubscribe function.
184
Open AT® TUTORIAL
Returned Values:
OK is returned on successful subscription of the IO flow.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
NOTE :
Unlike the standard Open AT OS interface, the Data block is not released by the adl_fcmSendData() API. The
Open AT Application can use any u8 * buffer.
This function sends a data block on the requested flow. This API does not perform any processing on the
provided data block, which is sent directly on the flow.
The prototype of this API gives the definition of the API along with the parameters that need to be passed.
Prototype:
Parameters:
Handle: Handle returned by the adl_fcmSubscribe function.
DataBlock: The data block buffer must be written using the following type:
typedef struct
{
u16 Reserved1 [4];
u32 Reserved3;
185
Open AT® TUTORIAL
Returned Values:
NOTE :
As the standard Open AT OS interface, the data block will be released by the adl_fcmSendDataExt () API on OK and
ADL_FCM_RET_OK_WAIT_RESUME return values. The Open AT Application must only use the dynamic allocated
buffers.
Prototype:
Parameters:
186
Open AT® TUTORIAL
Way: As flows have two ways (to and from the Open AT Application), this parameter specifies the direction
in which the buffer status is requested. The possible values are:
ADL_FCM_WAY_FROM_EMBEDDED,
ADL_FCM_WAY_TO_EMBEDDED
Returned Values:
ADL_FCM_RET_BUFFER_EMPTY is returned if the requested flow and way buffer is empty.
ADL_FCM_RET_BUFFER_NOT_EMPTY is returned if the requested flow and way buffer is not empty, and the
FCM is still processing data on this flow.
Prototype:
Parameters:
Flow: The flow (UART, USB, GSM etc) to query for the availability. The value this parameter can take is
defined by enum adl_fcmFlow_e.
Returned Values:
TRUE is returned if the specified port is available for FCM service.
FALSE is returned if the specified port is not available for FCM service.
5. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
/* Global variable */
u8 Handle; //FCM handle
bool fcmCtrlH (adl_fcmEvent_e event );
bool fcmDataH (u16 DataLen, u8 * Data);
void adl_main (adl_InitType_e InitType )
{
187
Open AT® TUTORIAL
Handle=adl_fcmSubscribe(ADL_FCM_FLOW_V24_UART1,fcmCtrlH, fcmDataH);
TRACE (( 1, "Embedded Application: Main" ));
}
bool fcmCtrlH ( adl_fcmEvent_e event )
{
TRACE ((1, "Control event received --> %d", event));
switch(event)
{
case ADL_FCM_EVENT_FLOW_OPENNED:
TRACE (( 1, "Flow Opened" ));
/* Switching V24 state from AT to Data. */
adl_fcmSwitchV24State(Handle, ADL_FCM_V24_STATE_DATA);
break;
case ADL_FCM_EVENT_V24_DATA_MODE:
TRACE (( 1, "Flow in Data Mode" ));
/* sending data to the external application via V24 serial link */
adl_fcmSendData(Handle, "This is a test case", 20);
break;
}
return TRUE;
}
Summary
The following points have been covered in this chapter
The ADL library provides FCM APIs for the handling of the different Input Output flows (V24, GSM and GPRS).
Subscribe to the flows using the adl_fcmSubscribe API.
The V24 flow has both the Data and Command modes. In the Command mode, AT commands can be sent. Data
can be sent in the Data mode.
The adl_fcmSwitchState API is used to switch between the two states in the V24 mode.
The data that comes from different flows is captured in the Data Handlers.
The FCM related events are received in the control handlers.
188
Open AT® TUTORIAL
CHAPTER 17
Open UART
1. Objective
The ADL Open Device service provides a raw access to any device behaving as a serial port. In order to get a raw access
to the device, software block component called Service Provider (SP) supplies APIs which allows manipulating the
device. The APIs of this SP are based on a Generic Interface. For each existing device class, there is only one generic
interface. For example, a SP which allows to access to an UART, the SP is based on UART generic interface.
get a raw access to the device behaving via SPs defined by Firmware or Open AT application.
retrieves the SP's interfaces at runtime to access to the raw device configuration (read, write, I/O
control, close functions).
189
Open AT® TUTORIAL
Figure 59: Illustration of the mechanism between the Service Provider and the Service User
If data transmissions are too fast compared to the data processing, overruns (lost of chars, hard/soft FIFO overrun)
could occur.
Best results are achieved if flow control is activated to avoid overruns. (UART FIFO overruns if remote sends too many
data and cannot be processed fast enough, therefore flow control is needed to stop / resume data flow).
Soft flow control XON/XOFF characters can be used if only RxD/TxD line are available without RTS/CTS.
190
Open AT® TUTORIAL
At start up, DTE (Data Terminal Equipment) application see the modem CTS high, meaning that DTE can send
data to DCE.
Modem can be either in connected mode or not connected mode. A modem is connected if a GSM data call
or GPRS data session is running. Once connected, a modem is Online and all the data from DTE to DCE are
considered as data payload and sent to the remote modem. A modem is Offline if Data sent to or received
from the DTE are AT commands.
To be accessible, a SP of device has to be previously registered in the Firmware. Then its services can be accessed by the
SU.
191
Open AT® TUTORIAL
Requests: Allow a service user to directly handle any UART service provider.
Notifications: Allow a UART service provider to notify event occurrences to service user.
NOTE :
Before requesting, or being notified by a UART service provider, an Open AT application shall retrieve a direct access (by
using the ADL Open Device service) to this UART service provider
There are five request functions that are provided by the Open UART interface:
An open function to:
Optionally retrieve the UART service provider’s interface (through a generic interface
container).
Retrieve a unique UART service provider reference (handle) which shall be subsequently
provided as parameter to the rest of the request functions.
Optionally install event handlers to manage the UART service provider notifications.
Set the role of the UART which allows the service user to indicate to the UART service
provider which running mode shall be established.
A write function to instruct the UART to send characters over the serial line.
An io_control function to configure, or get information from, the UART service provider.
A close function to release the UART interface (and the handle previously allocated).
There are six notifications that the UART service provider notifies the event occurances to the UART service user:
The completion of the current emission (write completion at the byte level and also at the bit level).
192
Open AT® TUTORIAL
The availability of received data (UART service provider uses an internal buffer).
NOTE :
Calling request functions while application event handlers are running is not supported. Doing such a call might
generate system instabilities
Prototype:
Parameters:
dev_clss_id: The device class identifier the service provider to be opened belongs to. To open a UART service
provider application has to use the DF_UART_CLID value.
param: Service provider configuration, to be defined accordingly to the dev_clss_id parameter in the UART
case address of a sUartSettings_t structure is required.
Returned values:
Handle: A positive UART service provider handle on success, to be used in further Open UART service
function calls.
Sample code
#include "adl_OpenDevice.h"
#include "wm_uart.h"
static psGItfCont_t uart_if;
static u32 uart2_hdl;
void adl_main( adl_InitType_e InitType )
{
sUartSettings_t settings;
sUartLc_t line_coding;
// Set the line coding parameters
193
Open AT® TUTORIAL
line_coding.valid_fields = UART_LC_ALL;
line_coding.rate = (eUartRate_t)( UART_RATE_USER_DEF | 57600 );
line_coding.stop = UART_STOP_BIT_1;
line_coding.data = UART_DATALENGTH_8;
line_coding.parity = UART_PARITY_NONE;
// UART2 will be opened in NULL MODEM role / with synchronous read/write
settings.identity = "UART2";
settings.role = UART_ROLE_NM;
settings.capabilities = NULL;
settings.event_handlers = NULL;
settings.interface = &uart_if;
settings.line_coding = &line_coding;
uart_hdl = adl_OpenDevice( DF_UART_CLID, &settings );
if( !uart_hdl )
{
// UART2 opening failed...
return;
}
// UART2 successfully opened, write some bytes
uart_if.write( uart_hdl, "Tx Some bytes", 13 );
…
}
This function allows the application to read the bytes received by the UART service provider. Before using
this function the application shall open the UART service provider (shall own the UART interface as well as a
valid UART handle).
Two running modes are supported: zero copy (ZC) or non zero copy (NZC) modes. The running mode
selection is achieved by the application when it provides the UART SP with either the On Rx Data Complete
(ZC selected) or the On Rx Data Available (NZC selected) event handlers.
When UART SP is running in (ZC) mode the read function runs in an asynchronous way. Application
provisions a read providing the UART SP with reception buffer address and size information. UART SP returns
an operation pending indication. While an asynchronous read operation is pending application is allowed to
invoke the read function which will have the following effects:
Current reception buffer address and size information are erased by the UART SP. According to the new
parameters provided the asynchronous read operation is:
Either cancelled in case reception buffer address and size are set to NULL. Or
Continued in case buffer address and size are set to non NULL values.
UART SP completes the pending read operation by firing the On Rx Data Complete event.
194
Open AT® TUTORIAL
When UART SP is running in (NZC) mode the read function runs in a synchronous way. Application should
trigger the read function call after UART SP called its On Rx Data Available event handler. Application
provides UART SP with the reception buffer address and size parameters. These parameters shall contain
non NULL values otherwise the UART SP returns an error. UART SP returns the amount of data actually
stored in the reception buffer. Application should call the read function while UART SP returns a non NULL
amount of copied bytes.
Prototype:
195
Open AT® TUTORIAL
Parameters:
Handle: Handle of the UART service provider previously returned by the adl_OpenDevice function. Setting
this parameter with a value different from the one obtained by the call to the adl_Open Device function
generates an error.
pData: Address where the received data shall be put. NULL value is not supported when UART SP is running
in NZC mode.
len: Size (in bytes) of the memory area provided to store the received data. NULL value is not supported
when UART SP is running in NZC mode.
Returned values:
Synchronous mode
Any positive value greater or equal than CH_STATUS_NORMAL and strictly lower than
CH_STATUS_PENDING indicates the amount (including 0) of bytes copied from the UART service
provider to the application reception buffer.
CH_STATUS_ERROR: either pData or len or both parameters set with NULL values, or invalid UART
service provider handle.
Asynchronous mode
CH_STATUS_ERROR: Invalid UART service provider handle.
Both modes
CH_STATUS_ERROR: no reception event handler installed.
Sample Code
#include "adl_OpenDevice.h"
#include "wm_uart.h"
static psGItfCont_t uart_if;
static u32 uart2_hdl;
static u8 rx_buf[ 256 ];
static void on_rxc_handler( u32 user_data, psGData_t evt_par)
{
// Code to obtain new Rx buffer and size to be returned to the UART SP
// Just in case where there is no more available reception buffer
*(u64*)evt_par.buf = 0LL;
}
static void on_rxda_handler( u32 user_data, psGData_t evt_par)
{
// Code to set an ADL event to unlock an synchronous read
}
196
Open AT® TUTORIAL
197
Open AT® TUTORIAL
p_rx_buf += nb_read;
}
}
Two running modes are supported: Asynchronous (A) and synchronous (S) modes. The running mode
selection is achieved by the application when it provides the UART SP with either the On TX Complete or the
On TX Empty event handlers (A). When there is no transmission completion event handler, the write
operation is executed in synchronous (S) mode.
When UART SP is running in (S) mode the application is blocked while the byte transmission occurs.
When UART SP is running in (A) mode the application enables a write providing the UART SP with the
transmission buffer address and size parameters. UART SP returns an operation pending indication. While an
asynchronous write operation is pending application is allowed to invoke the write function with both
transmission buffer address and size parameters set with a NULL value. As consequence the pending write
operation is cancelled.
According to the current transmission event handler installed UART SP completes the pending write
operation by firing either the On TX Complete/Empty event. Application has then the possibility to provide
further data to write, directly in the On TX Complete/Empty event handler, without any further call to the
Write API.
198
Open AT® TUTORIAL
Parameters:
Handle: Handle of the UART service provider previously returned by the adl_OpenDevice function. Setting
this parameter with a value different from the one obtained by the call to the adl_OpenDevice function
generates an error.
pData: Address of the data block to be sent. NULL value is not supported when UART SP is running in (S)
mode.
len: Size (in bytes) of the data block to be sent. NULL value is not supported when UART SP is running in (S)
mode.
199
Open AT® TUTORIAL
Returned values:
Synchronous mode
CH_STATUS_NORMAL operation successfully completed.
CH_STATUS_ERROR: either pData or len or both parameters set with NULL values.
Asynchronous mode
CH_STATUS_ERROR: Asynchronous write operation is already pending.
CH_STATUS_NORMAL: Asynchronous write cancellation successfully completed.
CH_STATUS_PENDING: Asynchronous write operation successfully started.
Both modes
CH_STATUS_ERROR: invalid UART service provider handle.
Prototype:
Parameters:
Handle: Handle of the UART service provider previously returned by the adl_OpenDevice function. Setting
this parameter with a value different from the one obtained by the call to the adl_OpenDevice function
generates an error.
pParam: IO command parameter. Type of this parameter depends on the Cmd parameter value.
Returned values:
200
Open AT® TUTORIAL
Prototype:
Parameters:
Handle: Handle of the UART service provider previously returned by the adl_OpenDevice function. Setting
this parameter with a value different from the one obtained by the call to the adl_OpenDevice function
generates an error.
Returned values:
This notification allows the application to be aware of the completion of the pending asynchronous write
operation. It occurs when the last byte, of the previously submitted data block, is being transmitted by the
UART service provider. Before being notified the application shall open the UART service provider (must own
the UART SP interface as well as a valid UART SP handle) and configure the UART service provider with its On
TX Complete notification handler.
Prototype:
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on every
occurrence of the transmission completion.
evt_param: Address of a sGData_t structure allowing the application to provide the UART service provider
with address and size parameters of a new data block to be transmitted. In case application does not have
any more data block to be transmitted it shall set the buf and len fields of the sGData_t structure to a NULL
value.
Returned values:
Not Applicable.
201
Open AT® TUTORIAL
Before being notified the application shall open the UART service provider (must own the UART SP interface
as well as a valid UART SP handle) and configure the UART service provider with its On TX Empty notification
handler.
Prototype:
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on each
transmitter empty notification.
evt_param: Address of a sGData_t structure allowing the application to provide the UART service provider
with address and size parameters of a new data block to be transmitted. In case application does not have
any more data block to be transmitted it shall set the buf and len fields of the sGData_t structure to a NULL
value.
Returned values:
Not Applicable.
Or on reception timeout. Which means at least 1 character has been stored in the previously provided Rx
buffer and no activity occurred on the RX line for a time comprises in the range [3.5 … 4.5] characters time.
Before being notified the application shall open the UART service provider (must own the UART SP interface
as well as a valid UART SP handle) and configure the UART service provider with its On Rx Complete
notification handler.
Prototype:
202
Open AT® TUTORIAL
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on each
receive complete notification.
evt_param: Address of a sGData_t structure allowing the application to provide the UART service provider
with address and size parameters of a new reception data block. In case application does not have any more
available reception data block it shall set the buf and len fields of the sGData_t structure to a NULL value.
Returned values:
Not Applicable.
Prototype:
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on each
occurrence of the received data available notification.
evt_param: This parameter is mandatory but UART service provider does not use it. Application shall ignore
its content.
Returned values:
Not Applicable.
This notification allows the application to be aware of any UART signal state change. It occurs when at least
one input signal state, from the embedded module point of view, is modified.
In DCE mode: the DTR signals state changes are notified.
In DTE mode: the RI, DCD and DSR signals state changes are notified.
In Null Modem, DTE and DCE modes: the CTS and BREAK signals state changes are notified.
203
Open AT® TUTORIAL
Before being notified the application shall open the UART service provider (must own the UART SP interface
as well as a valid UART SP handle) and configure the UART service provider with its On Signal State Change
notification handler.
Prototype:
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on each
occurrence of the received data available notification.
evt_param: Provide to application the identities and current states of the modified signals.
Returned values:
Not Applicable.
Prototype:
Parameters:
user_data: Generic 32 bits information the application previously provided during the event handler
configuration. The UART service provider is required to give back this information to the application on each
occurrence of the received data available notification.
Returned values:
Not Applicable.
NOTE :
Please refer to the ADL_User_Guide for more details on the structures definition referred in the above functions
204
Open AT® TUTORIAL
NOTE :
FCM and Open UART cannot be simultaneously used on the same port.
Summary
The following points have been covered in this chapter:
ADL Open Device service provides a raw access to any device behaving as a serial port. In order to get a raw
access to the device, software block component called Service Provider (SP) supplies APIs which allows
manipulating the device.
ADL provides Open UART Interface to give direct access to the embedded module UART Service Providers (SP).
Open UART Service Provider provides five request functions i.e. read, write, I/O control and close functions and
provides six notifications which include write completion at the byte level, write completion at the bit level,
availability of received data, change in the signal states, errors and completion of the current reception.
205
Open AT® TUTORIAL
206
Open AT® TUTORIAL
CHAPTER 18
General Purpose Input Output
1. Objective
This chapter introduces the GPIO (General Purpose Input Output) APIs available in the ADL library. It describes the
General Purpose Input Output pins, their usage, and the procedure to write into and read from the GPIOs.
GPO (General purpose Output): This pin can be used to send the data (output only).
GPI (General purpose Input): This pin can be used to receive the data (input only).
GPIO (General purpose Input Output): This pin can be used to send and receive data (input and
output)
These pins can be used when the embedded module needs to send data to trigger external devices, or if the embedded
module needs to be triggered by an external device.
3. Availability of GPIOs
207
Open AT® TUTORIAL
This type lists the label field definition (b0-b15 of adl_ioDefs_t). Each IO is identified by a number and a type.
Note that b14-b15 is reserved.
Code
type def enum
{
ADL_IO_NUM_MSK = (0xFFF),
ADL_IO_TYPE_POS = 12,
ADL_IO_TYPE_MSK = (3UL<<ADL_IO_TYPE_POS),
208
Open AT® TUTORIAL
ADL_IO_GPI = (1UL<<ADL_IO_TYPE_POS),
ADL_IO_GPO = (2UL<<ADL_IO_TYPE_POS),
ADL_IO_GPIO = (3UL<<ADL_IO_TYPE_POS),
_IO_LABEL_MSK = ADL_IO_NUM_MSK | ADL_IO_TYPE_MSK
} adl_ioLabel_e;
Description
ADL_IO_NUM_MSK Number field (b0-b11; 0->4095)
ADL_IO_TYPE_MSK Type field (b12-b13):
ADL_IO_GPI - To identify a GPI
ADL_IO_GPO - To identify a GPO
ADL_IO_GPIO - To identify a GPIO (GPO + GPI)
ADL_IO_LABEL_MSK Mask including ADL_IO_NUM_MSK and ADL_IO_TYPE_MSK
Description
ADL_IO_LEV_MSK Level field: the Level of GPIO
ADL_IO_LEV_HIGH - High Level
ADL_IO_LEV_LOW - Low Level
Code
type def enum
{
ADL_IO_DIR_POS = 17,
ADL_IO_DIR_MSK = (3UL<<ADL_IO_DIR_POS),
ADL_IO_DIR_OUT = (0UL<<ADL_IO_DIR_POS),
ADL_IO_DIR_IN = (1UL<<ADL_IO_DIR_POS),
ADL_IO_DIR_TRI = (2UL<<ADL_IO_DIR_POS)
} adl_ioDir_e;
209
Open AT® TUTORIAL
Description
ADL_IO_DIR_MSK Dir field: The direction of GPIO
ADL_IO_DIR_OUT - Set as Output
ADL_IO_DIR_IN - Set as Input
ADL_IO_DIR_TRI - Set as a Tristate
Code
type def enum
{
ADL_IO_ERR_POS = 28,
ADL_IO_ERR_MSK = (7UL<<ADL_IO_ERR_POS),
ADL_IO_ERR = (0UL<<ADL_IO_ERR_POS),
ADL_IO_ERR_UNKWN = (1UL<<ADL_IO_ERR_POS),
ADL_IO_ERR_USED = (2UL<<ADL_IO_ERR_POS),
ADL_IO_ERR_BADDIR = (3UL<<ADL_IO_ERR_POS),
ADL_IO_ERR_NIH = (4UL<<ADL_IO_ERR_POS),
ADL_IO_GERR_POS = 31,
ADL_IO_GERR_MSK = (1UL<<ADL_IO_GERR_POS),
ADL_IO_GNOERR = (0UL<<ADL_IO_GERR_POS),
ADL_IO_GERR = (1UL<<ADL_IO_GERR_POS)
} ioError_e;
Description
ADL_IO_ERR_MSK Error cause (b28-b30):
ADL_IO_ERR - Unidentified error
ADL_IO_ERR_UNKWN - Unknown GPIO
ADL_IO_ERR_USED - Already used
ADL_IO_ERR_BADDIR - Bad direction
ADL_IO_ERR_NIH - GPIO is not in the handle
ADL_IO_GERR_MSK General error field (b31):
ADL_IO_GNOERR - No Error (b28-30 are unsignificant)
ADL_IO_GERR - Error during the treatment (see b28-b30 for the cause)
Code
210
Open AT® TUTORIAL
ADL_IO_CAP_MSK = (3UL<<ADL_IO_CAP_POS),
ADL_IO_CAP_OR = (1UL<<ADL_IO_CAP_POS),
ADL_IO_CAP_IW = (2UL<<ADL_IO_CAP_POS)
} adl_ioCap_e;
Description
ADL_IO_CAP_MSK Capabilities field: Specials capabilities
ADL_IO_CAP_OR - Output is readable
ADL_IO_CAP_IW - Input is writable
Code
Description
ADL_IO_STATUS_MSK Status field: to get the status of the fields
ADL_IO_STATUS_USED - The IO is used by task
ADL_IO_STATUS_FREE - The IO is available
6. GPIO APIs
The GPIO APIs provided by the ADL library, are used to control the input-output pins. These pins can be subscribed
using the adl_ioSubscribe API. The subscribed input-output pins can be used to send and receive the data using the APIs
provided in the ADL library.
211
Open AT® TUTORIAL
Prototype:
s32 adl_ioGetCapabilitiesList ( u32 * GpioNb, adl_ioDefs_t ** GpioTab, adl_ioCap_t * GpioTypeNb )
Parameters:
GpioNb: Number of GPIO treated, it is the size of GpioTab array.
GpioTab: Returns a pointer to a list containing GPIO capabilities information (using adl_ioDefs_t ** type).
GpioTypeNb: Returns the number of each GPIO, GPO and GPI. This is an optional parameter. This parameter
will not be used if it is set to NULL.
Returned Values:
OK is returned on success.
Prototype:
s32 adl_ioEventSubscribe(adl_ioHdlr_f GPIOEventHandler)
Parameters:
GPIOEventHandler: Call-back function used to report all the events related to GPIO.
Prototype:
typedef void (*adl_ioHdlr_f) ( s32 GpioHandle, adl_ ioEvent_e Event,
u32 Size, void *param)
Parameters:
ADL_IO_EVENT_INPUT_CHANGED: One or several of the subscribed input have changed. Read the value
table.
Outputs available for each array element:
212
Open AT® TUTORIAL
Returned Values:
A positive or null handle is returned on successful subscription. This handle will be used for the
corresponding GPIO related operation.
ADL_RET_ERR_PARAM is returned if the parameter is invalid.
ADL_RET_ERR_NO_MORE_HANDLE is returned if GPIO service is subscribed for more than 128 times.
ADL_RET_ERR_SERVICE_LOCKED is returned if this API is called from a low level interrupt handler.
This API is available only from Open AT OS v4.1x and is used to unsubscribe from the GPIO event notification.
Prototype:
s32 adl_ioEventUnsubscribe (s32 GpioEventHandle)
Parameters:
GPIOEventHandle: Handle returned by the subscription function.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if GPIO service is unsubscribed with wrong handle.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if no GPIO service is subscribed.
ADL_RET_ERR_BAD_STATE is returned if a polling process is running in the current handle.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
s32 adl_ioSubscribe ( u32 GpioNb, adl_ioDefs_t * GpioConfig, u8 PollingTimerType, u32
PollingTime, s32 GpioEventhandle)
Parameters:
GPIONb: Size of GpioConfig array.
GpioConfig: GPIO subscription configuration array. The number of elements in this array is “GpioNb”. For
each element, the adl_ioDefs_t structure members have to be configured.
213
Open AT® TUTORIAL
PollingTimerType: Type of timer using which the polling will be performed. For instance, the value will be
ADL_TMR_TYPE_100MS for a timer of 100 millisecond granularity. The value should be ADL_TMR_TYPE_TICK
for a timer of 18.5 millisecond granularity.
PollingTime: The number of units (specified in PollingTimerType) after which the polling will be performed.
GpioEventHandle: GPIOEventHandle returned by adl_ioEventSubscribe () function. If no polling is requested,
this parameter is ignored.
Returned Values:
A positive or null handle is returned on success.
ADL_RET_ERR_PARAM is returned if a parameter has an incorrect value.
ADL_RET_ERR_DONE refers to the field adl_ioError_e for more information.
ADL_RET_ERR_NO_MORE_TIMERS is returned if no more timers are free to perform polling.
ADL_RET_ERR_NO_MORE_HANDLES is returned if no more GPIO handles are available.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level Interrupt handler.
Prototype:
s32 adl_ioUnsubscribe (s32 Handle)
Parameters:
Handle: Handle previously returned by a call to the adl_ioSubscribe function.
Returned Values:
OK is returned on success of execution of the function.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function isalled from a low level Interrupt handler.
This API is used to modify the direction (input or output) of the previously allocated GPIOs.
Prototype:
s32 adl_ioSetDirection (s32 GpioHandle, u32 GpioNb, adl_ioDefs_t *GpioDir)
Parameters:
GpioHandle: Handle returned by the subscription function.
214
Open AT® TUTORIAL
Returned Values:
OK is returned on success of execution of the function.
ADL_RET_ERR_PARAM is returned if one parameter has an incorrect value.
ADL_RET_ERR_DONE refers to the field adl_ioError_e for more information for each GPIO. If the error
information is ADL_IO_GNOERR, the process has been completed with success for this GPIO.
ADL_RET_ERR_UNKNOWN_HDL is returned if the handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level Interrupt handler.
Prototype:
s32 adl_ioRead ( s32 GpioHandle, u32 GpioNb, adl_ioDefs_t* GpioRead)
Parameters:
GpioHandle: Handle previously returned by a call to the adl_ioSubscribe function.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if a parameter is invalid.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
215
Open AT® TUTORIAL
ADL_RET_ERR_DONE refers to the field adl_ioError_e for more information. If the error information is
ADL_IO_GNOERR, the process has been completed with success for this GPIO.
Prototype:
s32 adl_ioReadSingle(s32 GpioHandle, adl_ioDefs_t Gpio)
Parameters:
GpioHandle: Handle returned by the subscription function.
Returned Values:
GPIO read value is returned on success (1 for a high level or 0 for a low level).
ADL_RET_ERR_UNKNOWN_HDL is returned if correct handle is specified.
ADL_RET_ERR_PARAM is returned if the parameters are incorrect.
ADL_RET_ERR_BAD_STATE is returned if the GPIO is not subscribed as output.
Prototype:
Parameters:
GpioHandle: Handle previously returned by a call to the adl_ioSubscribe function.
Returned Values:
OK is returned on success.
216
Open AT® TUTORIAL
Prototype:
s32 adl_ioWriteSingle(s32 GpioHandle, adl_ioDefs_t Gpio, bool State)
Parameters:
GpioHandle: Handle returned by the subscription function.
Gpio: Identifier of GPIO value of the identifier. Refer to adl_ioLabel_e for more details.
Returned Values:
OK: is returned on successful write operation.
ADL_RET_ERR_UNKNOWN_HDL is returned if incorrect handle is specified.
ADL_RET_ERR_PARAM is returned if the parameters are incorrect.
ADL_RET_ERR_BAD_STATE is returned if the GPIO is not subscribed as input.
7. Sample Code
#include "adl_global.h"
#include "adl_gpio.h"
// Subscription data
#define GPIO_COUNT1 2
#define GPIO_COUNT2 1
const u32 My_Gpio_Label1 [ GPIO_COUNT1 ] = { 1 , 2 }
const u32 My_Gpio_Label2 [ GPIO_COUNT2 ] = { 3 }
const adl_ioDefs_t MyGpioConfig1 [ GPIO_COUNT1 ] =
{ { ADL_IO_GPIO | My_Gpio_Label1 [ 0 ] | ADL_IO_DIR_OUT | ADL_IO_LEV_LOW },
{ ADL_IO_GPIO | My_Gpio_Label1 [ 1 ] | ADL_IO_DIR_IN } };
const adl_ioDefs_t MyGpioConfig2 [ GPIO_COUNT2 ] =
{ { ADL_IO_GPIO | My_Gpio_Label2 [ 0 ] | ADL_IO_DIR_IN } };
217
Open AT® TUTORIAL
218
Open AT® TUTORIAL
ADL_TMR_TYPE_100MS, 1, MyGpioEventHandle );
// Set output
adl_ioWriteSingle ( MyGpioHandle1, ADL_IO_GPIO | My_Gpio_Label1 \
[ 0 ] , TRUE );
// Read inputs
ReadValue = adl_ioReadSingle (MyGpioHandle1, ADL_IO_GPIO |
My_Gpio_Label1 [ 1 ] );
ReadValue = adl_ioReadSingle (MyGpioHandle2, ADL_IO_GPIO |
My_Gpio_Label2 [ 0 ] );
// Unsubscribe from the GPIO services
adl_ioUnsubscribe ( MyGpioHandle1 );
adl_ioUnsubscribe ( MyGpioHandle2 );
// Unsubscribe from the GPIO event service
adl_ioEventUnsubscribe ( MyGpioEventHandle );
}
Summary
219
Open AT® TUTORIAL
220
Open AT® TUTORIAL
CHAPTER 19
Bus Service
1. Objective
This chapter describes the bus service and its usage in the embedded module. ADL provides the bus service to handle
two SPI buses, an I2C bus and a parallel bus too.
2. Bus Description
Bus refers to a common data path or channel between multiple devices acting as peripherals. The following sections
give a brief explanation of the three kinds of buses supported in embedded module.
SPI (Serial Peripheral Interface) bus is a simple asynchronous serial interface for connecting low-speed,
external devices using a minimal number of wires. The devices connected to the SPI bus may be classified as
Master or Slave devices. A Master device initiates an information transfer on the bus and generates clock
and control signals. A Slave device is controlled by the master through a slave select (chip enable) line and is
active only when selected. A device can possess the functionality of a master and a slave; however, only one
master can control the bus. If a single slave is used – the SPI bus is a four-wire protocol. In the case of
multiple slaves, there are (3+n) wires, where n is the number of slaves.
SCK (Serial Clock): serial clock signal to regulate the flow of data bits. It is generated by the master
to synchronize data transfer.
MOSI (Master Out Slave Input): used to transfer data from the master to the slave device.
MISO (Master In Slave Out): used to transfer data from the slave to the master device.
SS (Slave Select): used to select a particular slave device when multiple slave devices are connected
to a master.
Additionally the Load and Busy signals can be used to synchronise the data transfer. For more information
see the ADL user guide.
221
Open AT® TUTORIAL
When using SPI, data is simultaneously transmitted and received, making it a full-duplex protocol.
The schematic diagram and timing diagrams of unidirectional and bidirectional SPI buses are shown below:
Figure 66: Timing diagram for Unidirectional SPI bus with flash device as example
Figure 68: Timing diagram for Bi-directional SPI bus with flash device as example
222
Open AT® TUTORIAL
Each device connected by the I2C bus is identified by a unique address. In case of a data transfer, each device
can be classified as a Master or a Slave. Here too, a Master is a device which initiates the data transfer and
generates the clock signal to permit that transfer.
Figure 69: Schematic diagram of typical I2C bus with master and two independent slaves
Parallel bus can be used for device which supports high speed data transfer. The parallel bus data width can
be up to 32 bits thus allowing transfer of 32 bits in parallel.
3. Bus APIs
This section describes the APIs that are available in embedded module for bus management. Include the adl_bus.h
header file to use the bus service.
This following API is used to subscribe to a bus service and manage bus related events. Simultaneously 8
configurations can be configured and can be connected to 8 different devices.
Prototype:
Parameter:
BusType: The bus which should be subscribed. The bus type is defined to the enum adl_busType_e.
typedef enum
{
ADL_BUS_ID_SPI, //SPI bus
ADL_BUS_ID_I2C, //I2C bus
223
Open AT® TUTORIAL
BlockId: Id of the block to use in the range 1-N, where N (i2c_NbBlocks/ spi_NbBlocks/Para_NbBlocks) is
specific to each bus type and embedded module platform.
SPI: The setting for the SPI bus. This structure adl_busSPISetting_t is defined below:
typedef struct
{
u32 Clk_Speed;
u32 Clk_Mode;
u32 ChipSelect;
u32 ChipSelectPolarity;
u32 LsbFirst;
adl_ioDefs_t GpioChipSelect;
u32 LoadSignal;
u32 DataLinesConf;
u32 MasterMode;
u32 BusySignal;
} adl_busSPISettings_t;
ChipSelect: Pin to use for chip select signal. Defined values are:
LsbFirst: Priority of the data transfer through the SPI bus, various defined values are:
224
Open AT® TUTORIAL
GpioChipSelect: It is used in case GPIO is chosen for the Chip select signal. It defines the label to be used for
chip select signal.
DataLinesConf: It is used to define if the single line handles both the input and output. Following are the
value defined:
ADL_BUS_SPI_DATA_BIDIR: One PIN to handle both input and output.
ADL_BUS_SPI_DATA_UNDIR: Two separate PIN for input and output.
I2C: The setting for the I2C bus. The settings structure adl_busI2Csetting_t is given below
typedef struct
{
u32 ChipAddress;
u32 Clk_Speed;
u32 AddrLength;
u32 MasterMode;
} adl_busI2CSettings_t;
ChipAddress: It is used to set the N bit address on the I2C bus. Note that only b1 to bN bits are used to set
the address. The b0 bit and most significant bytes are neglected.
N Value depends on the embedded module capabilities, and on the adl_busI2CSettings_t::AddrLength field
configuration. For example, if the I2C address is set to A0, the ChipAddress parameter has to be set to the
0xA0 value.
Clk_Speed: Used to set the speed for the I2C bus. Following are the values defined.
ADL_BUS_I2C_CLK_STD: Standard I2C bus speed (100 kbits/s).
ADL_BUS_I2C_CLK_FAST: Fast I2C bus speed (400 kbits/s).
ADL_BUS_I2C_CLK_HIGH: High I2C bus speed(3.4Mbits/s)
AddrLength: This parameter is used to set the I2C chip address length.
225
Open AT® TUTORIAL
ADL_BUS_I2C_ADDR_7_BITS: Chip address is 7 bits long. This is the default value if adl_busSubscribe
function is used.
ADL_BUS_I2C_ADDR_10_BITS: Chip address is 10 bits long.
PARALLEL BUS: The setting for the parallel bus. The settings structure adl_busParallelsetting_t is given
below .
typedef struct
{
u8 Width;
u8 Mode;
u8 pad [2];
adl_busParallelTimingsCfg_t ReadCfg;
adl_busParallelTimingsCfg_t WriteCfg;
adl_busParallelCs_t Cs;
adl_busParallelPageCfg_t PageCfg;
adl_busParallelSynchronousCfg_t SynchronousCfg;
u32 AddressPin;
} adl_busParallelsetting_t ;
ReadCfg: Defines the timing configuration of the read process. This is defined by:
typedef struct
{
u8 AccessTime;
226
Open AT® TUTORIAL
u8 SetupTime;
u8 HoldTime;
u8 TurnaroundTime;
u8 OptoOpTurnaroundTime;
u8 pad[3]; // Internal use only
} adl_busParallelTimingCfg_t;
AccessTime: Access time. Refer Mode parameter and PTS for more information.
SetupTime: Setup time Refer Mode parameter and PTS for more information.
HoldTime: Hold time. Refer Mode parameter and PTS for more information.
TurnaroundTime: Turnaround time. Refer Mode parameter and PTS for more information.
WriteCfg: Defines the timing configuration of the write process. This is defined by adl_busPrallelTimingCfg_t
as mentioned for ReadCfg parameter.
PageAccessCycles: Defines the access cycle between address change and valid data output.
227
Open AT® TUTORIAL
typedef struct
{
u8 BurstSize;
u8 ClockDivisor;
s32 UseWaitEnable:1;
s32 WaitActiveDuringWS:1;
s32 Reserved:30;
} adl_busParallelSynchronousCfg_t;
Returned values:
Prototype:
Parameters:
Handle: Handle returned by the adl_busSubscribe function.
228
Open AT® TUTORIAL
Returned Values:
OK is returned on successfully unsubscribing from the bus service.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler
Prototype:
Parameters:
229
Open AT® TUTORIAL
ADL_BUS_CMD_PARA_GET_MAX_SETTINGS (Available for the Parallel bus only): Gets Parallel bus
maximum values.
ADL_BUS_CMD_PARA_GET_MIN_SETTINGS (Available for the Parallel bus only): Gets Parallel bus
minimum values.
Return Values
OK is returned on successful execution of the API.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_PARAM is returned if a parameter has an incorrect value.
ADL_RET_ERR_DONE is returned if an error occurs during the operation.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level Interrupt handler.
3.4. Reading Data from the Subscribed Bus (SPI and I2C)
The following API should be used to read data from a subscribed bus.
Prototype:
s32 adl_busRead( s32 Handle, adl_busAccess_t * pAccessMode, u32 Length, void * pDataToRead )
or
s32 adl_busReadExt( s32 Handle, adl_busAccess_t * pAccessMode, u32 Length, void *
pDataToRead, void * Context )
Parameters:
Handle: Handle returned by the adl_busSubscribe function.
pAccessMode: Bus access mode, defined according to the following type:
typedef struct
{
u32 Address;
u32 Opcode;
} adl_busAccess_t;
Address: This is usable for both SPI and I2C buses. The address parameter allows 32 bits to be sent on the
bus, before the read and the write process is started. The number of bits to send is set by the
ADL_BUS_CMD_SET_ADD_SIZE IOCtl command. If less than 32 bits are required to be sent; only the most
significant bits are sent on the bus.
Opcode: This parameter can be used only over the SPI bus. The Opcode parameter allows sending 32 bits
over the bus before the read or the write process. The number of bits to send is set by the
230
Open AT® TUTORIAL
ADL_BUS_CMD_SET_OP_SIZE IOCtl command. If less than 32 bits are required to be sent; only the most
significant bits are sent on the bus. Usable only for SPI bus (ignored for I2C bus).
For example: If “BBB” has to be sent over the bus the Opcode parameter has to be set to 0xBBB00000 value,
and the OpcodeLength parameter has to be set to 12.
Context: Pointer to an application context, which will be provided back to the application when the
asynchronous read operation end event will occur.
Return Values
OK is returned on successful execution of the API.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_PARAM is returned if a parameter has an incorrect value.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler in
synchronous mode.
The following API is used to read from previously subscribed parallel bus.
Prototype:
s32 adl_busDirectRead( s32 Handle, u32 ChipAddress, u32 DataLen, void *Data)
Parameter:
DataLen: Number of items (16 bits or 8 bits set as bus width) to be read.
Returned Value:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the handle is invalid.
ADL_RET_ERR_PARAM is returned if parameters are incorrect.
231
Open AT® TUTORIAL
Prototype:
Parameters:
Handle: Handle returned by the adl_busSubscribe function.
Address: This is usable for both SPI and I2C buses. The address parameter allows 32 bits to be sent on the
bus, before the read and the write process is started. The number of bits to send is set by the
ADL_BUS_CMD_SET_ADD_SIZE IOCtl command. If less than 32 bits are required to be sent; only the most
significant bits are sent on the bus.
Opcode: This parameter can be used only over the SPI bus. The Opcode parameter allows sending 32 bits
over the bus before the read or the write process. The number of bits to send is set by the
ADL_BUS_CMD_SET_OP_SIZE IOCtl command. If less than 32 bits are required to be sent; only the most
significant bits are sent on the bus. Usable only for SPI bus (ignored for I2C bus).
For example: If “BBB” has to be sent over the bus the Opcode parameter has to be set to 0xBBB00000 value,
and the OpcodeLength parameter has to be set to 12.
Context: Pointer to an application context, which will be provided back to the application when the
asynchronous read operation end event will occur.
Returned Values:
232
Open AT® TUTORIAL
Prototype:
s32 adl_busDirectWrite( s32 Handle, u32 ChipAddress, u32 DataLen, void *Data)
Parameter:
Handle: Handle returned during the bus subscription.
DataLen: Number of item (16 bits or 8 bits set as bus width) to be written.
Returned Value:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is incorrect.
ADL_RET_ERR_PARAM is returned incorrect parameter.
233
Open AT® TUTORIAL
};
// BUS Handles
s32 MySPIHandle, MyI2Chandle;
// Data buffers
u8 WriteBuffer [ WRITE_SIZE ], ReadBuffer [ READ_SIZE ];
234
Open AT® TUTORIAL
adl_busUnsubscribe ( MyI2CHandle );
}
Summary
The following points have been covered in this chapter
Bus refers to a common data path or channel between multiple devices acting as peripherals.
Embedded module support three buses – SPI bus, I2C bus and parallel bus.
The APIs provided for bus management are defined in the adl_bus.h header file.
SPI and I2C buses are serial buses.
PARALLEL bus support is provided from Open AT OS v4.1x and AirPrime Q26XX embedded module.
To subscribe to the bus service, use the adl_busSubscribe API.
To unsubscribe from the bus service, use the adl_busUnsubscribe API.
To read data from a subscribed SPI/I2C bus, use the adl_busRead API. To read data from a parallel bus, use
adl_busDirectRead API.
To write data to a subscribed SPI/I2C bus, use the adl_busWrite API. To write data to a parallel bus, use
adl_busDirectWrite API.
235
Open AT® TUTORIAL
236
Open AT® TUTORIAL
Chapter 20 - Watchdog
CHAPTER 20
Watchdog
1. Objective
This chapter describes the watchdog service and its usage in the embedded module. Open AT OS provides a watchdog
service to access to the embedded module hardware watchdog timer.
APIs related to the watchdog service are declared in the adl_wd.h header file.
2. Watchdog Timer
A watchdog timer is a hardware timer that triggers a system reset in the main program, due to some fault conditions,
such as a hang. The reset is done in order to bring the system back to normal operation state. The most common use of
watchdog timers is in embedded systems, where this specialized timer is often a built-in unit of a microcontroller.
Watchdog timers may also trigger control systems to move into a safety state, such as turning off motors, high-voltage
electrical outputs, and other potentially dangerous subsystems until the fault is cleared.
ADL provides APIs to disable/enable hardware watchdog and also to start/stop software watchdog.
237
Open AT® TUTORIAL
Chapter 20 - Watchdog
The lowest priority task re-starts the Watchdog timer when it is being scheduled. If the lowest priority task is
not scheduled in 5 seconds, the timer expires and causes a system reset. This reset is done in order to avoid
any tasks hogging the embedded module for long time. For e.g. a task in infinite loop.
Open AT OS provides APIs which can be used for disabling the hardware watchdog for a specified duration.
This avoids the embedded module restart when Open AT Application takes more than the hardware
watchdog duration. This feature can be used in the Open AT Application which has operations which takes
more than hardware watchdog time. Ex: SSL Applications.
adl_wdPut2Sleep
adl_wdAwake
Open AT OS maintains a software watchdog timer for Open AT Application tasks. Open AT Application task
can start this timer and reset it before the expiry. If Open AT Application task is unable to reset the timer in
specified time, timer will expire and it will cause a reset. This mechanism will ensure that all Open AT
Application tasks are being scheduled and the system is stable. In case of instability, reset will ensure the
stability.
adl_wdActiveAppWd
adl_wdRearmAppWd
adl_wdDeActiveAppWd
238
Open AT® TUTORIAL
Chapter 20 - Watchdog
When watchdog is declared in one of the Open AT Application tasks and if another task declares it
again, the last Watchdog timer value is overwritten.
When delaying the Hardware watchdog, the GSM stack will still be pre-empting the Open AT
Application if needed. It is strongly advised to calibrate the delay using the worst case scenario
(GPRS or CSD transfers ongoing).
When delaying the HW watchdog the application watchdog shall still be re-armed regularly. Either
increase temporarily the Application watchdog for the time of the delay, or do the “heavy”
treatment in a less priority task than the one re-arming the Application watchdog.
Prototype:
s8 adl_wdPut2Sleep (u32 i_u32_SleepDuration)
Parameters:
i_u32_SleepDuration: This parameter indicates the watchdog sleep duration in number of ticks.
Returned Values:
This function returns OK on success or ADL_RET_ERR_PARAM error code if wrong argument is used.
Prototype:
s8 adl_wdAwake (void)
Parameters:
None.
Returned Values:
This function returns remaining time before automatic watchdog reactivation in number of ticks.
239
Open AT® TUTORIAL
Chapter 20 - Watchdog
This API is used to activate the Open AT Application watchdog. Open AT Application watchdog must be
rearmed regularly to indicate that it is still alive. embedded module resets if watchdog timer expires.
Prototype:
s32 adl_wdActivateAppWd (u32 i_u32_Duration)
Parameters:
i_u32_Duration: This parameter indicates the watchdog sleep duration in number of ticks.
Returned Values:
This function returns OK on success or ADL_RET_ERR_NOT_SUPPORTED if watchdog service is not supported.
Prototype:
s32 adl_wdRearmAppWd (void)
Parameters:
None.
Returned Values:
This function returns OK on success or ADL_RET_ERR_NOT_SUPPORTED if watchdog service is not supported.
Prototype:
s32 adl_wdDeActiveAppWd (void)
Parameters:
None.
Returned Values:
This function returns OK on success or ADL_RET_ERR_NOT_SUPPORTED if watchdog service is not supported.
240
Open AT® TUTORIAL
Chapter 20 - Watchdog
6. Sample Code
#include "adl_global.h"
#include "adl_wd.h"
const u16 wm_apmCustomStackSize = 4096;
u8 wd_command = 0;
bool heavy_treatment_done = FALSE;
u32 counter1;
241
Open AT® TUTORIAL
Chapter 20 - Watchdog
adl_tmrSubscribe(FALSE,90,ADL_TMR_TYPE_100MS,TimerHandler);
}
}
break;
}
}
case 2:
{
242
Open AT® TUTORIAL
Chapter 20 - Watchdog
u32 ret;
/* Use the function adl_wdPut2Sleep - Reset due to WD*/
/* WD sleep time is less than the heavy treatment execution time */
TRACE((1,"sleep HW WD 10s "));
ret = adl_wdPut2Sleep(ADL_TMR_S_TO_TICK(10));
TRACE((1,"Return value of adl_wdPut2Sleep = %d", ret));
counter1 = 5;
// Lets activate the application watchdog for 30 seconds
ret = adl_wdActiveAppWd(ADL_TMR_S_TO_TICK(10));
243
Open AT® TUTORIAL
Chapter 20 - Watchdog
}
break;
default:
break;
}
}
Summary
The following points have been covered in this chapter
ADL provides Watchdog APIs to stop/start the hardware watchdog and also the application watchdog.
The adl_wdPut2Sleep API should be used to deactivate the hardware watchdog.
The adl_wdAwake API should be used to resume the hardware watchdog.
The adl_wdActivateAppWd API should be used to activate the application watchdog.
The adl_wdRearmAppWd API should be used to rearm the application watchdog.
The adl_wdDeActiveAppWd API should be used to deactivate the application watchdog.
244
Open AT® TUTORIAL
CHAPTER 21
SIM Service
1. Objective
This chapter introduces the SIM service and its related APIs. The various SIM- and PIN-related events are explained
here.
Following is list of SIM- and PIN-related events and their corresponding numeric values:
SIM Events Numeric Description
Value
ADL_SIM_EVENT_REMOVED 1 This event is received when the SIM card is removed from
embedded module.
ADL_SIM_EVENT_INSERTED 2 This event is received when the SIM card is inserted into
the Embedded module.
ADL_SIM_EVENT_FULL_INIT 3 This event is received when the SIM card is initialized
completely or WIND: 4 has been received by Open AT
Application. After receiving this event any SIM-based AT
commands such as phonebook command or SMS
command can be executed.
245
Open AT® TUTORIAL
4. SIM States
SIM State describes the current state of the SIM – whether it is inserted or removed and so on. A SIM can be in only one
state at any given instant. Based on the SIM state, the embedded module can decide which functions can be used at
that time. For example if SIM state is set as ADL_SIM_STATE_FULL_INIT (defined below) then all the SIM related
commands could be processed.
SIM state is set automatically by the embedded module whenever a SIM-related event occurs. SIM states have been
defined as enumerated data type of type “adl_simState_e” as shown below.
typedef enum
{
ADL_SIM_STATE_INIT,
ADL_SIM_STATE_REMOVED,
ADL_SIM_STATE_INSERTED,
ADL_SIM_STATE_FULL_INIT,
ADL_SIM_STATE_PIN_ERROR,
ADL_SIM_STATE_PIN_OK,
ADL_SIM_STATE_PIN_WAIT,
ADL_SIM_STATE_LAST
} adl_simState_e;
246
Open AT® TUTORIAL
Following is list of SIM states, their corresponding numeric value and name in Open AT OS.
SIM Events Numeric Description
Value
ADL_SIM_STATE_INIT 0 This SIM state is set when the SIM is initializing. At this
time SIM PIN state is not known to the Open AT OS
ADL_SIM_STATE_REMOVED 1 This state is set when the SIM is removed from the
embedded module.
ADL_SIM_STATE_INSERTED 2 This state is set when the SIM is inserted into the
embedded module.
ADL_SIM_STATE_FULL_INIT 3 This state is set when the SIM is completely initialized or
WIND: 4 is received by Open AT OS.
ADL_SIM_STATE_PIN_ERROR 4 This state is set when the incorrect PIN code is issued.
ADL_SIM_STATE_PIN_OK 5 This state is set when the correct PIN code is issued. After
issuing the correct PIN code, the Open AT OS waits for the
complete initialization.
ADL_SIM_STATE_PIN_WAIT 6 This state is set when the SIM is inserted into the
embedded module but the PIN code is not issued yet.
ADL_SIM_STATE_LAST 7 This is last SIM state. It is never set. It has been defined
for the programming purpose.
adl_simSubscribe
adl_simUnsubscribe
adl_simGetState
Prototype:
This API subscribes to SIM service and specifies a callback function which is called whenever SIM- or PIN-
related events are received. It also allows you to enter PIN code of the SIM.
Parameters:
247
Open AT® TUTORIAL
Handler: Handler is the callback function which is called whenever a SIM or PIN event is received by the
Open AT Application. has the following declaration:
The input parameter to this callback function is a SIM event. Refer to the section on Events Related to the
SIM and PIN.
PinCode: PinCode is defined as ASCII * and is the string containing the PIN code of the SIM. If it is set to
NULL or if the provided code is incorrect, then the PIN code should be entered by the external application.
This argument is used only the first time the SIM service is subscribed.
Returned Value:
OK is returned on success.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level Interrupt handler.
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if the service was already subscribed with the same
handler.
ADL_RET_ERR_PARAM is returned if the function was called with a null handler.
The following API should be used to unsubscribe from the SIM service:
Prototype:
Returned Value:
OK is returned on success.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level Interrupt handler.
Prototype:
248
Open AT® TUTORIAL
Parameters:
None.
Returned Values:
This API returns the current SIM states (refer to the section on
SIM States).
NOTE :
The SIM service can be subscribed several times in Open AT Application.
If SIM service is subscribed multiple times, and any event occurs, then all the handlers will be called by the
Open AT OS.
You can only unsubscribe a subscribed handler of the SIM service, or an error will be returned.
The SIM be in only one state at any point of time.
This API can be used to enter a PIN code of the inserted SIM.
Prototype:
Parameters:
PinCode: This parameter holds the PIN code.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if the Pin Code is not informed.
ADL_RET_ERR_BAD_STATE is returned if the SIM is not waiting for any Pin Code to be entered.
Prototype:
249
Open AT® TUTORIAL
Parameters:
PukCode: This parameter holds the PUK code.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if the PukCode or NewPinCode is not informed.
ADL_RET_ERR_BAD_STATE if the SIM is not waiting for PIN or PUK, and nothing entered yet from ext.
Prototype:
Returned Values:
adl_simRem_e structure which holds the PIN and PUK remaining attempts.
The description of adl_simRem_e structure is as follows:
typedef struct
{
s8 PinRemaining; //Contains remaining attempts on PIN before lock PIN
s8 PukRemaining; //Contains remaining attempts on PUK before lock PUK
} adl_simRem_e;
6. Sample Code
/* Mandatory header file to be included to use SIM service */
#include adl_sim.h
/* Global variable is declared to capture the SIM state */
adl_simState_e simState;
/* This function is called whenever any SIM event is received */
void simHandler (u8 Event)
{
/* Here received SIM event has been handled */
switch (Event)
{
case ADL_SIM_EVENT_INSERTED:
adl_atSendResponse (ADL_AT_UNS,”\r\SIM is inserted\r\n”);
break;
250
Open AT® TUTORIAL
case ADL_SIM_EVENT_REMOVED:
adl_atSendResponse (ADL_AT_UNS,”\r\SIM is removed\r\n”);
break;
}
}
/* Open AT entry point function */
void adl_main (adl_InitType_e adlInitType)
{
/* subscribe for SIM service, whose handler is simHandler and PIN */ /* is given as 0000*/
adl_simSubscribe (simHandler, “0000”)
}
Summary
251
Open AT® TUTORIAL
252
Open AT® TUTORIAL
CHAPTER 22
Short Message Service
1. Objective
This chapter describes the SMS (Short Message Service) Service used to implement the exchange of short messages
between subscribers in a GSM network. The SMS service provides a means of sending messages of limited size to and
from GSM/UMTS mobiles. SMS can be classified on basis of:
Origin:
Mobile-originated messages are transported from an MS (Mobile Station) to a service centre
Mobile-terminated messages are transported from a service centre to an MS.
Data Mode:
Text Mode: All commands and responses are in ASCII format.
PDU mode: PDU stands for Protocol Data Unit. In this mode a complete SMS message including all
header information is given as a binary string (in hexadecimal format).
2. What is SMS?
The SMS provides a means to transfer short messages between a GSM/UMTS MS and an SME (Short Message Entity) via
a SC (Service Centre). The SC serves as a relaying station of the message transfer between the MS and the SME.
3. Basic Services
The Short Message Service comprises two basic services:
SMMT (Short Message Mobile Terminated)
SMMO (Short Message Mobile Originated)
SMMT denotes the capability of the GSM/UMTS system to transfer an SMS submitted from the SC
to one MS, and to provide information about the delivery of the SMS either by a delivery report or a
failure report, with a specific mechanism for later delivery.
253
Open AT® TUTORIAL
Short Message
Delivery
SC MS
Report
Figure 70 - Mobile Terminated Short Message Service
SMMO denotes the capability of the GSM/UMTS system to transfer an SMS submitted by the MS to one SME via an SC,
and to provide information about the delivery of the SMS either by a delivery report or a failure report. The message
must include the address of that SME to which the SC shall eventually attempt to relay the short message.
Short Message
Submission
MS SC
Report
Figure 71 - Mobile Originated Short Message Service
The text message to be transferred by means of SMMT or SMMO can contain up to 140 bytes.
The following API should be used to subscribe and use the SMS service:
Prototype:
254
Open AT® TUTORIAL
Parameters:
smsHandler: smsHandler is called each time an SMS is received from the network. The handler is declared:
bool (*adl_smsHdlr_f ) ( ascii *SmsTel, ascii *SmsTimeLength, ascii *SmsText)
Parameters:
SmsTel: This parameter contains the telephone number of the originating MS in text mode
and NULL in PDU mode.
SmsTimeLength: This parameter contains the SMS time stamp in text mode and SMS
length in PDU mode.
SmsText: This parameter contains the actual SMS text (in text mode), or the SMS PDU (in
PDU mode). PDU stands for Protocol Data Unit and contains the SMS content along with
required header information as a part of it.
Returned Values:
TRUE: if the SMS must be forwarded to the external application. If the SMS service is
subscribed several times, a received SMS will be forwarded to the external application
only if each of the handlers return TRUE. This is called the SMS Read operation and the
SMS is then stored in the SIM memory. The external application is notified by sending an
unsolicited code: +CMTI:”SM”,<>.
FALSE: in case the SMS should not be forwarded to the network, this function sends False
as a return value.
smsCtrlHandler: SMS control handler captures the events received during SMS sending process. The function
type is defined below:
typedef void (* adl_smsCtrlHdlr_f )( u8 Event, u16 Nb)
Parameters:
Nb: This parameter takes different values depending upon the event received in SMS
control handler.
Event: Event received while sending SMS include:
Event Description Nb Parameter
ADL_SMS_EVENT_SENDING_OK This event notifies that Nb parameter value
the SMS is sent not relevant
successfully
ADL_SMS_EVENT_SENDING_ERROR Error occurred when Nb parameter takes
sending the SMS the error number of
the CMS error(+CMS
ERROR”)
ADL_SMS_EVENT_SENDING_MR SMS sent successfully. Nb parameter
This event is received contains the sent
along with Message Reference
ADL_SMS_EVENT_SENDI value.
NG_OK event.
255
Open AT® TUTORIAL
Mode: This parameter is used to specify which mode was used to send the SMS. As
described above there are two modes:
ADL_SMS_MODE_PDU: This parameter indicates that the smsHandler should be called in
PDU mode on the receipt of each SMS.
ADL_SMS_MODE_TEXT: This parameter indicates that the smsHandler should be called in
Text mode on the receipt of each SMS.
Returned Values:
Positive or null handle is returned in case of successful subscription on SMS service. This handle is required
for further SMS operations.
ADL_RET_ERR_PARAM is returned in case of wrong parameter is specified.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
Handle: This is the handle returned by the adl_smsSubscribe function
SmsTel: This parameter holds the telephone number of the recipient MS (in Text mode) OR Null (in PDU
mode).
SmsText: This parameter contains the SMS text in text mode or the SMS PDU in PDU mode.
Mode: This parameter is used to select between the Text or PDU SMS modes. The two possible values are:
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned in case of incorrect parameter value is specified.
ADL_RET_ERR_UNKNOWN_HDL is returned if the handle provided to the adl_Send () function is different
from the actual handle returned by the adl_sms_Subscribe () function.
ADL_RET_ERR_BAD_STATE is returned if due to some reason the embedded module is not ready to send the
SMS. For instance, if the initialization is not done yet, or if the process of sending the SMS is already in
progress.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interruption handler.
256
Open AT® TUTORIAL
Prototype:
s8 adl_smsUnsubscribe( u8 Handle)
Parameters:
Handle: This parameter is the handle returned by the earlier call to the adl_smsSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is not correct. The handle provided to
adl_smsUnsubscribe () function should be same as that returned by the adl_smsSubscribe () function.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if the subscription fails and the user tries to unsubscribe from
the service.
ADL_RET_ERR_BAD_STATE is returned in case the SMS send process is in progress and the Open AT
Application executes the unsubscribe function.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
257
Open AT® TUTORIAL
5. Sample Code
/* sample code implementing the SMS send functionality */
#include "adl_global.h"
#include "adl_sms.h"
const u16 wm_apmCustomStackSize = 4096;
// Local variables
u8 Event;
u16 Nb;
s8 smshandle;
//ascii telno[]="<Telephone No.>";
ascii telno[]="9844472947";
ascii *smstimelnth;
ascii *smstext="The text for sms goes here";
s8 sendhandle;
s8 unshandle;
//Local Functions
bool SmsHandler(ascii * telno, ascii *smstimelnth,ascii *smstext)
{
adl_atSendResponse(ADL_AT_UNS,"inside sms hsndler");
return (0);
}
258
Open AT® TUTORIAL
NOTE :
The SMS service must be subscribed before using any of SMS service API.
The adl_smsSend () function must be called after WIND 4 indication. For this adl_atUnSoSubscribe () function
can be used to subscribe to WIND 4 unsolicited response and further functionality can be implemented in the
Handler of this function. This is because the embedded module is able to accept all commands after WIND 4
indication.
At the end of Open AT Application, the SMS service must be unsubscribed.
In case of dynamic memory allocation, ensure that the allocated memory is released at the end of program.
259
Open AT® TUTORIAL
Summary
260
Open AT® TUTORIAL
CHAPTER 23
Call Service
1. Objective
This chapter introduces you to the call service and its procedures for:
Various call-related events and APIs are also explained in this chapter.
Following is a list of events related to the call service and their corresponding numeric values and descriptions:
Call Events Description
ADL_CALL_EVENT_RING_VOICE The embedded module has received the
voice call.
ADL_CALL_EVENT_RING_DATA The embedded module has received the data
call.
ADL_CALL_EVENT_NEW_ID The embedded module has received the
WIND: 5,x indication. x can have any value.
ADL_CALL_EVENT_RELEASE_ID The embedded module has received the
WIND: 6,x indication. x can have any value.
ADL_CALL_EVENT_ALERTING The embedded module has received the
WIND: 2 indication.
ADL_CALL_EVENT_NO_CARRIER The Embedded module has received the NO
CARRIER indication.
ADL_CALL_EVENT_NO_ANSWER The embedded module has received the NO
ANSWER indication.
261
Open AT® TUTORIAL
262
Open AT® TUTORIAL
If the call service is subscribed to multiple times using the function adl_callSubscribe, and the
ADL_CALL_EVENT_SETUP_FROM_EXT event is received by the call handler function, then the following conditions can
occur:
Case 1: If all the handlers return ADL_CALL_FORWARD then call set up is performed.
Case 2: If any of the handlers return ADL_CALL_NO_FORWARD or ADL_CALL_NO_FORWARD_ATH or
ADL_CALL_NO_FORWARD_ATA constant, then CME ERROR: 600 is sent to the external application.
adl_callSubscribe
adl_callSetup
adl_callSetupExt
adl_callHangup
adl_callHangupExt
adl_callAnswer
adl_callAnswerExt
adl_callUnsubscribe
Prototype:
This API subscribes to call service and specifies a callback function which is called whenever events related to
the call service are received.
Parameters:
CallHandler: the callback function which is called whenever an event related to the call is received by the
Open AT Application. The Handler is defined as the following function pointer:
263
Open AT® TUTORIAL
Event: An event related to the call service. These events are explained in the section on Events Related to the
Call Service.
Call_Id: The Identifier associated with the event. The following table lists the call events and their
corresponding Call_IDs:
Call Events Call Id
ADL_CALL_EVENT_RING_VOICE 0
ADL_CALL_EVENT_RING_DATA 0
ADL_CALL_EVENT_NEW_ID The call identification number of the corresponding
+WIND: 5 indication.
ADL_CALL_EVENT_RELEASE_ID The call identification number of the corresponding
+WIND: 6 indication.
ADL_CALL_EVENT_ALERTING 0
ADL_CALL_EVENT_NO_CARRIER 0
ADL_CALL_EVENT_NO_ANSWER 0
ADL_CALL_EVENT_BUSY 0
ADL_CALL_EVENT_SETUP_OK For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the speed of the
data call.
ADL_CALL_EVENT_ANSWER_OK For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the speed of the
data call.
ADL_CALL_EVENT_CIEV For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the speed of the
data call.
ADL_CALL_EVENT_HANGUP_OK For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the
ADL_CALL_DATA_FLAG constant.
ADL_CALL_EVENT_SETUP_OK_FROM_EXT For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the speed of the
data call.
ADL_CALL_EVENT_ANSWER_OK_FROM_EXT For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the speed of the
data call.
ADL_CALL_EVENT_HANGUP_OK_FROM_EXT For voice calls, the value of the call ID is 0.
For data calls, the value of the call ID is the
ADL_CALL_DATA_FLAG constant.
ADL_CALL_EVENT_AUDIO_OPENNED 0
264
Open AT® TUTORIAL
Following is the list of possible return values of the call handler and their corresponding descriptions:
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned when the incorrect parameter is specified.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
265
Open AT® TUTORIAL
Parameters:
CallHandler: This parameter is the callback function which is called whenever the Open AT Application
receives an event related to the call service. For parameter information, refer to the section on the
adl_callSubscribe API.
Returned Values:
OK (Numeric Value = 0) is returned on successful execution of the API.
ADL_RET_ERR_PARAM (Numeric Value = -2) is returned if the input parameter (CallHandler) is set to NULL.
ADL_RET_ERR_UNKNOWN_HDL (Numeric Value = -3) is returned if the provided handler value is incorrect.
ADL_RET_ERR_NOT_SUBSCRIBED (Numeric Value = -5) is returned if the service is not subscribed.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
The call service can be subscribed to multiple times in the Open AT Application.
You can only unsubscribe from a subscribed handler of the call service, or else an error is returned
This API is used to setup an outgoing GSM voice/data call from a specific port.
Prototype:
Parameters:
Returned Values:
OK is returned on success
ADL_RET_ERR_PARAM is returned if incorrect parameter is mentioned.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
As adl_callSetup() API does not have any parameter to mention the port. This API makes an outgoing call from
Open AT OS virtual port.
266
Open AT® TUTORIAL
Prototype:
Parameters:
Port: The port from which the call should be disconnected. The values this parameter can take are defined in
the adl_port_e enum.
Returned Values:
OK is returned on success
ADL_RET_ERR_PARAM is returned if incorrect parameter is mentioned.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
As adl_callHangup() API is also provided by Open AT OS which does not have any parameter to mention the port.
This API does the hang-up from Open AT OS virtual port.
Prototype:
Parameters:
Port: The port from which the call should be answered. The values this parameter can take are defined in the
adl_port_e enum.
Returned Values:
OK is returned on success
ADL_RET_ERR_PARAM is returned if incorrect parameter is mentioned.
ADL_RET_ERR_SERVICE_LOCKED is returned if it is called from a low level interrupt handler.
267
Open AT® TUTORIAL
NOTE :
As adl_callAnswer() API does not have any parameter to mention the port. This API accepts call from Open AT OS
virtual port.
4. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
268
Open AT® TUTORIAL
break;
case ADL_CALL_EVENT_ANSWER_OK:
TRACE((1,"ADL_CALL_EVENT_ANSWER_OK"));
break;
case ADL_CALL_EVENT_HANGUP_OK:
TRACE((1,"ADL_CALL_EVENT_HANGUP_OK"));
adl_callUnsubscribe (CallHandler);
break;
case ADL_CALL_EVENT_SETUP_OK_FROM_EXT:
TRACE((1,"ADL_CALL_EVENT_SETUP_OK_FROM_EXT"));
break;
case ADL_CALL_EVENT_ANSWER_OK_FROM_EXT:
TRACE((1,"ADL_CALL_EVENT_ANSWER_OK_FROM_EXT"));
break;
case ADL_CALL_EVENT_HANGUP_OK_FROM_EXT:
TRACE((1,"ADL_CALL_EVENT_HANGUP_OK_FROM_EXT"));
break;
case ADL_CALL_EVENT_AUDIO_OPENNED:
TRACE((1,"ADL_CALL_EVENT_AUDIO_OPENNED"));
break;
case ADL_CALL_EVENT_ANSWER_OK_AUTO:
TRACE((1,"ADL_CALL_EVENT_ANSWER_OK_AUTO"));
break;
case ADL_CALL_EVENT_RING_GPRS:
TRACE((1,"ADL_CALL_EVENT_RING_GPRS"));
break;
case ADL_CALL_EVENT_SETUP_FROM_EXT:
TRACE((1,"ADL_CALL_EVENT_SETUP_FROM_EXT"));
break;
case ADL_CALL_EVENT_SETUP_ERROR_NO_SIM:
TRACE((1,"ADL_CALL_EVENT_SETUP_ERROR_NO_SIM"));
break;
case ADL_CALL_EVENT_SETUP_ERROR_PIN_NOT_READY:
TRACE((1,"ADL_CALL_EVENT_SETUP_ERROR_PIN_NOT_READY"));
break;
case ADL_CALL_EVENT_SETUP_ERROR:
TRACE((1,"ADL_CALL_EVENT_SETUP_ERROR"));
break;
default:
break;
}
return retValue;
}
269
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
Open AT OS provides the APIs to handle events related to call.
Events related to the call service are issued to the Open AT Application by the external application and the
embedded module.
To subscribe to a call service, use the adl_callSubscribe function.
To unsubscribe from a call service, use the adl_callUnsubscribe function.
To set up a call, use the adl_callSetup function.
To hang up a call, use the adl_callHangup function.
To answer a call, use the adl_callAnswer function.
270
Open AT® TUTORIAL
CHAPTER 24
General Packet Radio Service
1. Objective
This chapter introduces the General Packet Radio Service (GPRS) and its usage in embedded module. It covers in detail
the APIs and events related to GPRS, and also include prototypes to help you work with this service. This information is
provided through the following sections of this chapter:
2. Overview of GPRS
GPRS is a packet-based, wireless communication service that extends the GSM mobile data system using multiple slots
of the radio channel for faster transmission speeds. It does not set up a continuous channel from a portable terminal for
the transmission and reception of data, but transmits and receives data in packets, thereby making efficient use of the
available radio spectrum. This makes it easier and more practical to send and receive data between mobile devices.
The main benefits of GPRS are that it reserves radio resources only for situations when there is data that must be sent,
and that it reduces reliance on traditional circuit-switched network elements. The mobile stations in a cell share the
same radio resources. Only when a station has data to send, does it gain control of the resources. In this way there is
better utilization of the radio resources. In addition to this, GPRS allows improved quality of data services in terms of
reliability, response time, and features supported. Hence, GPRS is of utmost importance in migration of the existing
GSM network to a 3G network.
Open AT OS provides the GPRS API set to use the GPRS functionality and to handle GPRS-related events, errors and
indications.
You should subscribe to the GPRS service, set up and activate the GPRS connection in order to use the GPRS network.
Then use Flow Control APIs to communicate over the GPRS channel. See section on FCM for more details.
Once a GPRS connection is established, the PDP (Packet data Protocol) is used to indicate the type of packet (IP or PPP)
that you want to send over the established connection.
271
Open AT® TUTORIAL
3. GPRS-related Events
GPRS-related events can be issued both by the network and by the mobile equipment. These events indicate the mobile
or network status.
You assign a Cid (Context ID) number which is used to identify a GPRS data circuit. The attributes of the context indicate
the route for the Data Access Point Name, type of data application (usually IP), quality of service and whether or not the
data link is activated.
The following table lists the GPRS-related events/Cid pairs, their corresponding numeric values and descriptions:
272
Open AT® TUTORIAL
4. GPRS-related APIs
Following is the list of APIs that provide GPRS-related functionality:
adl_gprsSubscribe
adl_gprsUnsubscribe
adl_gprsSetup
adl_gprsSetupExt
adl_gprsAct
adl_gprsActExt
adl_gprsDeact
adl_gprsDeactExt
adl_gprsGetCidInformation
273
Open AT® TUTORIAL
adl_gprsIsAnIPAddress
Use the following API to subscribe to the GPRS network. It specifies a callback function which is invoked
whenever GPRS-related events are received.
Prototype:
Parameters:
GprsHandler: Callback function which is called whenever a GPRS-related event is received by the Open AT
Application:
Parameters:
The input argument of this callback function is the GPRS event and GPRS Cid. GPRS Events and Cid are
explained in the preceding section – GPRS-Related Events.
Returned Values:
Value Description
ADL_GPRS_FORWARD The GPRS event indications will be sent to the external
application.
ADL_GPRS_NO_FORWARD The GPRS event indications will not be sent to the external
application.
ADL_GPRS_NO_FORWARD_ATH The GPRS event indications will not be sent to the external
application. The Open AT Application will terminate the
incoming activation request by sending an ‘ATH’
command.
ADL_GPRS_NO_FORWARD_ATA The GPRS event indications will not be sent to the external
application. The Open AT Application will terminate the
incoming activation request by sending an ‘ATA’
command.
Returned Values:
274
Open AT® TUTORIAL
Use the following API to unsubscribe from the GPRS service. After executing this function, the callback
function (Gprshandler) will not be called anymore when any GPRS events are received.
Prototype:
Parameters:
Gprshandler: Handler function used with the adl_gprsSubscribe API.
Returned Values:
This API returns the following values:
OK: This value is returned on successful execution of the API.
ADL_RET_ERR_PARAM: This value is returned if the given parameter is incorrect.
ADL_RET_ERR_UNKNOWN_HDL: This value is returned if the provided handler is unknown.
ADL_RET_ERR_NOT_SUBSCRIBED: This value is returned if the service is not subscribed.
ADL_RET_ERR_BAD_STATE: The service is currently processing another GPRS API. The Open AT Application
should wait for the corresponding event (indication of the end of processing) in the GPRS handler.
ADL_RET_ERR_SERVICE_LOCKED: if the function is called from a low level interrupt handler.
You can only unsubscribe from a subscribed GPRS service. If you try to unsubscribe from GPRS (using
adl_gprsUnsubscribe) without having subscribed to it, the ADL_RET_ERR_NOT_SUBSCRIBED error will be
returned.
The following API should be used to get information about a specific activated PDP context (identified by its
Cid):
Prototype:
You can also use this API to get information about the DNS (domain name system) and gateway IP address.
Parameters:
Cid: The Cid of the PDP context about which we want information.
Infos: This parameter is a structure containing the information of the activated PDP context. The structured
is as follows:
275
Open AT® TUTORIAL
typedef struct
{
u32 LocalIP;
u32 DNS1;
u32 DNS2;
u32 Gateway;
}adl_gprsInfosCid_t;
Parameters:
LocalIP: Local IP address of the mobile station (only if is activated, or else it is 0).
DNS1: First DNS IP address (only if it is activated, or else it is 0).
DNS2: Second DNS IP address (only if it is activated, or else it is 0).
Gateway: Gateway IP address (only if it is activated, or else it is 0).
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned in case of a invalid parameter. Note that the Cid value must be in the
range of 1 to 4.
ADL_RET_ERR_BAD_STATE is returned when the service is still processing another GPRS API. The Open AT
Application should wait for the corresponding event (indication of the end of processing) in the GPRS
handler.
ADL_RET_ERR_PIN_KO is returned if PIN is not entered, or “+WIND:4” indication has not yet occurred.
ADL_NO_GPRS_SERVICE is returned if GPRS service is not supported by the product.
NOTE : If your Open AT Application opens the GPRS FCM flow in addition to subscribing to GPRS services, then
the adl_gprsAct () API must be called before opening the flow. Similarly adl_gprsDeact () API must be called
after receiving the ADL_FCM_EVENT_FLOW_CLOSED event.
Give due attention to the return value of the gprshandler() function (specified in adl_gprsSubscribe () API).
Your external application will receive GPRS-related events based on the return values of gprshandler()
function..
Prototype:
276
Open AT® TUTORIAL
ADL also provides adl_gprsSetup () API which can be used to set up a GPRS service. This function executes
adl_gprsSetupExt on Open AT virtual port. Note that it is not possible to forward the events generated by
this API to external application.
Parameters:
Cid: Context identifier of the PDP context. This parameter can take values from 1 to 4.
param: This parameter contains the information related to context id. This includes the APN, user name,
password and IP address. This parameter is defined by a structure adl_gprsSetupParams_t which is defined
below:
typedef struct
{
ascii * APN;
ascii * Login;
ascii * Password
ascii * FixedIP;
bool HeaderCompression;
bool DataCompression;
}adl_gprsSetupParams_t;
Port: The port from which the setup should be made. The values this parameter can take are defined in the
adl_port_e enum.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if incorrect parameter is entered.
ADL_RET_ERR_PIN_KO is returned if PIN is not entered.
ADL_RET_ERR_BAD_STATE is returned if GPRS service is processing another GPRS related API.
ADL_GPRS_CID_NOT_DEFINED is returned if context id is already activated.
ADL_GPRS_NO_SERVICE is returned if GPRS not supported.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
1. As adl_gprsSetup() API does not have any parameter to mention the port. This API defines the context id for
Open AT OS virtual port.
2. Multiple context ids (up to 4) can be defined but only one can be activated at a time.
This API is used to activate a previously defined context id from a specific port. After activation, network
allocates an IP address to the embedded module.
277
Open AT® TUTORIAL
Prototype:
Parameters:
Cid: Context identifier of the PDP context. This parameter can take values from 1 to 4.
Port: The port from which the context id should be activated. The values this parameter can take are defined
in the adl_port_e.
Returned Values:
OK on success
ADL_RET_ERR_PARAM, if incorrect parameter is entered.
ADL_RET_ERR_PIN_KO, if PIN is not entered
ADL_RET_ERR_BAD_STATE, if GPRS service is not available.
ADL_GPRS_CID_NOT_DEFINED, if CID is already activated
ADL_GPRS_NO_SERVICE, if GPRS not supported.
ADL_RET_ERR_SERVICE_LOCKED: if the function is called from a low level interruption handler.
NOTE :
As adl_gprsAct () API does not have any parameter to mention the port. This API does the activation from
Open AT OS virtual port.
Prototype:
Parameters:
Cid: Context identifier of the PDP context. This parameter can take values from 1 to 4.
Port: The port from which the context id should be deactivated. The values this parameter can take are
defined in the adl_port_e enum.
Returned Values:
OK is returned on success.
278
Open AT® TUTORIAL
NOTE :
As adl_gprsDeactExt() API does not have any parameter to mention the port, this API deactivates the context id
from Open AT OS virtual port.
Prototype:
Parameters:
AddressStr: The string to check whether it is a valid IP address.
Returned Values:
5. Sample Code
/* sample code implementing the GPRS functionality */
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
/* Global variables */
adl_gprsSetupParams_t GPRS_Params;
u8 Cid;
ascii APN[] = "airtelgprs.com";
ascii UserID[] = "airtel";
ascii PWD[] = "tango";
279
Open AT® TUTORIAL
{
case ADL_GPRS_EVENT_ME_CONTEXT_DEACT:
TRACE (( 1, "ADL_GPRS_EVENT_ME_CONTEXT_DEACT" ));
break;
case ADL_GPRS_EVENT_NW_DETACH:
TRACE (( 1, "ADL_GPRS_EVENT_NW_DETACH" ));
break;
case ADL_GPRS_EVENT_ME_DETACH:
TRACE (( 1, "ADL_GPRS_EVENT_ME_DETACH" ));
break;
case ADL_GPRS_EVENT_NO_CARRIER:
TRACE (( 1, "ADL_GPRS_EVENT_NO_CARRIER" ));
break;
case ADL_GPRS_EVENT_DEACTIVATE_OK:
TRACE (( 1, "ADL_GPRS_EVENT_DEACTIVATE_OK" ));
break;
case ADL_GPRS_EVENT_ACTIVATE_OK:
TRACE (( 1, "GPRS Event activated"));
break;
case ADL_GPRS_EVENT_DEACTIVATE_KO:
TRACE (( 1, "ADL_GPRS_EVENT_DEACTIVATE_KO" ));
break;
case ADL_GPRS_EVENT_ACTIVATE_KO:
TRACE (( 1, "ADL_GPRS_EVENT_ACTIVATE_KO" ));
break;
case ADL_GPRS_EVENT_SETUP_OK:
TRACE (( 1, "ADL_GPRS_EVENT_SETUP_OK" ));
/* Activate context */
ret = adl_gprsAct ( Cid );
TRACE((1,"Return value of adl_gprsAct = %d", ret));
break;
case ADL_GPRS_EVENT_SETUP_KO:
TRACE (( 1, "ADL_GPRS_EVENT_SETUP_KO" ));
break;
case ADL_GPRS_EVENT_ME_ATTACH:
TRACE (( 1, "ADL_GPRS_EVENT_ME_ATTACH" ));
break;
case ADL_GPRS_EVENT_ME_UNREG:
TRACE (( 1, "ADL_GPRS_EVENT_ME_UNREG" ));
ret = adl_gprsSetup (Cid, GPRS_Params);
TRACE((1,"Return value of adl_gprsSetup = %d", ret));
break;
case ADL_GPRS_EVENT_ME_UNREG_SEARCHING:
TRACE (( 1, "ADL_GPRS_EVENT_ME_UNREG_SEARCHING" ));
ret = adl_gprsSetup (Cid, GPRS_Params);
TRACE((1,"Return value of adl_gprsSetup = %d", ret));
break;
280
Open AT® TUTORIAL
default:
TRACE (( 1, "Embedded: Default section called."));
break;
}
return ADL_GPRS_FORWARD;
}
Summary
The following points have been covered in this chapter
GPRS (General packet radio service) allows information to be sent and received across mobile phone networks.
To subscribe to the GPRS service use the adl_gprsSubscribe () API.
To set up the PDP context parameters for GPRS network connection, use the adl_gprsSetup () API. The
parameters required to connect to the GPRS network are APN (access point name), log in ID of the GPRS
account and the password of the GPRS account.
To activate the PDP context, use adl_gprsAct () API. This API should be used before the FCM flow is opened.
To deactivate the PDP context, use the adl_gprsDeact () API. This API should be used only when the FCM flow is
closed - that is, after receiving the ADL_FCM_EVENT_FLOW_CLOSED event to avoid a embedded module lock.
To unsubscribe from the GPRS service, use the adl_gprsUnsubscribe () API.
281
Open AT® TUTORIAL
282
Open AT® TUTORIAL
CHAPTER 25
Application Safe Mode Service
1. Objective
This chapter introduces the application safe mode service and its related APIs. The various events related to the
application safe mode are explained here. The aim of this chapter is to help you understand ways to handle the +WDWL
and +WOPEN command issued by external application to embedded module. The following points are covered in this
chapter:
APIs related to the application safe mode service are declared in the adl_safe.h header file.
Open AT Application stops running. In such situations, use the application safe mode service to capture the command
and prevent it from being processed on the Firmware.
Another example could be a case when an external application issues the +WDWL command to overwrite the currently
running Open AT Application. Use the application safe mode service to manage these types of situations.
283
Open AT® TUTORIAL
Following is a list of application safe mode events and their corresponding numeric values:
Safe Mode Events Description
ADL_SAFE_CMD_WDWL This event is received when the AT+WDWL command is
issued by an external application.
ADL_SAFE_CMD_WDWL_READ This event is received when the AT+WDWL? command is
issued by an external application.
ADL_SAFE_CMD_WDWL_OTHER This event is received when the custom +WDWL command
syntax is issued by the external application.
ADL_SAFE_CMD_WOPEN_STOP This event is received when the AT+WOPEN=0 command is
issued by the external application.
ADL_SAFE_CMD_WOPEN_START This event is received when the AT+WOPEN=1 command is
issued by the external application
ADL_SAFE_CMD_WOPEN_GET_VERSION This event is received when the AT+WOPEN=2 command is
issued by the external application
ADL_SAFE_CMD_WOPEN_ERASE_OBJ This event is received when the AT+WOPEN=3 command is
issued by the external application
ADL_SAFE_CMD_WOPEN_ERASE_APP This event is received when the AT+WOPEN=4 command is
issued by the external application
ADL_SAFE_CMD_WOPEN_SUSPEND_APP This event is received when AT+WOPEN=5 command is
issued by external application.
ADL_SAFE_CMD_WOPEN_READ This event is received when the AT+WOPEN? command is
issued by the external application.
ADL_SAFE_CMD_WOPEN_TEST This event is received when the AT+WOPEN=? command is
issued by the external application.
ADL_SAFE_CMD_WOPEN_OTHER This event is received when the custom +WOPEN command
syntax is issued by the external application.
ADL_SAFE_CMD_WOPEN_AD_GET_SIZE This event is received when the AT+WOPEN=6 command is
issued by the external application for retreiving the
A&D memory size.
ADL_SAFE_CMD_WOPEN_AD_SET_SIZE This event is received when the AT+WOPEN=6,<size>
command is issued by the external application for setting
the
A&D memory size.
284
Open AT® TUTORIAL
adl_safe.h is the header file which is required to use the Application Safe Mode service.
Prototype:
Parameters:
WDWLopt: Firmware provides the AT+WDWL? command (Read mode) to read the status of the software
version. WDWLopt is the additional option for the WDWL command. For example, if you pass a value of
ADL_CMD_TYPE_PARA|0x11 , then the AT+WDWL command can be executed with exactly one argument.
Refer to the Subscribing to AT commands section for more details.
WOPENopt: Firmware provides the AT+WOPEN? (Read mode) command, the AT+WOPEN=? (Test mode) and
the AT+WOPEN=<param> (Param Mode) command to erase, run or stop the Open AT Application.
WOPENopt is the additional option for the WOPEN command. For example, if you pass the value of 0x22 ,
then the AT+WDWL command can be executed with up to two arguments. Refer to the Subscribing to AT
commands section for more details.
SafeHandler: The callback function which is called whenever an event related to the application safe mode is
received by the Open AT Application. The Handler is defined as the following function pointer:
Parameters:
CmdType: The CmdType argument of this callback function is an event related to the
application safe mode. These events are explained in the section on Safe Mode Events.
Paras: The paras argument of this callback function is the structure which holds the
command and its parameter to which you have subscribed. Refer to the Subscribing to AT
commands section for more detail.
285
Open AT® TUTORIAL
Return Value:
FALSE: If the return value of this handler is FALSE then the command is not forwarded to
Firmware. In this case command is processed by Open AT Application. If the return value
of this
TRUE: If the return value of this handler is TRUE then the command is forwarded to lower
layer forprocessing, which sends the response to the external application.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if the parameter is given an incorrect value.
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if the service is already subscribed.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
SafeHandler: This parameter is the callback function which is called whenever an event related to the
application safe mode is received by the Open AT Application. For parameter information, refer to the
section on the
s8 adl_safeSubscribe API
Returned Values:
Prototype:
286
Open AT® TUTORIAL
Parameters:
CmdType: The CmdType argument of this function can have any event related to the application safe mode
service other than ADL_SAFE_CMD_WDWL_OTHER and ADL_SAFE_CMD_WOPEN_OTHER.
The ADL_SAFE_CMD_WOPEN_SUSPEND_APP may be used to suspend the Open AT Application task. The
execution may be resumed using the AT+WOPENRES command, or by sending a signal on the hardware
Interrupt pin.
rsphdl: The rsphdl argument is the callback function which is called whenever a response is received by Open
AT Application for the +WDWL and +WOPEN commands. If its value is set to NULL then all the responses are
forwarded to the external application. Refer to argument RspHdl of API adl_atCmdCreate for more details on
this argument.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if the parameter is given an incorrect value.
LOCKED is returned if the function is called from a low level interrupt handler.
NOTE :
The application safe mode service can be subscribed only once in the Open AT Application.
+WDWL command is at least subscribed in ACTION and READ mode for the API adl_safeSubscribe.
+WOPEN command is at least subscribed in TEST, READ and PARAM mode for the API adl_safeSubscribe.
You can only unsubscribe from a subscribed handler of the application safe mode service, or else an error is
returned.
ADL_SAFE_CMD_WDWL_OTHER and ADL_SAFE_CMD_WOPEN_OTHER values are not allowed for the argument
CmdType of the adl_safeRunCommand function.
By default all the responses are subscribed for the rsphdl argument of adl_safeRunCommand function
5. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
287
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter
Open AT OS provides the application safe mode service to handle events related to this mode.
Events related to the application safe mode are issued by the external application to the embedded module.
To subscribe an application safe mode service, use the adl_safeSubscribe function.
To unsubscribe from an application safe mode service, use the adl_safeUnSubscribe function.
To run the standard WDWL and WOPEN command use the adl_safeRunCommand function
288
Open AT® TUTORIAL
CHAPTER 26
Open SIM Access (OSA) Service
1. Objective
The embedded module provides interface to connect multiple SIM cards. The embedded Module has a defined default
interface for a SIM card. Along with this, user can connect SIM cards through different hardware interfaces such as
UART, I2C, SPI, USB etc.
When additional SIM card is connected, the OSA service can be used to select the additional SIM card.
The SIM driver in Firmware programs SIM card using set of packets/commands. These packets/commands are referred
as APDU and are defined in 3GPP TS 11.11.
External SIM
Open AT Application
APDU request
UART/BUSExternal SIM
response exchange
Open AT Firmware
External SIM
Local SIM
The ADL Open SIM Access (OSA) service allows the application to handle APDU requests & responses with an external
SIM card, connected through one of the embedded module interfaces (UART, SPI, and I2C).
Open SIM Access feature has to be enabled on the embedded module in order to make this service available. The Open
SIM Access feature state can be read using AT+WCFM=5 command: this feature state is represented by the bit 5
(00000020 in hexadecimal format) of the command response.
289
Open AT® TUTORIAL
Prototype:
Parameter:
Prototype:
void (*adl_osaHandler_f) ( adl_osaEvent_e Event, adl_osaEventParam_u* Param)
Parameter:
Event: Following are the events for OSA service:
OSA Service Events Description
ADL_OSA_EVENT_INIT_SUCCESS OSA service has been successfully subscribed.
ADL_OSA_EVENT_INIT_FAILURE OSA service subscription failure.
ADL_OSA_EVENT_ATR_REQUEST This event is notified after the successful
subscription of OSA service. On receiving the
ATR request the embedded module must reset
the remote SIM.
ADL_OSA_EVENT_APDU_REQUEST This event is received by the application each
time embedded module has to send a APDU
request to the remote SIM. It has to be
forwarded to the remote SIM by the
application.
ADL_OSA_EVENT_SIM_ERROR This event is notified to the application in case
an error has occurred in embedded module due
to response. OSA is automatically unsubscribed
on receiving error.
290
Open AT® TUTORIAL
Param: Parameter corresponding to different event received. The structure defines the various parameter
that are received
typedef union
{
adl_osaStatus_e ErrorEvent;
struct {
{
u16 Length;
u8 * Data;
} RequestEvent;
} adl_osaEventParam_u;
Data: Data corresponding to the event. The data is received in case of event
ADL_OSA_EVENT_APDU_REQUEST.
Returned Value:
Prototype:
291
Open AT® TUTORIAL
Parameter:
OsaHandle: The handle returned at the time of subscription of the OSA service.
Status: Status to be supplies to the embedded module in response to ATR and APDU request. Following
status values are defined.
ADL_OSA_STATUS_OK: Response data buffer has been received from SIM card.
ADL_OSA_STATUS_CARD_NOT_ACCESSIBLE: No response from SIM card.
ADL_OSA_STATUS_CARD_REMOVED: SIM card has been removed.
ADL_OSA_STATUS_CARD_UNKNOWN_ERROR: Generic error code for all other errors.
Length: ATR and APDU request response buffer length.
Data: ATR and APDU buffer address.
Returned Value:
OK is returned on success.
A negative value is returned on failure.
ADL_RET_ERR_PARAM: if there is an error in the parameter
ADL_RET_ERR_UNKNOWN_HDL: if the unknown OSA handle is specified
ADL_RET_ERR_BAD_STATE: if the OSA service is not waiting for an APDU or ATR request response
Prototype:
Parameter:
OsaHandle: The handle returned at the time of subscription of the OSA service.
Returned Value:
OK is returned on success. An ADL_OSA_EVENT_CLOSED confirmation event will be received in the service
handler.
A negative value is returned on failure.
ADL_RET_ERR_UNKNOWN_HDL: if the unknown OSA handle is specified
ADL_RET_ERR_SERVICE_LOCKED: if the function is called from a low level interrupt handler
ADL_RET_ERR_NOT_SUBSCRIBED: if OSA service is not subscribed using adl_osaSubscribe () API.
ADL_RET_ERR_BAD_STATE: if Firmware is waiting for an ATR or APDU request from the simcard, and
unsubscription is forbidden until the simcard's request is granted.
4. Sample Code
// Example showing OSA service API usage.
#include "adl_global.h"
#include "adl_osa.h"
292
Open AT® TUTORIAL
293
Open AT® TUTORIAL
294
Open AT® TUTORIAL
CHAPTER 27
List Management
1. Objective
Open AT implements its own linked list data structures using Open AT OS list management APIs. The list management
functionality is extensively used in Open AT Application which needs to store data dynamically at runtime. The data
type (integers/strings) of the stored data can vary depending on the type of Open AT Application and its requirements.
This chapter describes the list management API and its usage in embedded module.
Item destruction callback function (FreeItem) is used to delete items from the list.
The data structure is defined as follows:
typedef struct
{
s16 ( * CompareItem ) ( void *, void * );
295
Open AT® TUTORIAL
Prototype:
Parameters:
Attr: This parameter is used to define the attributes of the created list. A logical OR operation can be
performed on the following values to set the value of this parameter:
funcTable: Pointer to a structure containing the comparison and item destruction callback functions (defined
in List Management Structure section).
Returned Values:
Prototype:
Parameters:
list: The list that must be destroyed.
296
Open AT® TUTORIAL
Returned Values:
None.
Prototype:
Parameters:
list: The list to be cleared.
Returned Values:
None.
Prototype:
Parameters:
list: The list from which to get the item count.
Returned Values:
297
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
Position of the added item is returned on success.
ERROR is returned if an error occurred while adding the item to the list.
NOTE :
The item pointer should not point to a const because it will be released in an item destruction
operation.
If the list has the WM_LIST_SORTED attribute, the item will be inserted at the appropriate place
after calling the CompareItem callback (if defined). Otherwise, the item is appended at the end
of the list.
If the list has the WM_LIST_ NODUPLICATES attribute, the item will not be inserted if the
CompareItem callback function(if defined) returns 0 on any item that was added previously. In
this case, the returned index (position) belongs to the existing item.
Prototype:
Parameters:
list: The list into which you want to insert an item.
item: The item that you want to insert into the specified list.
index: The location on the list at which you want to insert the item.
Returned Values:
298
Open AT® TUTORIAL
NOTE :
The item pointer should not point to a const as it will be released in an item destruction operation.
This API will always insert the provided item at the given index irrespective of the list attribute.
Use the following API to read an item from a given index of the specified list:
Prototype:
Parameters:
list: The list from which the item must be read.
index: The location from which the item must be read.
Returned Values:
Pointer to the requested item is returned on success.
NULL is returned if the index is invalid.
Prototype:
Parameters:
Returned Values:
299
Open AT® TUTORIAL
Prototype:
s16 wm_lstFindItem ( wm_lst_t list, void * item )
This API calls the CompareItem callback function on each list item until it returns 0 - indicating that the item
has been found.
Parameters:
list: The list you want to search.
item: The item that you want to locate on the specified list.
Returned Values:
Prototype:
Parameters:
list: The list that you want to search.
item: The item that you want to find on the list.
Returned Values:
The s16 buffer holding the indices of all the items that are found. 0 is the first position and ERROR is the last
element of this buffer.
NOTE :
The s16 buffer returned by this API must be released by the Open AT Application after it is processed.
This API should be used only if the list must not be changed while processing the returned buffer. Otherwise, the
API wm_lstFindNextItem should be used
Use the following API to find the next item index that corresponds to the provided item in the specified list:
Prototype:
300
Open AT® TUTORIAL
This API calls the CompareItem callback function on each list item to get the items that match the provided
item. This API should be called until it returns an ERROR in order to get the index of all the items
corresponding to the selected item.
Parameters:
Returned Values:
Index of the found item is returned on success.
ERROR is returned In all other cases.
NOTE :
The difference between the wm_lstFindNextItem and the wm_lstFindAllItem APIs is that even if the list is
updated between two calls to the wm_lstFindNextItem, the function will not return an item that it located on the
previous search operation.
To restart a search with the wm_lstFindNextItem, call the wm_lstResetItem first.
Prototype:
Parameters:
Returned Values:
None.
301
Open AT® TUTORIAL
6. Sample Code
/* sample code implementing the list management APIs */
#include "adl_global.h"
#if __OAT_API_VERSION__ >= 400
const u16 wm_apmCustomStackSize = 4096;
#else
u32 wm_apmCustomStack[1024];
const u16 wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif
wm_lst_t ListPtr;
u16 Count;
static wm_lstTable_t ListTable =
{
( void * ) NULL,
( void * ) NULL
};
char Item1[] = "Sierra Wireless";
char Item2[] = "Open-AT";
char Item3[] = "Training";
char Item4[] = "ADL";
void adl_main ( adl_InitType_e InitType )
{
s16 Position;
char *buffer;
u16 index;
TRACE (( 1, "Embedded Application: Main" ));
ListPtr = wm_lstCreate(WM_LIST_SORTED, &ListTable);
wm_lstClear (ListPtr);
Count = wm_lstGetCount(ListPtr);
TRACE (( 1, "Number of elements in the list = %d", Count ));
Position = wm_lstAddItem(ListPtr, Item1);
Position = wm_lstAddItem(ListPtr, Item2);
Position = wm_lstAddItem(ListPtr, Item3);
Count = wm_lstGetCount(ListPtr);
TRACE ((1, "Number of elements in the updated list = %d",Count));
Position = wm_lstInsertItem(ListPtr, Item4, 1);
Count++;
TRACE (( 1, "Item inserted at position %d", Position ));
for(index=0; index<Count; index++)
{
buffer = (char *)wm_lstGetItem(ListPtr, index);
TRACE (( 1, buffer ));
}
Count = wm_lstDeleteItem(ListPtr, --Count);
Position = wm_lstFindItem(ListPtr, "Open-AT");
302
Open AT® TUTORIAL
NOTE :
The wm_lstInsertItem API gives the developer the independence to insert a data item at any position in the list, whereas
the wm_lstAddItem API appends the data item by itself to the list according to the list attribute defined in the
wm_lstCreate API.
The wm_lstDestroy API clears all the data stored in the list as well as deletes the list. The list pointer cannot be used again
after the list is deleted. On the contrary, the wm_lstClear API only clears the contents of list. It does not destroy the list
and hence, the list pointer can be used again to add new data to the list.
Summary
The following points have been covered in this chapter
Data stored in a list is different from the data stored using flash object IDs. The data stored in the list is lost once
an Open AT Application is stopped.
Open AT ADL library directly uses the list management APIs defined for Open AT OS basic APIs. These APIs are
declared in the basic API header file wm_list.h.
wm_lstCreate API should be used to create a list.
wm_lstDestroy API should be used to clear and destroy a list.
wm_lstClear API should be used to clear a list.
wm_lstGetCount API should be used to get the current item count of the specified list.
wm_lstAddItem API should be used to add an item to a list.
wm_lstInsertItem API should be used to insert an item to the specified list at the given location.
wm_lstGetItem API should be used to read an item from a list.
wm_lstDeleteItem API should be used to delete an item from a given index of the given list.
wm_lstFindItem API should be used to find an item from a list.
wm_lstFindAllItem API should be used to find all items similar to a given item from a list.
wm_lstFindNextItem API should be used to find the next item in the given list.
wm_lstResetItem API should be used to reset all the previously found items by the wm_lstFindNextItem API
303
Open AT® TUTORIAL
304
Open AT® TUTORIAL
CHAPTER 28
AT FCM/IO Port Service
1. Objective
This chapter introduces the AT FCM/IO port service and its usage in embedded module. It covers in detail, the APIs and
events related to AT FCM/IO service. It also includes prototypes to help you work with this service. This information is
provided through the following sections of this chapter:
Introduction to this service
AT FCM/IO service related events
AT FCM/IO service related macros
AT FCM/IO service related APIs
2. Introduction
AT commands and data can be sent through physical or logical ports.
Physical ports includes
o UART1
o UART2
o USB
Logical ports includes
o CMUX logical ports
o Bluetooth logical ports
o GSM/GPRS data ports
To monitor the states of these physical or logical ports, AT FCM/IO port service is used. Using AT FCM/IO service
following information can be captured for the physical and logical ports:
State of port – Opened/Closed
State of hardware signals DSR and CTS
NOTE :
There is no access to CTS/DSR, when port is opened and flow control is deactivated.
305
Open AT® TUTORIAL
306
Open AT® TUTORIAL
Prototype:
Parameters:
Port: This parameter determines the logical port for which the physical port should be searched. The values
this parameter can take are defined in the adl_port_e enum.
Returned values:
Prototype:
Parameters:
Event: This parameter determines the event which should be queried. The values this parameter can take
are defined in the adl_portEvent_e enum.
Returned values:
307
Open AT® TUTORIAL
Prototype:
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
Returned values:
Prototype:
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
Returned values:
TRUE is returned if the specified port is physical or Bluetooth port.
FALSE is returned if the specified port is not a physical or Bluetooth port.
This macro is used to check whether a particular port can be used by Flow control manager or not.
Prototype:
308
Open AT® TUTORIAL
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
Returned values:
TRUE is returned if the specified port can be used by FCM service.
FALSE is returned f the specified port cannot be used by FCM service.
Prototype:
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum
Returned values:
TRUE is returned if the specified port can be used by AT commands APIs.
FALSE is returned if the specified port cannot be used by AT commands APIs.
This API is used to subscribe to port service. The subscription allows Open AT Application to monitor the
events related to AT FCM/IO service.
Prototype:
Parameters:
PortHandler: This is the call back handler, which receives the events related to AT FCM/IO service. This
handler should be defined as shown below:
309
Open AT® TUTORIAL
NOTE :
Only 127 subscriptions are allowed in the AT FCM/IO service.
Prototype:
s8 adl_portUnsubscribe ( u8 Handle )
Parameters:
Handle: Handle returned by adl_portSubscribe() API
Returned values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if unknown handle is passed.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if the service is not subscribed.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
310
Open AT® TUTORIAL
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
Returned values:
Prototype:
Parameters:
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
Signal: The signal which should be queried for the state. The values this parameter can take are defined in
the adl_portSignal_e enum.
Returned values:
Prototype:
Parameters:
Handle: Handle retuned by adl_portSubscribe() API.
Port: This parameter determines the port which should be queried. The values this parameter can take are
defined in the adl_port_e enum.
311
Open AT® TUTORIAL
Signal: The signal which should be polled for the state. The values this parameter can take are defined in the
adl_portSignal_e enum. This enum is defined in the section 22.4.1.
PollingTimerType: This parameter determined the type of the time that should be used for polling. The type
could be one of the following:
ADL_TMR_TYPE_100MS – 100 ms timer
ADL_TMR_TYPE_TICK – 18.5 ms time
PollingTimerValue: The polling timer value in terms of PollingTimerType
Returned values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there is an error in the parameter.
ADL_RET_ERR_BAD_STATE is returned if the port is not opened.
ADL_RET_ERR_UNKNOWN_HDL is returned if unknown handle is passed.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if the service is not subscribed.
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if a polling process has already started.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
Returned values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there is an error in the parameter.
ADL_RET_ERR_BAD_STATE is returned if the port is not opened.
ADL_RET_ERR_UNKNOWN_HDL is returned if unknown handle is passed.
ADL_RET_ERR_BAD_HDL is returned if no polling process is running.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if the service is not subscribed.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
7. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 4096;
312
Open AT® TUTORIAL
TRACE (( 1, "PortHandler: Event %d, Port %d, State %d", Event, Port, State ));
Summary
313
Open AT® TUTORIAL
314
Open AT® TUTORIAL
CHAPTER 29
RTC Service
1. Objective
This chapter introduces the RTC service and its usage in embedded module. It covers in detail the APIs and events
related to RTC, and also include prototypes to help you work with this service. This information is provided through the
following sections of this chapter:
2. Introduction
The RTC service allows Open AT Application to access the internal clock provided by embedded module. This service
also allows converting the time to following formats:
Macro/Constant Description
ADL_RTC_DAY_SECONDS Seconds count in a day
ADL_RTC_HOUR_SECONDS Seconds count in a hour
ADL_RTC_MINUTE_SECONDS Seconds count in a minute
ADL_RTC_MS_US µseconds count in a millisecond
ADL_RTC_SECOND_FRACPART_STEP Second fractional part step value (in µs)
ADL_RTC_GET_TIMESTAMP_DAYS From a TimeStamp date extract the days number
ADL_RTC_GET_TIMESTAMP_HOURS From a TimeStamp date extract the hours number
ADL_RTC_GET_TIMESTAMP_MINUTES From a TimeStamp date extract the minutes number
ADL_RTC_GET_TIMESTAMP_SECONDS From a TimeStamp date extract the seconds number
315
Open AT® TUTORIAL
Macro/Constant Description
ADL_RTC_GET_TIMESTAMP_MS From a TimeStamp date extract the milliseconds number
ADL_RTC_GET_TIMESTAMP_US From a TimeStamp date extract the µseconds number
Prototype:
Parameters:
None
Returned values:
Prototype:
Parameters:
TimeStructure: The structure which will be filled by ADL with RTC data. This structure is defined below:
typedef struct
{
u32 Pad0 // Not used
u32 Pad1 // Not used
u16 Year; // Year (Four digits)
u8 Month; // Month (1-12)
316
Open AT® TUTORIAL
Returned values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there is an error in the parameter.
Prototype:
Parameters:
TimeStructure: The structure which has the RTC data to set. This structure is defined below:
typedef struct
{
u32 Pad0 // Not used
u32 Pad1 // Not used
u16 Year; // Year (Four digits)
u8 Month; // Month (1-12)
u8 Day; // Day of the Month (1-31)
u8 WeekDay; // Day of the Week (1-7)
u8 Hour; // Hour (0-23)
u8 Minute; // Minute (0-59)
u8 Second; // Second (0-59)
u32 SecondFracPart; // Second fractional part
u32 Pad2; // Not used
} adl_rtcTime_t;
317
Open AT® TUTORIAL
Returned values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there is an error in the parameter.
This API is used to convert the time to the UNIX or YY/MM/DD/HH/MM/SS format.
Prototype:
Parameters:
TimeStructure: Time in YY/MM/DD/HH/MM/SS format. This structure which will be converted or filled with
converted RTC data depending upon the Conversion parameter. This structure is defined below:
typedef struct
{
u32 Pad0 // Not used
u32 Pad1 // Not used
u16 Year; // Year (Four digits)
u8 Month; // Month (1-12)
u8 Day; // Day of the Month (1-31)
u8 WeekDay; // Day of the Week (1-7)
u8 Hour; // Hour (0-23)
u8 Minute; // Minute (0-59)
u8 Second; // Second (0-59)
u32 SecondFracPart; // Second fractional part
u32 Pad2; // Not used
} adl_rtcTime_t;
TimeStamp: Time in UNIX format. This structure which will be converted or filled with converted RTC data
depending upon the Conversion parameter. This structure is defined below:
typedef struct
{
u32 TimeStamp; // Seconds elapsed since 1st January 1970
u32 SecondFracPart; // Second fractional part (0-32767)
} adl_rtcTimeStamp_t;
318
Open AT® TUTORIAL
Conversion: This parameter determines whether time will be converted to UNIX or YY/MM/DD/HH/MM/SS
format. The value this parameter can take are defined below in the adl_rtcConvert_e enum:
// Conversion modes
typedef enum
{
ADL_RTC_CONVERT_TO_TIMESTAMP, // RTC Time Structure to
// TimeStamp conversion
ADL_RTC_CONVERT_FROM_TIMESTAMP, // TimeStamp to RTC Time
// Structure conversion
} adl_rtcConvert_e;
Returned values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there is an error in the parameter.
ERROR is returned in case of an internal error
Prototype:
Parameters:
TimeStamp1: This is the first UNIX based Timestamp used for comparision. The value this parameter can take
are defined in the adl_rtcTimeStamp_t structure. Please refer section 28.3.4 for description of this structure.
TimeStamp2: This is the second UNIX based Timestamp used for comparison. The values this parameter can
take are defined in the adl_rtcTimeStamp_t structure. Please refer section Error! Reference source not
found. for description of this structure.
Result: Result of the difference between TimeStamp1 and TimeStamp2. The value this parameter can take
are defined in the adl_rtcTimeStamp_t structure. Please refer section 28.3.4 for description of this structure.
Returned values:
319
Open AT® TUTORIAL
5. Sample Code
#include "adl_global.h"
const u16 wm_apmCustomStackSize = 1024
320
Open AT® TUTORIAL
Summary
The following points have been covered in this section
RTC APIs can be used to access internal RTC time
RTC time is available in two formats
o UNIX format
o YY/MM/DD/HH/MM/SS format
321
Open AT® TUTORIAL
322
Open AT® TUTORIAL
CHAPTER 30
Real Time Operating System
1. Introduction to RTOS
RTOS is an operating system, which provides a system, which guarantees a certain capability within a specified time
constraint. RTOS provides facilities which, if used properly, guarantee deadlines can be met generally (soft real-time) or
deterministically (hard real-time). . This amount of accuracy is achieved through specialized scheduling algorithms. The
main criterion for an RTOS is to schedule tasks in minimal latency.
Determinism: This means system takes same amount of time to a certain work. For e.g. A mobile
phone could be called a real-time system, if it can place a call whenever a call button is pressed and
each time it takes fixed amount of time to place the call let’s say 10 milliseconds.
Timeliness: This means system completes the time meeting the deadlines. For e.g. in the above
example, 10 milliseconds – 1 second could be an acceptable time for the user. However if the
mobile phone takes more than 1 second to place the call, it cannot be called a real-time system.
Predictability: This means the output from the system is predictable. This parameter is again related
to determinism and timeliness. For e.g. you can predict the amount of time mobile phone could
take to place the call.
A Real-time operating system will provide specialized features to cater to the needs of above
mentioned parameters. The features are listed below:
Multitasking: A system has needs for different applications. For e.g. telemetry system has one
application logic to communicate with the server and application logic for data acquisition. RTOS
provides multitasking so that these different applications can run in parallel. These tasks can have
different configurable priorities which is very useful to decide the real-time nature of the system.
Scheduling Algorithms: RTOS provides specialised scheduling algorithms to allow the system to be
deterministic. A RTOS must have facility to configure these scheduling algorithms to help designing
a real-time system. These algorithms could be priority based or time based. RTOS should take fixed
amount of time to execute these algorithms and this time should be known to the user. This allows
systems to be more predictable.
This is the main difference between a general purpose OS and RTOS. In a operating system like
Windows, it is difficult to predict the time. For e.g. A notepad application could take different
323
Open AT® TUTORIAL
amount of time to save a file of the same size. However in a RTOS, the time will be always the same
and hence providing much more predictable system.
Inter-process communication: It is highly likely that tasks will interact with each other in a multi-
tasking system. This interaction could be one of the following:
Interrupts and high-precision timers: RTOS allows developer to control the communication with
various devices through interrupts and also allows controlling the flow of application through high
precision timers.
You can create intelligent internet-enabled applications directly on the embedded module. This shortens development
time and reduce materials cost. However earlier, it was not possible for developer to write time critical application
along with GSM/GPRS capabilities. To overcome the limitation, Sierra Wireless has introduced the feature “RTOS”.
RTOS feature guarantees task execution within a specified time constraint. This feature allows user to:
NOTE :
AT+WCFM command should be used to enable RTOS feature.
324
Open AT® TUTORIAL
Using Open AT OS, you can write your code in following areas:
Low level Interrupt handlers
High level interrupt handlers
Open AT Applications
The Open AT Interrupt handler Level 1 has the highest priority than Firmware tasks. This Interrupt handler can be
attached to one of the following interrupts
External interrupts
Internal timer interrupts
DSP (Audio) interrupts
Following table lists the response time of various handlers and applications.
Handler/Application Response Time Description
Open AT Interrupt handler Less than 600 µs Please make sure that low-level handlers
Level 1 have minimum possible code so that it
does not have adverse effects on other
low priority tasks
Open AT Interrupt Task 1 to 10 ms The reaction time of this hander could go
handler up to 1 ms to 10ms depending upon
coding of the application. These handlers
should be used when a part of code needs
to be executed before Open AT
Applications
Open AT Application Task (s) Approximately 10 ms The reaction time depends on the
processing done by the Firmware tasks
and interrupt handlers. You can write up
to 64 tasks in this area.
325
Open AT® TUTORIAL
3. Scheduling policies
The Open AT OS implements following scheduling policy:
Fully pre-emptive
In fully pre-emptive policy, the higher priority task/interrupt handler will preempt the low priority task execution. The
context of the low priority will be saved during this time and same will be restored when the task resumes again.
4. RTOS APIs
To manage different interrupt handlers and applications, Open AT OS RTOS feature provides following set of APIs:
Task Management
o Multitasking
o Context
Inter-task communication
o Message service
Synchronization
o Semaphore service
Thread safe data management
o Queue service
Interrupts
o IRQ
o External interrupts
o Timer interrupts – TCU service
o Audio interrupts
Vari-speed
NOTE :
Currently service for UART interrupts and ADC interrupts are not available.
326
Open AT® TUTORIAL
E X TE RNAL
TAS K MANAGE M E NT
S Y CHRONI S A TI O N
TI ME R
AUDI O
UART
MANAGE ME NT
ADC
SPI
I NTE RRUP TS (I RQ)
Open AT® OS
These APIs are discussed in detail in chapters from 0 to Error! Reference source not found..
Summary
The following points have been covered in this chapter
RTOS feature guarantees task execution within a specified time constraint.
Using Open AT OS, user can write applications in following areas:
o Task Management
Multitasking
Context
o Inter-task communication
Message service
o Synchronization
Semaphore service
o Thread safe data management
Queue service
o Interrupts
IRQ service
External interrupts
Timer interrupts – TCU service
Audio interrupts
o VariSpeed
5.1. Introduction
Multitasking is a process by which multiple tasks share common processing resources and allows multiple
tasks to run at the same time.
User can define 64 tasks in an Open AT Application and the communication between tasks can be done
using:
Queues
Shared Memory Area
Mailboxes
327
Open AT® TUTORIAL
Task size is defined by the user within the RAM area available for Open AT Application. Typical size is up to
4KBytes per task.
StackSize: This parameter is used to provide required call stack size in bytes for the current task. A call stack
is the Open AT RAM area which contains the local variables and return addresses for function calls. Call stack
sizes are deduced from the total available RAM size for the Open AT Applicaion.
Name: This is a string parameter which identifies the task. This is usually used for debugging purposes.
Priority: This parameter defines the priority of the task. The priority level defined in this table should be from
1 to the task count. This priority determines the order in which the events are notified to the several tasks
when several information are received at the same time. The higher the priority level, higher the priority of
the task.
NOTE :
Last entry in the adl_InitTasks_t table must be set to NULL. Two tasks can’t have the same priority level.
Maximum of 64 tasks can be defined.
328
Open AT® TUTORIAL
6.1. Introduction
In multi-tasking environment, when a piece of code is being executed from several tasks/interrupts, context
APIs can be used to get the information about the current task context. This information could be useful to
re-use a piece of code for all the possible tasks/interrupts for e.g. a library providing a set of APIs could use
context APIs.
Open AT OS provides the context service interface that allows to get the task information at run time. This
information includes:
The current execution context
Number of tasks running
Current task state
The execution contexts are:
The application task context: This is the main application context, initialized on the task entry point
functions and scheduled each time a message is received. This context has a global low priority and
can be interrupted by any other tasks.
The high level interrupt handler context: This is also a task context, but with a higher priority than
the main application task. High level interrupt handlers run in this context. This context has a global
middle priority and can be interrupted by low level interrupt handler context. When an interrupt
raises an event monitored by a high level handler, this context will be immediately activated, even if
the application task was running.
The low level interrupt handler context: This is a context designed to be activated as soon as
possible on an interrupt event. This context has a global high priority and can’t be interrupted by
any other tasks. When an interrupt occurs, this context will be immediately activated, even if an
application task or high level handler or an Firmware task is running. Note that the time spent in this
context should be as short as possible.
The header file adl_ctx.h should be included to use the context service APIs.
Prototype:
Parameters:
None
Returned Values:
Context identifier of type adl_ctxID_e is returned on success. The adl_ctxID_e enum is defined below:
329
Open AT® TUTORIAL
ID of an application task's zero-based index if the function is called from an ADL service event handler.
ADL_CTX_LOW_LEVEL_IRQ_HANDLER is returned if the function is called from a low level interrupt handler.
ADL_CTX_HIGH_LEVEL_IRQ_HANDLER is returned if the function is called from a high level interrupt handler.
Prototype:
Parameters:
None
Returned Values:
Context identifier of type adl_ctxID_e is returned on success. The adl_ctxID_e enum is defined below:
typedef enum _adl_ctxID_e
{
// Low Level Interruption Handler context
ADL_CTX_LOW_LEVEL_IRQ_HANDLER =0xFD,
// High Level Interruption Handler context
ADL_CTX_HIGH_LEVEL_IRQ_HANDLER=0xFE,
// Reserved for internal use
ADL_CTX_ALL = 0xFF,
330
Open AT® TUTORIAL
ID of an application task's zero-based index if the function is called from an ADL service event handler.
ADL_CTX_HIGH_LEVEL_IRQ_HANDLER is returned if the function is called from a high level interrupt handler.
Interrupted task ID is returned if the function is called from a low level interrupt handler. The returned
value depends on the interrupted task:
An application task's zero-based index is returned if an Open AT Application task was running.
ADL_CTX_WAVECOM is returned if a Firmware task was running.
ADL_CTX_HIGH_LEVEL_IRQ_HANDLER is returned if a high level interrupt handler was running.
Prototype:
u8 adl_ctxGetTasksCount ( void )
Parameters:
None
Returned Values:
Prototype:
Parameters:
None
Returned Values:
Bitwise OR combination of the diagnostics listed in the adl_ctxDiagnostic_e type is returned on success. The
adl_ctxDiagnostic_e is defined below:
typedef enum
331
Open AT® TUTORIAL
{
// The Open AT IRQ processing mechanism has not been started (interrupt
// handlers stack sizes have not been supplied).
ADL_CTX_DIAG_NO_IRQ_PROCESSING= 0x01,
// Reserved for future use
ADL_CTX_DIAG_BAD_IRQ_PARAM= 0x02,
// High level interrupt handler is not supported
ADL_CTX_DIAG_NO_HIGH_LEVEL_IRQ_HANDLER= 0x04,
} adl_ctxDiagnostic_e;
This API can be used to get the current state of the context.
Prototype:
Parameters:
Context: Execution context from which the current state has to be queried
Returned Values:
Current execution context state (positive or null) of adl_ctxState type is returned on success.
typedef enum
{
ADL_CTX_STATE_ACTIVE,
ADL_CTX_STATE_WAIT_EVENT,
ADL_CTX_STATE_WAIT_SEMAPHORE,
ADL_CTX_STATE_WAIT_INNER_EVENT,
ADL_CTX_STATE_SLEEPING,
ADL_CTX_STATE_READY,
ADL_CTX_STATE_PREEMPTED,
ADL_CTX_STATE_SUSPENDED
} adl_ctxState_e;
ADL_RET_ERR_PARAM is returned on parameter error.
ADL_RET_ERR_BAD_HDL is returned if the low level interrupt handler execution context state is required.
332
Open AT® TUTORIAL
NOTE :
It is not possible to query the current state of the contexts below
(ADL_RET_ERR_BAD_HDL error will be returned):
1 the low level interrupt handler execution context (in any case)
2. the high level interrupt handler execution context, if the related adl_InitIRQHighLevelStackSize call stack has
not be declared in the application.
Prototype:
Parameters:
Task: Task identifier to be suspended.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned on parameter error.
ADL_RET_ERR_BAD_STATE is returned if the required task is already suspended.
NOTE :
The events which are received when the task is suspended are queued until the task is resumed. If too many
events occur, the application mailbox would be overloaded, and this would lead the embedded module to reset.
Prototype:
Parameters:
Returned Values:
OK is returned on success.
333
Open AT® TUTORIAL
NOTE : The events which are received when the task is suspended are queued until the task is resumed. If too
many events occur, the application mailbox would be overloaded, and this would lead the embedded module to
reset.
Prototype:
Parameters:
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned on parameter error.
ADL_RET_ERR_BAD_STATE is returned if the required task is not currently suspended.
NOTE :
1. The required task is resumed as soon as the function is called.
2. If the resumed task has a lower priority level than the current one, it will be scheduled as soon as the current
task process will be over.
3. If the resumed task has a higher priority level than the current one, it will be scheduled as soon as the function
is called.
Prototype:
Parameters:
TasksCount: Number of tasks to be resumed.
TaskIDArray: Array of tasks identifiers to be resumed.
334
Open AT® TUTORIAL
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned on parameter error.
ADL_RET_ERR_BAD_STATE is returned if the required task is not currently suspended.
NOTE :
1. The required task is resumed as soon as the function is called.
2. If the resumed task has a lower priority level than the current one, it will be scheduled as soon as the current
task process will be over.
3. If the resumed task has a higher priority level than the current one, it will be scheduled as soon as the function
is called.
Prototype:
Parameters:
Duration: Required sleep duration, in ticks (18.5 ms).
Returned Values:
OK is returned on success (when the function returns, the sleep duration has already elapsed).
ADL_RET_ERR_SERVICE_LOCKED is returned f the function was called from a low level interrupt handler (the
function is forbidden in this context).
335
Open AT® TUTORIAL
}
else
{
// Get the current task state
adl_ctxState_e State = adl_ctxGetState ( CurCtx );
}
}
// Somewhere in the application code, used within an high level interrupt handler
void MyIRQFunction ( void )
{
// Suspend the first application task
adl_ctxSuspend ( 0 );
// Resume the first application task
adl_ctxResume ( 0 );
Summary
The following points have been covered in this chapter
Multitasking is a process by which multiple tasks share common processing resources and allows multiple tasks
to run at the same time.
User can define 64 tasks in Open AT Application and the communication between tasks can be done using:
o Queues
o Shared Memory Area
o Mailboxes
Task size is defined by the user within the RAM area available for Open AT Application. Typical size is up to
4KBytes per tasks
In multi-tasking environment, when a piece of code is being executed from several tasks/interrupts, context
APIs can be used to get the information about the current task context.
Following APIs are available for context service:
o adl_ctxGetID to get the current context id
o adl_ctxGetTasksCount to get the current tasks count
o adl_ctxGetTaskID to get the current task id
o adl_ctxGetDiagnostic to get the diagnostic information
o adl_ctxSuspend to suspend the task
o adl_ctxSuspendExt to suspend several tasks
o adl_ctxResume to resume a task
o adl_ctxResumeExt to resume several tasks
o adl_ctxSleep to put a task to sleep for a specified duration
336
Open AT® TUTORIAL
7.1. Introduction
Open AT OS provides message service which can be used for communication amongst tasks. Each task is
provided with its own mailbox and the messages are exchanged using mailbox identifier as shown in the
below diagram.
Task 1 Task 2
Task 1 Task 2
Mai l box Mai l box
Open AT® OS
Figure 76 - Inter-Task Communication Example
ADL provides the Message service interface that allows to exchange message between tasks. The header file
adl_msg.h should be included in the Open AT Application to use this service.
Prototype:
Parameters:
Filter: This parameter defines the identifier and source context conditions to check each message reception
in order to notify the message handler. This is defined by the structure as mentioned below:
typedef struct
{
u32 MsgIdentifierMask;
u32 MsgIdentifierValue;
337
Open AT® TUTORIAL
adl__msgIdComparator_e Comparator;
adl__ctxID_e Source;
} adl_msgFilter_t;
Parameters:
MsgIdentifierMask: This parameter defines the bit mask to be applied to the incoming
message identifier at reception time. Only the bits set to 1 in this mask will be compared
for the service handlers notification. If the mask is set to 0, the identifier comparison will
always match.
MsgIdentifierValue: This parameter defines the message identifier value to be compared
with the received message identifier. Only the bits filtered by the MsgIdentifierMask mask
are significant.
Comparator: This parameter defines the operator to be used for comparing the received
message identifier. This is defined by the adl_msgIdComparator_e as mentioned below:
typedef enum
{
//Two identifiers are equal
ADL_MSG_ID_COMP_EQUAL,
//Two identifiers are different
ADL_MSG_ID_COMP_DIFFERENT,
//Received message identifier is greater than the subscribed
//message identifier
ADL_MSG_ID_COMP_GREATER,
//Received message identifier is greater or equal to the subscribed
//message identifier
ADL_MSG_ID_COMP_GREATER_OR_EQUAL,
//Received message identifier is lower than the subscribed message
//identifier.
ADL_MSG_ID_COMP_LOWER,
//Received message identifier is lower or equal to the subscribed message
//identifier.
ADL_MSG_ID_COMP_LOWER_OR_EQUAL,
//Reserved for internal use
ADL_MSG_ID_COMP_LAST,
} adl_msgIdComparator_e;
Source: This parameter defines the incoming message source context. The ADL_CTX_ALL
constant should be used if the application wishes to receive all messages.
msgHandler: This parameter defines the message handler which will be notified each time a message is
received which matches with the filter conditions.
Prototype:
typedef void (*adl_msgHandler_f) ( u32 MsgIdentifier, adl_ctxID_e Source, u32 Length,
void * Data )
338
Open AT® TUTORIAL
Parameters:
MsgIdentifier: This is an identifier for the incoming message.
Source: This is the context of the source from which message has been received.
Length: This is the length of the message body. This is set to 0 in case the message doesn’t have the
body.
Data: This is the address of the message body. This is set to NULL in case the message doesn’t have
the body.
Returned Values:
Positive or null value will be returned on success.
Negative value is returned in case of an error.
ADL_RET_ERR_PARAM will be returned if a parameter has an incorrect value.
ADL_RET_ERR_SERVICE_LOCKED will be retuned if the function is called from a low level Interrupt handler.
Prototype:
Parameters:
MsgHandle: This is the handle returned by the adl_msgSubscribe API.
Returned Values:
OK will be returned on success.
ADL_RET_ERR_UNKNOWN_HDL will be returned if the supplied handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED will be returned if the function was called from a low level Interrupt
handler.
This API can be used to send message at any time to any running task. When a message is posted, the source
context identifier is automatically set accordingly to the current context:
If the message is sent from the application task, the source context identifier is set to task identifier of the
sending task.
If the message is sent from a low level Interrupt handler, the source context identifier is set to
ADL_CTX_LOW_LEVEL_IRQ_HANDLER.
If the message is sent from a high level Interrupt handler, the source context identifier is set to
ADL_CTX_HIGH_LEVEL_IRQ_HANDLER.
339
Open AT® TUTORIAL
Prototype:
Parameters:
DestinationTask: This parameter defines the destination task to which message has to be sent.
MessageIdentifier: This parameter defines the identifier to the message. The message reception filters will
be applied to this identifier before notifying the concerned message handlers.
Length: This parameter defines the length of the message. This should be set to 0 if the message doesn’t
have the message body.
Data: This parameter defines the address of the buffer which has the message body. This should be set to 0 if
the message doesn’t have the message body.
Returned Values:
OK will be returned on success.
ADL_RET_ERR_PARAM will be returned if a parameter has an incorrect value.
340
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter:
Message service provides the facility to send messages to other tasks.
Following APIs are provided by the Message service:
o adl_msgSubscribe API is used to subscribe for the Message service
o adl_msgUnsubscribe API is used to unsubscribe from the Message service
o adl_msgSend API is used to send the message to the other task
8.1. Introduction
Synchronization is a method which allows to co-ordinate multiple paths of execution. For e.g. in a system,
you could have a LCD task writing on LCD and another task to get the input data. In this case, LCD task should
be synchronized with input task in order to display only when input data is available. Open AT OS provides
Semaphore service to perform Synchronisation.
Along with Synchronisation, Semaphore can also be used to create critical section which cannot be
interrupted by any other task. This capability allows controlling the access of multiple tasks to shared
resources. Without using semaphores, it is possible for one task to corrupt a shared data while another task
is in the process of using or updating the data. This often leads to data corruption.
For e.g. Let us say, when two tasks wants to write in object id “1” at the same time, it could lead to
corruption of flash object. To avoid this, semaphores can be used. Semaphores will make sure that at a time
only one task could access the flash object.
The header file adl_sem.h should be included in the Open AT Application to use this service.
341
Open AT® TUTORIAL
Prototype:
Parameters:
SemCounter: This parameter defines the initial value of the semaphore counter.
Returned Values:
A positive semaphore service handle is returned on success.
A negative error value is returned in case of an error.
ADL_RET_ERR_NO_MORE_SEMAPHORES is returned when there are no more free semaphore resources
available. There are up to 100 semaphore resources are available.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level Interrupt handler.
Prototype:
Parameters:
None
Returned Values:
This function returns number of free semaphore resource.
This API can be used to consume a semaphore. In case Semaphore is consumed already, this task will be
suspended till the semaphore is available (Produced).
Prototype:
342
Open AT® TUTORIAL
Parameters:
SemHandle: This is the handle returned by adl_semSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned when the supplied handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
NOTE :
This API could cause an exception 205, if semaphore is consumed too many times.
This API can be used to consume a semaphore with certain time-out. If semaphore is not available, the API
time-outs after defined period.
Prototype:
Parameters:
SemHandle: This is the handle returned by adl_semSubscribe API.
TimeOut: This defines the time-out duration in 18.5ms steps.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned when the supplied handle is unknown.
ADL_RET_ERR_PARAM is returned when a supplied parameter value is wrong.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
ADL_RET_ERR_BAD_STATE is returned, if the semaphore is unavailable after TimeOut.
NOTE : This API could cause an RTK exception 206, if semaphore has been consumed too many times.
Prototype:
343
Open AT® TUTORIAL
Parameters:
SemHandle: This is the handle returned by adl_semSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned when the supplied handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
NOTE :
This API could cause an exception 133, if semaphore is produced too many times.
Prototype:
Parameters:
SemHandle: This is the handle returned by adl_semSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned when the supplied handle is unknown.
ADL_RET_ERR_BAD_STATE is returned when the semaphore inner counter value is different from the initial
value.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
Prototype:
Parameters:
344
Open AT® TUTORIAL
Returned Values:
TRUE, if the semaphore is consumed.
FALSE, if the semaphore is not consumed.
ADL_RET_ERR_UNKNOWN_HDL is returned when the supplied handle is unknown.
Summary
The following points have been covered in this chapter:
A semaphore is a protected variable and is a method for restricting access to shared resources (e.g. flash) in a
multiprogramming environment.
Following APIs are provided by the Semaphore service are:
o adl_semSubscribe to subscribe to semaphore service
o adl_semUnsubscribe to unsubscribe from semaphore service
o adl_semConsume to consume a semaphore
o adl_semConsumeDelay to consume a semaphore with time-out
o adl_semProduce to produce a semaphore
o adl_semGetResourceCount to get the number of free semaphore resources
o adl_semIsConsumed to check if semaphore is consumed or not
345
Open AT® TUTORIAL
9.1. Introduction
Open AT OS provides the Queue service to manage the thread safe data. Open AT OS makes sure that the
data is protected from the concurrent access.
Open AT OS supports both LIFO and FIFO approach for accessing data as shown in the below diagram.
Task 1 Task 2
Queue S ervi ce
Data
Open AT OS provides the Queue service to manage the thread safe data. The header file adl_queue.h should
be included in Open AT Application to use this service.
Prototype:
Parameters:
Option: This parameter defines the behaviour of the queue resource. This is defined by the
adl_queueOptions_e enum as defined below:
typedef enum
{
// First In, First Out method: First pushed item will be retreived first
ADL_QUEUE_OPT_FIFO,
// Last In, First Out method: Last pushed item will be retreived first
ADL_QUEUE_OPT_LIFO,
//Reserved for internal use
346
Open AT® TUTORIAL
ADL_QUEUE_OPT_LAST
} adl_queueOptions_e;
Returned Values:
A positive queue service handle is returned on success.
ADL_RET_ERR_PARAM is returned on parameter error.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler
Prototype:
Parameters:
Handle: This is the handle returned by the adl_queueSubscribe API.
Returned Values:
Prototype:
Parameters:
Handle: This is the handle returned by the adl_queueSubscribe API.
Returned Values:
347
Open AT® TUTORIAL
Prototype:
Parameters:
Handle: This is the handle returned by the adl_queueSubscribe API.
Item: This parameter defines the data to be added in the queue. Note that this parameter can’t be set to
NULL.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HANDLE is returned if the provided handle is invalid.
ADL_RET_ERR_PARAM is returned if the specified parameter is incorrect.
NOTE :
This API could cause an exception 144, if too many items are added in the queue.
Prototype:
Parameters:
Handle: This is the handle returned by the adl_queueSubscribe API.
Returned Values:
A pointer to the item is returned on success.
NULL is returned, if the queue is empty or the handle is unknown.
348
Open AT® TUTORIAL
s32 State;
// Item definitions
u32 MyItem1, MyItem2, *GotItem1, *GotItem2;
// Create a FIFO queue resource
MyHandle = adl_queueSubscribe(ADL_QUEUE_OPT_FIFO);
// Check the queue state (shall be empty)
State = adl_queueIsEmpty ( MyHandle );
// Push items
adl_queuePushItem ( MyHandle, &MyItem1 );
adl_queuePushItem ( MyHandle, &MyItem2 );
// Check the queue state (shall not be empty)
State = adl_queueIsEmpty ( MyHandle );
// Pop items (retrieved in FIFO order)
GotItem1 = adl_queuePopItem ( MyHandle );
GotItem2 = adl_queuePopItem ( MyHandle );
// Check the queue state (shall be empty)
State = adl_queueIsEmpty ( MyHandle );
// Delete the queue resource
adl_queueUnsubscribe ( MyHandle );
}
Summary
The following points have been covered in this chapter:
A Queue service is provided for providing thread safe data management.
This serviced can be used either by FIFO or LIFO method.
Following APIs are provided by the Queue service are:
o adl_queueSubscribe to create a queue with LIFO or FIFO approach
o adl_queueUnsubscribe to unsubscribe from queue service
o adl_queueIsEmpty to check if the queue is empty
o adl_queuePushItem to add item to the queue
o adl_queuePopItem to retrieve item from the queue
10.1. Introduction
Interrupts are asynchronous breaks in program flow that occur as a result of events outside the running
program. They are usually hardware related, occurring due to events such as a button press, timer expiration
or completion of a data transfer.
RTOS feature of the Open AT OS help you to handle interrupts generated by embedded module:
IRQ service to manage all the interrupts
External Interrupt Service for handling external interrupts
TCU Service for handling timer interrupts
Audio Service for handling audio interrupts
349
Open AT® TUTORIAL
IRQ service provides the facility to define the notification level of the interrupt handler during subscription.
The handler can be defined either as high-level handler or as a low-level handler. Lower the level of the
handler faster its notification.
Open AT Application task, call stack size is defined through constants. If the application does not provide one
of them, it will automatically be set to zero, and the associated context (Low level or High level) will not be
usable at run time.
During run-time, if the stack size is insufficient, Open AT OS causes an exception and resets the embedded
module.
Prototype:
Parameters:
Size: Size of the stack.
350
Open AT® TUTORIAL
Low-level interrupt handler gives you the access to execute the time critical process. Lower level handlers are
given higher priority in the Open AT Application. Their priority is higher than Open AT Application, AT
command task, Firmware (GSM task) but lesser than Firmware interrupt (GSM interrupt). 1ms is the
maximum reaction time for the lower level interrupt handler.
Below diagram shows the processing of the various tasks in the Open AT OS.
GSM CUS IRQ GSM CUS IRQ CUS IRQ GSM IRQ
4,615 ms 4,615 ms
IRQ = Interruption
As shown in the above figure, the GSM interrupt has more priority than the Level 1 Open AT interrupt. Hence
when Open AT Interrupt is in execution, the GSM interrupt can preempt the execution.
NOTE :
The Real Time Enhancement feature has to be enabled on the embedded module in order to use this service.
AT+WCFM=5 command can be used to check the Real Time Enhancement feature availability.
This API can be used to subscribe to the IRQ service. This handler is used to monitor the interrupt generated
by other services such as TCU or audio or external interrupt.
351
Open AT® TUTORIAL
Prototype:
Parameters:
IrqHandler: Call back function defined by the application. This handler will be called when the interrupt is
triggered.
Prototype:
352
Open AT® TUTORIAL
ADL_IRQ_ID_I2C_EOT,
// Reserved for internal use
ADL_IRQ_ID_LAST
} adl_irqID_e;
NotificationLevel: Level of notification. These are defined in the enum given below:
typedef enum
{
ADL_IRQ_NOTIFY_LOW_LEVEL, // Low level interrupt handlers
ADL_IRQ_NOTIFY_HIGH_LEVEL, // High level interrupt handlers
ADL_IRQ_NOTIFY_LAST // Reserved for internal use
} adl_irqNotificationLevel_e;
Data: Input/output data field is specific to the type of the interrupt. These are defined in the
structure given below:
typedef struct
{
union
{
void * LowLevelOuput;
void * HighLevelInput;
} UserData; //Allows the application to exchange data between
//low level and high level interrupt handlers
void * SourceData; //Provides to handlers an interrupt source
//specific data
u32 Instance //Instance identifier of the interrupt event which has
//just occurred.
void * Context //Context
} adl_irqEventData_t;
Returned Values:
Return value is valid only valid in case of low-level handle.
TRUE: The higher-level interrupt will be called if it is subscribed for the same interrupt.
FALSE: The higher-level interrupt corresponding to the interrupt will not be called.
NotificationLevel: Allow to categorize a handler as a low level or a high-level handler. Lower the
level of the handler faster is the notification. The different level of the handler that can be set is
defined in the following enum.
typedef enum
{
ADL_IRQ_NOTIFY_LOW_LEVEL, // Low level interrupt handlers
ADL_IRQ_NOTIFY_HIGH_LEVEL, // High level interrupt handlers
ADL_IRQ_NOTIFY_LAST // Reserved for internal use
} adl_irqNotificationLevel_e;
353
Open AT® TUTORIAL
Parameters:
ADL_IRQ_NOTIFY_LOW_LEVEL: The value defines the level of notification of the handler as low. This
handler has priority higher than Firmware task, AT command task, Open AT Application task and the
higher-level handler but lower than Firmware interrupt. The maximum time of execution of this
type of handler is 1ms.
ADL_IRQ_NOTIFY_HIGH_LEVEL: The value defines the level of notification of the handler as high.
The handler with this level will have a priority higher that AT command task, Open AT Application
task but lower than Firmware interrupt Firmware task and lower level handler. The maximum time
of execution of this type of handler is 1ms – 10ms.
PriorityLevel: This parameter defines the priority level of the given interrupt handler.
The lowest priority level is always 0.
The highest priority level should be retrieved using adl_irqGetCapabilities API.
Options: This parameter defines the interrupt handler notification options. This parameter can have
the following value:
ADL_IRQ_OPTION_AUTO_READ: If this option is set, than source related information structure is
automatically read by IRQ service and supplied to the interruption handler. In case of higher level
handler, this is the only way to retrieve the source information.
Returned Values:
A positive or null IRQ service handle is returned on success. This handle will be used further IRQ & interrupt
source services function calls.
ADL_RET_ERR_PARAM is returned, if the parameters specified are incorrect.
ADL_RET_ERR_NOT_SUBSCRIBED is returned, if a low or high level handler subscription is required while the
associated context call stack size was not supplied by the application.
ADL_RET_ERR_BAD_STATE is returned if the function is called in RTE mode.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler (the
function is forbidden in this context)
NOTE :
This API cannot be used in RTE mode. It returns ADL_RET_ERR_BAD_STATE in case if it is used in RTE mode.
This API can be used to subscribe to the IRQ service. This API is same as adl_irqSubscribe() except that this
API allows to define all the parameters through a structure instead of independent configurations.
Prototype:
Parameters:
IrqHandler: Call back handler defined by the application. This handler will be called when the interrupt is
triggered.
354
Open AT® TUTORIAL
Prototype:
bool (*adl_irqHandler_f) (adl_irqID_e Source, adl_irqNotifyLevel_e NotificationLevel,
adl_irqEventData_t *Data);)
Parameters:
Source: Source of the interrupt. These are defined in the enum given below:
typedef enum
{
//RX path interrupt sources raised by the Audio Stream Listen
//service
ADL_IRQ_ID_AUDIO_RX_LISTEN,
// TX path interrupt sources raised by the Audio Stream Listen
//service
ADL_IRQ_ID_AUDIO_TX_LISTEN,
// RX path interrupt sources raised by the Audio Stream Play
//service
ADL_IRQ_ID_AUDIO_RX_PLAY,
// TX path interrupt sources raised by the Audio Stream Play
//service
ADL_IRQ_ID_AUDIO_TX_PLAY,
// Interrupt sources raised by the External Interrupt Pin source
ADL_IRQ_ID_EXTINT,
// Interrupt sources raised by the Timer Interrupts source
ADL_IRQ_ID_TIMER,
// Capture interrupt sources raised by the Timer Interrupts source
ADL_IRQ_ID_EVENT_CAPTURE,
// Detection interrupt sources raised by the Timer Interrupt source
ADL_IRQ_ID_EVENT_DETECTION,
// SPI bus asynchronous end of transmission event
ADL_IRQ_ID_SPI_EOT,
// I2C bus asynchronous end of transmission event
ADL_IRQ_ID_I2C_EOT,
// Reserved for internal use
ADL_IRQ_ID_LAST
} adl_irqID_e;
NotificationLevel: Level of notification. These are defined in the enum given below:
typedef enum
355
Open AT® TUTORIAL
{
ADL_IRQ_NOTIFY_LOW_LEVEL, // Low level interrupt handlers
ADL_IRQ_NOTIFY_HIGH_LEVEL, // High level interrupt handlers
ADL_IRQ_NOTIFY_LAST // Reserved for internal use
} adl_irqNotificationLevel_e;
Data: Input/output data field is specific to the type of the interrupt. These are defined in the
structure given below:
typedef struct
{
union
{
void * LowLevelOuput;
void * HighLevelInput;
} UserData; //Allows the application to exchange data between
//low level and high level interrupt handlers
void * SourceData; //Provides to handlers an interrupt source
//specific data
u32 Instance //Instance identifier of the interrupt event which has
//just occurred.
void * Context //Context
} adl_irqEventData_t;
Returned Values:
Parameters:
ADL_IRQ_NOTIFY_LOW_LEVEL: The value defines the level of notification of the handler as low. This
handler has priority higher than Firmware task, AT command task, Open AT Application task and the
356
Open AT® TUTORIAL
higher-level handler but lower than Firmware interrupt. The maximum time of execution of this type of
handler is 1ms.
ADL_IRQ_NOTIFY_HIGH_LEVEL: The value defines the level of notification of the handler as high. The
handler with this level will have a priority higher that AT command task, Open AT Application task but
lower than Firmware interrupt Firmware task and lower level handler. The maximum time of execution
of this type of handler is 1ms – 10ms.
Config: This parameter defines the interrupt handler configuration. This is defined by the adl_irqConfig_t
structure as mentioned below:
typedef struct
{
adl_irqPriorityLevel_e PriorityLevel,
bool Enable,
u8 Pad[2] // Reserved for future use
adl_irqOptions_e Options
} adl_irqConfig_t;
Parameters:
PriorityLevel: This parameter defines the interrupt handler priority.
The lowest priority level is always 0.
The highest priority level should be retrieved using adl_irqGetCapabilities API.
Enable: This parameter field defines if the interrupt handler is enabled or not.
TRUE: If it is set to TRUE, the interrupt handler is enabled and any interrupt event on which is plugged
this handler will call the related function.
FALSE: If it is set to FALSE, the interrupt handler is disabled: all interrupt events on which are plugged this
handler are masked, and will be delayed until the handler is enabled again.
Options: This parameter defines the interrupt handler notification options. This parameter can have the
following value:
ADL_IRQ_OPTION_AUTO_READ: If this option is set, than source related information structure is
automatically read by IRQ service and supplied to the interruption handler. In case of higher level
handler, this is the only way to retrieve the source information.
Returned Values:
A positive or null IRQ service handle is returned on success. This handle will be used further IRQ & interrupt
source services function calls.
ADL_RET_ERR_PARAM is returned, if the parameters are incorrect.
ADL_RET_ERR_NOT_SUBSCRIBED is returned, if a low or high level handler subscription is required while the
associated context call stack size was not supplied by the application.
ADL_RET_ERR_BAD_STATE is returned, if the function is called in RTE mode.
ADL_RET_ERR_SERVICE_LOCKED is returned, if the function was called from a low level interrupt handler
(the function is forbidden in this context)
NOTE :
This API cannot be used in RTE mode. It returns ADL_RET_ERR_BAD_STATE in case if it is used in RTE mode.
357
Open AT® TUTORIAL
Prototype:
Parameters:
IrqHandle: This parameter is the IRQ handle returned during subscription for IRQ service.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned, if the supplied handle is unknown.
ADL_RET_ERR_BAD_STATE is returned, if the supplied handle is still used by an interrupt source service.
ADL_RET_ERR_SERVICE_LOCKED is returned, if the function was called from a low level interrupt handler.
Prototype:
Parameters:
IrqHandle: This parameter is the IRQ handle returned during subscription for IRQ service.
Config: This parameter is the configuration structure which defines the configuration parameters of the
interrupt handler.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied handle is unknown.
ADL_RET_ERR_PARAM is returned, if the parameters are incorrect.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
This API can be used to retrieve the current configurations of the interrupt handler.
358
Open AT® TUTORIAL
Prototype:
Parameters:
IrqHandle: This parameter is the IRQ handle returned during subscription for IRQ service.
Config: This parameter is the configuration structure which holds the configuration parameters retrieved
using this API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied handle is unknown.
ADL_RET_ERR_PARAM is returned if the parameters are incorrect.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
This API can be used to retrieve the interrupt service capabilities on the current platform.
Prototype:
Parameters:
Capabilities: This parameter defines the IRQ service capabilities. This is defined by the below structure:
typedef struct
{
u8 PriorityLevelsCount, // Priority level count
u8 Pad [3] // Reserved for internal use
u8 InstancesCount [ADL_IRQ_ID_LAST] // Instance count for each interrupt
//source identifier
} adl_irqCapabilities_t;
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if there the parameter specified is incorrect.
359
Open AT® TUTORIAL
// Interrupt handler
bool MyIRQHandler ( adl_irqID_e Source, adl_irqNotificationLevel_e
360
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter:
IRQ service provides the facility to subscribe to the interrupt handler.
These handlers will be called when the service linked to them trigger as interrupt.
Interrupt handler can be linked to the following:
o External interrupt
o TCU timer
o SPI and I2C buses
o Audio streaming process
In API provided by the IRQ service are:
o adl_irqSubscribe/adl_irqSubscribeExt API is used to subscribe for the IRQ service
o adl_irqUnsubscribe API is used to unsubscribe from the IRQ service
o adl_irqSetConfig API is used to configure interrupt handler configurations
o adl_irqGetConfig API is used to retrieve the current configuration of interrupt handler
o adl_irqGetCapabilities API is used to retrieve the capabilities of the IRQ service on the current
platform
The handlers subscribed are categorize as higher or lower level handler.
1. Lower the level of the handler faster is its notification.
11.1. Objective
This chapter will introduce you to external interrupts provided on the embedded module and how to use
them in your Open AT Application.
11.2.Introduction
Embedded module is provided with multiple external interrupts. These interrupts can be used in the Open
AT Application. The priority of handlers depends on the level of the handler defined at the time of
subscription of the handler.
The external interrupts are generated either on:
External
Interrupt Low Level Hi gh Level
Fi l ter I nterrupt I nterrupt
Handl ers Handl ers
361
Open AT® TUTORIAL
Debounce: Stable signal is required to generate the interrupts. Hence there will be delay in the generation of
interrupts as shown in the below diagram.
Figure 80 - Debounce
Stretching: Signal is stretched to stretched in order to detect even small glitches in the signal as shown in the
below diagram.
Clock
External
Interrupt
Actual
Interrupt
Stretched
signal
Figure 81 - Stretching
Prototype:
Parameters:
ExtIntID: Identifier of the external interrupt to be subscribed. These identifiers are defined in the
adl_extintID_e enum.
362
Open AT® TUTORIAL
LowLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for low level interrupts.
HighLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for high level interrupts.
Settings: The configuration for the external interrupt. These settings are defined in the adl_extintConfig_t
structure.
Returned Values:
Prototype:
Parameters:
ExtIntHandle: Handle returned during external interrupt service subscription.
Settings: This defines the external pin configuration.
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM is returned if one parameter has an incorrect value.
ADL_RET_ERR_NOT_SUPPORTED is returned if one parameter refers to a mode or a configuration not
supported by the embedded module.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied External Interrupt handle is unknown.
Prototype:
363
Open AT® TUTORIAL
Parameters:
ExtIntHandle: Handle returned during external interrupt service subscription.
Settings: External pin configuration to be retrieved.
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM is returned if one parameter has an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied External Interrupt handle is unknown.
Prototype:
Parameters:
typedef struct
{
u8 PinState; // External interrupt pin status
} adl_extintInfo_t;
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM is returned if one parameter has an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied External Interrupt handle is unknown.
Prototype:
364
Open AT® TUTORIAL
Parameters:
ExtIntHandle: This is the handle returned during subscription.
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied External Interrupt handle is unknown
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
PinCapabilities: This is the pointer to the adl_extintCapablities_t structure which holds the capabilities of the
external interrupt.
typedef struct
{
u8 NbExternalInterrupt; //Number of external interrupt
bool RisingEdgeSensitivity //Rising edge sensitivity supported
bool FallingEdgeSensitivity //Falling edge sensitivity supported.
bool BothEdgeSensitivity //Both edge detector supported.
bool LowLevelSensitivity //Low level sensitivity supported.
bool HighLevelSensitivity //High level sensitivity supported.
bool BypassMode //Bypass mode supported.
bool StretchingMode //Stretching mode supported.
bool DebounceMode //Debounce mode supported.
u8 MaxDebounceDuration //Debounce max duration in ms.
u8 DebounceNbStep //Number of step for debounce duration.
u8 PriorityLevelsCount //Available priority levels for the External Interrupt
//service (to be used as a adl_irqPriorityLevel_e
// value in the IRQ service
u8 Pad [4] //Internal use.
} adl_extintCapabilities_t
365
Open AT® TUTORIAL
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM is returned if one parameter has an incorrect value.
Prototype:
Parameters:
ExtIntHandle: External Interruption service handle, previously returned by the adl_extintSubscribe function.
Status: Status to be set.
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM if the parameter has incorrect value
ADL_RET_ERR_UNKNOWN_HDL if the supplied external interruption handle is unknown
ADL_RET_ERR_ALREADY_SUBSCRIBED if the FIQ status is tried to be set on more than one handle
Prototype:
Parameters:
ExtIntHandle: External Interruption service handle, previously returned by the adl_extintSubscribe function.
Status: FIQ status to be retrieved.
366
Open AT® TUTORIAL
Returned Values:
OK is returned on success.
A negative error value is returned on error:
ADL_RET_ERR_PARAM if the parameter has incorrect value
ADL_RET_ERR_UNKNOWN_HDL if the supplied external interruption handle is unknown
367
Open AT® TUTORIAL
{
// Un-subscribes from the ExtInt service
adl_extintUnsubscribe ( ExtIntHandle );
}
Summary
The following points have been covered in this chapter:
External Interrupt service provides the facility to service the interrupts generated by the external interrupt pins.
The API provided by the External Interrupt service are:
o adl_extintSubscribe API is used to subscribe for the External interrupt service
o adl_extintUnsubscribe API is used to unsubscribe from the External Interrupt service
o adl_extintSetConfig API is used to configure external interrupt configurations
o adl_extintGetConfig API is used to retrieve the current configuration of external interrupt
o adl_extintRead API is used to read the status of the external interrupt
o adl_extintGetCapabilities API is used to retrieve the capabilities of the external interrupts
12.1.Objective
This chapter will introduce you to TCU service provided on the embedded module to handle the interrupts
generated by the timers.
12.2. Introduction
The TCU service serves the following needs of a real time system:
Provides a way to define accurate timers with a precision in order of µs.
Allows to measure the number of edges (Events) occurred on a PIN in a given stipulated time.
Allows detecting an edge in a given time.
There are three types of TCU service which are provided by Open AT OS as mentioned below:
Accurate Timers Service
Event Capture Service
Event Detection Service
The timer duration is configured using adl_tcuSubscribe API. When the timer expires, the interrupt handler
defined by the IRQ service will be notified with the following parameters:
the Source parameter will be set to ADL_IRQ_ID_TIMER
the adl_irqEventData_t::SourceData field of the Data parameter will be set to NULL.
368
Open AT® TUTORIAL
Timer
External
Interrupt
PIN
If timeout specified,
Handler called with 2 0 0 1
If timeout not specified,
global variable is x=1 x=2 x=3
updated to x
Figure 82 - Event Capture Service
This service is used to detect events on a given embedded module pin. The interrupt handler defined by the
IRQ service will be notified:
if no event is detected in a given period of time configured by adl_tcuSubscribe API, the interrupt handler is
called to inform the inactivity
if embedded module pin is interrupted
369
Open AT® TUTORIAL
Timer
Expiry Expiry Expiry
Re-started
Timer
External
Interrupt PIN
Actual
Interrupt
Prototype:
Parameters:
SrvID: This parameter defines the type of TCU service to be subscribed. This is defined by the
adl_tcuService_e enum as mentioned below:
enum
{
ADL_TCU_ACCURATE_TIMER, //Accurate timer service
ADL_TCU_EVENT_CAPTURE, //Event capture service
ADL_TCU_EVENT_DETECTION //Event detection service
} adl_tcuService_e;
370
Open AT® TUTORIAL
LowLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for low level interrupts.
HighLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for high level interrupts.
Settings: This parameter is the TCU service configuration according to the SrvID parameter value.
Accurate Timer Service Settings: Following structure defines the parameter settings which should be used for
configuring accurate timer:
typedef struct
{
adl_tcuTimerDuration_t Duration,
u32 Periodic
} adl_tcuTimerSettings_t;
Parameters:
Duration: This parameter defines the time duration used for defining accurate timers. This is defined by the
adl_tcuTimerDuration_t structure as mentioned below:
typedef struct
{
u32 DurationValue,
adl_tcuTimerUnit_e DurationUnit
} adl_tcuTimerDuration_t;
Parameters:
Duration Value: This parameter defines the timer duration value set by the DurationUnit parameter.
Duration Unit: This parameter defines the unit of the timer duration. This is defined by the following
enumeration:
typedef enum
{
//Timer duration is in microseconds
ADL_TCU_TIMER_UNIT_US = 1,
// Timer duration is in milliseconds
ADL_TCU_TIMER_UNIT_MS = 1000,
// Timer duration is in seconds
ADL_TCU_TIMER_UNIT_S = 100000,
//Reserved for future use
ADL_TCU_TIMER_UNIT_ALIGN = 0x7FFFFFFF
} adl_tcuTimerUnit_e;
371
Open AT® TUTORIAL
Event Capture Service Settings: Following structure defines the parameter settings which should be used for
configuring event capture service:
typedef struct
{
u16 CapturePinID
adl_tcuEventType_e EventType
u32 Duration
u32* EventCounter
} adl_tcuEventCaptureSettings_t;
Parameters:
CapturePinID: This parameter is the pin identifier on which the service has to monitor events.
EventType: This parameter is the type of events as mentioned below:
enum
{
// No event detected
ADL_TCU_EVENT_TYPE_NONE = (s16)0xFFFF,
// Capture or detect rising edge events only
ADL_TCU_EVENT_TYPE_RISING_EDGE = 0,
// Capture or detect falling edge events only
ADL_TCU_EVENT_TYPE_FALLING_EDGE,
// Capture or detect events on both edges
ADL_TCU_EVENT_TYPE_BOTH_EDGE
} adl_tcuEventType_e;
Duration: This parameter defines the duration of the capture. This is used only if the EventCounter
parameter is set to NULL, otherwise it will be ignored. When this parameter is used, the related IRQ service
handlers are called on every duration expiry, indicating to the application the number of events that have
occurred since the previous handler call.
EventCounter: This parameter is an address of 32 bit variable provided by the application. Note that the
address variable has to either a global/static one, or an allocated heap buffer. This is used to store the events
counter value.
If this address is provided, interrupt events will not be generated, but the event counter value will be
incremented, each time a new event is detected.
If this address is set to NULL, the service will generate events, on the time base defined by the Duration
parameter.
Event Detection Service Settings: Following structure defines the parameter settings which should be used
for configuring event detection service
typedef struct
{
u16 DetectionPinID,
372
Open AT® TUTORIAL
adl_tcuEventType_e EventType,
u32 Duration
} adl_tcuEventDetectionSettings_t;
Parameters:
DetectionPinID: This parameter is the pin identifier on which the service has to monitor events.
EventType: This parameter is the type of events as mentioned below:
enum
{
// No event detected
ADL_TCU_EVENT_TYPE_NONE = (s16)0xFFFF,
// Capture or detect rising edge events only
ADL_TCU_EVENT_TYPE_RISING_EDGE = 0,
// Capture or detect falling edge events only
ADL_TCU_EVENT_TYPE_FALLING_EDGE,
// Capture or detect events on both edges
ADL_TCU_EVENT_TYPE_BOTH_EDGE
} adl_tcuEventType_e;
Duration: This parameter is a optional parameter used to determine the duration for which there has been
no edge/pulse on a interrupt pin and generates event to notify handler that no event has occurred for a
given time slot.
If it is set to 0, the inactivity detection will be disabled.
If this value is greater than 0, it is the inactivity detection period duration: if no event has occurred since the
last notification when the duration expires, the associated handlers will be called to warn the application
about this inactivity.
Context: This parameter is the application context, which will be provided back to the application when the
TCU events occur.
Returned Values:
A positive TCU service handle is returned on success. This handle is in further TCU service function calls.
ADL_RET_ERR_PARAM is returned on a supplied parameter error.
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if the service was already subscribed for this configuration.
ADL_RET_ERR_BAD_HDL is returned if one or both supplied interrupt handler identifiers are invalid.
ADL_RET_ERR_BAD_STATE is returned if the function is called in RTE mode.
ADL_RET_ERR_NOT_SUPPORTED is returned if the required service is not supported on the current platform.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function was called from a low level interrupt handler.
NOTE :
This API cannot be used in RTE mode. It returns ADL_RET_ERR_BAD_STATE in case if it is used in RTE mode.
373
Open AT® TUTORIAL
Prototype:
Parameters:
Handle: This parameter is the TCU service handle returned by adl_tcuSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the TCU handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler
Prototype:
Parameters:
Handle: This parameter is the TCU service handle returned by adl_tcuSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the TCU handle is unknown.
This API is used to stop the TCU service event generation. Once the service is stopped interrupt events will
not be generated anymore.
Prototype:
374
Open AT® TUTORIAL
Parameters:
Handle: This parameter is the TCU service handle returned by adl_tcuSubscribe API.
OutParam: This is the optional output parameter based on the service type. If not used, it should be set to
NULL.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the TCU handle is unknown.
NOTE :
If the TCU service is already stopped, calling this API will not any effect. In this scenario it returns OK as response.
// Global variables
// TCU service handle
s32 TCUHandle;
// IRQ service handle
s32 IrqHandle;
// TCU Accurate timer configuration: periodic 5ms timer
adl_tcuTimerSettings_t Config = { { 5, ADL_TCU_TIMER_UNIT_MS }, TRUE };
375
Open AT® TUTORIAL
// Global variables
//Cyclic Timer pointer
adl_tmr_t *timer_ptr;
//Cyclic timer period
u16 timeout_period = 5;
// TCU service handle
s32 TCUHandle;
// Event counter to be provided to the API
u32 EventCounter;
// TCU Event capture configuration: on pin 0, count falling edges, with a provided event counter
adl_tcuEventCaptureSettings_t Config = { 0, ADL_TCU_EVENT_TYPE_FALLING_EDGE,0, &EventCounter };
376
Open AT® TUTORIAL
// Global variables
// TCU service handle
s32 TCUHandle;
// IRQ service handle
s32 IrqHandle;
// TCU Event capture configuration: on pin 0, counts rising edge events, and notify the handler every second
adl_tcuEventCaptureSettings_t Config = { 0, ADL_TCU_EVENT_TYPE_RISING_EDGE,8, NULL };
377
Open AT® TUTORIAL
// Global variables
// TCU service handle
s32 TCUHandle;
// IRQ service handle
s32 IrqHandle;
// TCU Event detection configuration: on pin 0, detects rising edge events,and set a 200 ms timeout
adl_tcuEventDetectionSettings_t Config = { 0,ADL_TCU_EVENT_TYPE_RISING_EDGE, 200 };
378
Open AT® TUTORIAL
{
// Stops event generation
adl_tcuStop ( TCUHandle, NULL );
// Un-subscribes from the TCU service
adl_tcuUnsubscribe ( TCUHandle );
}
Summary
The following points have been covered in this chapter:
TCU service is used to serve the following needs of the real-time system.
o Provides a way to define accurate timers with a precision in order of µs.
o Allows to measure the number of edges(Events) occurred on a PIN in a given stipulated time.
o Allows to detect a edge in a given time.
There are 3 type of TCU services:
o Accurate Timer Service
o Event Detection Service
o Event Capture Service
The API provided by TCU service are:
o adl_tcuSubscribe API is used to subscribe for the TCU service
o adl_tcuUnsubscribe API is used to unsubscribe from the TCU service
o adl_tcuStart API is used to start the TCU service
o adl_tcuStop API is used to stop the TCU service
379
Open AT® TUTORIAL
380
Open AT® TUTORIAL
CHAPTER 31
Power Consumption Modes
1. Objective
This chapter will introduce you to the different power consumption modes supported by embedded module, the steps
to configure the low power modes and power consumed in low power modes
2. Introduction
The power consumption of a device is dependent on the interactions with the network and its peripherals. There are
multiple ways to switch the module to a low power mode in order to reduce the power consumption.
The key contributions to the power consumption arise from the following:
The embedded module consumes maximum power in connected mode i.e. when a connection is active with the
network. When there is no active connection, the power consumption is lesser when compared to the connected mode.
381
Open AT® TUTORIAL
The embedded module can be switched to this mode by using “AT+WBHV=1,2” command. The embedded
module must be restarted in order to take the new behaviour into account. To disable this mode, use the AT
command AT+WBHV=1,0.
In this mode, the embedded module can automatically wake up on unsolicited events such as external
interruption, key press, alarm and Open AT timer expiration*.
382
Open AT® TUTORIAL
To activate the embedded module in this mode; use AT+CPOF command, when the ON/OFF switch is LOW.
This mode can be deactivated by placing the ON/OFF switch to HIGH or after alarm wake up.
NOTE :
* Indicates that the Open AT timer expiration is nothing but the software strict timer expiration. The timer is
strict if the parameter “Strict” of the API adl_tmrSubscribeExt is set to TRUE, which will awake the embedded
module from the SLEEP mode with GSM stack ON when it occurs.
4. Power Measurement
This section describes the various steps to be followed to make the power measurement. Figure below describes the
hardware configuration.
In the figure above, VBATT 1 is used to supply only the MAX 3237 in order to avoid over consumption on the multimeter
display. The consumption of this component is roughly 15 mA alone. VBATT 2 supplies power to the module in order to
read the real value on the multimeter display. RTC is supplied a battery backup of 2.8 V. After configuring in the above
383
Open AT® TUTORIAL
mentioned manner, the value of the multimeter should be read to note the power consumption. Each of the commands
should be given and the difference in power consumption can be noted.
Summary
The following points have been covered in this chapter:
Power consumption of a device is dependent on the interactions with the network and its peripherals. Open AT
provides multiple ways to switch the module to a low power mode in order to reduce the power consumption
The various modes supported are:
o Active mode with GSM stack ON
o Active mode with GSM stack OFF
o Sleep mode with GSM stack ON
o Sleep mode with GSM stack OFF
o Alarm Mode and
o OFF mode
384
Open AT® TUTORIAL
CHAPTER 32
Audio Service
1. Objective
This chapter will introduce you to the Audio service provided by the Open AT OS and how to use them in your Open AT
Application.
2. Introduction
Embedded module is capable of managing following audio format:
Single/Dual tone
DTMF
Melody
PCM Audio Stream
AMR/AMR-WB Audio Stream
These audio formats could be used on following resources:
Output
Speaker
Buzzer
Outgoing voice call
Input
Microphone
Incoming voice call
Single tone can be played on speaker or buzzer. However, the dual tone can only be played on speaker.
Following parameters can be configured for these tones:
Frequency in Hz
2 frequencies in case of dual tone
Gain in dB
Duration in multiple of 20 ms
385
Open AT® TUTORIAL
2.2. DTMF
DTMF is a common method to send signaling information during a call. . This tone is a combination of two
tones with pre-defined frequency. DTMF allows to send tones for 0-9,A-D,*,# characters. Open AT allows
developer:
To play the DTMF tones on speaker or voice call
To process DTMF tones received through microphone or voice call
When DTMF tone is received, low level or high level interrupt handlers will be called as per the configuration
of IRQ service.
Note: As per the configuration of IRQ service, low level or high level
interrupts handlers will be called when DTMF is received
2.3. Melody
Melody is used to alert the user when:
An incoming SMS is arrived
An incoming call indication is received
Open AT allows defining a mono-tone melody and playing the same on speaker or buzzer. Following
parameters can be configured for melody:
Tempo of the melody (Speed)
Number of times the melody can be played
Gain
386
Open AT® TUTORIAL
Interrupt Handlers
PCM/AMR Buffer
Wireless CPU®
Figure 87 - Example for PCM/AMR/AMR-WB Audio Stream
3. Header file
Open AT OS provides interfaces to handle audio resources and play or listen supported audio formats on these
resources (single/dual tones, DTMF tones, melodies, audio streams, decoded DTMF streams).
Open AT Application should include adl_audio.h header file to use this service.
Prototype:
387
Open AT® TUTORIAL
Parameters:
audioResource: This parameter defines the type of audio resource of the embedded module. These
resources are usable either to play a pre-defined/stream audio format (output resources), or to listen to an
incoming audio stream (input resources). This parameter can have one of the following value:
typedef enum
{
ADL_AUDIO_SPEAKER, // Speaker (output resource)
ADL_AUDIO_BUZZER, // Buzzer (output resource)
ADL_AUDIO_MICROPHONE, // Current microphone (input resource)
ADL_AUDIO_VOICE_CALL_RX, // Running voice call incoming channel
//(input resource)
ADL_AUDIO_VOICE_CALL_TX // Running voice call outgoing channel
//(output resource)
} adl_audioResources_e;
audioEventHandler: This is the call back function which will be called when events related to audio resource
occurs. This is defined by the following format:
typedef void(*) adl_audioEventHandler_f(s32 audioHandle, adl_audioEvents_e Event)
Parameters:
audoHandle: This is the handle of the audio resource which is associated to the event.
Event: This parameter is the type of the event received. This parameter can have one of the following
value:
typedef enum
{
ADL_AUDIO_EVENT_NORMAL_STOP,
ADL_AUDIO_EVENT_RESOURCE_RELEASED
} adl_audioEvents_e;
Parameters:
ADL_AUDIO_EVENT_NORMAL_STOP: This event is received when the pre-defined audio format
play ends.
ADL_AUDIO_EVENT_RESOURCE_RELEASED: This event is received when the resource is
automatically unsubscribed (ADL_AUDIO_RESOURCE_OPTION_ALLOW_PREEMPTION).
Options: This defines the audio resource subscription option. This parameter can have one of the
following values:
typedef enum
{
ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION = 0x00,
ADL_AUDIO_RESOURCE_OPTION_ALLOW_PREEMPTION = 0x01
} adl_audioResourceOption_e;
388
Open AT® TUTORIAL
Parameters:
ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION: When this option is used, the resource
subscriber owns the resource until un-subscription time.
ADL_AUDIO_RESOURCE_OPTION_ALLOW_PREEMPTION: When this option is used, the resource can
be used by other services such as incoming voice call melody, outgoing voice call tone play, SIM
Toolkit application tone play. In this scenario, un-subscription happens automatically and the event
ADL_AUDIO_EVENT_RESOURCE_RELEASED will be received in the event handler.
Returned Values:
Positive or null is returned if allocation succeeds.
ADL_RET_ERR_PARAM is returned if the parameter has an incorrect value.
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if the resource is already subscribed.
ADL_RET_ERR_NOT_SUPPORTED is returned if the resource is not supported.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
Prototype:
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_NOT_SUBSCRIBED is returned if no audio resource has been subscribed.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if called from a low level interrupt handler.
This API is used to play a single or dual tone on current speaker and only a single tone on buzzer. Only the
speaker output is able to play tones in two frequencies. The second tone parameters are ignored on buzzer
output. The specified output stops to play at the end of tone duration or when Open AT Application called
adl_audioStop API.
389
Open AT® TUTORIAL
Prototype:
s32 adl_audioTonePlay (s32 audioHandle, u16 Frequency1, s16 Gain1, u16 Frequency2, s16 Gain2,
u32 Duration )
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
Frequency1: This parameter sets the frequency for the 1st tone in Hz.
Gain1: This parameter sets the tone gain which will be applied to the 1st frequency value in dB.
Frequency2: This parameter sets the frequency for the 2nd tone in Hz.
Gain2: This parameter sets the tone gain which will be applied to the 2nd frequency value in dB.
Duration: This parameter sets the tone duration in ms. The value has to be a 20-ms multiple.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for tone playing.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for tone playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
Prototype:
s32 adl_audioTonePlayExt (s32 audioHandle, u16 Frequency1, s16 Gain1, u16 Frequency2, s16
Gain2, u32 Duration )
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
Frequency1: This parameter sets the frequency for the 1st tone in Hz.
Gain1: This parameter sets the tone gain which will be applied to the 1st frequency value in 1/100 of dB.
Frequency2: This parameter sets the frequency for the 2nd tone in Hz.
Gain2: This parameter sets the tone gain which will be applied to the 2nd frequency value in 1/100 of dB.
Duration: This parameter sets the tone duration in ms. The value has to be a 20-ms multiple.
Returned Values:
OK is returned on success.
390
Open AT® TUTORIAL
Prototype:
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
DTMF: This parameter sets the DTMF to play (0-9,A-D,*,#).
Gain: This parameter sets the DTMF gain in dB.
Duration: This parameter sets the DTMF duration in ms. The value has to be a 20-ms multiple.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for DTMF playing.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for DTMF playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
NOTE :
A DTMF can’t be stopped on client request when DTMF is played on voice call TX.
Prototype:
s32 adl_audioDTMFPlayExt (s32 audioHandle, ascii DTMF, s16 Gain, u32 Duration )
391
Open AT® TUTORIAL
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
DTMF: This parameter sets the DTMF to play (0-9,A-D,*,#).
Gain: This parameter sets the DTMF gain in 1/100 of dB.
Duration: This parameter sets the DTMF duration in ms. The value has to be a 20-ms multiple.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for DTMF playing.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for DTMF playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
NOTE :
A DTMF can’t be stopped on client request when DTMF is played on voice call TX.
Prototype:
Parameters:
ID: This parameter corresponds to the note identification as mentioned below:
#define ADL_AUDIO_C 0x01 //C
#define ADL_AUDIO_CS 0x02 //C #
#define ADL_AUDIO_D 0x03 //D
#define ADL_AUDIO_DS 0x04 //D #
392
Open AT® TUTORIAL
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for melody playing.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for melody playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
393
Open AT® TUTORIAL
Prototype:
Parameters:
Parameters:
ID: This parameter corresponds to the note identification as mentioned below:
#define ADL_AUDIO_C 0x01 //C
#define ADL_AUDIO_CS 0x02 //C #
#define ADL_AUDIO_D 0x03 //D
#define ADL_AUDIO_DS 0x04 //D #
#define ADL_AUDIO_E 0x05 //E
#define ADL_AUDIO_F 0x06 //F
#define ADL_AUDIO_FS 0x07 //F #
#define ADL_AUDIO_G 0x08 //G
#define ADL_AUDIO_GS 0x09 //G #
#define ADL_AUDIO_A 0x0A //A
#define ADL_AUDIO_AS 0x0B //A #
define ADL_AUDIO_B 0x0C //B
#define DL_AUDIO_NO_SOUND 0xFF //No sound
Scale: This parameter defines the note scale (0 - 7).
Duration: This parameter defines the note duration. This parameter can have one of the following
value:
#define ADL_AUDIO_WHOLE_NOTE 0x10 //Whole note
#define ADL_AUDIO_HALF 0x08 //Half note
#define ADL_AUDIO_QUARTER 0x04 //Quarter note
#define ADL_AUDIO_HEIGHT 0x02 //Height note
#define ADL_AUDIO_SIXTEENTH 0x01 //Sixteenth note
#define ADL_AUDIO_DOTTED_HALF 0x0C //Dotted half note
#define ADL_AUDIO_DOTTED_QUARTER 0x06 //Dotted quarter
#define ADL_AUDIO_DOTTED_HEIGHT 0x03 //Dotted height
Tempo: This parameter is the tempo in bpm (1 beat = 1 quarter note).
CycleNumber: This parameter defines the number of times the melody should be played. If it is not
specified, the cycle number is infinite and melody should be stopped by client.
394
Open AT® TUTORIAL
Gain: This parameter sets the melody gain in frequency value in 1/100 of dB.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for melody playing.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for melody playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if this function is called from a low level interrupt handler.
NOTE :
1. Memory space has to be allocated for the audio stream buffer before playing starts and it has to be released
after playing stops.
2. Only audio PCM/AMR/AMR-WB sample can be played.
Prototype:
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
audioFormat: This parameter defines the audio stream formats for audio stream playing/listening as
mentioned below:
typedef enum _adl_audioFormats_e
{
ADL_AUDIO_DTMF, ///< Decoded DTMF sequence.
ADL_AUDIO_PCM_MONO_8K_16B, //< PCM mono 16 bits / 8 KHz
// Audio sample.
ADL_AUDIO_PCM_MONO_16K_16B, //< PCM mono 16 bits / 16 KHz
//Audio sample.
ADL_AUDIO_AMR //< AMR / AMR-WB Audio sample
} adl_audioFormats_e
LowLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for low level interrupts.
HighLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for high level interrupts.
buffer: This parameter is a buffer pointer which has audio stream data to be played. The below mentioned
structure allows the application to handle data buffer according to the audio format when an audio stream
395
Open AT® TUTORIAL
Parameters:
audioFormat: This parameter defines the audio stream formats for audio stream playing/listening as
mentioned below:
typedef enum _adl_audioFormats_e
{
ADL_AUDIO_DTMF, ///< Decoded DTMF sequence.
ADL_AUDIO_PCM_MONO_8K_16B, //< PCM mono 16 bits / 8 KHz
// Audio sample.
ADL_AUDIO_PCM_MONO_16K_16B, //< PCM mono 16 bits / 16 KHz
//Audio sample.
ADL_AUDIO_AMR //< AMR / AMR-WB Audio sample
} adl_audioFormats_e
DataBuffer: This parameter defines different types of buffers, which are used according to the audio
format when an audio stream interrupt occurs.
o This field stores audio sample during an audio stream listening or decoded
DTMF during an audio DTMF stream listening.
o It contains audio sample to play during an audio stream playing. This is defined
by the adl_audioStreamDataBuffer_u structure as mentioned below:
typedef union
{
u8 PCMData [1]
u8 AMRData [1];
adl_audioDecodedDtmf_u DTMFData
} adl_audiostreamDataBuffer_u;
Parameters:
PCMData: This parameter is the PCM stream data buffer. This buffer is used when playing or listening to an
audio PCM stream.
AMRData: This contains the AMR data as received on audio stream.
396
Open AT® TUTORIAL
DTMFData: This parameter is the DTMF stream data buffer. This buffer stores decoded DTMF when listening
to an audio DTMF stream according to the decoding mode which is used
BufferReady: When an audio stream is played, each time an interrupt occurs this flag has to set to TRUE
when data buffer is filled. If this flag is not set to TRUE, an ‘empty’ frame composed of 0x0 will be sent and
set the BufferEmpty flag to TRUE. Once the sample is played, BufferReady is set to FALSE by the firmware.
This pointer is initialized only when an audio stream is played. Currently, it is used only for PCM stream
playing.
BufferEmpty: When an audio stream is played, this flag is set to TRUE when empty data buffer is played (for
example, when an interrupt is missing). This flag is used only for information and it has to be set to FALSE by
application. This pointer is initialized only when an audio stream is played. Currently, it is used only for PCM
stream playing.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for audio stream playing or if
interrupt handler identifiers are invalid.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for audio stream playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if called from a low level interrupt handler.
NOTE :
1. It is mandatory to specify low level IRQ handler to make this API work properly. Hence IRQ service should be
subscribed to the low level interrupts with ADL_IRQ_OPTION_AUTO_READ option.
2. High level IRQ handler is a optional parameter.
3. Each time an audio sample is required, an interrupt handler will be notified to send the data. The interrupt
identifier will be set to ADL_IRQ_ID_AUDIO_RX_PLAY or ADL_IRQ_ID_AUDIO_TX_PLAY, according to the
resource used to start the stream play.
4. Some audio filters will be deactivated for audio sample playing (refer to "audio command" chapter in the AT
command Interface Guide [1] for more information).
5. For audio interrupt subscription ADL_IRQ_OPTION_POST_ACKNOWLEDGEMENT option is not available.
NOTE : Memory space has to be allocated for the audio stream buffer before playing starts and it has to be
released after playing stops.
This API is used to listen to a DTMF tone or an audio sample from microphone or voice call RX.
Prototype:
397
Open AT® TUTORIAL
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
audioFormat: This parameter defines the audio stream formats for audio stream playing/listening as
mentioned below:
typedef enum _adl_audioFormats_e
{
ADL_AUDIO_DTMF, ///< Decoded DTMF sequence.
ADL_AUDIO_PCM_MONO_8K_16B, //< PCM mono 16 bits / 8 KHz
// Audio sample.
ADL_AUDIO_PCM_MONO_16K_16B, //< PCM mono 16 bits / 16 KHz
//Audio sample.
ADL_AUDIO_AMR //< AMR / AMR-WB Audio sample
} adl_audioFormats_e;
LowLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for low level interrupts.
HighLevelIrqHandle: This parameter is the IRQ handle returned by IRQ service for high level interrupts.
buffer: This parameter is a buffer pointer which has audio stream data to be played. The below mentioned
structure allows the application to handle data buffer according to the audio format when an audio stream
interrupt occurs during a playing (adl_audioStreamPlay) or a listening to (adl_audioStreamListen) an audio
stream.
typedef struct
{
adl_audioFormats_e audioFormat
adl_audioStreamDataBuffer_u * DataBuffer
bool * BufferReady
bool * BufferEmpty
} adl_audiostream_t;
Parameters:
audioFormat: This parameter defines the audio stream formats for audio stream
playing/listening as mentioned below:
typedef enum _adl_audioFormats_e
{
ADL_AUDIO_DTMF, ///< Decoded DTMF sequence.
ADL_AUDIO_PCM_MONO_8K_16B, //< PCM mono 16 bits / 8 KHz
// Audio sample.
ADL_AUDIO_PCM_MONO_16K_16B, //< PCM mono 16 bits / 16 KHz
//Audio sample.
ADL_AUDIO_AMR //< AMR / AMR-WB Audio sample
} adl_audioFormats_e;
DataBuffer: This parameter defines different types of buffers, which are used according to the
audio format when an audio stream interrupt occurs.
398
Open AT® TUTORIAL
This field stores audio sample during an audio stream listening or decoded DTMF during an
audio DTMF stream listening.
It contains audio sample to play during an audio stream playing. This is defined by the
adl_audioStreamDataBuffer_u structure as mentioned below:
typedef union
{
u8 PCMData [1];
u8 AMRData [1];
adl_audioDecodedDtmf_u DTMFData;
} adl_audiostreamDataBuffer_u;
Parameters:
PCMData: This parameter is the PCM stream data buffer. This buffer is used when playing or listening to an
audio PCM stream.
AMRData: This contains the AMR data as received on stream.
DTMFData: This parameter is the DTMF stream data buffer. This buffer stores decoded DTMF when listening
to an audio DTMF stream according to the decoding mode which is used
BufferReady: When an audio stream is played, each time an interrupt occurs this flag has to set to TRUE
when data buffer is filled. If this flag is not set to TRUE, an ‘empty’ frame composed of 0x0 will be sent and
set the BufferEmpty flag to TRUE. Once the sample is played, BufferReady is set to FALSE by the firmware.
This pointer is initialized only when an audio stream is played. Currently, it is used only for PCM stream
playing.
BufferEmpty: When an audio stream is played, this flag is set to TRUE when empty data buffer is played (for
example, when an interrupt is missing). This flag is used only for information and it has to be set to FALSE by
application. This pointer is initialized only when an audio stream is played. Currently, it is used only for PCM
stream playing.
Returned Values:
OK is returned on success.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if an audio stream is listening or audio predefined signal is playing on
the required audio resource.
ADL_RET_ERR_BAD_HDL is returned if the audio resource is not allowed for audio stream playing or if
interrupt handler identifiers are invalid.
ADL_RET_ERR_NOT_SUPPORTED is returned if the audio resource is not available for audio stream playing.
ADL_RET_ERR_SERVICE_LOCKED is returned if called from a low level interrupt handler.
NOTE :
1. Low level IRQ handler is a optional parameter if high level IRQ handler is specified.
2. High level IRQ handler is a optional parameter if low level IRQ handler is specified.
3. Each time an audio sample or DTMF sequence is detected, an interrupt handler will be notified to require the
data. The interrupt identifier will be set to ADL_IRQ_ID_AUDIO_RX_LISTEN or ADL_IRQ_ID_AUDIO_TX_LISTEN,
according to the resource used to start the stream listen.
4. All audio filters will be deactivated for DTMF listening and only some audio filters for audio sample listening
(refer to "audio command" chapter in the AT command Interface Guide [1] for more information).
5. For audio interrupt subscription, ADL_IRQ_OPTION_POST_ACKNOWLEDGEMENT option is not available..
399
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_BAD_STATE is returned if no audio process is running on the required audio resource.
ADL_RET_ERR_SERVICE_LOCKED is returned this function is if called from a low level interrupt handler.
This API is used for configuring audio option according to audio resource and option type specified.
Prototype:
Parameters:
400
Open AT® TUTORIAL
If a NULL value is specified, DTMF decoder will be in Raw mode (default), Raw data’s coming from DTMF
decoder are sent every 20 ms via interrupt handlers. This mode implies to implement an algorithm in order
to detect the good DTMF. (Refer to adl_audioDecodedDtmf_u for more information about buffer type used).
Otherwise the Raw mode is disabled. The value specifies the blank duration which notifies the end of DTMF.
Each time a DTMF is detected, interrupt handlers are called.
ADL_AUDIO_AMR_SPEECH_CODEC_RATE: Allows defining which codec rate will be used for AMR stream
playing (adl_audioAmrCodecRate_e).
ADL_AUDIO_AMR_MIXED_VOICE: Allows defining if the AMR sample should be mixed to the voice when an
AMR audio sample is played (bool).
ADL_AUDIO_AMR_BUFFER_SIZE: Allows defining the buffer type to allocate for playing or listening to on an
AMR stream (u32).
value: This defines the value to be set.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
This API is used for get the value of the different audio options according to audio resource and option type
specified.
Prototype:
Parameters:
audioHandle: This is the audio handle returned by the adl_audioSubscribe API.
audioOption: This parameter specifies the configuration parameter. This parameter can be set to one of the
value as mentioned below:
ADL_AUDIO_DTMF_DETECT_BLANK_DURATION: This is a DTMF decoding option (u16); it allows defining the
blank duration (ms) in order to detect the end of a DTMF. This value will act on the embedded module
behaviour to return information about DTMF when listening to a DTMF audio stream. The value has to be a
10-ms multiple.
If a NULL value is specified, DTMF decoder will be in Raw mode (default), Raw data’s coming from DTMF
decoder are sent every 20 ms via interrupt handlers. This mode implies to implement an algorithm in order
to detect the good DTMF. (Refer to adl_audioDecodedDtmf_u for more information about buffer type used).
Otherwise the Raw mode is disabled. The value specifies the blank duration which notifies the end of DTMF.
Each time a DTMF is detected, interrupt handlers are called.
ADL_AUDIO_MAX_FREQUENCY: This parameter is the maximum frequency allowed to be played on the
required output resource in Hz. The data type of the parameter is u16.
ADL_AUDIO_MIN_FREQUENCY: This parameter is the minimum frequency allowed to be played on the
required output resource in Hz(u16).
401
Open AT® TUTORIAL
ADL_AUDIO_MAX_GAIN: This is the maximum gain which can be set to play a pre-defined audio format using
adl_audioDTMFPlayExt/adl_audioTonePlayExt/adl_audioMelodyPlayExt.The returned gain value is defined in
1/100 of dB (s16).
ADL_AUDIO_MIN_GAIN: This is the minimum gain which can be set to play a pre-defined audio format using
adl_audioDTMFPlayExt/adl_audioTonePlayExt/adl_audioMelodyPlayExt.The returned gain value is defined in
1/100 of dB (s16).
ADL_AUDIO_MAX_DURATION: This is the maximum duration which can be set to play a DTMF tone or a
single/dual tone using adl_audioDTMFPlay/adl_audioTonePlay. The returned duration value is defined in ms
(u32).
ADL_AUDIO_MIN_DURATION: This is the minimum duration which can be set to play a DTMF tone or a
single/dual tone using adl_audioDTMFPlay/adl_audioTonePlay. The returned duration value is defined in ms
(u32).
ADL_AUDIO_MAX_NOTE_VALUE: This is the maximum duration for a note (tempo) which can be set to play
play a melody using adl_audioMelodyPlay. This value is the maximal value which can be defined with
ADL_AUDIO_NOTE_DEF macro (u32).
ADL_AUDIO_MIN_NOTE_VALUE: This is the minimum duration for a note (tempo) which can be set to play
play a melody using adl_audioMelodyPlay. This value is the maximal value which can be defined with
ADL_AUDIO_NOTE_DEF macro (u32).
ADL_AUDIO_DTMF_RAW_STREAM_BUFFER_SIZE: This is the buffer type to allocate for listening to a DTMF
stream in raw mode or playing a DTMF stream, defined in number of bytes (u8).
ADL_AUDIO_DTMF_PROCESSED_STREAM_BUFFER_SIZE: This is the buffer type to allocate for listening to a
DTMF stream in Pre-processed mode, defined in number of bytes (u8).
ADL_AUDIO_PCM_8K_16B_MONO_BUFFER_SIZE: This is the user to get the buffer type to allocated for
playing or listening to on a PCM 8KHz 16 bits Mono stream, defined in number of bytes (u8)
ADL_AUDIO_PCM_16K_16B_MONO_BUFFER_SIZE: This is the user to get the buffer type to allocated for
playing or listening to on a PCM 16KHz 16 bits Mono stream, defined in number of bytes (u16)
ADL_AUDIO_AMR_WB_AVAILABLE: Allows knowing if AMR Wideband codec rates are available (bool).
ADL_AUDIO_AMR_SPEECH_CODEC_RATE: Allows getting codec rate that will be used for AMR stream playing
(adl_audioAmrCodecRate_e).
ADL_AUDIO_AMR_MIXED_VOICE: Allows checking if the AMR sample should be mixed to the voice when an
AMR audio sample is played (bool).
ADL_AUDIO_AMR_BUFFER_SIZE: Allows getting the buffer type to allocate for playing or listening to on an
AMR stream (u32).
value: This defines the option value according to audio option which has been set.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the provided handle is unknown.
ADL_RET_ERR_PARAM is returned if parameters have an incorrect value.
4. Sample Code
402
Open AT® TUTORIAL
s32 handle;
// audio event call-back function
void MyAudioEventHandler ( s32 audioHandle, adl_audioEvents_e Event )
{
switch ( Event)
{
case ADL_AUDIO_EVENT_NORMAL_STOP:
TRACE (( 1, " Audio handle %d: stop ", audioHandle ));
// unsubscribe to the speaker
Ret = adl_audioUnsubscribe ( handle );
break;
case ADL_AUDIO_EVENT_RESOURCE_RELEASED:
break;
default: break;
}
return;
}
403
Open AT® TUTORIAL
case ADL_AUDIO_EVENT_RESOURCE_RELEASED:
break;
default:
break;
}
return;
}
void adl_main ( adl_InitType_e InitType )
{
s32 Ret;
// Subscribe to the current speaker
handle = adl_audioSubscribe ( ADL_AUDIO_SPEAKER, MyAudioEventHandler,
ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION );
// Play a DTMF tone
Ret = adl_audioDTMFPlay( handle, 'A', -10, 10);
}
404
Open AT® TUTORIAL
// PCM samples
u16 PCM_Samples[160] = { ... , ... , ... , ... , ... , ... , 0 }; //size of PCM sample = 320 bytes
// PCM samples index
u8 indexPCM = 0;
// Low level interrupt handler
bool MyLowLevelIRQHandler ( adl_irqID_e Source, adl_irqNotificationLevel_e Notification Level, adl_irqEventData_t * Data
)
{
// copy PCM sample to play
wm_strcpy( StreamBuffer, PCM_Samples );
// Set BufferReady flag to TRUE
*( ( adl_audioStream_t * )Data->SourceData )->BufferReady = TRUE;
return FALSE;
}
405
Open AT® TUTORIAL
{
s32 Ret;
s32 BufferSize;
adl_irqConfig_t Config;
// Set configuration
Config.PriorityLevel = Caps.PriorityLevelsCount - 1; // Highest priority
Config.Enable = TRUE; // Interrupt handler enabled
Config.Options = ADL_IRQ_OPTION_AUTO_READ; // Auto-read option set
// Subscribe to the current speaker
handle = adl_audioSubscribe ( ADL_AUDIO_SPEAKER, MyAudioEventHandler
,ADL_AUDIO_RESOURCE_OPTION_FORBID_PREEMPTION );
// Memory allocation
Ret = adl_audioGetOption ( handle, ADL_AUDIO_PCM_8K_16B_MONO_BUFFER_SIZE, &BufferSize );
StreamBuffer = adl_memGet( BufferSize ); // release memory after audio stream playing
//Subscribe to low lever IRQ
MyIRQHandle = adl_irqSubscribeExt (MyLowLevelIRQHandler,ADL_IRQ_NOTIFY_LOW_LEVEL, &Config );
// Play an audio PCM stream
Ret = adl_audioStreamPlay( handle, ADL_AUDIO_PCM_MONO_8K_16B, MyIRQHandle, 0, StreamBuffer);
}
406
Open AT® TUTORIAL
407
Open AT® TUTORIAL
Summary
The following points have been covered in this chapter:
Audio service is used to handle audio resources, and play or listen supported audio formats on these resources
(single/dual tones, DTMF tones, melodies, PCM audio streams, decoded DTMF streams).
The API provided by Audio service are:
o adl_audioSubscribe API to subscribe to an audio resource
o adl_audioUnsubscribe API to unsubscribe from an audio resource
o adl_audioTonePlay API to play a single/dual tone
o adl_audioDTMFPlay API to play a DTMF tone
o adl_audioMelodyPlay API to play a melody
o adl_audioTonePlayExt API to play a single/dual tone with high precision gain
o adl_audioDTMFPlayExt API to play a DTMF tone with high precision gain
o adl_audioMelodyPlayExt API to play a melody with high precision gain
o adl_audioStreamPlay API to play an audio stream
o adl_audioStreamListen API to listen to an audio stream
o adl_audioStop API to stop playing or listening
o adl_audioSetOption API to set audio options
o adl_audioGetOption API to get audio options
408
Open AT® TUTORIAL
Chapter 33 – VariSpeed
CHAPTER 33
VariSpeed
1. Objective
This chapter explains the APIs that can be used to change the processor speed.
2. Introduction
Open AT provides VariSpeed feature which can be used to boost the processor clock from 26 MHz (standard mode) to
104 MHz(boost mode) without even resetting the embedded module. However, the power consumption of the
embedded module increases when operating at higher frequency such as 104 MHz.
The boost mode can be used when application needs to perform complex operation which will take more time. For e.g.
a data related application uses following approach for management of data:
Data Acquisition: Retrieves data from various sources
Data Processing: Performs complicated algorithms on the input data and creates the output data.
Data Transfer: Sends the output data to the server.
Here the Data Acquisition and Data Transfer can be done in normal mode. Data processing as it involves complex
processing can be in boost mode to get more performance.
Increasing
Speed
Boost Mode (104
MHz)
Standard
Mode
(26 MHz)
Decreasing
Speed
409
Open AT® TUTORIAL
Chapter 33 – VariSpeed
3. Header file
Open AT OS provides interfaces that can be used to boost the processor clock. Open AT Application should include
adl_vs.h header file to use these interfaces.
Prototype:
Parameters:
None
Returned Values:
A positive or null value is returned on success:
A negative error value is returned otherwise:
ADL_RET_ERR_ALREADY_SUBSCRIBED is returned if the service has already been subscribed.
ADL_RET_ERR_NOT_SUPPORTED is returned if the Real Time enhancement feature is not enabled on the
embedded module.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
Prototype:
Parameters:
VsHandle: This parameter is the handle returned by adl_vsSubscribe API.
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied handle is unknown.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
410
Open AT® TUTORIAL
Chapter 33 – VariSpeed
26 MHz
104 MHz
Prototype:
Parameters:
VsHandle: This parameter is the handle returned by adl_vsSubscribe API.
ClockMode: This parameter defines the clock mode as defined in the enum adl_vsMode_e. This enum is
defined below:
typedef enum _adl_vsMode_e
{
ADL_VS_MODE_STANDARD, // Standard clock mode(26 MHz)
ADL_VS_MODE_BOOST, // Boost clock mode(104 MHz)
ADL_VS_MODE_LAST // Reserved for internal use
} adl_vsMode_e;
Returned Values:
OK is returned on success.
ADL_RET_ERR_UNKNOWN_HDL is returned if the supplied handle is unknown.
ADL_RET_ERR_PARAM is returned if the supplied clock mode value is wrong.
ADL_RET_ERR_SERVICE_LOCKED is returned if the function is called from a low level interrupt handler.
4. Sample Code
#include "adl_global.h"
#include "adl_vs.h"
411
Open AT® TUTORIAL
Chapter 33 – VariSpeed
Summary
The following points have been covered in this chapter
Open AT OS RTOS feature allows user to boost the processor clock from 26 MHz to 104 MHz without even
resetting the embedded module.
Following APIs are available for vari-speed service:
o adl_vsSubscribe to subscribe to vari-speed service
o adl_vsUnsubscribe to unsubscribe from vari-speed service
o adl_vsSetClockMode to change the processor clock speed
412
Open AT® TUTORIAL
CHAPTER 34
Internet Plug-in for Open AT
1. Introduction
Welcome to the Internet Plug-in for Open AT. The following chapters will guide you through the features of the
Internet Plug-in provided into the OASiS. Clear examples, diagrams, exercises and tips will help you easily understand
and use the Internet Plug-In.
If you require additional information, please contact your Sierra Wireless representative.
2. Overview of TCP/IP
TCP/IP is a set of protocols that allows cooperating computers to share resources across a network. This defacto UNIX
standard is the protocol used for the Internet, and is the global standard for communications. Every node in a TCP/IP
network requires an IP address which is either permanently assigned or dynamically assigned at startup.
The TCP/IP protocol suite is implemented in the following 4 layers, similar in construct, but different in layer
combination from the OSI 7 layer model:
Physical layer
Network Layer
Transport Layer
Application layer
413
Open AT® TUTORIAL
5 – APPLICATION LAYER
5 – APPLICATION LAYER
Provides application access to
communication environment
44–- TRANSPORT
TRANSPORT LAYER
LAYER
3 - INTERNET LAYER
Establishes, maintains and
terminates end-to-end network
communication
The message (data) to be transmitted after an application initiates a communication is passed through different
layers, until it reaches the physical link to be used for data transmission. Each layer attaches its own header to the
data packet. At the receiving end, the corresponding protocol layers unpack the data and pass it on to the higher
layers.
TCP/IP is composed of two parts: TCP (Transmission Control Protocol) and IP (Internet Protocol). IP is the network
layer protocol of the TCP/IP suite and is responsible for moving packets of data from node to node. IP forwards each
packet based on a four-byte destination address (the IP number).
TCP is a connection-oriented and reliable transport layer protocol. This protocol is used for all the session-oriented
applications. TCP is responsible for verifying the correct delivery of data between client and server. It tests for errors
and requests retransmission if necessary.
UDP is an alternative to TCP; it is a connectionless protocol that can be used to send datagrams to the destination.
Sierra Wireless’s TCP/IP software includes UDP implementation too.
3. Objective
This chapter gives an introduction to the Internet Plug-In software which has been implemented on top of the Open
AT OS package provided by Sierra Wireless. This chapter also explains various application protocols supported by the
Internet Plug-in and its interfaces.
414
Open AT® TUTORIAL
application can run on an external device connected to the Sierra Wireless embedded module. This application will
decode the IP packets to understand the data received from the network, and also encode the data as IP packets and
send them back to the network.
Sierra Wireless’s TCP/IP software removes the need for any such external application. Sierra Wireless has provided the
TCP/IP software along with OASiS using which, an Open AT Application can understand data coming over the GPRS
network.
Thus, you can create intelligent internet-enabled applications directly on the embedded module. This will shorten
your development time and reduce materials cost.
5. TCP/IP software
The TCP/IP software provides the following protocols:
TCP Sockets
UDP Sockets
PING Service
FTP Service
HTTP Service
SMTP Service
POP3 Service
Bearer management using PPP and GPRS.
Sierra Wireless provides an Internet Plug-in (Also known as WIP library) in which TCP/IP protocols have been
implemented.
TCP/IP Plug-In
Open AT® OS ( TCP/UDP Channels, CGPS Plug-In Protocol
FTP, SMTP, HTTP, POP3 ) Implementation
OPIC Layer
415
Open AT® TUTORIAL
The basic functionalities(TCP/UDP) will be implemented in Firmware. The FTP/SMTP/POP3/HTTP functionalities will be
implemented in the Open AT Plug-In WIP library. Due to this, the applications which require only the basic TCP/UDP
sockets, will be smaller in size.
Summary
The following points have been covered in this chapter
Sierra Wireless provides a Internet plug-in which implements TCP/IP protocols
Internet Plug-In is available as a plug-in
Internet Plug-In APIs are available in two flavours
o APIs with default options
o APIs with configurable options
416
Open AT® TUTORIAL
CHAPTER 35
IP Stack Initialization
Internet Plug-In must be initialized before it can be used in an Open AT Application. During initialization, Internet Plug-
In initializes the local data structures used inside in the Internet Plug-In and also allows to configure the following
parameters:
Number of sockets
Number of buffers
DNS parameters
TCP/IP protocol options such as Time to live parameter
The header file that must be included to use initialization related APIs is “wip_net.h”.
1. Objective
This chapter describes the APIs that you can use to initialize the Internet Plug-In. This includes the APIs,
To initialize the Internet Plug-In with default configuration options
To initialize the Internet Plug-In with advanced configurable options
To configure the protocol specific options
To release the resource allocated during initialization
2. Initialization APIs
Prototype:
s8 wip_netInit( void)
Parameters:
None
Returned Values:
This function returns a value 0, if initialization was successful.
417
Open AT® TUTORIAL
Prototype:
Parameters:
opt: This specifies the first option in the list of options.
…: List of options supported by this API. All options must be followed by a variable. In case of get operation,
value will be copied to the variable while in case of set operation, value will be taken from the variable. The
options supported by this API are:
WIP_NET_OPT_TCP_REXMT_MAX: Maximum time between TCP retransmissions. Default value for
this parameter is 64 seconds.
WIP_NET_OPT_TCP_REXMT_MAXCNT: Maximum number of retransmissions. Default value for
this parameter is 12
WIP_NET_OPT_IP_FORWARD: Activating IP forwarding. Default value for this parameter is FALSE
WIP_NET_OPT_IP_NAT_TO_TCP : TCP flow timeout. Default value for this parameter is 15
seconds.
WIP_NET_OPT_IP_NAT_TO_TCP_FIN: TCP FIN flow timeout. Default value for this parameter is 2
seconds.
WIP_NET_OPT_IP_NAT_TO_UDP: UDP flow timeout. Default value for this parameter is 5 seconds.
WIP_NET_OPT_IP_NAT_TO_ICMP: ICMP flow timeout. Default value for this parameter is 2
seconds.
The list of options should be terminated by a macro WIP_NET_OPT_END.
Returned Values:
This function returns a value 0, if initialization was successful.
On error following values are returned:
WIP_NET_ERR_OPTION: Incorrect configuration parameter entered
WIP_NET_ERR_PARAM: Incorrect configuration parameter value entered
WIP_NET_ERR_NO_MEM: An error was encountered during memory allocation for initialization related
resources. Note that this value is returned only if Open AT Application is subscribed to Error service(
adl_errSubscribe() ) otherwise, the embedded module restarts.
The wip_netExit() API can be used to release the resources allocated during initialization of the Internet
Plug-In. Note that all the bearers which are opened should be closed before calling this function.
418
Open AT® TUTORIAL
Prototype:
s8 wip_netExit( void)
Parameters:
None
Returned Values:
This function always returns a value 0
Prototype:
Parameters:
Returned Values:
This function returns a value 0, if successful.
419
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
This function returns a value 0, if successful.
On error, following value is returned:
WIP_NET_ERR_OPTION: Incorrect configuration parameter entered
WIP_NET_ERR_PARAM: Incorrect configuration parameter value entered
3. Sample Code
void adl_main ( adl_InitType_e InitType )
{
s8 sRet;
420
Open AT® TUTORIAL
Summary
The following points have been covered in this section
Internet Plug-In must be initialized before it can be used in a Open AT Application.
Following APIs are available for initialization
wip_netInit() to initialize the Internet Plug-In with default options.
wip_netInitOpts() to initialize the Internet Plug-In with user-defined options
wip_netExit() to release the resources allocated during initialization
wip_setOpts() to set the TCP/IP protocol options
wip_getOpts() to get the current TCP/IP protocol options
421
Open AT® TUTORIAL
422
Open AT® TUTORIAL
CHAPTER 36
IP Stack Bearer Management
Internet Plug-In allows to setup the TCP/IP connection through one of the following bearers:
PPP client using GSM or UART interface
PPP server using GSM or UART interface
GPRS
Ethernet
Sierra Wireless Internet Plug-in supports multiple IP connection using different bearers. Also in PPP, it allows to use
following authentication protocols
CHAP
PAP
MSCHAP v1
MSCHAP v2
1. Overview
This chapter explains the process that can be used to setup TCP/IP connection using bearer management APIs. It also
explains the different APIs available for bearer management.
2. APIs
The header file that should be used for bearer management APIs is “wip_bearer.h”. When ethernet bearer is used,
“wip_eth.h” should be used.
The wip_bearerOpen() API can be used to attach to bearer interface such as UART, GSM, GPRS.
Prototype:
s8 wip_bearerOpen( wip_bearer_t *br, const ascii *device, wip_bearerHandler_f brHdlr, void
*context)
Parameters:
423
Open AT® TUTORIAL
Returned Values:
This function returns a value 0, if successful.
On error, following values are returned:
WIP_BERR_NO_DEV: Incorrect device entered
WIP_BERR_ALREADY: Device already used
WIP_BERR_NO_IF: Device not available
WIP_BERR_NO_HDL: Handle not available
Prototype:
Parameters:
br: Handle to the bearer
Returned Values:
This function returns a value 0, if successful.
On error, following value is returned:
WIP_BERR_BAD_HDL: Invalid handle
WIP_BERR_BAD_STATE: Bearer was not stopped before closing
The wip_bearerSetOpts() API can be used to configure the bearer specific options such as:
User name
Password
424
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
The wip_bearerGetOpts() API can be used to get the current configuration of the bearer specific options
such as:
User name
Password
Authentication protocol to use
Prototype:
Parameters:
425
Open AT® TUTORIAL
Returned Values:
This function returns a value 0, if successful.
On error following values are returned:
WIP_BERR_BAD_HDL: Invalid handle
WIP_BERR_OPTION: Invalid option
The wip_bearerStart() API can be used to establish the bearer connection using bearer interface such as
UART, GSM, GPRS.
Prototype:
Parameters:
br: Handle to the bearer
Returned Values:
Prototype:
Parameters:
br: Handle to the bearer
426
Open AT® TUTORIAL
brSrvHdlr: This is the call-back handler, which receives the events related to PPP server. This handler should
be defined as shown below:
s8 (*wip_bearerServerHandler_f)( wip_bearer_t br,wip_bearerServerEvent_t
*event, void *context)
Parameters:
br: Bearer Handle
event: PPP server related events
context: Pointer to application context as defined in wip_bearerAnswer() API
Returned Values:
A positive value should be returned from the handler, if the call has to be established else call will be
rejected.
context: Pointer to application context.
Returned Values:
Prototype:
Parameters:
br: Handle to the bearer
brSrvHdlr: This is the call-back handler, which receives the events related to PPP server. This handler
should be defined as shown below:
s8 (*wip_bearerServerHandler_f)( wip_bearer_t br,
wip_bearerServerEvent_t *event, void *context)
Parameters:
br: Bearer Handle
event: PPP server related events. These events include
WIP_BEV_DIAL_CALL: This event signal an incoming call. The call-back function must return a positive value
to accept this call.
WIP_BEV_PPP_AUTH_PEER: This signal a PPP authentication request. The call-back function must fill the
password (secret) field and should return a positive value to accept the request.
context: Pointer to application context as defined in wip_bearerStartServer() API
Returned Values:
A positive value should be returned from the handler, if the call has to be established else call will be
rejected.
context: Pointer to application context.
427
Open AT® TUTORIAL
Returned Values:
Prototype:
Parameters:
br: Handle to the bearer
Returned Values:
Prototype:
Parameters:
None
Returned Values:
428
Open AT® TUTORIAL
The wip_bearerFreeList() API can be used to release the memory allocated to get the list of available
bearers.
Prototype:
Parameters:
binfo: Pointer to the list of available bearers.
Returned Values:
None
wip_bearerOpen
wip_bearerSetOpts
Embedded TCP.IP
Application wip_bearerStart Plug-in
Connection up
In this mode the Sierra Wireless embedded module can connect to TCP/IP network over GPRS. Following
are the steps to setup an TCP/IP connection over GPRS:
429
Open AT® TUTORIAL
Ret_Open = wip_bearerOpen(&Br_Id,"GPRS",Bearer_Handler,NULL);
For e.g.
Ret_Option = wip_bearerSetOpts(Br_Id,WIP_BOPT_GPRS_APN,APNServ,
WIP_BOPT_LOGIN,APNUserName,
WIP_BOPT_PASSWORD,APNPassword,
WIP_BOPT_END);
For e.g.
Ret_Start =wip_bearerStart(Br_Id);
PPP Client
PPP Server
Client sends the authentication Inf o
430
Open AT® TUTORIAL
Internet Plug-in internally manages the connection between PPP server and client. Internet Plug-in provides
APIs to configure the PPP session parameters and start/stop a PPP session.
Sierra Wireless Internet Plug-in allows Sierra Wireless embedded module to behave as a
PPP client
PPP server
wip_bearerOpen
wip_bearerSetOpts
Embedded TCP/IP
Application wip_bearerStart Library
Connection Up
431
Open AT® TUTORIAL
For e.g.
For e.g.
/* Bearer connection handler */
void appBearerHandler( wip_bearer_t br, s8 event, void *context)
{
s8 sRet;
TRACE (( 1, "appBearerHandler: Event %d", event ));
switch(event)
{
432
Open AT® TUTORIAL
case WIP_BEV_IP_CONNECTED:
{
ascii Buffer[50];
TRACE (( 1, " WIP_BEV_IP_CONNECTED "));
sRet = wip_bearerGetOpts(appBearer,
WIP_BOPT_IP_ADDR, &appIpAddr,
WIP_BOPT_END);
TRACE (( 1, "wip_bearerGetOpts: %d", sRet));
wip_inet_ntoa(appIpAddr , IpAddr, 15);
}
break;
default:
break;
}
}
void appBearerConnection()
{
…..
/* Establish the PPP connection */
sRet = wip_bearerStart( appBearer );
TRACE (( 1, "wip_bearerStart: %d", sRet ));
}
wip_bearerOpen
wip_bearerSetOpts
Connection Up
This setup can be used when a private TCP/IP network needs to be established between two embedded
module or two devices. The Sierra Wireless embedded module in this setup acts as a PPP server which
allocates IP address to the PPP client. Following are the steps to setup an TCP/IP connection over PPP when
Sierra Wireless embedded module is a PPP server.
433
Open AT® TUTORIAL
wip_bearerOpen API can be used to select the interface for TCP/IP connection. Following parameters could
be provided during attachment:
Bearer identifier
Interface to use for attachment (UART or GSM)
Bearer call-back handler where connection related events will be received
Bearer context to identify particular attachment
For e.g.
s8 sRet;
wip_bearer_t appBearer;
ascii DeviceName[]="GSM";
/* Bearer connection handler */
void appBearerHandler( wip_bearer_t br, s8 event, void *context)
{
}
void appBearerConnection()
{
appBrCxt = adl_memGet(16);
wm_strcpy((char *) appBrCxt, "Br Context");
/* Open the bearer */
sRet = wip_bearerOpen( &appBearer,
DeviceName,
appBearerHandler,
(void *) appBrCxt);
TRACE (( 1, "wip_bearerOpen: %d", sRet ));
}
For e.g.
void appBearerConnection()
{
wip_inet_aton( "10.1.1.1", &InAddr);
wip_inet_aton( "10.1.1.2", &DstAddr);
/* Configure the bearer */
sRet = wip_bearerSetOpts( appBearer,
WIP_BOPT_IP_SETDNS, FALSE,
WIP_BOPT_IP_SETGW, FALSE,
WIP_BOPT_RESTART, FALSE,
WIP_BOPT_IP_ADDR, InAddr,
WIP_BOPT_IP_DST_ADDR, DstAddr,
WIP_BOPT_END);
TRACE (( 1, "wip_bearerSetOpts: %d", sRet ));
}
434
Open AT® TUTORIAL
For e.g.
/* PPP Server Handler */
s8 appPPPServHandler( wip_bearer_t br, wip_bearerServerEvent_t *event, void *context)
{
TRACE (( 1, "appPPPServHandler: Event %d", event->kind ));
switch (event->kind)
{
case WIP_BEV_PPP_AUTH_PEER:
{
//automatic PPS answer for trusted "Un" and "Pw"...
TRACE (( 1, "WIP_BEV_PPP_AUTH_PEER" ));
TRACE (( 1, "User name provided " ));
TRACE (( 1, event->content.ppp_auth.user ));
event->content.ppp_auth.secret = Pw;
event->content.ppp_auth.secretlen = wm_strlen(Pw);
}
break;
case WIP_BEV_DIAL_CALL:
{
TRACE (( 1, "WIP_BEV_DIAL_CALL" ));
//automatic GSM answer for trusted "PhoneNb"...
event->content.dial_call.phonenb = PhoneNb;
}
break;
}
return TRUE;
}
void appBearerConnection()
{
……
/* Start the PPP server */
sRet = wip_bearerStartServer( appBearer, appPPPServHandler, (void *) NULL);
TRACE (( 1, "wip_bearerStartServer: %d", sRet ));
}
435
Open AT® TUTORIAL
Summary
The following points have been covered in this section
Bearer management is done through one of the following bearers
o GSM
o UART
o GPRS
Sierra Wireless embedded module can be connected to TCP/IP network using
o PPP client using GSM or UART
o PPP Server using GSM or UART
o GPRS
Steps to establish TCP/IP connection using different bearers
436
Open AT® TUTORIAL
CHAPTER 37
IP Stack Channels
1. Objective
This chapter explains the concept of channel and also the associated APIs
2. Introduction
To manage the layered protocol structure of TCP/IP protocol suite, Internet Plug-In uses a concept of “channel”. A
channel is an abstract entity which opens a medium over which communication could occur. For e.g. TCP socket
channel allows user to transfer data to the remote socket using TCP protocol. All protocols in Internet Plug-In are
based on “channel” concept. These channel include:
TCP server channel
TCP and UDP socket channel
Ping channel
3. Architecture
Channels
Implemented Interface
Abstract Interface
In Internet Plug-In, the communication is achieved through channels. Channels are further inherited by
“DataChannel”. DataChannel has all properties of “Channels” and additionally it has functionality to transfer data.
Currently Internet Plug-In supports only two DataChannels
TCP Socket
437
Open AT® TUTORIAL
UDP Socket
TCP server cannot be used to transfer data. To transfer data, it creates a local TCP client socket. This process of
creating local socket is referred as “spawning”. A channel has following method or properties
4. Read/Write Events
Following section describes when and how the Read/Write events are generated.
When some data is received in the buffer, a WIP_CEV_READ event is generated to read the data from the
buffer as depicted in the figure 8. Note that the read event generation indicates the application to read the
data from the buffer using wip_read() API.
For bandwidth optimization over the air, the parameter WIP_COPT_RCV_LOWAT can be configured.
Consider the scenario where the application receives data in chunks. But the requirement is to read the
actual data packet size which is received from the remote end.
E.g. Let us consider that a data packet of size 500 bytes is sent over TCP from the server socket and the
client socket actually receives it in 5 chunks of 100 bytes each. The requirement is to read only 500 bytes at
a time and not chunks of 100 bytes. This necessitates the application to buffer the data and read only a
single chunk of 500 bytes. This could be achieved by setting a parameter WIP_COPT_RCV_LOWAT (i.e. set
to 499) and reading the required amount of data (i.e. 500). The read event will be received:
First time if there is more than WIP_COPT_RCV_LOWAT bytes to read in the socket’s read buffer
When read attempt returns less data than the requested data and there is more than
WIP_COPT_RCV_LOWAT bytes available in the buffer
An added advantage of using the parameter WIP_COPT_RCV_LOWAT includes optimization of bandwidth
over the air. For example, we know that an IP packet includes an overhead. But the same IP packet if
received in chunks will result in a comparatively higher overhead which would in turn affect the bandwidth
utilization.
Let’s consider an example,
438
Open AT® TUTORIAL
WIP_COPT_RCV_BUFSIZE (MAX) has been set to 5840 bytes and WIP_COPT_RCV_LOWAT (MIN) has been
set to 1000 bytes.
In this example, the diagram shown above explains the scenario when READ events are received:
Step 1: Attempt is made to read data (3000 bytes).The buffer is empty as data has not been received, so
no READ event is received and read will fail.
Step 2: Received 1400 bytes of data in the buffer. In this case, READ event will be received as the size of
readable data in the buffer is more than WIP_COPT_RCV_LOWAT, and no READ event has been sent since
the last unsuccessful attempt to read.
Step 3: More data (2100 bytes) is received in the buffer. In this case, READ event will not be received, as
READ event was already received in Step 2. Data is read (3000 bytes) from the buffer. Size of readable data
in the buffer is 500 bytes.
Step 4: Data is read (1500 bytes) from the buffer. Read attempt reads (500 bytes) less data than the
requested data, as the available data in the buffer is less.
Step 5: More data (2000 bytes) is received in the buffer. In this case, since the size of the readable data in
the buffer (2000 bytes) is more than WIP_COPT_RCV_LOWAT, and there has been an incomplete read (at
step 4) since last time a READ event has been received, a new READ event will be received.
Initially when the buffer is empty, WIP_CEV_WRITE event is generated as depicted in the figure 10. The
WIP_CEV_WRITE event is not generated when the buffer has no space to write data. Note that the write
event generation indicates the application to write the data to the buffer using wip_write() API.
For bandwidth optimization over the air, the parameter WIP_COPT_SND_LOWAT can be configured.
439
Open AT® TUTORIAL
In this example, the diagram shown above explains the scenario when WRITE events are received:
Step 1: WRITE event is received as the channel is opened for the first time and the buffer is empty.
Step 2: 4000 bytes of data are written to the buffer. In this case, WRITE event will not be received as
there is still memory (1840 bytes) to write more data
Step 3: Attempt is made to write data (2340 bytes) more than available buffer size. In this case, only 1840
bytes of data is written successfully to the buffer as the free buffer size is 1840 bytes. Remaining data (500
bytes) will be written to the buffer when the free buffer size becomes equal or more than
WIP_COPT_SND_LOWAT.
Step 4: Data is flushed (1340 bytes) from the buffer and now the free buffer is 1340 bytes. In this case,
WRITE event will be received, as the free buffer is more than WIP_COPT_SND_LOWAT and there has been
no WRITE event since last time a WRITE event has been received.
Step 5: Remaining data (500 bytes) is written to the buffer. In this case, WRITE event will not be received,
as there is still memory (840 bytes) to write more data.
5. APIs
Internet Plug-In provide an API wip_close() to close the channel opened during the TCP/UDP socket
communication or while sending a PING request. This API doesn’t raise any events.
Prototype:
Parameters:
Channel: The channel you want to close.
440
Open AT® TUTORIAL
Returned Values:
0 is returned on success.
In case of an error, it returns the following:
WIP_CERR_MEMORY: Insufficient memory
WIP_CERR_INVALID: Specified NULL channel
5.2. Finalizers:
Channels generally reserve some heap memory. Depending on their features, it can take some time
between the call to wip_close function and the actual releasing of the resources. Although the user might
be interested into knowing when a channel closing procedure has been completed, it cannot be reported as
a wip_event_t. Since WIP events are attached to the channel, and by definition, the channel does not exist
after its release.The users should not use a wip_channel_t in any way after wip_close function has been
called on it. If they do, unspecified problems including reboot and memory corruptions might occur. So in
order to let users monitor the completion of a channel closure, most channels can be added with a
finalizer.
A finalizer is a function which is called after the channel has been completely closed and all its associated
resources are freed. Finalizers are attached to channels with the WIP_COPT_FINALIZER option, either in the
wip_xxxCreateOpts function, or in the wip_setOpts function.This option will allow to pass a finalizer
function to the channel.
Prototype:
Parameters:
ctx: context argument
NOTE :
It is illegal to try to access the (recently destroyed) channel in the finalizer.
Prototype:
441
Open AT® TUTORIAL
Parameters:
Channel: The channel of which you want to change the context.
ctx: Pointer to the application context defined for particular instance.
Returned Values:
None
Prototype:
Parameters:
Channel: channel to query the state.
Returned Values:
The various state of the channel that can be returned are:
WIP_CSTATE_BUSY: The channel is still not open, it is being initialized.
WIP_CSTATE_READY: Channel is ready.
WIP_CSTATE_TO_CLOSE: Channel is closed.
Reading data from the channel
There are two mechanisms for using the read API to read data from a particular channel.
Polling mechanism
o Start a cyclic timer of 100 milliseconds.
o When timer expires, read the data from the channel using wip_read() or wip_readOpts()
API. Read using this API till it returns a value 0.
Event Driven
o Wait for a READ event in the channel call-back handler
o When the READ event is received, use wip_read() or wip_readOpts() API to read data.
Read using this API till it returns a value 0.
NOTE : READ event is not received each time the data is received by Internet Plug-In. It is only sent when the
buffer is empty or reached a threshold. The threshold can be set using a Internet Plug-In wip_setOpts() AP
Internet Plug-In provide an API to read the data received for a local socket. This data could be sent by the
remote socket in case of TCP or UDP.
442
Open AT® TUTORIAL
Prototype:
Parameters:
Channel: The channel from which that data should be read.
buffer: The buffer where data will be copied.
buf_len: Length of the buffer.
Returned Values:
The number of bytes read from the channel.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to receive data.
WIP_CERR_NOT_SUPPORTED: This channel does not support data read operation.
Internet Plug-In provide an API wip_readOpts() to read the data with advanced configurable options. This
options include size of receive buffer etc.
Prototype:
Parameters:
Channel: The channel from which data should be read.
buffer: The buffer where data will be copied.
buf_len: Length of the buffer.
Options: These option are dependent on the type of the channel from which the data is to be read. The
options set for the channel should terminate with WIP_COPT_END option.
Returned Values:
The number of bytes read from the channel. If nothing to read, a value 0 is returned.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to read data.
WIP_CERR_NOT_SUPPORTED: This channel does not support data read operation.
443
Open AT® TUTORIAL
Prototype:
Parameters:
Channel: The channel where data should be written.
buffer: The buffer to write.
buf_len: Length of the buffer.
Returned Values:
The number of bytes written to the channel.
In case of an error the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to accept data.
WIP_CERR_NOT_SUPPORTED: This channel does not support data writing operation.
Internet Plug-In provide an API wip_writeOpts() to write data to the channel with advanced configurable
options. In case of the UDP and TCP socket the data written over the channel will be sent to the peer
socket. This API also provide the facility to configure the parameters such as size of the transmission buffer.
Prototype:
444
Open AT® TUTORIAL
Parameters:
Channel: The channel where data should be written.
buffer: The buffer to write.
buf_len: Length of the buffer.
Options: Options are dependent on the type of the channel from which the data is to be written. The
options set for the channel should terminate with WIP_COPT_END option.
Returned Values:
The number of bytes written to the channel.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to accept data
WIP_CERR_NOT_SUPPORTED: This channel does not support data write operation.
WIP_CERR_INVALID: Invalid option
Prototype:
Parameters:
Channel: The channel to configure
Options: The options are dependent on the type of channel. For more information on these parameters,
refer to the particular channel APIs. For e.g. To find information on UDP related parameters, refer to
parameters used for wip_udpCreateOpts() API.
Returned Values:
0 on success
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This channel does not support this operation.
WIP_CERR_INVALID: Invalid option
Internet Plug-In provide an API wip_getOpts() to retrieve the configuration of a channel. The parameters
that can be read are different for TCP and UDP channels.
Prototype:
445
Open AT® TUTORIAL
Parameters:
Channel: The channel from where the configuration should be retrieved.
Options: The options are dependent on the type of channel. For more information on these parameters,
refer to the particular channel APIs. For e.g. To find information on UDP related parameters, refer to
parameters used for wip_udpCreateOpts() API.
Returned Values:
0 on success
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This channel does not support this operation.
WIP_CERR_INVALID: Invalid option.
WIP_CERR_CSTATE: The channel is not ready for retrieving the configuration. This will be returned either
when channel is still initializing or it is already closed.
WIP_CERR_NOT_SUPPORTED: This channel does not support this operation.
Summary
The following points have been covered in this section:
Channel is an abstract entity which opens a medium over which communication occurs.
Following channel are provided by the wip library:
TCP server
TCP socket (Data channel)
UDP socket (Data channel)
Ping
Following operation can be done on a channel:
Set the paramter of the channel.
Write the data to the channel.
Read the data from a channel.
Change the context of the channel.
Get the present state of the channel.
446
Open AT® TUTORIAL
CHAPTER 38
TCP and UDP Socket Service
1. Objective
This chapter will introduce you to TCP and UDP Socket services provided by Internet Plug-In and will explain how to
use them in your Open AT Application. The following topics are discussed in this chapter:
Preliminary tasks to be performed before opening a TCP/UDP socket.
TCP Sockets
Types of TCP sockets.
Configuring a TCP socket.
Creating a TCP Socket.
Transfer of Data
Terminating a TCP socket.
UDP Sockets
Configuring UDP socket.
Creating a UDP Socket.
Transfer of Data
Terminating a UDP socket.
2. Introduction
Sierra Wireless Internet Plug-In allows to transfer data using TCP/UDP sockets.
4. TCP sockets
TCP socket service provides you the capability of exchanging data with any TCP peer in the world. This opens a new
mode of communication for your embedded module. As your embedded module becomes internet enabled, you can
do a multitude of operations like:
447
Open AT® TUTORIAL
You can open a client/server TCP socket and can exchange status information with HTTP hosts. Hence, you can create
web sites which could be used to get data/status information from the embedded module which can be located
anywhere in the world.
You can also write Open AT Application to change embedded module settings using the data obtained from HTTP
hosts. In this way, you can manage/configure your embedded module by sitting in your home/office using a friendly
web interface.
You can create client/server Open AT Application on different embedded module which can then exchange
information over the established TCP sockets.
In addition to this, you can implement protocols like HTTP in your Open AT Application and can directly send HTTP
requests (Get/Post) from your Open AT Application. This increases the power of your Open AT Application.
You do not have to worry about the implementation of TCP socket communication as the Internet Plug-In handles all
the internal intricacies.
Closed
Listen
On reception of a connection request from a remote client socket, a server socket does the following,
Spawns a new socket (client) to connect to the remote socket
Data transfer is done between the spawned socket and the remote socket
Server socket remains in the listening mode and is ready to accept the request from other clients.
448
Open AT® TUTORIAL
Connect request
Client Socket
Spawn a new Spawned
By Server
socket
Connected
Transf er data
Socket
Closed
Closed
Channel
Closed/remote
Two socket are now close
connected and they can
send and receive data. Client Socket Spawned
Client Socket
Create f rom server
Connected
6. Include file
To use the TCP service include the following header file:
wip_tcp.h
Internet Plug-In provide an API wip_TCPServerCreate() to create a TCP server with default options. When a
connection request is received from remote socket, server spawns the client socket.
Prototype:
Parameters:
Port: This parameter indicates the port on which the TCP server will listen for incoming connections.
449
Open AT® TUTORIAL
Range: 1 to 65535.
Type: u16
commHandler: The event handler for client TCP sockets. This handler reacts to events corresponding to the
spawned client sockets and not corresponding to the server socket.
Prototype:
void (*wip_eventHandler_f) ( wip_channel_t Channel,
wip_event_t Event, void *ctx);
Parameters of the call-back handler:
Channel: Defines the communication channel corresponding to the client socket spawned by the server.
Event: Structure indicating the event corresponding to the channel. It also carries the data related to the
corresponding event. The various event and corresponding data that are notified are:
WIP_CEV_OPEN: Connection is established with the remote server. This event is sent when the
spawned socket accepts the connection request sent by the remote socket. In case of the client
socket this event is generated, when server accepts the connection request.
WIP_CEV_READ: This event signifies that the data is being received from the remote socket and
can be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when socket is closed.
ctx: Pointer to application context for a particular instance.
ctx: Pointer to application context for a particular instance.
Returned Values:
Created channel ID
NULL on error
NOTE :
The channel ID assigned to the socket spawned by the server is notified by the event structure.
Each WIP_CEV_WRITE and WIP_CEV_READ event will notify the channel to which the data can be written to or
read from.
Internet Plug-In provide the API wip_TCPServerCreateOpts() to create the socket with the user defined
parameters. This API allows you to configure the various advanced parameters such as transmission buffer
size, receive buffer size etc.
Prototype:
Parameters:
Port: This parameter indicates the port on which the TCP server will listen for incoming connections.
Range: 1 to 65535.
Type: u16
450
Open AT® TUTORIAL
commHandler: The event handler for client TCP sockets. This handler reacts to events corresponding to the
spawned client sockets and not corresponding to the server socket. Refer to section: 6.1 for more details.
ctx: Pointer to application context for a particular instance.
List of options supported by this API. All options must be followed by a variable. In case of get operation,
value will be copied to the variable while in case of set operation, value will be taken from the variable. The
options supported by this API are:
Returned Values:
Created channel ID
NULL on error
451
Open AT® TUTORIAL
/* Channel identifier */
wip_channel_t Channel; /*Channel for the Server*/
wip_channel_t Client_Channel; /*Channel ID for the Client spawned*/
452
Open AT® TUTORIAL
Prototype:
Parameters:
serverAddr: IP address of the server to which the client has to connect.
Port: This parameter indicates the port of server to which the TCP client socket has to connect.
Range: 1 to 65535.
Type: u16
commHandler: This is the call-back function that notifies the event corresponding the client sockets. Refer
to section: 6.1 for more details on commHandler.
ctx: Pointer to the application context.
Returned Values:
Created channel ID
NULL on error
453
Open AT® TUTORIAL
Prototype:
Parameters:
454
Open AT® TUTORIAL
Returned Values:
Created channel ID
NULL on error
switch(Event->kind)
{
case WIP_CEV_READ:
TRACE (( 1, "Inside WIP_CEV_READ"));
Data_Buffer = adl_memGet((u16) (Event->content.read.readable+1));
wm_memset(Data_Buffer,0x00,Event->content.read.readable);
/*Read the data send by the remote party */
Read = wip_read(Channel,Data_Buffer, Event->content.read.readable);
*(Data_Buffer+Read) ='\0';
if(Read>0)
{
/*Send the data read to the external application*/
adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1,Data_Buffer);
adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1,"\r\n");
}
else
455
Open AT® TUTORIAL
{
TRACE (( 1, "Read Error"));
}
_adl_memRelease(&Data_Buffer);
break;
case WIP_CEV_OPEN:
TRACE (( 1, "Inside WIP_CEV_OPEN"));
adl_atSendResponse(ADL_AT_UNS,"Client is connected\r\n");
break;
case WIP_CEV_WRITE:
TRACE (( 1, "Inside WIP_CEV_WRITE"));
Write = wip_write(Channel,"This is a test data",19);
break;
}
}
Internet Plug-In provide an API wip_abort() to abort channel. The channel will not be closed using this API.
Hence channel should be closed using wip_close() when user wants to close the channel. The wip_abort()
API aborts the TCP connection and data is not sent anymore on socket. The wip_close() API clears the
internal data allocated by Internet Plug-In for this channel.
Prototype:
Parameters:
456
Open AT® TUTORIAL
Returned Values:
0 on success
In case of an error a negative value is returned.
WIP_CERR_NOT_SUPPORTED: This value is returned in case this API is used to abort either TCP server or
UDP channel.
WIP_CERR_INTERNAL: This value is returned when there is a internal problems to abort the channel.
Prototype:
Parameters:
Channel: The channel ID of the socket to be shutdown.
read: If this parameter is set to TRUE, input communication over the socket will closed down. In other
words this socket will not be able to receive any data.
write: If this parameter is set to TRUE, then output communication will be closed down for the given
channel. In other words this socket will not be able to send any data.
Returned Values:
0 on success
In case of an error a negative value is returned.
WIP_CERR_NOT_SUPPORTED: This value is returned in case this API is used to shutdown either TCP server
or UDP channel.
WIP_CERR_INTERNAL: This value is returned when there is a internal problems to shutdown the channel.
7. UDP sockets
Like TCP socket services, UDP socket services too allow you to send and receive data (called UDP datagram) from any
UDP entity around the world. The difference between TCP and UDP is that, UDP is a connectionless protocol whereas
TCP is connection oriented protocol.
TCP provides reliable delivery of packets whereas UDP does not. In UDP, a packet (datagram) can be transmitted
without establishing a connection with the peer (i.e. a client can send a datagram without establishing a connection
with UDP server). They do not have a peer socket with which they will exclusively exchange the data. So with each
outbound data the destination IP has to be specified.
457
Open AT® TUTORIAL
The below diagram show the data communication between three UDP sockets. All sockets can send and receive data
between them.
Close
wip_UdpCreate() wip_UdpCreate()
wip_UdpCreate()
Data S1->S2
wip_write() S2 Read Event
wip_read()
Data S1<-S3
Read Event wip_write() S3
wip_read()
Data S2->S3
wip_write() S3 Read Event
wip_read()
wip_close() S2
Close
Prototype:
Parameters:
commHandler: The event handler attached to the UDP socket. This handler reacts to events corresponding
to the UDP.
Prototype:
void (*wip_eventHandler_f) (wip_channel_t Channel, wip_event_t Event, void *ctx)
Parameters of the call-back handler:
Channel: Defines the particular communication channel correspond to the opened UDP socket.
Event: Structure which indicates the type of event corresponding to the channel. This structure
also carries the data related to the corresponding event. The various event and corresponding
data that are notified are:
WIP_CEV_OPEN: This event is sent whenever the socket is open and ready to send and receive
data to the other sockets.
WIP_CEV_READ: This event signifies that the data is received from the remote socket and can be
read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event notifies the error corresponding the channel.
ctx: Pointer to the application context as defined in wip_UDPCreate() API
ctx: Pointer to the application context
458
Open AT® TUTORIAL
Returned Values:
Created channel ID
NULL on error
Internet Plug-In provide the API to create a API with advanced configurable options such as peer port, peer
IP address etc.
Prototype:
Parameters:
459
Open AT® TUTORIAL
Type: ascii
WIP_COPT_BOUND: Specifies if the socket is bound to a peer socket or not.
Type: boolean
WIP_COPT_FINALIZER: Function which is called after the channel has been completely closed using
wip_close function and all its associated resources have been released.
Type: wip_finalizer_f
Returned Values:
Created channel ID
NULL on error
Summary
The following points have been covered in this section
There are two types of TCP socket
o Server Socket
o Client socket
There are two APIs to open TCP server socket.
o wip_TCPServerCreate (socket with default parameter )
o wip_TCPServerCreateOpts(socket with user defined parameters)
There are two API to open a TCP client socket.
o wip_TCPClientCreate (socket with default parameter )
o wip_TCPClientCreateOpts(socket with user defined parameters)
In order to close the socket the API used is
o wip_abort
In order to close a particular communication(input/output) channel for the socket the API used is
o wip_shutdown
A UDP socket is connection less protocol.
At any time a socket can send and receive data from any peer socket, there is no dedicated communication
link between the socket.
In order to open an UDP socket there are two APIs provided.
o wip_UDPCreate (creating a UDP socket with default parameters)
o wip_UDPCreateOpts (creating a UDP socket with user defined parameters)
460
Open AT® TUTORIAL
CHAPTER 39
Management of IP Address
Formats
1. Objective
This chapter explain the APIs available in Internet Plug-In for managing IP address formats.
Prototype:
Parameters:
str: String containing the IP address in standard dot notation format.
addr: The function will fill this variable with address in u32 format.
461
Open AT® TUTORIAL
Returned Values:
TRUE is returned if the string contains a valid IP address.
FALSE is returned if the string does not contains a valid address.
Prototype:
Parameters:
addr: The IP address in u32 format.
buff: Buffer that will be filled with the address in standard dot notation format.
buflen: Length of the buffer.
Returned Values:
TRUE is returned if the provided buffer is long enough to store the IP address
FALSE is returned if buffer is not of sufficient size to store the IP address.
5. Sample Code
case WIP_BEV_IP_CONNECTED:
TRACE (( 1, " WIP_BEV_IP_CONNECTED "));
sRet = wip_bearerGetOpts(Br_Id,
WIP_BOPT_IP_ADDR, &appIpAddr, WIP_BOPT_END);
TRACE (( 1, "wip_bearerGetOpts: %d", sRet));
wip_inet_ntoa(appIpAddr , IpAddr, 15);
Summary
The following points have been covered in this section
Internet Plug-In provide the API to convert the IP address in 32 bit format to dot notation format and vice
versa.
The API provided for this purpose are:
o wip_inet_aton()
o wip_inet_ntoa()
462
Open AT® TUTORIAL
CHAPTER 40
File API for IP services
1. Objective
The Internet Plug-In provide APIs for establishing a connection to FTP/HTTP/SMTP/POP3 server.
Create session channel using wip_xxxClientCreate () or wip_xxxClientCreateOpts () for establishing a connection to the
server
Create data channel using wip_getFile ()/wip_getFileOpts ()/wip_putFile ()/ wip_putFileOpts() for data transfer.
This chapter explain the APIs available in Internet Plug-In for creating data channel which can be used for data
transfer.
2. File APIs
The Internet Plug-In provide APIs for
Creating data channel
Manipulating directory
Setting and retrieving protocol specific options
In order to use this service the header file that need to be included is
wip_file.h
Prototype:
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
file_name: Name of the file to be downloaded from the server
463
Open AT® TUTORIAL
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully for
exchanging data.
WIP_CEV_READ: This event signifies that the data is being received from the server and can
be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
Returned Values:
Prototype:
Parameters:
Returned Values:
Created data channel is returned on success.
NULL is returned on failure.
464
Open AT® TUTORIAL
Internet Plug-In provide an API wip_putFile () to create a data channel for uploading data to the server. This
API will create the data channel with default parameters.
Prototype:
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
file_name: Name of the file to be uploaded to the server
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully for
exchanging data.
WIP_CEV_READ: This event signifies that the data is being received from the server and can
be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
Returned Values:
Prototype:
Parameters:
465
Open AT® TUTORIAL
WIP_CEV_READ: This event signifies that the data is being received from the server and
can be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
...: This specifies the option specific to protocol with the option value. Note that the list must be terminated
by WIP_COPT_END.
Returned Values:
Prototype:
Parameters:
session_ch: Connection channel whose directory needs to be changed
directory_name: Name of the new directory
Returned Values:
Internet Plug-In provide an API wip_mkdir () to create a new directory in the current working directory.
When this API successfully creates the new directory, WIP_CEV_DONE event will be received in the event
handler, otherwise WIP_CEV_ERROR event will be received. During this operation, the channel will be in
WIP_CSTATE_BUSY state indicating that the no operation is allowed on this context till one of these events
are received.
Prototype:
466
Open AT® TUTORIAL
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
directory_name: Name of the new directory that needs to be created
Returned Values:
0 is returned if the new directory creation request has been sent successfully.
Negative error code is returned on failure.
Prototype:
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
file_name: Name of the file to delete
Returned Values:
Internet Plug-In provide an API wip_deleteDir () to delete an empty directory. When this API successfully
deletes a directory, WIP_CEV_DONE event will be received in the event handler, otherwise
WIP_CEV_ERROR event will be received. During this operation, the channel will be in WIP_CSTATE_BUSY
state indicating that the no operation is allowed on this context till one of these events are received.
Prototype:
Parameters:
467
Open AT® TUTORIAL
Returned Values:
0 is returned if the directory deletion request has been sent successfully.
Negative error code is returned on failure.
Internet Plug-In provide an API wip_renameFile () to change the file name. When this API successfully
changes the file name, WIP_CEV_DONE event will be received in the event handler, otherwise
WIP_CEV_ERROR event will be received. During this operation, the channel will be in WIP_CSTATE_BUSY
state indicating that the no operation is allowed on this context till one of these events are received.
Prototype:
Parameters:
Returned Values:
0 is returned if the renaming file request has been sent successfully.
Negative error code is returned on failure.
Internet Plug-In provide an API wip_getFileSize () to retrieve the file size in bytes. When this API successfully
retrieves the file size, WIP_CEV_DONE event will be received in the event handler, otherwise
WIP_CEV_ERROR event will be received.
Prototype:
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
file_name: File name whose size needs to be retrieved
Returned Values:
0 is returned if the retrieving file size request has been sent successfully.
Negative error code is returned on failure.
468
Open AT® TUTORIAL
2.11.Directory Listing
Internet Plug-In provide an API wip_list () for directory listing. Data channel will be created when this API is
called.
Prototype:
Parameters:
session_ch: Connection channel returned by wip_xxxClientCreate() / wip_xxxClientCreateOpts()
dir_name: Name of the directory whose content must be listed
evh: The event handler for the list channel.
Prototype:
void (*wip_eventHandler_f) ( wip_channel_t Channel, wip_event_t Event, void *ctx)
Parameters of the call-back handler:
Channel: Defines the list channel.
Event: Structure indicating the event corresponding to the channel. It also carries the
data related to the corresponding event. The various event and corresponding data that
are notified are:
WIP_CEV_OPEN: This event is sent when the list channel opens successfully.
WIP_CEV_READ: This event signifies that the list data is being received from the server
and can be read using the read API.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the last list data is read.
ctx: Pointer to application context for a particular instance.
ctx: Pointer to application context
Returned Values:
Prototype:
Parameters:
buffer: Memory area where the file info structure will be built
buf_len: Buffer length
…: A list of entry descriptions terminated with WIP_FOPT_END
469
Open AT® TUTORIAL
Returned Values:
Summary
The following points have been covered in this section
FILE APIs are used for creating the data channel which is used for data transfer when
FTP/HTTP/SMTP/POP3 protocol are used.
Following APIs are used for creating data channel
o wip_getFile (creating a data channel with default parameters for downloading data)
o wip_getFileOpts (creating a data channel with user defined parameters for downloading data)
o wip_putFile (creating a data channel with default parameters for uploading data)
o wip_putFileOpts (creating a data channel with user defined parameters for uploading data)
o wip_list (creating list channel for retreiving the details of directory in list format)
Following APIs are used for directory/file manipulation
o wip_cwd (changing the current working directory)
o wip_mkdir (creating new directory)
o wip_deleteFile (deleting file)
o wip_deleteDir (deleting empty directory)
o wip_renameFile (renaming file)
o wip_getFileSize (retreiving file size)
o wip_fileInfoInit (initializing wip_fileInfo_t strcture)
470
Open AT® TUTORIAL
CHAPTER 41
FTP Client
1. Objective
This chapter will introduce you to FTP Client services provided by Internet Plug-In and will explain how to use them in
your Open AT Application.
2. Introduction to FTP
File Transfer Protocol(FTP) is a TCP based service used for uploading/downloading a file from a FTP server. FTP uses
two ports, a data port and a command port. Usually port 21 is used as command port and 20 is used as data port. The
data port need not be 20 always it can be different port as well. There are two modes that FTP can operate:
Active mode
Passive mode
These two modes are initiated by the FTP client, and then acted upon by the FTP server.
In active mode, the client initiates a connection to the FTP server on its port 21 from a random unprivileged port (N >
1024). Port 21 is where the server is listening for commands issued to it, and in turn, which it will respond to. At this
point the client begins to listen on it’s command port + 1, and sends the PORT N+1 command to the server on its port
21. Once this is done the data transfer port (port 20) on the FTP server would initiate a connection to the FTP client’s
command port N+1 The main problem with FTP active mode actually falls on the client side. The FTP client doesn't
make the actual connection to the data port of the server, it simply tells the server what port it is listening on and the
server connects back to the specified port on the client. From the client side firewall this appears to be an outside
system initiating a connection to an internal client, and hence it blocks. The way the FTP gets around this problem is
by using passive FTP. The above scenario is depicted in the figure 16.
471
Open AT® TUTORIAL
In passive mode, the client starts up two connections to the FTP server i.e. it opens two random unprivileged ports
locally (N > 1024 and N+1). The first port contacts the server on port 21, but instead of then issuing a PORT command
and allowing the server to connect back to its data port (as in case of FTP active mode), the client will issue the FTP
PASV command. The result of this is that the server then opens a random unprivileged port (P > 1024) and sends the
PORT P command back to the client. The client then initiates the connection from port N+1 to port P on the server to
transfer data.
In passive mode, the client initiates both connections to the server, solving the problem of firewalls filtering the
incoming data port connection to the client from the server. The above scenario is depicted in the figure 17.
3. FTP APIs
The Internet Plug-In provide APIs for creating session/data channel with FTP protocol.
FTP requests are generated in two phases:
First, FTP session channel must be created using wip_FTPCreate () or wip_FTPCreateOpts (). This channel will store
information such as FTP server address, user name, password etc.
A new data channel is then created using either wip_getFile () / wip_getFileOpts () or wip_putFile ()/ wip_putFileOpts
() API for downloading or uploading file to FTP server.
In order to use this service the header file that need to be included is
wip_ftp.h
Prototype:
472
Open AT® TUTORIAL
Parameters:
server_name: This indicates the FTP server name to which connection should be established. This can be
either provided as DNS name or as a IP address.
evh: Event handler associated with the session channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the session channel is created successfully.
WIP_CEV_ERROR: This event is sent in case of an error.
WIP_CEV_PEER_CLOSE: This event is sent when the FTP server closes the connection.
Ctx: Pointer to application context.
Returned Values:
FTP session channel is returned on success.
NULL is returned on failure.
Prototype:
Parameters:
server_name: This indicates the FTP server name to which connection should be established. This can be
either provided as DNS name or as a IP address.
evh: Event handler associated with the session channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the session channel is created successfully.
WIP_CEV_ERROR: This event is sent in case of an error.
WIP_CEV_PEER_CLOSE: This event is sent when the FTP server closes the connection.
Ctx: Pointer to application context.
…: This provides the list of user defined options with values. The list should be terminated using
WIP_COPT_END.
WIP_COPT_TYPE: This indicates the data format used for transferring the data. By default “I”
type is used for data transmission. This can be either one of the following values:
o I (Image): In this mode, the data will be sent without any translation.
o B(Binary): In this mode, the data will be sent in binary mode.
o A(ASCII): In this mode, the data will be sent in Ascii mode.
WIP_COPT_PASSIVE: This indicates the FTP operation mode. By default FTP is used in Passive
mode. The can be either one of the following values:
o 0 (Active): The mode used for FTP operation is active.
o 1 (Passive): The mode used for FTP operation is passive.
WIP_COPT_USER: This indicates the login name for the FTP server. By default it is set to “anonymous”.
WIP_COPT_PASSWORD: This indicates the password used for authentication. By default it is set to
“wipftp@Sierra Wireless.com”.
473
Open AT® TUTORIAL
Returned Values:
FTP session channel is returned on success.
NULL is returned on failure.
Prototype:
Parameters:
Channel: The FTP session channel to configure
...: List of options supported for this API.
WIP_COPT_END: To mark the termination of the parameter list.
WIP_COPT_KEEPALIVE: To send the NOOP command for every nth second to keep the
connection alive
WIP_COPT_SND_BUFSIZE: The size of the transmission buffer for client socket.
WIP_COPT_RCV_BUFSIZE: The size of the receive buffer for the client socket.
WIP_COPT_SND_LOWAT: Minimum amount of space that should be available in the
transmission buffer. After the buffer is full, it triggers a WIP_CEV_WRITE event.
WIP_COPT_RCV_LOWAT: This parameter signifies the minimum amount of space that should
be available in the receive buffer before it triggers WIP_CEV_READ event.
WIP_COPT_NODELAY: If this flag is set, then data is sent immediately.
WIP_COPT_TOS: Type of service require, refer to RFC 791 for more details.
WIP_COPT_TTL: The time for which the data is valid.
WIP_COPT_TYPE: This indicates the data format used for transferring the data. By default “I”
type is used for data transmission. This can be either one of the following values:
o I (Image): In this mode, the data will be sent without any translation.
o B(Binary): In this mode, the data will be sent in binary mode.
o A(ASCII): In this mode, the data will be sent in Ascii mode.
WIP_COPT_PASSIVE: This indicates the FTP operation mode. By default FTP is used in Passive
mode. The can be either one of the following values:
o 0 (Active): The mode used for FTP operation is active.
o 1 (Passive): The mode used for FTP operation is passive.
474
Open AT® TUTORIAL
WIP_COPT_LIST_PLUGIN: This indicates the plug in handling the results from the LIST FTP
command.
WIP_COPT_FINALIZER: Function which is called after the channel has been completely closed
using wip_close function and all its associated resources have been released.
Returned Values:
0 is returned on success.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This value is returned in case channel does not support this operation.
WIP_CERR_INVALID: This value is returned in case of an invalid option.
Prototype:
Parameters:
Channel: The channel from where the configuration should be retrieved.
…: List of options supported for this API.
WIP_COPT_END: To mark the termination of the parameter list.
WIP_COPT_SND_BUFSIZE: The size of the transmission buffer for client socket.
WIP_COPT_RCV_BUFSIZE: The size of the receive buffer for the client socket.
WIP_COPT_SND_LOWAT: Minimum amount of space that should be available in the
transmission buffer. After the buffer is full, it triggers a WIP_CEV_WRITE event.
WIP_COPT_RCV_LOWAT: This parameter signifies the minimum amount of space that should
be available in the receive buffer before it triggers WIP_CEV_READ event.
WIP_COPT_ERROR: This parameter indicates the error number corresponds to the last error
encountered.
WIP_COPT_NREAD: This parameter indicates the number of bytes that can be currently read
on th socket.
WIP_COPT_NWRITE: This parameter indicates the number of bytes that can be currently
written on the socket.
WIP_COPT_NODELAY: If this flag is set, then data is sent immediately.
WIP_COPT_TOS: Type of service require, refer to RFC 791 for more details.
WIP_COPT_TTL: The time for which the data is valid.
WIP_COPT_PORT: Port occupied by the socket.
WIP_COPT_STRADDR: Local address of the socket in string format.
WIP_COPT_ADDR: Local address of the socket in IP address format.
WIP_COPT_PEER_PORT: Port of the peer socket.
WIP_COPT_PEER_STRADDR: Address of the peer socket in string format.
WIP_COPT_PEER_ADDR: Address of the peer socket in IP address format.
WIP_COPT_SUPPORT_READ: Fails if the channel does not support read operations. Otherwise
it does nothing.
WIP_COPT_SUPPORT_WRITE: Fails if the channel does not support write operations.
Otherwise it does nothing.
475
Open AT® TUTORIAL
WIP_COPT_TYPE: This indicates the data format used for transferring the data. By default “I”
type is used for data transmission. This can be either one of the following values:
o I (Image): In this mode, the data will be sent without any translation.
o B(Binary): In this mode, the data will be sent in binary mode.
o A(ASCII): In this mode, the data will be sent in Ascii mode.
WIP_COPT_PASSIVE: This indicates the FTP operation mode. By default FTP is used in Passive
mode. The can be either one of the following values:
o 0 (Active): The mode used for FTP operation is active.
o 1 (Passive): The mode used for FTP operation is passive.
WIP_COPT_LIST_PLUGIN: This indicates the plug in handling the results from the LIST FTP
command.
Returned Values:
0 is returned on success.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This value is returned in case this channel does not support this operation.
WIP_CERR_INVALID: This value is retunred when invalid option is provided.
WIP_CERR_CSTATE: The channel is not ready for retrieving the configuration. This will be returned either
when channel is still initializing or it is already closed.
3.5. Creating FTP Data Channel Without Options for Downloading File
Internet Plug-In provide an API wip_getFile () to create a data channel for downloading data from the FTP
server. This API will create the data channel with default parameters.
Prototype:
wip_channel_t wip_getFile( wip_channel_t session_ch, ascii *file_name, wip_eventHandler_f
evh, void *ctx)
Parameters:
session_ch: Connection channel returned by wip_FTPCreate() / wip_FTPCreateOpts()
file_name: Name of the file to be downloaded from the server
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully for
exchanging data.
WIP_CEV_READ: This event signifies that the data is being received from the server and can
be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
Returned Values:
476
Open AT® TUTORIAL
Prototype:
Parameters:
session_ch: Connection channel returned by wip_FTPCreate() / wip_FTPCreateOpts()
file_name: Name of the file to be downloaded from the server
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully for
exchanging data.
WIP_CEV_READ: This event signifies that the data is being received from the server and can
be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
...: This specifies the option specific to protocol with the option value. Note that the list must
be terminated by WIP_COPT_END.
WIP_COPT_FILE_NAME: Name of the file to be downloaded.
WIP_COPT_RESTART: Restart the download after the nth byte.
Returned Values:
Created data channel is returned on success.
NULL is returned on failure.
Prototype:
Parameters:
477
Open AT® TUTORIAL
WIP_CEV_OPEN: This event signifies that the data channel is created successfully for
exchanging data.
WIP_CEV_READ: This event signifies that the data is being received from the server and can
be read using the read API.
WIP_CEV_WRITE: This event signifies that Internet Plug-In is ready to send data.
WIP_CEV_ERROR: This event is sent in case of an error
WIP_CEV_PEER_CLOSE: This event is sent when the complete data is downloaded.
Ctx: Pointer to application context.
Returned Values:
Prototype:
Parameters:
Returned Values:
Created data channel is returned on success.
NULL is returned on failure.
478
Open AT® TUTORIAL
Internet Plug-In provide an API wip_read() which is used to read the file data. Note that this function is not
supported by FTP session channel.
Prototype:
Parameters:
Channel: FTP data channel returned by either wip_getFile () / wip_getFileOpts () / wip_putFile () /
wip_putFileOpts ()
buffer: The buffer where data will be copied.
buf_len: Length of the buffer.
Returned Values:
Prototype:
Parameters:
Channel: FTP data channel returned by either wip_getFile () / wip_getFileOpts () / wip_putFile () /
wip_putFileOpts ().
buffer: The buffer to write.
buf_len: Length of the buffer.
Returned Values:
The number of bytes written to the channel.
In case of an error the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to accept data.
WIP_CERR_NOT_SUPPORTED: This channel does not support data writing operation.
479
Open AT® TUTORIAL
Internet Plug-In provide an API wip_shutdown() to shut either the input or output communication of a
given socket. If both communications are shut down, the socket is closed. This API is used to indicate the
end of file while uploading the file to the FTP server.
Prototype:
Parameters:
Channel: The channel ID of the socket to be shutdown.
read: If this parameter is set to TRUE, input communication over the socket will closed down. In other
words this socket will not be able to receive any data.
write: If this parameter is set to TRUE, then output communication will be closed down for the given
channel. In other words this socket will not be able to send any data.
Returned Values:
0 is returned on success.
In case of an error a negative value is returned.
WIP_CERR_NOT_SUPPORTED: This value is returned in case this API is used to shutdown either TCP server
or UDP channel.
WIP_CERR_INTERNAL: This value is returned when there is a internal problems to shutdown the channel.
Prototype:
Parameters:
Returned Values:
0 is returned on success.
In case of an error, it returns the following:
WIP_CERR_MEMORY: Insufficient memory
WIP_CERR_INVALID: Specified NULL channel
480
Open AT® TUTORIAL
4. Sample Code
#include "adl_global.h"
#include "wip_net.h"
#include "wip_bearer.h"
#include "wip_ftp.h"
#define FTP_PORT 21
#define FTP_MODE 1
const ascii * FTP_TYPE = 'A';
const ascii * FTP_STR_HOSTNAME = "81.80.89.163";
const ascii * FTP_STR_USERNAME = "ndt-ftp";
const ascii * FTP_STR_PASSWORD = "ndt-ftp";
const ascii * FTP_FILENAME = "./test.txt";
TRACE((1,"ftpDataHandler: WIP_CEV_READ"));
while( wip_read(ftpDataCh, buf, 256 ) > 0 )
{
TRACE((1, buf));
}
}
481
Open AT® TUTORIAL
break;
case WIP_CEV_WRITE:
TRACE((1,"ftpDataHandler: WIP_CEV_WRITE"));
break;
case WIP_CEV_PEER_CLOSE:
TRACE((1,"ftpDataHandler: WIP_CEV_PEER_CLOSE"));
wip_close(ftpDataCh);
wip_close(ftpCnxCh);
break;
case WIP_CEV_ERROR:
TRACE((1,"ftpDataHandler: WIP_CEV_ERROR"));
break;
}
}
482
Open AT® TUTORIAL
WIP_COPT_PASSWORD, FTP_STR_PASSWORD,
WIP_COPT_PASSIVE, FTP_MODE,
WIP_COPT_TYPE, FTP_TYPE,
WIP_COPT_PEER_PORT, FTP_PORT,
WIP_COPT_END);
TRACE (( 1, "wip_FTPCreateOpts: %x",ftpCnxCh ));
break;
case WIP_BEV_CONN_FAILED:
TRACE (( 1, "evh_bearer: <WIP_BEV_CONN_FAILED>"));
wip_bearerClose( bearerHandle );
break;
case WIP_BEV_STOPPED:
TRACE (( 1, "evh_bearer: <WIP_BEV_STOPPED>"));
wip_bearerClose(bearerHandle );
break;
default:
TRACE (( 1, "evh_bearer: <Other Events>"));
break;
}
}
483
Open AT® TUTORIAL
Summary
The following points have been covered in this section
FTP APIs are used for creating FTP session and data channel.
Following APIs are used for creating FTP session channel
o wip_FTPCreate (creating a FTP session channel with default parameter)
o wip_FTPCreateOpts (creating a FTP session channel with userd defined parameters)
Following APIs are used for creating FTP data channel
o wip_getFile (creating a data channel with default pa
o rameters for downloading file)
o wip_getFileOpts (creating a data channel with user defined parameters for downloading file)
o wip_putFile (creating a data channel with default parameters for uploading file)
o wip_putFileOpts (creating a data channel with user defined parameters for uploading file)
wip_getOpts API is used for retrieving the configuration parameters from the FTP session channel
wip_setOpts API is used for configuring the parameters of the FTP session channel
wip_read API is used for reading file data from the FTP data channel
wip_write API is used for writing file data to the FTP data channel
wip_shutdown API is used for shutting down the FTP data channel
wip_close API is used for closing both FTP session and data channel
484
Open AT® TUTORIAL
CHAPTER 42
HTTP Client
1. Objective
This chapter will introduce you to HTTP Client services provided by Internet Plug-In and will explain how to use them
in your Open AT Application.
2. Introduction to HTTP
HTTP is an application level protocol of the TCP/ IP suite, which is used to deliver virtually all files and other data on
the World Wide Web. It is used to transmit resources that are identified by a URL. The most common kind of a
resource can be a file, but it can also be dynamically generated content, which is the result of execution of a script or
an application on the server.
HTTP is a request / response based protocol operating between Web Clients and Web Servers. A browser is also
known as a HTTP Client because it sends requests to a HTTP server. HTTP servers listen and respond to incoming
requests.
485
Open AT® TUTORIAL
Thus, the Client sends a request to the server (HTTP Request ). The server processesthe request and sends a response
to the client (HTTP Response).
4. HTTP Request
The HTTP request has the following message format for transferring entities:
A Request line
Zero or more header lines
A Blank line which separates the headers from the message body
Message body
The Request line of the HTTP request (from a client to a server) includes:
The method to be applied on the resource
The identifier of the resource
The HTTP protocol version in use
The Method field in request line of HTTP indicates the method to be performed on the object identified by the URL.
Some of the methods are listed below:
GET
HEAD
POST
PUT
DELETE
486
Open AT® TUTORIAL
http://10.66.67.207/index.html
Protocol
Method URI
Version
The second part of the request line is the Uniform Resource Identifier (URI) that identifies the resource upon which
the request has to be applied. The last part of the request line specifies the version of HTTP.
The request also contains optional header lines. It provides additional information about the request to the server. For
example,
User_Agent is a header that indicates the type of client being used.
User_Accept indicates to the server, the type of data that the client can accept
In the HTTP request message, the message body is optional and it is influenced by the choice of the method.
5. HTTP Response
In response to a HTTP Request sent by a HTTP Client (Web Browser typically), the server sends a HTTP Response. The
HTTP response to requests is usually a program output (Dynamic content ) and not a static file.
The first line of a Response message is the Status-Line. It consists of:
The protocol version
Numeric status code
Description of the status code
HTTP Status Codes: The response status line contains the status of processing of the HTTP Request. In case
of success, it will contain the status code 200 and description is OK. The status line in this case will be “HTTP/ 1. 0 200
OK“.
In case of Error, the server sends an appropriate error code back to the client . The HTTP error codes are standardized.
Some of the commonly found error codes:
HTTP/ 1. 0 404 Not Found
HTTP/ 1. 0 500 Internal Server Error
The Error/Success codes of the HTTP response are standardized in the following manner:
1xx: indicates informational message only
2xx: indicates success of some kind
3xx: redirects the client to another URL
4xx: indicates an error on the client' s part
5xx: indicates an error on the server' s part
487
Open AT® TUTORIAL
<html>
<head>
<title> Welcome to Wavecom </title>
</head>
<body>
HTTP Message Body …..
</body>
7. HTTP Methods
HTTP method specifies the approach that is to be applied on a resource identified by URL. HTTP has many methods.
The most commonly used ones are GET, POST and HEAD methods.
GET Method: The GET method is the most frequently used method. It is used by default to get static content. This
method can also be used to submit data from a HTML web page to the server. In GET method, the data submitted will
be sent as part of the URL. Hence, in GET method parameters are encoded and passed along with the URL. Usually,
parameters are passed as name-value pairs. As GET method sends data as part of URL, there is a physical restriction
on the size of it being sent.
POST Method: A POST method is used to send data as part of the HTTP message body. In certain cases, the client may
need to send megabytes of information. In these situations, POST method is the right choice.
A POST request passes all its data of unlimited length, directly as part of its HTTP request body. The exchange is
invisible to the client. The URL does not contain the data submitted. Consequently, POST requests cannot be book
marked or emailed or in some cases, even reloaded. Hence, confidential information sent to the server, such as the
credit card number, should be sent via POST method. Moreover, because GET requests can be easily book marked,
they should not be used in situations like placing an order or updating a database.
Note: Never use GET method when passing sensitive data like passwords, credit card numbers, etc.
HEAD Method: The HEAD method is similar to the GET method, except that it asks the server to return only the
Response headers and not the content (i.e., No Message Body). This method is useful for the clients to check the
characteristics of the resource without actually downloading it, thus saving bandwidth. The HTTP Clients usually use
the HEAD method when they do not need the file' s contents.
HEAD method is used for example:
To determine the document's size
To know document's modification time
To know general availability of a web page
488
Open AT® TUTORIAL
PUT Method: The PUT method can be used to put a page at a specific URL. If there’s already a page there, it deletes
the existing page and creates the new page. If there’s no page there, a new one is created. The PUT method is a much
more limited operation that never does anything more than PUT one page at a specified URL.
Both PUT and POST can be used to create new pages. However PUT should be used when the client specifies the
location for the page. PUT is normally the right protocol for a web editor like DreamWeaver or BBEdit. POST is used
when the client sends the page to the server, and the server then tells the client where to put the page. POST is
normally the right protocol for a blog editor like TypePad or anything that inputs into a content management system.
DELETE Method: The DELETE method is used to delete the resource identified by the Request URI. Note that all the
servers don’t support this method as this method can be used by the client to delete the resource at the server.
NOTE :
DELETE method is optional and some servers may not support the same.
8. HTTP Versions
HTTP 1.0 was the original version. In HTTP 1.0, the client would initiate and close the connection to the server on each
request. For example, if a page index.html is accessed by the client and the page contains ten image files in its body,
the browser would have to initiate and close the connection eleven times. i.e., the client opens a new TCP/ IP
connection and places a request for the resource (first request ). On receipt of the response, the connection is closed.
Further, similar request - reply transaction (ten transactions) happens for each picture to be downloaded.
Performance problems with HTTP1.0: HTTP 1.0 suffers from poor performance because it makes new TCP/ IP
connection for every request . This significantly increases the overhead associated with opening those connections.
Further, the client is not able to send requests until the reply to the previous one has been received. The performance
becomes worse when the network is busy.
The latest version of HTTP is HTTP 1.1. In this version of HTTP, the connection established is maintained until the
browser is closed. This feature is known as persistent connection. Persistent connections allow many requests to
occur within a single TCP/ IP connection. i.e. , instead of opening multiple TCP connections for each object to be
retrieved, one TCP/ IP connection is opened and multiple HTTP requests are issued through that connection.
9. HTTP APIs
The Internet Plug-In provide APIs for generating HTTP requests. The Sierra Wireless Internet Plug-In provide following
features:
Support for HTTP version 1.1 (default) and 1.0
Persistent connections (with HTTP 1.1)
Connection to a HTTP proxy server
Basic and digest (MD5) authentication
Chunked transfer coding
Setting HTTP request headers
Getting HTTP response headers
GET, HEADER, POST and PUT methods
First, HTTP request channel must be created using wip_HTTPClientCreate () or wip_HTTPClientCreateOpts (). This
channel will store information such as HTTP version, address of proxy server, HTTP request header which are common
489
Open AT® TUTORIAL
to all further HTTP requests. Note that, when HTTP 1.1 is used, a new TCP channel is not created for each request is
sent to the same server or proxy, instead the TCP connection is maintained by the HTTP session whenever possible.
A new data channel is then created using either wip_getFile () / wip_getFileOpts () or wip_putFile ()/ wip_putFileOpts
() API for each HTTP GET/HEADER/POST/PUT request.
In order to use this service the header file that need to be included is
wip_http.h
Internet Plug-In provide an API wip_HTTPClientCreate () to create the HTTP session channel. This API will
create the HTTP session channel with default parameters.
Prototype:
Parameters:
evh: Event handler associated with the session channel. Currently, there is no event defined for HTTP
session and hence it can be set to NULL.
Ctx: Pointer to application context.
Returned Values:
Prototype:
Parameters:
evh: Event handler associated with the session channel. Currently, there is no event defined for HTTP
session and hence it can be set to NULL.
Ctx: Pointer to application context.
…: This provides the list of user defined options with values. The list should be terminated using
WIP_COPT_END.
WIP_COPT_END: To mark the termination of the parameter list.
WIP_COPT_RCV_BUFSIZE: Sets the size of the TCP socket receive buffer.
WIP_COPT_SND_BUFSIZE: Sets the size of the TCP socket send buffer.
490
Open AT® TUTORIAL
WIP_COPT_PROXY_STRADDR: Sets the hostname of the HTTP proxy server, a NULL value disables
the proxy server.
WIP_COPT_PROXY_PORT: Sets the port number of the HTTP proxy server, the default value is 80.
WIP_COPT_HTTP_VERSION: Defines the HTTP version to be used by the session.
WIP_COPT_HTTP_HEADER: This option adds a HTTP message header field that will be sent on each
request. The first value is the field name (without the colon), the second value is the field value
(without CRLF), a NULL value can be passed to remove a previously defined header field.
WIP_COPT_HTTP_HEADER_LIST: This option adds a list of HTTP message header fields to send with
each request. The value points to an array of wip_httpHeader_t structures, the last element of the
array has its name field set to NULL.
WIP_COPT_FINALIZER: Function which is called after the channel has been completely closed using
wip_close function and all its associated resources have been released.
Returned Values:
HTTP session channel, a positive integer, is returned on success.
NULL is returned on failure.
9.3. Creating HTTP Data Channel Without Options for Downloading URL Data
Internet Plug-In provide an API wip_getFile () to create a data channel for downloading data from the
specified URL. This API will create the data channel with default parameters. When this API is used, HTTP
GET method is used to send request.
Prototype:
Parameters:
session_ch: Session channel returned by wip_HTTPClientCreate() / wip_HTTPClientCreateOpts()
url: Name of the URL to which HTTP request has to be sent.
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully. This event is
received when response message header has been received. The wip_getOpts () API can be used
to retrieve the header information:
WIP_COPT_HTTP_STATUS_CODE: 3-digit response status code
WIP_COPT_HTTP_STATUS_REASON: the reason phrase
WIP_COPT_HTTP_HEADER: value of response header fields.
WIP_CEV_READ: This event signifies that the response message body data is being received from
the server and can be read using the read API.
WIP_CEV_WRITE: This event is sent when request message body data can be written by the
application using write API.
WIP_CEV_ERROR: This event is sent in case of an error.
WIP_CEV_PEER_CLOSE: This event is sent after the entire response message, including response
header and response body data, has been received.
Ctx: Pointer to application context.
491
Open AT® TUTORIAL
Returned Values:
Created data channel is returned on success.
NULL is returned on failure.
9.4. Creating HTTP Data Channel With Options for Downloading URL Data
Internet Plug-In provide an API wip_getFileOpts () to create a data channel for downloading data from the
specified URL. This API will create the data channel with user defined parameters.
Prototype:
Parameters:
492
Open AT® TUTORIAL
Returned Values:
Created data channel is returned on success.
NULL is returned on failure.
9.5. Creating HTTP Data Channel Without Options for Uploading URL Data
Internet Plug-In provide an API wip_putFile () to create a data channel for uploading data to the specified
URL. This API will create the data channel with default parameters. When this API is used, HTTP PUT
method is used to send request.
Prototype:
Parameters:
session_ch: Session channel returned by wip_HTTPClientCreate() / wip_HTTPClientCreateOpts()
url: Name of the URL to which HTTP request has to be sent.
evh: Event handler associated with the data channel. This handler receive following events:
WIP_CEV_OPEN: This event signifies that the data channel is created successfully. This event is
received when response message header has been received. The wip_getOpts () API can be used
to retrieve the header information:
WIP_COPT_HTTP_STATUS_CODE: 3-digit response status code
WIP_COPT_HTTP_STATUS_REASON: the reason phrase
WIP_COPT_HTTP_HEADER: value of response header fields.
WIP_CEV_READ: This event signifies that the response message body data is being received from
the server and can be read using the read API.
WIP_CEV_WRITE: This event is sent when request message body data can be written by the
application using write API.
WIP_CEV_ERROR: This event is sent in case of an error.
WIP_CEV_PEER_CLOSE: This event is sent after the entire response message, including response
header and response body data, has been received.
Ctx: Pointer to application context.
Returned Values:
9.6. Creating HTTP Data Channel With Options for Uploading URL Data
Internet Plug-In provide an API wip_putFileOpts () to create a data channel for uploading data to the
specified URL. This API will create the data channel with user defined parameters.
493
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
Internet Plug-In provide an API wip_read () which is used to read the response message body. Note that
this function is not supported by HTTP session channel.
494
Open AT® TUTORIAL
Prototype:
Parameters:
Channel: HTTP request channel returned by either wip_getFile () / wip_getFileOpts () / wip_putFile () /
wip_putFileOpts ()
buffer: The buffer where data will be copied.
buf_len: Length of the buffer.
Returned Values:
The number of bytes read from the channel is returned on success.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to receive data
WIP_CERR_NOT_SUPPORTED: This channel does not support data read operation
Prototype:
Parameters:
Returned Values:
The number of bytes written to the channel is returned on success.
In case of an error the various negative error codes that are returned are described below:
WIP_CERR_CSTATE: The channel is not ready to accept data.
WIP_CERR_NOT_SUPPORTED: This channel does not support data writing operation.
Internet Plug-In provide an API wip_shutdown() to shut either the input or output communication of a
given socket. If both communications are shut down, the socket is closed. on a request channel to signals
the end of the message body, it has no effect if the request has no message body. Note that this function is
not supported by HTTP session channel.
495
Open AT® TUTORIAL
Prototype:
Parameters:
Returned Values:
0 is returned on success.
In case of an error a negative value is returned.
WIP_CERR_NOT_SUPPORTED: This value is returned in case this API is used to shutdown either TCP server
or UDP channel.
WIP_CERR_INTERNAL: This value is returned when there is a internal problems to shutdown the channel.
Prototype:
Parameters:
496
Open AT® TUTORIAL
WIP_COPT_FINALIZER: Function which is called after the channel has been completely closed using
wip_close function and all its associated resources have been released.
Returned Values:
0 is returned on success.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This channel does not support this operation.
WIP_CERR_INVALID: Invalid option.
Retrieving the Configuration of a HTTP Session/Data Channel
Internet Plug-In provide an API wip_getOpts() to retrieve the configuration of a HTTP Session channel.
Prototype:
s32 wip_getOpts(wip_channel_t Channel,…)
Parameters:
Channel: HTTP session channel from where the configuration should be retrieved.
…: List of options supported for this API.
Following are the options supported by HTTP session channel:
WIP_COPT_END: To mark the termination of the parameter list.
WIP_COPT_SND_BUFSIZE: The current size of the TCP socket send buffer.
WIP_COPT_RCV_BUFSIZE: The current size of the TCP socket receive buffer.
WIP_COPT_PROXY_STRADDR: The hostname of the HTTP proxy server, a NULL value disables the
proxy server.
WIP_COPT_PROXY_PORT: The port number of the HTTP proxy server, the default value is 80.
WIP_COPT_HTTP_VERSION: The HTTP version to be used by the session.
Following are the options supported by HTTP data channel:
WIP_COPT_END: To mark the termination of the parameter list.
WIP_COPT_HTTP_STATUS_CODE: The 3-digit status code of the response.
WIP_COPT_HTTP_STATUS_REASON: The reason phrase of the response, the first value points to
the buffer where the reason phrase is to be written, the second value is the size of the buffer.
WIP_COPT_HTTP_HEADER: The value of the HTTP message header field with the name given by
the first value, the second value points to the buffer where the field value is to be written, the
third value is the size of the buffer.
Returned Values:
0 is returned on success.
In case of an error, the various negative error codes that are returned are described below:
WIP_CERR_NOT_SUPPORTED: This channel does not support this operation.
WIP_CERR_INVALID: Invalid option.
WIP_CERR_CSTATE: The channel is not ready for retrieving the configuration. This will be returned either
when channel is still initializing or it is already closed.
Aborting a HTTP session Channel
Internet Plug-In provide an API wip_abort() to abort and close the HTTP session channel. Note that this API
is supported only by HTTP session channel.
Prototype:
s32 wip_abort (wip_channel_t Channel);
Parameters:
Channel: The HTTP session channel which has to be aborted.
497
Open AT® TUTORIAL
Returned Values:
0 is returned on success.
In case of an error a negative value is returned.
WIP_CERR_NOT_SUPPORTED: This value is returned in case this API is used to abort either TCP server or
UDP channel.
WIP_CERR_INTERNAL: This value is returned when there is a internal problems to abort the channel.
Closing HTTP Session/Data channel
Internet Plug-In provide an API wip_close() to close the HTTP session or data channel. When this API is used
to close HTTP session channel, it releases all the resources associated with the session channel. Note that
closing session channel will not close the data channel. The data channel should be closed explicitly by
calling this function. Closing the data channel will make the session ready for another request.
Prototype:
s32 wip_close(wip_channel_t Channel)
Parameters:
Channel: HTTP session or data channel that should be closed.
Returned Values:
0 is returned on success.
In case of an error, it returns the following:
WIP_CERR_MEMORY: Insufficient memory
WIP_CERR_INVALID: Specified NULL channel
#define HTTP_PORT 80
const ascii * HTTP_STR_HOSTNAME = "http://koivi.com/php-http-auth/protect.php";
const ascii * HTTP_STR_USERNAME = "tester";
const ascii * HTTP_STR_PASSWORD = "testing";
const ascii * HTTP_URLNAME = "http://koivi.com/php-http-auth/protect.php";
498
Open AT® TUTORIAL
TRACE((1,"httpDataHandler: WIP_CEV_READ"));
while( wip_read(httpDataCh, buf, 256 ) > 0 )
{
TRACE((1, buf));
}
}
break;
case WIP_CEV_WRITE:
TRACE((1,"httpDataHandler: WIP_CEV_WRITE"));
break;
case WIP_CEV_PEER_CLOSE:
TRACE((1,"httpDataHandler: WIP_CEV_PEER_CLOSE"));
wip_close(httpDataCh);
wip_close(httpCnxCh);
break;
case WIP_CEV_ERROR:
TRACE((1,"httpDataHandler: WIP_CEV_ERROR"));
break;
}
}
499
Open AT® TUTORIAL
WIP_COPT_END);
TRACE (( 1, "wip_getFileOpts: %x",httpDataCh ));
}
500
Open AT® TUTORIAL
Summary
The following points have been covered in this section
HTTP APIs are used for creating HTTP session and data channel.
Following APIs are used for creating HTTP session channel
o wip_HTTPClientCreate (creating a HTTP session channel with default parameter)
o wip_HTTPClientCreateOpts (creating a HTTP session channel with userd defined parameters)
Following APIs are used for creating HTTP data channel
o wip_getFile (creating a data channel with default pa
o rameters for downloading file)
o wip_getFileOpts (creating a data channel with user defined parameters for downloading file)
o wip_putFile (creating a data channel with default parameters for uploading file)
o wip_putFileOpts (creating a data channel with user defined parameters for uploading file)
wip_getOpts API is used for retrieving the configuration parameters from the HTTP session channel
wip_setOpts API is used for configuring the parameters of the HTTP session channel
wip_read API is used for reading file data from the HTTP data channel
wip_write API is used for writing file data to the HTTP data channel
wip_shutdown API is used for shutting down the HTTP data channel
wip_abort API is used for aborting the HTTP data channel
wip_close API is used for closing both HTTP session and data channel
501
Open AT® TUTORIAL
502
Open AT® TUTORIAL
Appendix
APPENDIX
Abbreviations and Acronyms
The following table lists the abbreviations that you will encounter in this document:
Abbreviation/Acronym Description
A&D Application And Data Storage
ADL Application Development Layer
ADC Analog to Digital Converter
APDU Application Protocol Data Unit
API Application Programming Interface
APN Access Point Name
ARPANET Advanced Research Projects Agency NETwork (U.S. Department of Defense)
ASCII American Standard Code for Information Interchange
AT Attention
CGPS Companion Global Positioning System
Cid Context Identifier
CLIP Caller Line Identification Presentation
CHAP Challenge-Handshake Authentication Protocol
CTS Clear To Send signal
DHCP Dynamic Host Configuration Protocol
DNS Domain Name System
DOTA Download Over The Air
DSR Data Set Ready
DTMF Dual Tone Multi Frequency
EDGE Enhanced Data for Global Evolution
EEPROM Electrically Erasable Programmable Read Only Memory
EXTINT External Interruption
FCM Flow Control Manager
FIFO First In First Out
FTP File Transfer Protocol
GCC GNU Compiler Collection
GPI General Purpose Input
GPIO General Purpose Input Output
GPO General Purpose Output
GPRS General Packet Radio Service
GPS Global Positioning System
GSM Global System for Mobile communication
HTTP Hyper Text Transfer Protocol
I2C Inter Integrated Circuit
IDE Integrated Development Environment
IP Internet Protocol
503
Open AT® TUTORIAL
Appendix
Abbreviation/Acronym Description
IO Input Output
JRE Java Runtime Environment
LIFO Last In First Out
LSB Least Significant Byte
MO Mobile Originated
MS Mobile Station
MSB Most Significant Byte
MSCHAP v1 Microsoft Challenge Handshake Authentication Protocol version 1
MSCHAP v2 Microsoft Challenge Handshake Authentication Protocol version 2
MT Mobile Terminated
OASiS Open AT Embedded Software Suite
OS Operating System
OSA Open Sim Access
OSI Open Systems Interconnect
PAP Password Authentication Protocol
PASV FTP command to enter passive mode
PC Personal Computer
PDF Portable Document Format
PDP Packet data Protocol
PDU Protocol Data Unit
PIN Personal Identification Number
POP3 Post Office Protocol Version 3
PPP Point–to–Point Protocol
PUK Personal Unblocking Key
AirPrime Q24 Series AirPrime Q24 Classic, AirPrime Q24Plus, AirPrime Q24 Extended and AirPrime Q24 Auto
RAM Random Access Memory
RFC Request for Comments
ROM Read Only Memory
RTE Remote Task Execution
RTOS Real Time Operating System
SC Service Centre
SDK Software Development Kit
SGT Software Generation Toolkit
SIM Subscriber Identity Module
SME Short Message Entity
SMS Short Message Services
SMMT Short Message Mobile Terminated
SMMO Short Message Mobile Originated
SMTP Simple Mail Transfer Protocol
SPI Serial Peripheral Interface
TCP Transmission Control Protocol
TCU Timer & Capture Unit
UART Universal Asynchronous Receiver& Transmitter
UDP User Datagram Protocol
UMTS Universal Mobile Telecommunications System
URI Universal Resource Identifier
504
Open AT® TUTORIAL
Appendix
Abbreviation/Acronym Description
URL Universal Resource Locator
USB Universal Serial Bus
WAP Wireless Application Protocol
WIP Sierra Wireless Internet Plug-In
505
Open AT® TUTORIAL
Appendix
Glossary
The following table lists and describes the technical terms that you will find in this document.
Term Description
Dual Tone Multi Frequency The type of audio signals that are generated when the buttons on a touch-tone
(DTMF) telephone are pressed. Pressing a button generates two simultaneous tones which
are decoded by the exchange to determine which key is pressed.
Embedded application Open AT Application sources to be compiled and run on a Sierra product.
Embedded software Open AT Application binary: Set of Open AT Application and Open AT OS.
External application Application external to Sierra product that sends AT commands through the serial
port.
Gain The amount of increase that an amplifier provides on the output side of the circuit.
GPS External mode The GPS embedded module is driven by an external host. The GSM embedded
module cannot control or detect GPS frames.
GPS Internal mode The GPS embedded module is driven by the GSM embedded module.
Melody A melody is a succession of tones of varying pitch forming a distinctive sequence.
Pre–parsing Process for intercepting AT commands and AT responses.
Protocol Data Unit The Protocol Data Unit contains the SMS content along with required header
information as a part of it.
Remote Mode An Open AT Application execution mode where the Open AT Application is
executed on a simulated environment on the PC without actually downloading it on
the target embedded module.
Short Message Entity An entity which may send or receive Short Messages. The SME may be located in a
fixed network, a mobile, or a SMSC (Short Messages Service Centre).
Short Message Service The SMS (Short Messaging Service) that allows a SME (Short Message Entity) to
send short text messages to other SME.
Short Message Service Centre To allow SMS (Short Message Service) messages to be sent from your mobile phone
you will require a SMSC number. This will instruct your mobile phone to send all
SMS messages to this centre. The SMSC forwards the short message to the
indicated destination subscriber number.
Target Mode The Open AT Application is downloaded on the actual target (WISMO embedded
module) and is executed in the real time environment.
Tone Tone represents a sound of fixed pitch of a unique single frequency only.
Xmodem Protocol File transfer protocol for transferring files over serial lines. XMODEM uses 128-byte
packets with error detection, allowing the receiver to request retransmission of
corrupted packets. XModem is fairly slow but reliable.
Embedded application Open AT Application sources to be compiled and run on a Sierra Wireless product.
Firmware A binary file which manages the lower level functionality (hardware and software
(such as GSM and GPRS protocol)).
Internet Plug-In Sierra Wireless Internet Plug-In is a Plug-In provided with Open AT OS which can be
used for creating sockets, FTP, SMTP, HTTP and POP3 sessions.
Embedded module Open AT OS compatible product supporting an Open AT Application.
506
Open AT® TUTORIAL
Appendix
Copyright
© 2012 Sierra Wireless. All rights reserved.
Trademarks
AirCard® and “Heart of the Wireless Machine®” are filed or registered trademarks of Sierra Wireless. Watcher® is a
trademark of Sierra Wireless, registered in the European Community. Sierra Wireless, the Sierra Wireless logo, the red
wave design, and the red-tipped antenna are trademarks of Sierra Wireless.
Contact Information
Phone: 1-604-232-1488
Sales Desk: Hours: 8:00 AM to 5:00 PM Pacific Time
E-mail: sales@sierrawireless.com
Sierra Wireless
13811 Wireless Way
Post:
Richmond, BC
Canada V6V 3A4
Technical Support: support@sierrawireless.com
RMA Support: repairs@sierrawireless.com
Fax: 1-604-231-1109
Web: www.sierrawireless.com
Consult our website for up-to-date product descriptions, documentation, application notes, firmware upgrades,
troubleshooting tips, and press releases: http://www.sierrawireless.com
Special Thanks
Special thanks not only to the Open AT® training organizers Sylvain O., Catherine T., and Jacques S., but also to Infosys
team for their constant help.
507
Open AT® TUTORIAL
APPENDIX
508