You are on page 1of 4

Software Development Automation with Scripting Languages http://dev.emcelettronica.

com/print/51795

Your Electronics Open Source


(http://dev.emcelettronica.com)
Home > Blog > allankliu's blog > Content

Software Development Automation with


Scripting Languages
By allankliu
Created 03/06/2008 - 02:46

BLOG Microcontrollers

The Scripting languages are deployed in many operative systems,


either in UNIX/Linux or Windows. These languages are developed for
general purpose process automation and web programming. But you
can consider using them for the software development process in
many ways. Among these languages, awk and Perl are suitable for
automate and speed up software development for embedded
systems, because many embedded systems only have cross tool
chain, without powerful IDE supports for process automation. Here I
will show you why we need them and how these tools help us.

As a software developer, you might be involved in many trivial daily development processes, such
as processing all source code in C files, head files, makefiles, map file, batch file and linker error
message and all many other files in proprietary formats. Perl is similar to C, sed, shell and awk,
and it is good at manipulating text, which is the major reason to be one of the most popular
language in web programming. This feature makes it the good choice for text processing in your
project.

Perl vs. awk

Perl is much powerful than awk with many extension modules via CPAN, an online Perl module
inventory. But Perl is bigger than awk as well. If you only need a handy tool to complete a simple
source file, which is demonstrated in following sample application, awk is very convenient. If you
are planning to use the scripts to automate a big project, Perl is a better choice with more
features.

Benefits

Today, more and more ICs are system ICs. That fact means every single device has hundreds or
thousands of registers. When you, as a software developer, cut and paste all the register
definitions from the datasheet to the source files, you will definitely find the whole process trivial,
and it might generate many errors and takes more time to convert them into head files. Perl can
help you to simplify this process by exporting the register tables in the PDF file to a text file, and
then converting it into head files or other formats.

Source Code Generator

Assembly is very common in embedded system software. The head files for assembly and C
source files should have same register definition in different syntax. You can use a script to
convert definition from #define in C files/head files to equivalent assembly definition files.

1 din 4 03.06.2008 21:00


Software Development Automation with Scripting Languages http://dev.emcelettronica.com/print/51795

Format Conversion

A lot of embedded system tool chain has proprietary file formats. It is possible to convert them into
other formats with a script.

Statistics for Project management

It is very important and useful to have an insight of a project by displaying the statistic chart of the
source code. These figures include line of code, comment, ROM footprint (parsed by map file)
and other data. These files can be converted into a text database as project history.

Port Binary Data into Project

It is possible to convert binary application data into source code with a script. For example,
convert a GIF file format into a C source file as embedded image data. It also works for
embedded fonts.

Project Porting

To port a project to a new platform will generate a lot of errors in the beginning, because the new
target systems might miss a lot of functions. As a result, the linker will report thousands of errors.
It takes time to add all functions to remove the errors. With a Perl script, you can locate these
missing functions from the linker errors, and then search the prototypes for these functions and
add dummy function bodies for them. It is very quick to solve these linker errors. But you must
complete the functions with real bodies by yourself.

Project Configuration

Since makefiles are text files as well, scripts can be used to configurate the project by updating
rules of makefiles.If different software components are configured by these makefiles, the whole
project can be re-configured and rebuild by this ways. The system architect should organize the
project configuration very carefully, because the script is powerful and dangerous. It will bring
hidden risk if the system is maintained by a not well organized script.

Testing Automation

Perl has many modules available on CPAN, including WIN32::SerialPort module and useful
TCP/IP modules. A testing engineer can use this feature to test the remote system via RS232 or
TCP/IP connection automatically and generate the test report report. And Perl can run command
via exec() function. So even you are not using serial port, if you can access the remote device with
Linux device file, Windows DLL or executable in command prompt which connects to your target
hardware, you can call it in Perl. This is quite useful in testing automation, production automation.
But it requires more knowledge in PC programming.

Document Automation

Perl supports Doxygen, it is very easy to generate project report with Perl script in HTML, XML
and even Windows Word (not for all versions). You will not feel headache to synchronize the
content of your report with your source code. The document generation could be integrated into
your makefile as well.

Sample Application

This code is a part of real project from Philips Semiconductors. The register definition is written in
C source file, but the makefile will call an awk to parse the C source, generate head files to be
included in the C source file, and update the dependency rules in makefile. A make file can rebuild
whole project.
hwic.c

2 din 4 03.06.2008 21:00


Software Development Automation with Scripting Languages http://dev.emcelettronica.com/print/51795

/*
#I2C_MAP_BEGIN --- begin definition of I2C-MAP
Write registers:
REG_CON1 0x04 0 0 0 0 ST3 ST2 ST1 ST0
REG_CON2 0x05 0 0 0 0 SP3 SP2 SP1 SP0
REG_CON3 0x06 SAP ST 0 SMU LMU 0 0 0
#I2C_MAP_END --- end definition of I2C-map
*/
i2cmap.awk

BEGIN \
{
open_map_file = 0
print "/* Translated by AWK-script */\n"
}

function print_define(string, value)


{
if (string != "0")
{
print "#define BIT_" string "\t" value
print "#define BYTE_" string "\t" $1
}
}

#==================================
# Keyword #I2C_MAP_BEGIN detected
# Open map file
#==================================
#
toupper($1) == "#I2C_MAP_BEGIN" \
{
open_map_file = 1
}

#==================================
# Keyword #I2C_MAP_END detected
# Close map file
#==================================
toupper($1) == "#I2C_MAP_END" \
{
open_map_file = 0
}

#==================================
# Register definition detected
# Print register defintions
#==================================
(index($1,"REG_") == 1) && (NF == 10) \
{
if (open_map_file == 1)
{
print "#define " $1 "\t" $2
print_define($10,"0x01")
print_define($9, "0x02")
print_define($8,"0x04")
print_define($7,"0x08")
print_define($6,"0x10")
print_define($5,"0x20")
print_define($4,"0x40")
print_define($3,"0x80")
print "\n"
}
}

END \
{
print "/* End translated by AWK-script */"
}

3 din 4 03.06.2008 21:00


Software Development Automation with Scripting Languages http://dev.emcelettronica.com/print/51795

makefile

# Using awk script to generate *.h file

%foreach X in $(MAP_INCLUDES)
$(X): i2cmap.awk gawk.exe $[f,,$(X),c]
%echo Generating $(X) ...
-$(.PATH.exe)\gawk -f$(.PATH.awk)\i2cmap.awk $(.PATH.c)\$[f,,$(X),c] > $(.PATH.h)\$(X)
-touch -f$(.PATH.c)\$[f,,$(X),c] $(.PATH.h)\$(X)
%endfor

......

HWIC.OBJ: HWIC.H hwic.c

Installation

You don't have to install these utility if you are working on UNIX/Linux. You can install Cygwin on
Windows PC. You must enable gmake, Perl and gawk during installation.

Trademarks

Source URL: http://dev.emcelettronica.com/software-development-automation-scripting-languages

4 din 4 03.06.2008 21:00