Anda di halaman 1dari 71

Embedded Systems

Special Lecture
By

N.SHANMUGASUNDARAM
Asst. Professor – ECE Department
Mahendra Engineering College

13/4/2009 1
What is an Embedded System?

Embedded system is a
 Microcontroller based
 Software driven
 Reliable
 Real time control system
 Autonomous or Human interactive
 Operating on diverse physical variables
 In diverse environments

13/4/2009 2
What is an Embedded System?

Embedded system is a Hardware with Software embedded in it,


for a dedicated application.

DRIVES

13/4/2009 3
SMART Embedded Systems …

13/4/2009 4
SMART Embedded Systems …

13/4/2009 5
SMART Embedded Systems …

13/4/2009 6
3 MAIN COMPONENTS of Embedded System

 HARDWARE
Processor, RAM, ROM, ADC, DAC, Timers, Ports, etc.

 APPLICATION SOFTWARE
written in Assembly, C, C++, Java, etc.

 RTOS (to supervise the Application Software)


µC OS-II, Win CE, VxWorks, Embedded Linux, etc.

13/4/2009 7
CLASSIFICATION of Embedded Systems

• SMALL SCALE:
8/16 bit CPU, little H/w, less S/w complexity, No RTOS,
Battery operated.

• MEDIUM SCALE:
16/32 bit µC or DSPs, Complex H/w & S/w design, RTOS
Source code Engg tools, IDE.

• SOPHISTICATED:
Configurable processors, Cutting edge applications,
Highly complex H/w and S/w design,

13/4/2009 8
SKILLS for Embedded System Engineer

• HARDWARE:
µP / µC, DSPs, Memories, Peripheral devices, sensors,
Computer architecture, Digital electronics, Electronic system design,
Control system, Data communication.

• SOFTWARE:
IDE - Editor, Assemblers, Compilers, Linkers, Debuggers, Simulator.
Programming languages - Assembly, C, C++, Java
RTOS – Vxworks, Win CE, RTLinux, etc.

13/4/2009 9
COMPONENTS of Embedded System Hardware

13/4/2009 10
PROCESSORS for Embedded Systems

PROCESSOR
ALU
Control
Unit

Types of Processor
• General Purpose Processor (µc, µP, DSP, EP,MP)
• Application Specific System Processor
• Multiprocessor system
• GPP/ASIP core with other hardware integrated in ASIC chip.

13/4/2009 11
OTHER HARDWARE for Embedded Systems

1. Power supply circuit


2. Memory - EPROM, RAM, EEPROM (flash), CACHE
3. I/O Ports - 8255 (PPI), 8251 (UART)
4. Timers - 8253
5. ADC / DAC - ADC0809, DAC0800
6. Display & Keyboard Controllers - 8279
7. Programmable Interrupt Controllers - 8259

13/4/2009 12
SOFTWARE Components in Embedded Systems

Programming Languages: 1. Machine code


2. Assembly language
3. High level languages ie., C, C++

Software Tools: Editor Simulator


Assembler Loader
Compiler Stethoscope
Linker Trace scope
Debugger IDE

13/4/2009 13
Software Development Chain

13/4/2009 14
HARDWARE in Exemplary Embedded Systems

MOBILE PHONE
Processor Multi processor on a Chip
Bus Size 32
Architecture RISC
Cache Memory Yes
ROM 1 MB
EEPROM 32 KB
RAM 1 MB
I/O Ports KBD & Display ports
DAC & ADC Yes
Modulation / Demodulation Yes
DSP instructions Yes

13/4/2009 15
SOFTWARE in Exemplary Embedded Systems

MOBILE PHONE
Editor yes
Interpreter No
Assembler No
Cross Assembler No
Compiler yes
Locator yes
Simulator yes
Source code Engg tools yes
RTOS yes
IDE yes
Stethoscope yes

13/4/2009 16
Exemplary SOC for Mobile Phone

13/4/2009 17
Types of I/O Devices

13/4/2009 18
Structure of Serial Port

13/4/2009 19
Structure of Parallel Port

13/4/2009 20
BUSES for Communication

Buses

Serial Parallel

I2C, CAN, USB, … ISA, EISA, PCI, …

I2C : Bus for communication between multiple ICs.


CAN: Bus used in automobiles with centrally controlled network.
USB: Bus for communication between CPU and devices like mouse, etc.

ISA, EISA, PCI are standard buses for parallel communication used in
PCs, computer network devices, etc.

13/4/2009 21
Types of TIMERS

