Documente Academic
Documente Profesional
Documente Cultură
INTRODUCTION TO EMBEDDED
SYSTEMS
Introduction to embedded real time systems
The build process for embedded systems
Embedded system design process
Embedded computory applications
Types of memory
Memory management methods
Definition
• Embedded system is a computer system
designed for specific control tasks.
• It is dedicated to a specific task
• Design engineers can optimize it to reduce the
size and cost of the product and increase the
reliability and performance.
A “short” list of Embedded Systems
• Auto focus cameras • Network cards
• ATMs • Pagers
• Avionic systems • PDAs
• Automatic transmission • Photocopiers
• Battery Chargers • Portable Video games
• Camcorders • Pont of Sales terminals
• Cell phones • Printers
• Cordless Phones • Scanners
• Digital Cameras • Satellite phones
• DVD players • Teleconferencing systems
• Electronic Toys/Games • Televisions
• Fax machines • Set-top boxes
• Medical Equipment • VCR’s
• Microwave ovens • Video phones
• Modems • Washers and dryers
and many more ….
Embedded systems from real life
Mobile Phones and Base Stations
• Multiprocessor
▫ 8-bit/32-bit for UI; DSP for signals
▫ 32-bit in IR port; 32-bit in Bluetooth
• 8-100 MB of memory
• All custom chips
gearboxes
Theft prevention with
smart keys
Blind-angle alert systems
Extremely Large
• Functions requiring
computers:
▫ Radar
▫ Weapons
▫ Damage control
▫ Navigation
▫ basically everything
• Computers:
▫ Large servers
▫ 1000s of processors
Embedded systems from real life
Inside Your PC
• Custom processors
▫ Graphics, sound
• 32-bit processors
▫ IR, Bluetooth
▫ Network, WLAN
▫ Harddisk
▫ RAID controllers
• 8-bit processors
▫ USB
▫ Keyboard, mouse
Characteristics of Embedded Systems (1)
Must be dependable,
• Reliability R(t) = probability of system working correctly
provided that is was working at t=0
• Maintainability M(d) = probability of system working
correctly d time units after error occurred.
• Availability A(t): probability of system working at time t
• Safety: no harm to be caused
• Security: confidential and authentic communication
Even perfectly designed systems can fail if the assumptions
about the workload and possible errors turn out to be wrong.
Making the system dependable must not be an after-thought,
it must be considered from the very beginning
Characteristics of Embedded Systems (2)
Must be efficient
▫ Energy efficient
▫ Code-size efficient
(especially for systems on a chip)
▫ Run-time efficient
▫ Weight efficient
▫ Cost efficient
Dedicated towards a certain application
Knowledge about behavior at design time can be used to
minimize resources and to maximize robustness
Dedicated user interface
(no mouse, keyboard and screen)
Hybrid systems (analog + digital parts).
Characteristics of Embedded Systems (3)
lens
output analog
input analog
CPU
mem
embedded
computer
Typical Embedded System
Phase 5 : HW / SW Integration
Memory Management
• Memory hierarchy
▫ small amount of fast, expensive memory – cache
▫ some medium-speed, medium price main memory
▫ gigabytes of slow, cheap disk storage
Modeling Multiprogramming
Degree of multiprogramming
Analysis of Multiprogramming
System Performance
Swapping (1)
Swapping (2)
Paging (2)
The relation between
virtual addresses
and physical
memory addres-
ses given by
page table
41
Top-level
page table
• Estimate by …
▫ logging page use on previous runs of process
▫ although this is impractical
48
A Pentium selector
49
Level
SEMAPHORES.
SWITCHING
1. INTEL I/O INSTRUCTIONS
I/O DEVICE CONTROL
• Devices controlled via special registers of a device controller
• CPU needs to control devices
▫ Read or write control signals or data in special registers of a device
controller
• General interfaces
▫ Port I/O: Special I/O machine instructions that trigger the bus to select
the proper I/O port & move the data into or out of a device register
E.g., IN, INS, OUT, OUTS on numerous Intel architectures
▫ Memory mapped I/O: The I/O registers of the device become part of
the linear memory space of the “RAM” of the computer; standard
memory load and store machine instructions are used
• E.g., a serial port might use port I/O, while a graphics
controller could have a memory-mapped image of the
computer screen
I/O structure
• IN and OUT transfer data between an I/O device and the
microprocessor's accumulator (AL, AX or EAX).
▫ The I/O address is stored in:
• Register DX (variable addressing).
• The byte, p8, immediately following the opcode (fixed
address).
Example
IN AL,19H ; 8 bits are saved to AL from I/O port 19 H
IN EAX, DX ; 32 bits are saved to EAX
OUT DX,EAX ; 32 bits are written to port DX from EAX
OUT 19H,AX ; 16 bits are written to I/O port 0019H
EXAMPLE I/O PORT INSTRUCTIONS
Contd..
• Only 16-bits (A0 to A15) are decoded.
• Address connections above A15 are undefined
for I/O instructions.
▫ 0000H-03XXH are used for the ISA bus.
Contd..
• interaction between processor and memory. to
execute an instruction, the processor must be
able to request 3 things from memory:
• 1. instruction FETCH
• 2. operand (variable) load LOAD
• 3. operand (variable) store STORE
memory really only needs to be able to do 2
operations
1. read (fetch or load) 2. write (store)
POLLING
• Polling, or polled operation, refers to actively
sampling the status of an external device by a
client program as a synchronous activity.
• Polling is most often used in terms of (I/O), and
is also referred to as polled I/O or software
driven I/O.
GENERAL METHODS FOR ACCESSING DEVICES
INTERRUPT
µC
D2
D3
Microcontroller interacting with three devices
Types of interrupt
Interrupt
Hardware Software
Hardware interrupt
• Interrupts are set by hardware components (like for instance the
timer component) or by peripheral devices such as a hard disk.
• There are two basic types of hardware interrupts: non maskable
interrupts (nmi) and (maskable) interrupt requests (irq).
Software interrupt
• Software interrupts are initiated with an INT instruction
and, as the name implies, are triggered via software.
• For example, the instruction INT 33h issues the
interrupt with the hex number 33h.
• Real mode address space of the i386, 1024 (1k)
bytes are reserved for the interrupt vector table
(IVT).
• Table contains an interrupt vector for each of the
256 possible interrupts. Every interrupt vector in
real mode consists of four bytes and gives the jump
address of the ISR (also known as interrupt handler) for
the particular interrupt in segment: offset format.
Operation of Interrupt
Interrupt complete
Interrupt-driven I/O cycle
…
Hardware response
• Hardware response corresponds to the sequence of events within the processor
• Kernel • Scheduler
▫ Piece of a multitasking (or: dispatcher)
system that controls tasks ▫ controls which task will run
▫ Primary task = context ▫ Mostly priority based
switching
▫ Priority-based kernel =
▫ Extra ROM and RAM gives highest priority task
needed -> problem for that is ready to run control
single-chip processors of the CPU
▫ RAM gets eaten
▫ Extra CPU-time needed (2
tot 5%)
MULTITASKING
• Multitasking is the ability of a computer to run more
than one program, or task , at the same time.
Multitasking contrasts with single-tasking, where one
process must entirely finish before another can begin.
MS-DOS is primarily a single-tasking environment,
while Windows 3.1 and Windows NT are both multi-
tasking environments.
• MULTITASKING, there are two major sub-
categories: preemptive and non-preemptive (or
cooperative).
• In non-preemptive multitasking , use of the
processor is never taken from a task; rather, a task
must voluntarily yield control of the processor before
any other task can run. Windows 3.1 uses non-
preemptive multitasking for Windows applications.
• Preemptive multitasking differs from non-preemptive multitasking in
that the operating system can take control of the processor without the
task's cooperation. (A task can also give it up voluntarily, as in non-
preemptive multitasking.) The process of a task having control taken
from it is called preemption. Windows NT uses preemptive
multitasking for all processes except 16-bit Windows 3.1 programs.
As a result, a Window NT application cannot take over the processor
in the same way that a Windows 3.1 application can.
• A preemptive operating system takes control of the processor from a
task in two ways:
1. When a task's time quantum (or time slice) runs out. Any given task
is only given control for a set amount of time before the operating
system interrupts it and schedules another task to run.
2. When a task that has higher priority becomes ready to run. The
currently running task loses control of the processor when a task
with higher priority is ready to run regardless of whether it has time
left in its quantum or not.
Preemptive and non-preemptive kernels
• non-preemptive kernel
▫ also: "cooperative multitasking"
▫ A task has to give up the CPU itself
▫ releasing the CPU has to be done fast
▫ small interrupt latency
▫ every task can run completely
before the CPU is released
▫ less danger for corruption
(non-reentrant functions)
▫ bad response on high-priority
tasks
▫ crash of a task, or endless
loop --> ??
Preemptive and non-preemptive kernels
• Preemptive kernel
▫ Used when response time important
▫ eg. microC/OS-II
▫ Highest priority task ALWAYS gets control
▫ Highest priority tasks gets
immediate control
▫ response time very short
▫ Non-reentrant functions
cannot be used!
▫ After execution of task
continue with highest priority
task (not interrupted task)
5. SCHEDULING-THREAD STATES,
PENDING THREADS, CONTEXT SWITCHING
running
Thread::Yield
(voluntary or involuntary)
Thread::Sleep
(voluntary) Scheduler::Run
blocked ready
Thread::Wakeup
Thread Operations
• Create - thread creation is a subset of process creation, and
is faster.
• Exit (terminate)
• Suspend
• Resume
• Sleep
• Awaken
• Cancel (Cancel signals can be masked.)
• Join
• join
▫ Thread operation in which the calling thread is blocked
until the thread it joins terminates.
Thread Implementation Considerations
• synchronous signal
▫ signal generated due to execution of the currently running thread's execution.
• asynchronous signal
▫ signal generated for reasons unrelated to the current instruction of the running
thread.
• signal mask
▫ A data structure which blocks specified signals from being delivered to a thread.
• pending signal
▫ A signal which has not yet been delivered.
• A signal can be pending because the recipient thread is not running, or has
masked the the signal.
• signal handler
▫ Code that is executed in response to a particular signal type.
Thread types
• Inactive: the thread is unknown to the scheduler
• Pending: the thread is waiting for an external
event or a shared resource
• Ready: the thread is waiting for the scheduler to
give it control
• Running: the thread is currently running
Pending thread
Pending Running
Ready
Inactive
Context switching
Running Ready
In computing, a context switch is the process of storing and restoring the state
(context) of a process or thread so that execution can be resumed from the same point
at a later time. This enables multiple processes to share a single CPU and is an essential
feature of a multitasking operating system. What constitutes the context is determined
by the processor and the operating system.
Context switches are usually computationally intensive, and much of the design of
operating systems is to optimize the use of context switches. Switching from one
process to another requires a certain amount of time for doing the administration –
saving and loading registers and memory maps, updating various tables and lists etc.
A context switch can mean a register context switch, a task context switch, a stack
frame switch, a thread context switch, or a process context switch.
Semaphores
• In computer science, particularly in operating systems, a semaphore is a variable or abstract
data type that is used for controlling access, by multiple processes, to a common resource in a
parallel programming or a multi user environment.
• A useful way to think of a semaphore is as a record of how many units of a particular
resource are available, coupled with operations to safely (i.e., without race conditions) adjust
that record as units are required or become free, and, if necessary, wait until a unit of the
resource becomes available. Semaphores are a useful tool in the prevention of race
conditions; however, their use is by no means a guarantee that a program is free from these
problems. Semaphores which allow an arbitrary resource count are called counting
semaphores, while semaphores which are restricted to the values 0 and 1 (or
locked/unlocked, unavailable/available) are called binary semaphores.
• The semaphore concept was invented by Dutch computer scientist Edsger Dijkstra in 1962 or
1963,[1] and has found widespread use in a variety of operating systems.