You are on page 1of 5

OpenAVL - an AVL free project (II) - using an open source compiler too! http://dev.emcelettronica.


Your Electronics Open Source

Home > Blog > allankliu's blog > Contenuti

OpenAVL - an AVL free project (II) - using

an open source compiler too!
By allankliu
Created 09/17/2008 - 03:40

Technology avl c compiler compiler gps


The prototype board is still under development. The major hardware issue is the RF
interference from GSM module to GPS module. I will reveal the schematics and PCB layout
in detail as soon as it works and fulfils desired RF performance. I will debug the firmware in
the AVR simulator before the real hardware platform is available.

GCC and New Code Base

As I mentioned in my last blog ( OpenAVL - an AVL Open Source project (I)), I decided to use
ATMEGA128L (see the Datasheet) and the new code bases in order to develop the firmware
faster. The new codes come from the open source AVRlib project and the AVR application
note AN323. My preferred compiler is WinAVR (GCC for AVR). It is a free but powerful
compiler collection, including a GNU C/C++ compiler, a simulator for AVR, and a GDB insight
debugger. All of these free tools work seamlessly with AVR Studio, the official development
IDE available from Atmel Corporation.

Although WinAVR is very powerful and comparable to any commercial compilers, the
framework of GCC is an ANSI C compiler for RAM based operation system. It doesn't support
some popular keywords as other commercial embedded compilers do (ROM/Flash). The
firmware developers have to be aware of these differences to prevent wasting valuable RAM

For instance, the declared variables including constants are initialized and placed in RAM by
GCC. It has to be avoided because embedded systems are usually RAM restricted systems.
The constants should be placed in ROM anyway. The constants placed in EEPROM and
ROM should be declared by special macros in GCC/WinAVR. Otherwise, the variables in
ROM will be copied to RAM and then start to be evaluated. Before you start to use WinAVR
in a project, please visit an AVR developer community site,,
which offers many notes on using WinAVR.

GCC has different approach to define an Interrupt Service Routine (ISR). I want to reserve all
of the ISR prototypes in case I have to use another commercial compiler. I use macro based
conditional compile directives to keep them all.

As result of the first round code integration, I successfully built the whole project. It takes
12KB ROM and 1KB RAM memories. ATMEGA128L has 128KB ROM and 4KB RAM

1 din 5 17.09.2008 20:47

OpenAVL - an AVL free project (II) - using an open source compiler too!

memories. It is possible to use a cheaper AVR with smaller memories as ATMEGA64. In next
generation GPRS (General Packet Radio Service) based AVL design, if we implement the
TCP/IP stack in system controller, instead of embedded TCP/IP stack in M2M/GPRS module,
the RAM allocation has to be optimized and overlapped. Otherwise, a TCP/IP connection
over GPRS will use up 4KB RAM easily.

Software Structure

Here is the software logical diagram to present the internal logical connection between the
software modules.

M2M and SiRF hardware modules

The M2M module connects to ATMEGA128 UART0 at 9600bps. The GPS module connects
to ATMEGA128 UART1 at 4800bps. The SiRF-III supports its binary and common NMEA
protocols. Here NMEA is preferred. In the future GPRS based design, the baud rate of M2M
connectivity should be able to switch to a higher speed, i.e. 115.2kbps.


The UART driver comes from AVRlib, which supports dual hardware UART, interrupt driven
and buffer management. The driver gets the microcontroller running frequency from the
makefile or the macro definition in a header file. The driver can support software UART as

Hardware Features and Drivers

The hardware modules cover GPIO, ADC/DAC, timers and power management. The GPIO
and ADC can be used in local keypad input and battery measurement. The timer offers time
base for all the high level modules, including update interval, event timeout and

2 din 5 17.09.2008 20:47

OpenAVL - an AVL free project (II) - using an open source compiler too!

measurement. All of these modules come from AVRlib as well. However I still evaluate if the
timer driver is flexible enough to meet the system requirement.

AVL is a slow application system, because both AT command and NMEA protocol are quite
slow. The AVL can be designed as an interrupt and event driven system to save power. But
the overall power management policy and algorithm is still under design. And the power
management also involves application level module interactivities.

All of these drivers are general purpose modules, which offer services for the higher modules.