Timers

Hardware Software
Timer Timer

13/4/2009 22
Structure of Hardware Timer

13/4/2009 23
Usage of TIMERS

1 Real Time Clock (RTC) for the system


2 Initiating an Event after a preset time delay
3 Initiating an Event after a comparison of preset times
4 Capturing the count value in timer on an event
5 Finding time interval between two events
6 Watchdog timer
7 Baud rate control for Serial communication
8 Scheduling of various tasks in RTOS
9 Time slicing of various tasks
10 Time division multiplexing

13/4/2009 24
Programming Embedded Systems in Assy & C

Assembly C, C++
1. Full use of processor specific 1. Software development cycle is short
instructions. due to usage of functions, std library
functions, modular programming
approach, Top down design, etc.
2. Machine codes are Compact. 2. Data type declarations make
programming easy.
3. Device driver code needs only 3. Type checking eliminates errors.
few assembly instructions.
4. Usage of Control structures
like if-then, do-while, for, etc.
5. Portability to different hardware
and OS.

13/4/2009 25
Programming Embedded Systems using C++

Combines the advantage of OOPS, C & Assembly.

Special features: Data Encapsulation, inheritance, etc.

Advantages : Reusability of software components.

Disadvantages: Standard C++ programming makes code complex


and lengthy, due to features like Templates, Multiple
inheritance, Exception handling, Virtual base classes,
Namespaces, etc.

Solution : Special version of C++ (Embedded C++)


has provision for selective disabling of features.

13/4/2009 26
Phases of Software Development

1. Definition and Analysis a) Complete Specification of the System.


of the System b) Specification of the data, functions, tasks,..
Requirement c) System behaviour
d) Constraints of Design
e) Human machine interaction
f) Expected life cycle
g) Validation criteria & time delivery schedule

2. Development The process of software


Designing, Coding and Testing.

3. Support a) Correction of bugs


b) Addition of extra functions as per changing
environment

13/4/2009 27
S/w development of Typical application (Automobiles)

Development of a Embedded system in a Car to monitor


Instrument clusters, Engine performance, Automatic Gear box,
Brakes, etc., the typical code will be as follows

Watch 1254
Recording data of usage / malfunction 168
Engine speed 399
Vehicle speed 557
Odometer 999
Wake-up / Sleep down 252
Fuel 376
Alarms 4781
Coolant Temperature 537
Light Control 1925
Automatic gear box 207
(Total 11643 LOC)
13/4/2009 28
Source Code Engineering tool

It is a tool for source code development, compiling, debugging and testing.

eg. SNiFF+ from WindRiver® Systems

Features of SNiFF+
• Comprehension, Navigation and Browsing
• Editing
• Configuring (selective disabling of C++ features)
• Compiling
• Debugging

13/4/2009 29
Code / Memory Optimization

It is a process of making the code compact and fitting into a small


memory space without affecting code performance.

Techniques for code optimization:


• Use of unsigned byte
• Avoiding std lib functions, when simple coding is possible.
• Usage of Assy code, when target processor is well known.
• Usage of Global Variable, when no chance for shared data problem.
• Reduce usage of frequent function calls.
• Usage of delete / free, to release the used memory.
• Disabling the used features of C++.

13/4/2009 30
Process / Tasks / Threads

Process : It is a sequentially running program with its state.

Task : An application consisting of tasks controlled by scheduling


mechanism of an OS.

Threads : Light weighted sub-process in application program,


controlled by process control entity.

13/4/2009 31
Comparison of Function / ISR / Task

Function ISR Task

- Set of instructions for - ISR is independent - Task is independent.


performing an actions.
- Call from H/w & S/w. - Sync done by RTOS.
- Called by Proc/Task/ISR.
- ISR has Priority. - Scheduler runs one
- Each Fn has a context
- Each ISR has Context. task at a time.
- Provision for nested
Function calls.

13/4/2009 32
Inter Process Communication (IPC)

13/4/2009 33
Inter Process Communication (IPC)

IPC: Some information generated by a processes / tasks, by setting / resetting


a flag / value, or generates an output so that it lets another process take
note / use of it.

Types: 1) Signal
2) Semaphores (flags, mutex, resource key, counting)
3) Queues, Pipes or Mailbox (eg. LCD display in Mobile – Time, Ph No.)
4) Sockets (eg. COM port in PC to connect modem, port 80 –
web server)
5) Remote Procedure Calls (RPC) – for distributed processes

13/4/2009 34
Shared Data Problem & its Solutions

