You are on page 1of 41

Real-Time and Embedded

Systems

Nam Ho
Dr. Anh-Vu Dinh-Duc
Module Outline

 Introduction to Real-Time Systems


 Real-Time Task Scheduling
 Real-Time Operating Systems (RTOS)
 Measuring Execution Time and Real-
Time Performance
 Development of Embedded Systems
 Our Research Results in Embedded
Systems
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 2
Development of Embedded
Systems

 Development Process
 Consists of cycles of editing-testing-
debugging
 Processor and hardware part once
chosen remains fixed, the application
software codes have to be perfected by a
number of runs and tests

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 3


Development of Embedded
Systems

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 4


Development of Embedded
Systems

Cross-Platform Development
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 5
Cross-Platform Development
 Software for an embedded system is developed on
one platform but runs on another
 The host system is the system on which the
embedded software is developed
 The target system is the embedded system under
development
 A set of connections might be available between
the host and the target system
 JTAG
 BDM
 Serial Port
 Ethernet

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 6


Host System

 Offering essential development tools


(toolchain)
 Editor
 Cross compiler, assembler
 Linker
 Source-level debugger
 Produces executable binary image that will run
on target system
 At PC, workstation, laptop
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 7
Toolchain for Building
Embedded Software

Building Process

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010


Target system 8
GNU Toolchain for Development
of Embedded Systems

 Free Software
 GNU make: Automation tool for compilation and
build
 GNU Compiler Collection (GCC): Suite of compilers
for several programming languages
 GNU Binutils: Suite of tools including linker,
assembler and other tools
 GNU Debugger (GDB): Code debugging tool
 C Library: uLibc, gLibc
 Supporting x86, ARM, MIPS, PowerPC, SuperH …

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 9


Integrated Development
Environments (IDE)
 An IDE is referred as a programming environment
that has been packaged as an application program
 Typically consisting of
 Code editor
 Simulator
 Toolchain
 Graphical user interface (GUI) builder
 Companies design the IDE to develop embedded
systems on specified microcontrollers
 Including BSP
 Startup Code
 Device Driver
 …
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 10
KEIL IDE

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 11


Eclipse IDE for C/C++ Developer
with GNU Toolchain for ARM

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 12


Target System
 Actual hardware for the embedded system under development
 Embedded developers are required to understand the target system
 How to store the program image on the target embedded system
 How to develop and debug the system iteratively

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 13


Target System & Final System
 In target system, it might be repeated downloading
of the codes during the development phase
 Reprogramming the EEPROM or the flash memory
each time the code changes due to bugs or code
addition is time consuming
 Developers transfer the image directly into the
target system's RAM memory over serial/network
connection or through JTAG/BDM interface
 Final system (product) may employs ROM in place
of flash, EEPROM or EPROM in embedded system

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 14


Compiling & Linking

Compiling/Linking

How ?

Executable
image
How ?

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 15


Compiling
 Output from compilation is an object file
 An object file contains
 File size, binary code and data size, and
source file name from which it was created
 Machine-architecture-specific binary
instructions and data
 Symbol table and the symbol relocation
table
 Debug information, which the debugger
uses
 Two common object file formats
 COFF (common object file format)
 ELF (extended linker format)

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 16


Compiling – The ELF Format

.o .elf

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 17


Compiling – Object File

 Object file contains header


that describe the rest of
the sections
 Blocks regrouped
 Code blocks in “text” section
 Initialized global variables in
“data” section
 Uninitialized global
variables in “bss” section

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 18


Linking

 Linker combines several object (.o) files into a


single executable file (.elf)
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 19
Linking – Linker

 Merges text, data, and bss sections


 Unresolved symbol matching
 Referred variable is undeclared in one file but is
declared in another file
 Linker will replace with reference to the actual
variable
 Normally, the address in the executable
image is the absolute address (physical
address)
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 20
Linking – Linker Script
 Set of linker directives that controls how the
linker combines the sections and allocates
the segments into the target system
 Two of the more common directives
supported by most linkers are MEMORY
and SECTION
 The MEMORY directive is used to describe the
target system’s memory map
 The SECTION specifies how the sections are to