EEPROM and Parameters

Both EEPROM and Parameters modules come from AVRlib. AVR is an ideal chip because it
contains all kinds of essential memories in one chip, from SRAM, flash to EEPROM. The
EEPROM module is basically written in inline assembly. The Parameters stand for
parameters access module, which offers parameters access over EEPROM. These modules
are very important for the system initialization and setup.


The GSM and OTA modules offer low-level communication layers for AVL. The GSM is the
AT commands based communication driver. The GSM module comes from AN322. On the
basis of GSM, the OTA offers user command parsing, decoding and handling.


The NMEA and GPS modules offer GPS information for AVL. The NMEA comes from
AVRlib, but with some modification. The NMEA reads the message over UART1, parses the
NMEA sentences and then offers service for higher GPS module. The GPS module keeps all
of the update information locally, from where the AVL can read.

Event and Error

These two modules will collect the system events and error messages, stored locally. These
modules are part of the main program. During the update routine, the events and errors will
be sent over OTA.


The top AVL module is basically the main program. It initializes the whole system, update the
modules. All of the business related routines are implemented here. For example, checking
the speed limitation, checking the battery voltage, checking physical connectivity to the GPS
and GSM modules, checking the coverage of GPS and GSM, checking the GPS fix timeout,
and many other routines.

The AVL module also checks the errors and events from Event and Error modules, and
initializes a SMS feedback to the registered user account.

Software Release

In the attachment you'll find the firmware. I plan to put the official release project on a public
open source project directory server, i.e. Google or Sourceforge.

M2M Modules for GPRS based AVL

The IP based application is the main trend of the M2M applications. Since TC35 only

3 din 5 17.09.2008 20:47

OpenAVL - an AVL free project (II) - using an open source compiler too!

supports GSM SMS and CSD based communications, it is not suitable for an IP based
application. Three low-end GPRS modules are compared in the following table. The TCP/IP
can be implemented either in M2M module or the system controller. The designers have to
make their own decisions according to the programming complexity, system cost and
development lead-time.

TC39 is a basic GPRS module, which offers low cost and pin-to-pin compatibility with TC35.
However the TCP/IP stack has to be implemented in the system controller, it requires
programming skills and RAM optimization.

Q2403 is another basic GPRS module from Wavecom. It is similar to TC39. It supports quad
band, slightly bigger than TC39. Fortunately, Techfaith offers a fully compatible version in the
name of Centel / PIML. PIML offers Wavecom Q2403 compatible design with embedded
TCP/IP support and lower price. It is a wise choice only if PIML can offer the same quality of

GE863 from Telit is the smallest GPRS module. Its BGA package makes it as the best choice
in a personal tracking device. It supports custom Python script, and offers enough GPIO.
There is a GPS version available. The designer can write the Python script, download to the
module and start to deploy it in a tracking project. The hardware design and firmware design
effort is reduced to minimum. However it requires BGA handling and manufacturing
capability, which is not common in a non-commercial product.

Model TC39 Q2403 GE863

Vendor Siemens/Cinterion Telit

RF GSM900/1800 Quad band Quad band

GPRS class 10 class 10 class 10

AT command (new w/
Control AT command AT command
Open AT)

SIM external 3V integrated 3V external/int 3V

Supply 3.3~4.8V 3.1~4.5V 3.4~4.2V

Voice hands free basic hands free

50 ohm soldered
Antenna 50 ohm GSC antenna pad

Interface 40-pin ZIP con. 60-pin ZIP con. BGA-84

Script N/A N/A (new w/ Lua) Python




Length 54.5 58 41.4

4 din 5 17.09.2008 20:47

OpenAVL - an AVL free project (II) - using an open source compiler too!

Width 36 32 31.4

Thickness 3.6 3.9 3.6

Scalable Yes Yes Yes, GPS/SIM/Quad/PY

A basic GPRS module

A basic GPRS module, Smallest form factor in
w/ more IO, checks
TCP/IP has to be GPRS module. The best
Comment PIML for replacement
implemented in external choice for personal
with embedded
microcontroller. tracking application.

Attachment Size
src.rar 262.57 KB


Source URL:

5 din 5 17.09.2008 20:47