Shared Data Problem: Conflict arising on a common variable due to usage


by multiple tasks / processes on it.

Eg. Interrupt changing the


subsequent bits while processing a 32 bit data on a
8-bit CPU.

Solutions: 1) Use of modifier “Volatile”


2) Use of “Re-entrant” functions
3) Putting shared variable in circular queues
4) Disabling interrupts on execution of Critical
section
5) Using Semaphores

13/4/2009 35
Semaphore & its types

Types of Semaphores: 1) Single, 2) Multiple, 3) Mutex


4) P & V 5) Counting

13/4/2009 36
GOALS of Operating System

1. Facilitating easy sharing of resource as per schedule and allocation.


2. Facilitating easy implementation of application software.
3. Optimally scheduling the processes on one / more CPU.
4. Maximizing the system performance without any security breach.
5. Providing the management functions for Processes, tasks, etc.
6. Providing the management functions for Devices, Files, etc.
7. Providing easy interface and management functions for network & protocols.
8. Providing portability of application software on different hardware.
9. Providing interoperability of application on different networks.
10. Providing common set of interfaces.

13/4/2009 37
STRUCTURE of Operating System

Application Software

API

System Software
(with functions other than in OS) Eg. Device driver for Multimedia device

OS interface

OS Consists of KERNEL
(Operated in User and Supervisory modes)
Hardware – OS
Interface
Hardware

13/4/2009 38
KERNEL of Operating System

- OS is a middle layer between Application Software & Hardware.


- It consists of KERNEL and other functions not provided by Kernel.
- KERNEL is operated in Supervisory mode and
Other functions are operated in User Mode.

KERNEL Services

 Process Management
 Memory Management
 Inter Process Communication
 I/O management
 Interrupt Control
 Device drivers

13/4/2009 39
Process Management in OS

Process management consists of


creation, activation, running, blocking, resumption, deactivation, deletion of processes.

A. Process Creation: Initial and Subsequent process.

B. Management of Created process:


- Processing resource requests
- Allocation of Resources (through Message / system calls)
- Controlling of process through PCB.
- Scheduling and synchronization

13/4/2009 40
Memory Management in OS

A. Memory Allocation: at the time of creation of a new process / tasks.

B. Memory Management after allocation:


- Fixed block allocation
- Dynamic block allocation
- Dynamic page allocation
- Dynamic data memory allocation
- Dynamic address reallocation
- Multiprocessor memory allocation

13/4/2009 41
Device Management in OS

A. Manages Physical / Virtual devices (eg. Pipes & sockets).

B. Three standard approach to three types of device drivers


a) Programmed I/O poling
b) Interrupt driven through ISR
c) DMA

C. Functions of Device manager


It includes function like Device detection & addition, device allocation and
registration, device sharing, device buffer management, device access
management.

13/4/2009 42
File System Organization & Implementation

- File is a named entity stored on secondary storage device.

- It contains data in different formats.


- Both real and Virtual files (Pipe) are managed.

Functions to Organize Files in systematic way:


 Open
 Write
 Read
 Seek
 Close

13/4/2009 43
Real Time Operating System (RTOS)

RTOS is an OS for Embedded system


for response time and event controlled processes.

RTOS Services:
• Basic OS functions - PM, RM, MM, DM, FSM, I/o, etc.
• RTOS main functions - RT task scheduling and latency control
• Time management - Time Allocation, time slicing & monitoring for efficiency.
• Predictability - Predicting time behaviour and initiation of task
synchronization
• Priorities Management - Allocation and Inheritance
• IPC - Synchronization of Tasks using IPC.

13/4/2009 44
Why need RTOS?

Reasons for need of RTOS Occasions for NO need of RTOS

 When efficient scheduling in  Small scale embedded system


needed for multitasks with time never use RTOS.
constraints.  Instead of functions in RTOS,
 Task synchronization is standard lib functions in C can be
needed. used.
 Interrupt latency Control is eg. malloc(), free(),
essential.
fopen(), fclose(), etc.

13/4/2009 45
RTOS Task Scheduling Models

A. Control flow strategy  Complete control of i/p and o/ps.


 Co-operative scheduler adopts this
strategy.
 Worst case latencies are well defined.

B. Data flow strategy  Interrupt occurrences are predictable.


 Task control not deterministic.
Eg.network. (Packet arrival not predictable)
 Pre-emptive scheduler adopts this
strategy.

C. Control-data flow strategy  Task scheduler fns are designed with


predefined time-out delays.
 WC latency is deterministic, because the
