Python.
A rapid solution on
embedded Linux
Tran Duc Hong
FPT Space Laboratory
About
My names Tran Duc Hong
Working in Embedded field for 04 years.
Technical leader in Embedded Linux at FPT Embedded
Software Company.
Consultant in F1-Sattlite. Its the first satellite which is the first
satellite investigated by domestic company.
Email me if you have any interested in: [email protected]
Agenda
C/C++ on Embedded Linux
Whys Python?
Idea
Solution
Comparison
Python vs. C/C++
Python vs. Ruby, Tcl/Tk, Perl
Real project
QnA
C/C++ on Embedded Linux
C/C++ are the most popular languages in
embedded world.
Its powerful
Small footprint.
Low memory and CPU consumption.
Access directly to low layer such as LCD, keyboard, bus, etc.
C/C++ on Embedded Linux
But an development processes are so complicated
It takes much time.
A lot of risks for non-experience guys
Leak memory
Run and test
Different compiler version on each platforms.
Syntax on gcc for x86 is not the same as gcc for ARM
Performance utilize
Change platforms, a lot of work must be done.
and much more
Thus, we need expertise guys, even for developing some
application not for low-level.
Have any solution?
Rapid in development.
Easy to represent logic activities.
Easy for developing high-level application.
Easy for accessing low-level hardware.
Easy for migrating when switch platform.
Whys Python?
Language is very simple.
Its scripting language
It look like Visual Basic
Procedure-oriented programming
Handling exception
Multi-threading support
Free & Open Source
Portable
Easy to compile for ARM, PowerPC
Extensible
Write our own module on C/C++ then use on Python code.
Embeddable
Embed Python within C/C++ programs to give 'scripting' capabilities
Extensive Libraries
8354 open source packages from Python Package Index. (Counted on
01-Dec-2009)
Whys Python?
Python syntax
Exception handling
x = int(raw_input("Please enter
an integer: "))
if x < 0:
x = 0
print Negative changed to
zero
elif x == 0:
print Zero
elif x == 1:
print Single
else: print More
while True:
try:
x =
int(raw_input("Please
enter a number: "))
break
except ValueError:
print "Oops! That was
no valid number. Try
again...
Class definition
class MyClass:
"""A simple example class"""
i = 12345
def f(self):
return 'hello world'
Real solution
Python + C/C++ + Real-time application interface
(RTAI)
Python: Simple, powerful, easy to represent logic activities.
C/C++ : Access directly to peripherals, kernel. Bit & memory
manipulation.
RTAI : Suitable for any modules require timing, precious in 0.05ms.
Real solution (contd.)
Python + C/C++ + Real-time application interface (RTAI)
Daemon
in C/C+
+
Python
apps
User
layer
Kernel
layer
Shell scripts
Python apps(.py)
LCD
Keyboard
LCD
Keyboard
Camera
USB
Camera
Kernel + Real time support
Hardware
USB
Logic
represent
entity
C/C++
module
User layer
Driver
Kernel
Comparison
Python vs. Perl, Tcl/Tk
More complex than Python
Big footprint
Consume a lot of memory and CPU time
Perl module write on C/C++ are not easy.
Very hard for embedded Perl script within C/C++
program
Python vs. Ruby
Python run faster than Ruby
Benchmark from community.
Real project
Use on some router embedded device
CPU: Intel xScale 500Mhz, Memory: 256MB, Flash: 512MB
Use on F1-sattlite project
CPU: Cirrus EP9301, Core ARM9TDMI 200Mhz, Memory: 128MB, Flash: 128MB
Test result
Environment
CPU: Cirrus EP9301, Core ARM9TDMI 200Mhz, Memory: 128MB,
Flash: 128MB
Have many kind of peripherals such as GPIO, ADC, I2C, SPI,
1Wire, RS232, etc.
Using Linux 2.4.25 non Real-time patched.
Use on F1-sattlite project.
Constraints
Some module required strictly timing, such as Morse generator
(signal timing, 0.05ms precision )
Safety is the most concerning.
Rapid to develop prototype and testing.
Easy to debug for developer.
Test result (contd.)
Latency/Response time
Linux kernel 2.4.26 with EP9301 patched
Linux kernel 2.4.26 with EP9301 + Realtime
patched
QnA