be merged and at what location they are to be
placed

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 21


Linking – Linker Script
MEMORY {
ROM: origin = 0x0000h, length = 0x0020h
FLASH: origin = 0x0040h, length = 0x1000h
RAM: origin = 0x1000h, length = 0x10000h
}

SECTION {
.text :
{
my_section *(.text)
}
loader : > FLASH
GROUP ALIGN (4) :
{
.text,
.data : {}
.bss : {}
} >RAM
}

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 22


Linking – Linker Script

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 23


Downloading the Executable
Image to the Target System

 Programming the entire image into the


EEPROM or flash memory
 Downloading the image over either a
serial (typically RS-232) or network
connection
 Downloading the image through either
a JTAG or BDM interface

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 24


Downloading the Executable
Image to the Target System

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 25


Downloading the Executable
Image to the Target System
 The boot image prepares the system to execute the loader (ex. Testing RAM)
 The loader prepares the serial or network connection to receive the image
from host
 Setting the baud rate
 Initiating the transfer protocol (FTP, TFTP)
 The monitor (boot image + loader) has a set of commands allowing the
developer to (via serial/network connection)
 download the image
 read from and write to system memory locations
 set and clear different types of breakpoints
 single-step instructions
 reset the system
 Target debug agent functions much like the monitor
 The target agent gives the host debugger enough information to provide visual
source-level debug capability
 Sometimes a RTOS vendor offers a host-based debugger (target server)
 Debugging solutions
 ICE
 JTAG
 BDM
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 26
Downloading the Executable
Image to the Target System
VxWork runs on the x86 target

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 27


Debugging the Executable
Image on the Target System
 How to debug the loader/ monitor ? (Board bring-up
process)
 Using an Emulator
 A circuit for emulating target system
 Debug startup code and programs running from ROM

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 28


Debugging the Executable
Image on the Target System
 In-Circuit Emulator (ICE)
 Replaces microprocessor in target system
 Expensive

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 29


Debugging the Executable
Image on the Target System

 On-Chip Debugging (OCD)


 Built-in microprocessor debugging
 BDM and JTAG solutions

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 30


Debugging the Executable
Image on the Target System
 JTAG (Joint Test Action
Group)
 Founded by electronics
manufacturers to develop a
new and cost-effective test
solution
 The IEEE1149.1 standard

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 31


Debugging the Executable
Image on the Target System

 BDM (Background Debug Mode)


 Introduced by Motorola and found on
its processor chips

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 32


Target Boot Scenarios
 After embedded processors are powered
on, they fetch and execute at the reset
vector
 The reset vector is usually a jump instruction
into another part of the memory space
where the real initialization code is found
 After that the startup initialization code can
begin at the flash memory address
 Initializes the hardware (only the necessary
devices)
 Contains the target image loader
8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 33
Target Boot Scenarios

ldr pc, [pc, #64] ; 00000040 <Reset_Addr>

Embedded
processors are built-
in a small boot code

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 34


Target Boot Scenarios
 The application image contains the RTOS,
the kernel, and the application code written
by the embedded developer
 The application image begins executing
after the loader completes its works
 Executing from ROM using RAM for data
 Executing from RAM after image transfer
from ROM
 Executing from RAM after image transfer
from Host

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 35


Executing from ROM using
RAM for data

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 36


Executing from RAM after
image transfer from ROM

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 37


Executing from RAM after
image transfer from Host

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 38


Target System Software
Initialization Sequence

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 39


Target System Software
Initialization Sequence

Setting up execution handlers


Initializing interrupt handlers
Initializing bus interfaces, such as
PCI, and USB
Initializing board peripherals such as
serial, LAN, and SCSI.
Task objects
Semaphore objects
Message-queue objects
Timer services
Interrupt services
Memory-management services
Creating necessary stacks

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 40


Reference

 Qing Li and Carolyn Yao, Real-Time


Concepts for Embedded Systems,
CMP Books, 2003
 Raj Kamal, Embedded Systems -
Architecture, Programming and
Design, McGraw-Hill Pulisher, 2008

8/20/2010 Embedded Systems Course: Development of Embedded Systems - 2010 41