max delay is predefined.
 Cyclic Co-op Schd, Pre-emp Schd, Fixed
time Schd, Dynamic RT Schd uses this
strategy.

13/4/2009 46
Co-operative Round robin Scheduling

Other Types of Co-operative scheduling: i) using ordered list.


ii) using time slicing with timers

Dis-advantages: Longer execution time of a low priority task makes a higher


priority task wait until it finishes.

13/4/2009 47
Pre-emptive Scheduling

13/4/2009 48
Other Scheduling techniques and Critical Section

Critical Section: It is an important portion of a task, which should not be


blocked as it uses a shared variable.

Here, Pre-emptive scheduling leads to conflict.

Other Scheduling
Techniques: 1) Fixed real time scheduling of Tasks
2) Probabilistic timed Petrinets
3) Multi Thread Graphs (MTG)

13/4/2009 49
RTOS - Real Time Operating
System

 A Real-Time Operating System (RTOS) is an operating


system (OS) intended for real-time applications in
Embedded systems.

 A key characteristic of real-time operating systems is the


level of its consistency concerning the amount of time it
takes to accept and complete an application's task.

 A real-time OS has an advanced algorithm for scheduling.

 Key factors in an real-time OS are a minimal interrupt


latency and a minimal thread switching latency.

13/4/2009 50
Basic functions of RTOS

13/4/2009 51
Need for Tested RTOS

While designing a complex embedded systems, we need a tested bug


free codes for the following.

• Multiple task functions in C or C++.


• Real time clock based software timers (RTCSWT).
• Software for Co-operative scheduler.
• Software for a Pre-emptive scheduler.
• Device drivers and Device managers.
• Functions for Inter Process Communications.
• Network functions
• Error handling functions and exception handling functions.
• Testing and System debugging software.

A readily available RTOS package provides the above functions and a


lot of time is saved for coding the same.

13/4/2009 52
Options in RTOS

Options
for
RTOS

PSoS
Linux VxWorks
Own RTOS Based µC/ OS-II Nucleus
(Freeware)
RTOS Win CE
Palm OS

13/4/2009 53
µC/OS-II (MUCOS)

 µC/OS-II is Free Open-source RTOS designed by Jean J. Labrosse


in 1992.

 µC/OS-II is intended for Non-commercial use.

 µC/OS-II codes are in C and few CPU specific modules are in ASSY.

 µC/OS-II code Port on MANY Processors that are commonly used in


ES design.

13/4/2009 54
Features of µC/OS-II

 µC/OS-II is a Scalable OS.


 µC/OS-II uses Pre-emptive Scheduler (for multitasking).
 µC/OS-II has System level functions.
 µC/OS-II has Task service functions.
 µC/OS-II has Task delay functions.
 µC/OS-II has Memory allocation functions.
 µC/OS-II has IPC functions.
 µC/OS-II has Semaphore, Queue, Mailbox functions.

when OS or OS_ used as prefix, it denotes a function / variable


is a µC/OS-II function or variable.

Eg. OSTaskCreate() ---→ µC/OS-II function for TASK CREATION.

13/4/2009 55
Source code files of µC/OS-II

A. Processor dependent source files

Os_cpu.h Processor definition header file


Os_cfg.h Kernel building configuration file
Os_tick.c C file for ISR and RTOS timers
Os_cpu_c.c Processor C codes file
Os_cpu-a.s12 Assy code for task switching functions (68HC12)

13/4/2009 56
Source code files of µC/OS-II
(contd..)

B. Processor independent source files


Ucos.ii.h MUCOS header file
Ucos.ii.c MUCOS header file
Os_core.c For RTOS core
Os_time.c For RTOS timer
Os_task.c For RTOS task related functions
Os_mem.c For Memory partitioning
Os_sem.c For Semaphore related functions
Os_q.c For Queue related functions

13/4/2009 57
RTOS System level functions

The System level functions are

void OSInit (void) At the beginning prior to OSStart()

void OSStart (void) After OSInit() and task creating functions

void OSTickInit (void) To initialize System timer ticks

void OSIntEnter (void) Just after the start of ISR codes

Void OSIntExit (void) before return form the ISR codes

OS_ENTER_CRITICAL Macro to disable all interrupts

OS_EXIT_CRITICAL Macro to enable all interrupts

13/4/2009 58
Task Service functions

These functions are used to create task, suspend and resume, and
time setting and retrieving functions.

unsigned byte OSTaskCreate (…) Must call before running a task

unsigned byte OSTaskSuspend (..) Called for blocking a task

unsigned byte OSTaskResume (..) Called for resuming a blocked task

void OSTimeset (..) When system time is to be set

Unsigned int OSTimeGet (void) Find present count when time is read

13/4/2009 59
Time Delay functions

MUCOS Time delay functions for the tasks are

void OSTimeDly (…) To delay a task by count-1 value

unsigned byte OSTimeDlyResume (…) To resume a task after a preset delay

void OSTimeDlyHMSM (…) Time delay to block a task

13/4/2009 60
Memory related functions

MUCOS memory related functions for the tasks are

OSMem *OSMemCreate (…) To create and initialize memory partition

void *OSMemGet (..) To find the pointer of memory control block

unsigned byte OSMemQuery (..) To find pointers of memory blocks


and data structures
unsigned byte OSMemPut (…) To return a pointer of memory block

13/4/2009 61
Semaphore related functions

When a semaphore created by OS and used a resource acquiring key, it must


be initialized with “1” to indicate the resource is available.

MUCOS Semaphore related functions for the tasks are

OS_Event OSSemCreate (…) To create and initialize a semaphore

void OSSemPend (..) To check whether a semaphore is pending

unsigned short OSSemAccept (..) To check whether SemVal > 0

unsigned byte OSSemPost (…) If SemVal = 0 or more, increments, and


makes a semaphore again not pending.
unsigned byte OSSemQuery (…) To get semaphore information

13/4/2009 62
Other functions

Apart from the previous said functions, MUCOS has functions related to

• Mailbox

• Queue

13/4/2009 63
Automatic Chocolate Vending Machine (ACVM)

13/4/2009 64
Applications
 Medical instrumentation
 Military applications
 Aerospace research
 Robotics
 Consumer Electronics
 Industrial Applications
 Automobiles
 Telecommunication

13/4/2009 65
Breakthrough in Embedded System Designs

13/4/2009 66
Market Potential for Embedded Systems

According to analyst firm,


the embedded system opportunity is expected to touch

• US$ 360 billion (in terms of devices)

• US$ 36 billion (up from the existing US$ 2 billion).

Experts also predict that there will be a ten-fold increase in the number of
people employed in the embedded systems industry,

from the current 60,000 professionals to over six lakh people by 2015.

- Source: NASSCOM

13/4/2009 67
Embedded Systems Companies in Bangalore

Sadhanasoft Click Technologies (I) Pvt. Ltd. Nihar Infoway Ltd. Infobahn (India) Pvt. Ltd.

Vision Comptech Datamation Koenig Solutions Pvt. Ltd. Convergent Communications (India) Pv
Integrators Ltd Consultants Pvt. Ltd.

Optimal Infotech Pvt. Ltd. Compucom Software Ltd. Surya Soft-Tech Ltd Kale Consultants Ltd

Datamation Surya Soft-Tech Ltd Mphasis-BFL Ltd


Consultants Pvt. Ltd. Rhombus Technologies Pvt. Ltd.

Mphasis-BFL Ltd Global Automation ( Kale Consultants Ltd MindEdge Solutions

Karishma Software Ltd. Binary Semantics Ltd. Netmumbai


Parsec Technologies (India) Ltd.

Virgosys Software Pvt. Ltd. Polaris Software Lab Ltd Cybersol Technologies Pvt Ltd SolutionNet India Pvt. Ltd.

IQura Technologies Pvt. Ltd. SDI Infotech Pvt. Ltd. Datum Technologys Gateway WebSystems
(India) Ltd Pvt. Ltd.

Worldwide Infotech Inc. Java Softech Pvt. Ltd. Binary Semantics Ltd. Learnet India Ltd.

Intrepid Solutions Private Ltd Webspectrum KPIT Infosystems Ltd


Global Software Initiatives Pvt. Ltd.
Software Pvt. Ltd.

iBilt Technologies Ltd iTech Workshop Pvt. Ltd. Datum Technologys Perfect E Com Solution Pvt
(India) Ltd Ltd.

13/4/2009 68
References

1. Rajkamal, Embedded Systems Architecture, Programming and Design,


TMH, First reprint Oct. 2003

2. David E.Simon, An Embedded Software Primer, Pearson Education Asia,


First Indian Reprint 2000.

3. www.embedded.com

4. www.micrcontroller.com

13/4/2009 69
Thank You

13/4/2009 70
Thank You
for your PATIENCE.

13/4/2009 71

Anda mungkin juga menyukai