Professional Documents
Culture Documents
Complete Notes Koe062 Final
Complete Notes Koe062 Final
EMBEDDED SYSTEMS
KOE062
GYANENDRA SINGH
UNIT-1 - INTRODUCTION TO
EMBEDDED SYSTEMS
Preprocessing
Compiling
Linking
Locating
6. What is a compiler and a cross compiler?
Compiler: Compiler is a program that creates an object file from the source codes. It checks the language
grammar/semantics. For eg: tcc. It converts high level language codes into machine codes.
1
Cross Compiler: A compiler that runs on one computer platform and produces code for another is called
a cross-compiler. The use of a cross-compiler is one of the defining features of embedded software
development.
7. List the important considerations when selecting a processor.
Instruction set
Maximum bits in an operand
Clock frequency
Processor ability
8. Classify the processors in embedded system.
a. General purpose processor
Microprocessor
Microcontroller
Embedded processor
Digital signal processor
Media processor
c. Multiprocessor system using GPP and ASSP GPP core or ASIP core integrated into either an
ASIC or a VLSI circuit or an FPGA core integrated with processor unit in a VLSI chip.
ROM/PROM/EEPROM/Flash
Cache memory
(i) Program Flow control Unit. (ii) Execution Unit
10. What are the two essential units of a processor on a embedded system?
11. What are the different modes of DMA transfer? Which one is suitable
forembedded system?
Single transfer at a time and then release of the hold on the system bus.
Burst transfer at a time and then release of the hold on the system bus. A burstmay
be of a few kB.
Bulk transfer and then release of the hold on the system bus after the transferis
completed.
2
12. Define ROM image and RAM.
ROM image: Final stage software is also called as ROM image .The final implement able software for a
product embeds in the ROM as an image at a frame. Bytes at each address must be defined for creating
the image.
RAM: RAM refers Random Access Memory. It is a memory location that can be accessed without
touching the other locations.
13. What are the uses of timers?
The time intervals between two events can be computed
Initiating an event after a preset time delay.
Capturing the count value
Watch dog timer
14. What is a watch dog timer?
The watch dog timer is a timing device that resets the system after a predefined
timeout. It is activated within the first few clock cycles after power-up. It has a number of
applications. Example: Mobile phone display turnoff in case of no interactions takes place
within a specified time.
The build is often referred either to the process of converting source code files into
stand alone software artifacts that can be run on a computer or the result of doing so. The process of
converting the source code representation of the embedded software into an executable binary image
involves three distinct steps.
Each of the source files must be compiled or assembled into an object file.
All of the object files that result from the first step must be linked together toproduce a
single object file called the re-locatable program.
Physical memory addresses must be assigned to the relative offsets within there- locatable
program in a process called relocation.
The result of the final step is a file containing an executable binary image that is readyto run on the
embedded system.
3
C/C++
Compiler Pre-processor
Object
Linker
Re-locatable
Locator
Executable
>Led.o
>Led.exe Processor
Target
Host computer
Printf(―LIVESIMPLE!‖);
Compilation involves both gcc compiler and assembler. First, the gcc compiler converts
the livesimple.i file into livesimple.s file. The file livesimple.s Unit 2 and 3.docx assembly code.
The gcc conversion command is
Syntax: [root@host~]#gcc
assembly code without creating–s
thelivesimple.i
object file.
Second, The
the assembler
option –translates
s tells the
thelivesimple.s file into
gcc compiler to machine
convertlanguage format andcreating
the preprocessed codeantoobject file
called livesimple.o
Syntax: [root@host`]# as livesimple.s – o livesimple.o
The option – o converts the assembly file into object file.
Linking: A linker links the compiled codes of application software, object codes from library and OS
kernel. Linking is necessary because there are number of codes to be linked for the final binary file. The
linker file in the binary for run on a computer is commonly known as executable file or simply ‗.exe‘ file.
This process converts the object file into a new object file that is a special relocatable copy of
the program. No memory addresses have been assigned to the
5
code until this process. An object file needs to be linked with many C run time library files, system
functions etc., to form an executable object file. For example: in livesimple.c program, printf statement is
needed. So printf.o file must be linked. The linker (Id) will perform all those tasks.
Syntax: [root@host~] # Id – dynamic-linker/
Locating: The tool that performs the conversion from relocatable program to executable binary image
is called a locator. In embedded systems, the next step after linking is the use of locator for the program –
codes and data in place of the loader. The features of locator are,
The locator is specified by the programmer the available addresses at the RAM and ROM in
target. The programmer has to define the available addresses to
load and create file for permanently locating codes using a device programmer.
It uses cross-assembler output, a memory allocation map and provides the locator
program output file. It is the final step of software design process for the embedded
system.
The locator locates the I/O tasks and hardware device – driver codes at the addresses
without reallocation. This is because the port and device addresses for these are fixed
for a given system.
The locator program reallocates the linked file and creates a file for permanent location
of codes in a standard format.
Output:
In windows, the executable file is denoted as livesimple.exe but there is no need of .exeextension file in
LIVESIMPLE!
Linux environment.
2. Discuss in detail about the structural units in embedded processor.
Address
Processor Data
Memory
Control
6
STRUCTURAL UNIT IN A PROCESSOR:
1. Memory Address Register (MAR): It holds the address of the byte or word to
be fetched from external memories. Processor issues the address of instructionor data to MAR
before it initiates fetch cycle.
2. Memory Data Register (MDR): It holds a byte or word fetched (or to sent) froman
external memory or IO address.
3. System Buses:
a. Internal Bus: It internally connects all the structural units inside the processor. Its width can
be 8, 18, 32, 48 or 64 bits.
b. Address Bus: An external bus that carries the address from MAR to memory as well as to
IO devices and other units of system.
c. Data Bus: An external bus that carries, during a read or write operation, the bytes for
instruction or data from or to an address. The address is determined by MAR.
d. Control Bus: An external set of signals to carry control signals to processor or
memory or device.
4. Bus Interface Unit (BIU): An interface unit between processor‘s internal unitsand
external buses.
5. Instruction Register (IR): It sequentially takes instruction codes (opcode) to
execution unit of processor.
6. Instruction Decoder (ID): It decodes the instruction received at the IR and
passes it to processor CU.
7. Control Unit (CU): It controls all the bus activities and unit functions needed for
processing.
8
A unit that controls the fetching of data into the I and D. caches in advance from the memory
units. The instructions and data are delivered when needed by the processor‘s execution units.
The processor does not have to fetch data just before executing the instruction. Pre-fetching unit
improves performance by fetching instruction and data in advance for processing.
It is a set of registers used while processing the instructions of the supervisory system program.
9. Floating Point Processing Unit (FLPU):
A unit separate from ALU for floating point processing, which is essential in processing
mathematical function fast in a microprocessor or DSP.
10. Floating Point Register set (FRS):
A register set dedicated for storing floating point numbers in a standard format and used by FLPU
for its data and stack.
11. Multiply and Accumulate Unit (MAC):
There is also a MAC unit for multiplying coefficients of a series and accumulating these during
computations.
9
12. Atomic Operation Unit (AOU):
It lets a user (compiler) instruction, when broken into a number of processor instruction called
atomic operations, finish before an intercept of a process occurs. This prevents problems from
arising out of shared data between various routines and tasks.
10
Chained block transfers
Linked block transfers
Fly- by transfers
For DMA operation, the CPU prepares the construction of a descriptor (1). It contains all
information for the DMAC to independently perform the DMA operation. It initializes the operation by
writing a command to a register in a DMAC (2a) or to a command area, where the DMAC can poll for the
command and/or the descriptor (2b). Then the DMAC addresses the device data register (3) and read the
data into a temporary data register (4). In another bus transfer cycle, it addresses the memory block (5)
and writes the data from the temporary data register to the memory block (6).
The DMAC increments the memory block address and continue with this loop
until the block length is reached. The completion of the DMA operation is signalled to the processor by
sending an IRQ signal.
11
A memory leak is a gradual loss of available computer memory, when a program repeatedly fails
to return memory that it has obtained for temporary use. Due to memory leak, run out of memory problem
will occur.
Stack overflow means that the stack exceeds the allocated memory block when there is no
provision for additional stack space. Memory manager controls the memory leaks and stack overflows.
Memory Management strategies are
1. Fixed blocks allocation: Memory address space is divided into blocks with processes of small
address spaces getting a lesser number of blocks and processes of big address spaces getting a
large number of blocks.
2. Dynamic block allocation: Memory manager allocates variable size blocks dynamically
allocated from a free list of memory blocks description table atdifferent phases of a process.
3. Dynamic Page Allocation: Memory has fixed sized blocks called pages and the memory
management unit allocates the pages dynamically with a page descriptor table.
4. Dynamic data memory allocation: The manager allocates memory dynamically to
different data structures like the nodes of a list, queues and stacks.
5. Dynamic address relocation: The manager dynamically allocates the addresses
bound to the relative address. It adds the relative address to address with relocation register. This
is also called run-time dynamic address binding.
6. Multiprocessor Memory Allocation: it adopts the tight coupling or loose coupling
between two or more processors.
7. Memory protection to OS functions: It means that the system call and function call in
user space are distinct. The memory of kernel functions is distinct and can be addressed
only by the system calls. The memory space is called kernelspace.
8. Memory Protection among the tasks: Read and write operations are not permitted
to the particular memory space allocated to another task. This
12
protection increases the memory requirement for each task and also theexecution time of the
code of the task.
The Manager optimizes the memory needs and memory utilization. The memorymanages the
following:
1. Use of memory addresses space.
2. Mechanism to share memory space
3. Mechanism to restrict sharing of a given memory space.
4. Optimization of memory.
Working Principle:
The programmer uses the emulator to load programs into the embedded system, run them, step
through them slowly and view and change data used by the system‘s software. It imitates the
central processing unit of the embedded system‘s computer.
The house of Microchip offers in circuit emulators are of 3 types: MPLAB ICE 2000, MPLAB
ICE 4000, REAL ICE.
13
ICE consists of a small dual port pod. One port is a probe that plugs into the microprocessor
socket of the target system. The second port is interfaced to a computer (or) workstation.
Limitations of ICE:
Timer is a very common and useful peripheral. It is a device that counts the regular interval (δT)
clock pulse at its input. The counts are stored and incremented on each pulse. It has output bits for the
period of counts. The counts multiplied by interval δT gives the time.
Number of counting the interval x δT = Time
Timer is a programmable device, (i.e) the time period can be adjusted by writing specific bit
patterns to some of the registers called timer-control registers.
A counter is more general version of the timer. It is a device that counts the input
for events that may occur at irregular or regular intervals. The count gives the number of
14
The figure (b) provides the structure of another timer where a multiplexer is usedto choose
between an internal clock and external clock. The mode bit when set or reset
decided the selection. For internal clock (Clk) it behaves like the timer in Figure (a). For
The figure (c) shows a timer with the terminal count. This can generate an event
if a particular interval of time has been elapsed. The counter restarts after every terminal count. For
example, in 8051 microcontroller, there is a presence of two bit timer/counter registers, Timer 0 and
Timer 1.
In timer mode, register is incremented after every machine cycle.
1 machine cycle = 12 Oscillator periods
So count rate = 1/12 of Oscillator frequency.
If crystal frequency is 12 MHz, then timer clock frequency is 1 MHz.
In counter mode, Register is incremented in response to 1 to 0 transition at the corresponding external
input pin T0 and T1.
15
Blind Counting Synchronisation:
A blind counting free running counter with prescaling, compare and capture registers has a
number of applications. It is useful for action or initiating a chain of actions and processor interrupts at
the present instances as well as for noting the instances of occurrences of the events and processor
intercepts for requesting the processor to use the captured counts on the events for future actions.
Watch dog Timer:
It is a timing device that resets the system after a predefined time out. It starts
after a few clock cycles from power up. After restart, system works normally, if any failure occurs in
past.
A watch dog timer is a piece of hardware that can be used to automatically detect
software abnormalities and reset the processor if any. It is based on the counter that counts down from
some initial value to zero.
The watchdog timer is a chip external to the processor. However, it could also be included within
the same chip as the CPU. This is done in many microcontrollers.
The process of restarting the watch dog timer‘s counter is sometimes called
“Kicking the dog”.
16
started, it never resets or never reloaded to another value. Example: DS1307 chip is a real time clock
integrated circuit.
Consider the block diagram shown below. The Arduino UNO is used for reading time from
DS1307 and display it on 16X2 LCD. DS1307 sends time/data using 2 lines to Arduino. A buzzer is also
used for alarm indication, which beeps when alarm is activated.
PROCESSOR:
SELECTION OF PROCESSOR:
Most embedded systems need some type of processor. For a system designer,the following are
important considerations when selecting a processor.
1. Instruction set
2. Maximum bits in an operand
3. Clock frequency in MHz
4. Processing speed in Million Instructions Per Second (MIPS)
5. Processing ability to solve the complex algorithms used in meeting thedeadlines for their
processing.
6. Register – windows provides fast context switching in a multitasking system.
7. Power efficient embedded system requires a processor that has auto-shut down feature for its
units and programmability for disabling use of caches when the processing need for a
function or instruction set does not have constraint of execution time. It is also required to
have stop, sleep, and wait instructions. It may alsi require special cache design
8. Burst mode accesses external memories fast, reads fast and writes fast.
9. Atomic operation unit provides hardware solution to shared data problem, when designing
embedded software or else special programming skills and
efforts are to be made when sharing the variables among the multiple tasks.
10. A processor may also be configured at the initial program stage big-endian orLittle endian
storage of words. Eg: ARM processors.
11. The strong ARM family processors from Intel and Tiger SHARC from Analogdevices have
high power efficiency features.
18
2. 8051 has only 2 timers Times 0 & Times 1, but 8052 has an additional timer
– Timer 2, which is used for the development of Real Time OperatingSystem.
3. Some Microcontrollers support master slave mechanism with the features ofI2C
and SPI supported in-built pins.
4. 8051 family member 83C152JA has two direct memory access (DMA)channels on-
chip.
5. For interfacing more number of devices, we need more pins in
microcontrollers to develop a particular application.
6. 80196KC has a PTS (Peripheral Transactions Server) that supports DMA
functions.
MICROPROCESSORS:
Microprocessor is a single VLSI chip that has a CPU and may have some other units.
Example: caches, floating point processing, arithmetic unit, pipelining etc. RAM, ROM and I/O
units will not present within a CPU chip itself. Microprocessor accepts binary data as input &
process data according to the instructions given and provides results as output. CPU has two
basic functional units such as Control unit and Arithmetic Logic Unit (ALU). Example: 8085,
8086.
MICROCONTROLLER:
MECHANISM IN MICROCONTROLLERS:
STEPS:
HARVARD ARCHITECTURE
Seperate memory for data and program with separate buses for each. Both program instructions
and data values can be fetched at the same time. Operational speed is higher than Von Neumann
architecture.
Examples:
By using this feature this mathematical part will performed in a single clock cycle. Applications
performed in this processor are fixed point & floating point operations, matrix operations, convolution,
correlation, parallelism etc.
21
Examples: C5000, C6000 single core processor families are manufactured byTexas Instruments.
C6000 processor fetch eight 32 bit instructions per clock cycle.
High MIPS(Million Instruction per second) or MFLOP (Million Floating Point IPS) multiprocessor
system is required,
Examples : Multi port 100Mbps network transceiver, fast 100 Mbps switches, routers,multichannel fast
encryptions and decryptions system.
ICD (In Circuit Debug): The next best thing to ICE is ICD (In Circuit Debug). This is for PIC
microcontroller. BDM (Background Debug Mode) is for non PIC microcontroller. For ICD the
processor has a small amount of built-in hardware that can halt the processor when the
program reaches a specific address. The software can then read back all the registers and
processor state.
Simulation: With a source code simulator you can step through the high level language code
and see its effect on memory and variables without having to look at the assembler code
directly. This let you focus on high level language operation and let you concentrate on the
problem you are trying to solve. One great advantage of simulator is that you do not have to
wait toRS232:
Serial download and
New program the target
microcontrollers have a processor. So you
built-in UART cangives virtually free debug tool that
which
uses minimum resources and need very little software coding. For debug output you need to connect the
cut out the time consuming programming just by using the simulator.
UART output in TX to a suitable level translator circuit a MAX 232 chip. You may even get away with
direct connection to the input of your PC serial port – using a translator chip will always work.
Advantages: Minimal coding, simple to use, minimal extra hardware.
Disadvantage: a) Takes long time to output a character (~1ms)
the end).
Logic Analyzer: This tool attaches to the pins you want to observe and captures the waveforms
displaying multiple traces on a single display. It uses a trigger module that can be set to activate the
combinations of the input signals or on their length. So you can trigger on specific patterns or on glitches
or both.
For non-microcontroller based systems where the data and address bus are exposed, a logic analyzer can
show the address and data organised into hex words i.e. readable. Some can disassemble the instruction
showing what the processor was doing at the trigger point.
24
For a microcontroller based system the logic analyzer can be useful in examining peripheral operation.
Example: for debugging the SPI or I2C buses some logic analyzers also have built in support for these
protocols.
Another use of the logic analyzer is to capture output over a long period of timedepending on the memory
capacity of the logic analyzer.
25
(P) 2348-0017
Unit-II
Types of ports
3
0
(P) 2348-0017
1. Serial Port :
Electrical Specifications :
1. Voltages:
There can be two states in the signal level of RS232C pins.
Mark state – It is the high bit which is represented by binary 1 and have
negative voltages. Its voltage limits for transmitting signal ranges from -5 to -
15V. Its voltage limits for receiving signals ranges from -3 to -25V.
Space state – It is the low bit which is represented by binary 0 and have
positive voltages. Its voltage limits for transmitting signal ranges from +5 to
+15V. Its voltage limits for receiving signals ranges from +3 to +25V.
2. Cables and Wires :
The maximum cable length for RS232C is equals to
15.24 meters or equal to the capacitance of 2500pF. Limits for the impedance of
wires ranges from 3 ohms to 7 ohms.
3 Data and Slew rates :
Rate of data transmission through RS232C is up to 20Kbps. The rate of change
in signal levels ie. slew rate is up to 30V/microsecond.
4. Current :
Maximum current rating is 3Amps at the maximum operating voltage of 250V
AC.
Pins and Working :
3
2
(P) 2348-0017
RS232C requires 25 pins connector for connecting DTE and DCE. Here is the
list of pins and signals of RS232C and the connection between DTE and DCE
using drivers and receivers.
1. TXD & RXD –
Transmit Data and Receive Data on the DTE are the serial data lines. These
lines have opposite functions on a DCE. TXT sends outgoing data to DCE.
RXD receives incoming data from DTE.
4. DCD –
DCE activates the Data Carrier Detect in order to show that it has been
connected to DTE.
5. RI –
When an incoming call on the telephone line is detected by DCE, then the
Ring Indicator gets activates.
3
3
Handshaking:
Before the actual data transfer, signals are transmitted from DTE(P)to2348-0017
DCE in
order to make connections by a process known as handshaking. Following is the
sequence of signal handshaking:
Initially, the computer activates RTS signal to modem when a data is
transferred from computer to modem.
Modem in turn activates the DCD and then the CTS gets activated.
Computer then sends data on TXD. After the data transmission is
completed, the computer deactivates the RTS which causes the modem to
deactivate CTS.
Applications :
However, most of functions performed by RS232C has been taken by the USB,
but they are still successful in performing following applications.
1. It is used in establishing communication between the computer and
embedded systems.
2. Due to its lower costs, It plays a vital role in CNC machines and servo
controllers
3. Some microcontroller boards and PLC machines use RS232C.
4. RS232C ports are used to communicate in headless systems in the absence
of any network connection.
5. Many Computerized Numerical Control Systems are contains RS232C
port.
Limitations :
1. It cannot be used for chip to chip or chip to sensor device communication
2. It degrades the performance of the system in the presence of noise and
requires shorter cables due to having common grounds between DTE and
DCE
3. The cost of system increases as RS232C interface needs separate
transceiver chips.
4. Its performance degrades to short distances only when transfer speed is
high.
RS422 protocol
RS422 is similar to RS232 protocol, and can be programmed in the same way,
3
however, offers a few advantages and disadvantages. One problem is that you need to
4
purchase an RS422 port or at least an RS422 to RS232 converter, since PC's don't
come standard with this interface. Also, you may find that there are fewer(P)devices
2348-0017
supporting RS422. Some advantages are:
1. Long Distance Runs - Up to 500 feet is generally supported, and with repeaters,
even further distances can be achieved.
2. Multi-Drop - Usually, up to 32 devices can be connected per port, and even
more using repeaters. Devices are distinguished by unique addresses that are
assigned to each device. For example, if you have 5 devices attached to a port,
they would be addressed as units 1 to 5. If you want to communicate to unit #1,
you send a command to unit #1. All units HEAR the command, but only the
addressed unit will respond. This also applies to RS485. The addresses can be
set via switches or software, depending on the design of the device.
3. Noise Resistant - Since it uses a separate FLOATING transmit and receive pair
(four wires), it offers better noise immunity than RS232.
RS485 protocol
RS485 is very similar to RS422. So much so that it often causes confusion. Both are
multi-drop, and both can communicate via very long distances, so then why choose
one over the other? First of all, RS485 is generally a 2-wire system, although some
manufacturers may specify 4-wire RS485, which is far less common and very similar
to RS422 protocol. It is important that you identify which one is being employed
when considering an instrument. Here are some main differences between 2-wire
RS485 and RS422:
Note:it may be easier to use an rs232 to rs485 converter that sits outside the pc. Make
sure that the converter has intelligent control of the transmitters so that it will
automatically take care of the switching for you and will be transparent to the user.
Then, program the device as you would an rs422 or rs232 device. One such device is
our model cat-285.
What is CAN?
CAN is short for ‘controller area network’. Controller area network is an electronic communication bus
defined by the ISO 11898 standards. Those standards define how communication happens, how wiring is
configured and how messages are constructed, among other things. Collectively, this system is referred to as
a CAN bus.
3
6
What We'll Cover
(P) 2348-0017
To get deeper into the details of CAN, the CAN bus is a broadcast type of bus. This means that all nodes can
“hear” all transmissions. There is no way to send a message to just a specific node; all nodes will invariably
pick up all traffic. The CAN hardware, however, provides local filtering so that each node may react only on
the interesting messages. We’ll discuss this more in Section 2, “CAN Messages”.
We’ll also discuss how the bus uses Non-Return To Zero (NRZ) with bit-stuffing. In this system, the
modules are connected to the bus in a wired-and fashion: if just one node is driving the bus to a logical 0,
then the whole bus is in that state regardless of the number of nodes transmitting a logical 1.
The CAN standard defines four different message types. The messages uses a clever scheme of bit-wise
arbitration to control access to the bus, and each message is tagged with a priority.
The CAN standard also defines an elaborate scheme for error handling and confinement which is described in
more detail in Section 7, “CAN Error Handling”.
Bit timing and clock synchronization is discussed in Section 6 of this tutorial. Here’s a bit timing
calculator you can use to calculate the CAN bus parameters and register settings.
CAN bus wiring may be implemented using different physical layers (Section 3), some of which are
described here, and there are also a fair number of CAN bus connector types (Section 5) in use. We also
provide a number of oscilloscope pictures (Section 4) for those interested in the details of a message.
CAN Messages
The CAN bus is a broadcast type of bus. This means that all nodes can ‘hear’ all transmissions. There is no
way to send a message to just a specific node; all nodes will invariably pick up all traffic. The CAN
hardware, however, provides local filtering so that each node may react only on the interesting messages.
The Data Frame is the most common message type. It comprises the following major parts (a few details are
omitted for the sake of brevity):
3
7
the Arbitration Field, which determines the priority of the message when two or more nodes are
contending for the bus. The Arbitration Field contains:
(P) 2348-0017
For CAN 2.0A, an 11-bit Identifier and one bit, the RTR bit, which is dominant for data
frames.
For CAN 2.0B, a 29-bit Identifier (which also contains two recessive bits: SRR and IDE) and
the RTR bit.
the CRC Field, which contains a 15-bit checksum calculated on most parts of the message. This
checksum is used for error detection.
an Acknowledgement Slot; any CAN controller that has been able to correctly receive the message
sends an Acknowledgement bit at the end of each message. The transmitter checks for the presence of the
Acknowledge bit and retransmits the message if no acknowledge was detected.
Note 1: It is worth noting that the presence of an Acknowledgement Bit on the bus does not mean that any of
the intended addressees has received the message. The only thing we know is that one or more nodes on the
bus has received it correctly.
Note 2: The Identifier in the Arbitration Field is not, despite of its name, necessarily identifying the contents
of the message.
3
8
(P) 2348-0017
The Remote Frame
The Remote Frame is just like the Data Frame, with two important differences:
it is explicitly marked as a Remote Frame (the RTR bit in the Arbitration Field is recessive), and
The intended purpose of the Remote Frame is to solicit the transmission of the corresponding Data Frame. If,
say, node A transmits a Remote Frame with the Arbitration Field set to 234, then node B, if properly
initialized, might respond with a Data Frame with the Arbitration Field also set to 234.
Remote Frames can be used to implement a request-response type of bus traffic management
Simply put, the Error Frame is a special message that violates the framing rules of a CAN message. It is
transmitted when a node detects a fault and will cause all other nodes to detect a fault – so they will send
Error Frames, too. The transmitter will then automatically try to retransmit the message. There is an elaborate
scheme of error counters that ensures that a node can’t destroy the bus traffic by repeatedly transmitting Error
Frames.
The Error Frame consists of an Error Flag, which is 6 bits of the same value (thus violating the bit-stuffing
rule) and an Error Delimiter, which is 8 recessive bits. The Error Delimiter provides some space in which the
other nodes on the bus can send their Error Flags when they detect the first Error
SCK .
Master Output → Slave Input (MOSI):
SIMO, MTSR - correspond to MOSI on both master and slave devices, connects to each
other
SDI, DI, DIN, SI - on slave devices; connects to MOSI on master, or to below connections
SDO, DO, DOUT, SO - on master devices; connects to MOSI on slave, or to above
connections
Master Input ← Slave Output (MISO):
SOMI, MRST - correspond to MISO on both master and slave devices, connects to each
other
SDO, DO, DOUT, SO - on slave devices; connects to MISO on master, or to below
connections
SDI, DI, DIN, SI - on master devices; connects to MISO on slave, or to above connections
Slave Select:
Operation[edit]
The SPI bus can operate with a single master device and with one or more slave devices.
If a single slave device is used, the SS pin may be fixed to logic low if the slave permits it. Some
slaves require a falling edge of the chip select signal to initiate an action. An example is
the Maxim MAX1242 ADC, which starts conversion on a high→low transition. With multiple slave
devices, an independent SS signal is required from the master for each slave device.
4
0
Most slave devices have tri-state outputs so their MISO signal becomes high
impedance (electrically disconnected) when the device is not selected. Devices without tri-state
(P) 2348-0017
outputs cannot share SPI bus segments with other devices without using an external tri-state buffer.
Data transmission[edit]
(Note: refer to the ‘Variations’ section later in this article for further details.)
A typical hardware setup using two shift registers to form an inter-chip circular buffer
To begin communication, the bus master configures the clock, using a frequency supported by the
slave device, typically up to a few MHz. The master then selects the slave device with a logic level
0 on the select line. If a waiting period is required, such as for an analog-to-digital conversion, the
master must wait for at least that period of time before issuing clock cycles.
During each SPI clock cycle, a full-duplex data transmission occurs. The master sends a bit on the
MOSI line and the slave reads it, while the slave sends a bit on the MISO line and the master reads
it. This sequence is maintained even when only one-directional data transfer is intended.
Transmissions normally involve two shift registers of some given word-size, such as eight bits, one
in the master and one in the slave; they are connected in a virtual ring topology. Data is usually
shifted out with the most significant bit first. On the clock edge, both master and slave shift out a bit
and output it on the transmission line to the counterpart. On the next clock edge, at each receiver the
bit is sampled from the transmission line and set as a new least-significant bit of the shift register.
After the register bits have been shifted out and in, the master and slave have exchanged register
values. If more data needs to be exchanged, the shift registers are reloaded and the process repeats.
Transmission may continue for any number of clock cycles. When complete, the master stops
toggling the clock signal, and typically deselects the slave.
Transmissions often consist of eight-bit words. However, other word-sizes are also common, for
example, sixteen-bit words for touch-screen controllers or audio codecs, such as the TSC2101
by Texas Instruments, or twelve-bit words for many digital-to-analog or analog-to-digital
converters. Multiple SPI devices may also be daisy-chained to conserve pins.
Every slave on the bus that has not been activated using its chip select line must disregard the input
clock and MOSI signals and should not drive MISO (i.e., must have a tristate output) although some
devices need external tristate buffers to implement this.
SPI Interface bus is commonly used for interfacing microprocessor or microcontroller with memory
like EEPROM, RTC (Real Time Clock), ADC (Analog – to – Digital Converters), DAC (Digital –
to – Analog Converters), displays like LCDs, Audio ICs, sensors like temperature and pressure,
memory cards like MMC or SD Cards or even other microcontrollers.
In UART (or any common serial port), where the communication happens over RX and TX line,
there is no clock signal i.e. it is an asynchronous communication. In this type of communication,
there is no control over the data sent or whether the transmitter and receiver have same data rates.
In order to overcome this, UART uses synchronisation bits i.e. Start bit and Stop bits and also a pre
agreed data transfer speeds (typically 9600 bps). If the baud rates of transmitter and receiver are not
matched, the data sent from the transmitter will not reach the receiver properly and often garbage or
junk values are received.
For short distance communication, Synchronous Serial Communication would be a better choice
and in that Serial Peripheral Interface or SPI in particular is the best choice. When we say short
distance communication, it often means communication with in a device or between the devices on
the same board (PCB).
The other type of Synchronous Serial Communication Protocol is I2C (Inter – Integrated
Communication, often called as I Squared C or I Two C). For this article, we will focus on SPI.
SPI is a Synchronous type serial communication i.e. it uses a dedicated clock signal to synchronise
the transmitter and receiver or Master and Slave, speaking in SPI terms. The transmitter and receiver
are connected with separate data and clock lines and the clock signal will help the receiver when to
look for data on the bus.
4
2
(P) 2348-0017
The clock signal must be supplied by the Master to the slave (or all the slaves in case of multiple
slave setup). There are two types of triggering mechanisms on the clock signal that are used to
intimate the receiver about the data: Edge Triggering and Level Triggering.
The most commonly used triggering is edge triggering and there are two types: rising edge (low to
high transition on the clock) and falling edge (high to low transition). Depending on how the
receiver is configured, up on detecting the edge, the receiver will look for data on the data bus from
the next bit. S
Since both the clock and data are sent by the Master (or transmitter), we need not worry about the
speed of data transfer.
What makes SPI so popular among other Synchronous Serial Communication protocols (or any
serial communication for that matter) is that it provides a high speed secured data transfer with
reasonably simple hardware like shift registers at relatively less cost.
Because of its simple interface, flexibility and ease of use, SPI has become a standard and soon
other semiconductor manufacturers started implementing it in their chips.
In SPI protocol, the devices are connected in a Master – Slave relationship in a multi – point
interface. In this type of interface, one device is considered the Master of the bus (usually a
4
3
Microcontroller) and all the other devices (peripheral ICs or even other Microcontrollers) are
considered as slaves.
(P) 2348-0017
In SPI protocol, there can be only one master but many slave devices.
Since, the SPI bus is implemented using 4 signals or wires, it is sometimes called as Four Wire
Interface. Let us first see a simple interface between a single master and single slave that are
connected using SPI protocol and then we will explain about the 4 wires.
The following image depicts a Master (Processor) connected to a Slave (Peripheral) using SPI
bu
s.
Master – Out / Slave – In or MOSI, as the name suggests, is the data generated by the Master and
received by the Slave. Hence, MOSI pins on both the master and slave are connected together.
Master – In / Slave – Out or MISO is the data generated by Slave and must be transmitted to Master.
MISO pins on both the master and slave are ties together. Even though the Signal in MISO is
produced by the Slave, the line is controlled by the Master. The Master generates a clock signal at
SCLK and is supplied to the clock input of the slave. Chip Select (CS) or Slave Select (SS) is used
to select a particular slave by the master.
Since the clock is generated by the Master, the flow of data is controlled by the master. For every
clock cycle, one bit of data is transmitted from master to slave and one bit of data is transmitted
from slave to master.
4
4
This process happen simultaneously and after 8 clock cycles, a byte of data is transmitted in both
directions and hence, SPI is a full – duplex communication.
(P) 2348-0017
If the data has to be transmitted by only one device, then the other device has to send something
(even garbage or junk data) and it is up to the device whether the transmitted data is actual data or
not.
This means that for every bit transmitted by one device, the other device has to send one bit data i.e.
the Master simultaneously transmits data on MOSI line and receive data from slave on MISO line.
If the slave wants to transmit the data, the master has to generate the clock signal accordingly by
knowing when the slave wants to send the data in advance. If more than one slave has to be
connected to the master, then the setup will be something similar to the following image.
Even though multiple slaves are connected to the master in the SPI bus, only one slave will be
active at any time. In order to select the slave, the master will pull down the SS (Slave Select) or CS
(Chip Select) line of the corresponding slave.
Hence, there must by a separate CS pin on the Master corresponding to each of the slave device. We
need to pull down the SS or CS line to select the slave because this line is active low.
4
5
SPI Hardware
The hardware requirement for implementing SPI is very simple when compared to UART(P) 2348-0017
and I2C.
Consider a Master and a single Slave are connected using SPI bus. The following image shows the
minimal system requirements for both the devices.
From the image, the Master device consists of a Shift Register, a data latch and a clock generator.
The slave consists of similar hardware: a shift register and a data latch. Both the shift registers are
connected to form a loop. Usually, the size of the register is 8 – bits but higher size registers of 16 –
bits are also common.
During the positive edge of the clock signal, both the devices (master and slave) read input bit into
LSB of the register. During the negative cycle of the clock signal, both the master and slave places a
bit on its corresponding output from the MSB of the shift register.
Hence, for each clock cycle, a bit of data is transferred in each direction i.e. from master to slave
and slave to master. So, for a byte of data to be transmitted from each device, it will take 8 clock
cycles.
In fact, the master and slave have to agree on certain synchronization protocols. For this, two
features of the clock i.e. the Clock Polarity (CPOL or CKP) and Clock Phase (CPHA) come in to
picture.
Clock Polarity determines the state of the clock. When CPOL is LOW, the clock generated by the
Master i.e. SCK is LOW when idle and toggles to HIGH during active state (during a transfer).
Similarly, when CPOL is HIGH, SCK is HIGH during idle and LOW during active state.
Clock Phase determines the clock transition i.e. rising (LOW to HIGH) or falling (HIGH to LOW),
at which the data is transmitted. When CPHA is 0, the data is transmitted on the rising edge of the
clock. Data is transmitted on the falling edge when4CPHA is 1.
6
Depending on the values of Clock Polarity (CPOL) and Clock Phase (CPHA), there are 4 modes of
operation of SPI: Modes 0 through 3.
(P) 2348-0017
Mode 0:
Mode 0 occurs when Clock Polarity is LOW and Clock Phase is 0 (CPOL = 0 and CPHA = 0).
During Mode 0, data transmission occurs during rising edge of the clock.
Mode 1:
Mode 1 occurs when Clock Polarity is LOW and Clock Phase is 1 (CPOL = 0 and CPHA = 1).
During Mode 1, data transmission occurs during falling edge of the clock.
Mode 2:
Mode 2 occurs when Clock Polarity is HIGH and Clock Phase is 0 (CPOL = 1 and CPHA = 0).
During Mode 2, data transmission occurs during rising edge of the clock.
Mode 3:
Mode 3 occurs when Clock Polarity is HIGH and Clock Phase is 1 (CPOL = 1 and CPHA = 1).
During Mode 3, data transmission occurs during falling edge of the clock.
SPI Configurations
There are two types of configurations in which the SPI devices can be connected in an SPI bus.
They are Independent Slave Configuration and Daisy Chain Configuration.
In Independent Slave Configuration, the master has dedicated Slave Select Lines for all the slaves
and each slave can be selected individually. All the4 clock signals of the slaves are connected to the
master SCK. 7
Similarly, all the MOSI pins of all the slaves are connected to the MOSI pin of the master and all
the MISO pins of all the slaves are connected to the MISO pin of the master.
(P) 2348-0017
In Daisy Chain Configuration, only a single Slave Select line is connected to all the slaves. The
MOSI of the master is connected to the MOSI of slave 1. MISO of slave 1 is connected to MOSI of
slave 2 and so on. The MISO of the final slave is connected to the MISO of the master.
Consider the master transmits 3 bytes of data in to the SPI bus. First, the 1st byte of data is shifted to
slave 1. When the 2nd byte of data reaches slave 1, the first byte is pushed in to slave 2.
Finally, when the 3rd byte of data arrives in to the first slave, the 1st byte of data is shifted to slave 3
and the second byte of data is shifted in to second slave.
If the master wants to retrieve information from the slaves, it has to send 3 bytes of junk data to the
slaves so that the information in the slaves comes to the master.
4
8
Applications of SPI
Memory: SD Card , MMC , EEPROM , Flash (P) 2348-0017
Sensors: Temperature and Pressure
Control Devices: ADC , DAC , digital POTS and Audio Codec.
Others: Camera Lens Mount, touchscreen, LCD, RTC, video game controller, etc.
Advantages
SPI is very simple to implement and the hardware requirements are not that complex.
Supports full – duplex communication at all times.
Very high speed of data transfer.
No need for individual addresses for slaves as CS or SS is used.
Only one master device is supported and hence there is no chance of conflicts.
Clock from the master is configured based on speed of the slave and hence slave doesn’t have to
worry about clock.
Disadvantages
Each additional slave requires an additional dedicated pin on master for CS or SS.
There is no acknowledgement mechanism and hence there is no confirmation of receipt of data.
Slowest device determines the speed of transfer.
There are no official standards and hence often used in application specific implementations.
There is no flow control.
4
9
(P) 2348-0017
According to I2C protocols, the data line can not change when the clock line is high, it can change
only when the clock line is low. The 2 lines are open drain, hence a pull-up resistor is required so
that the lines are high since the devices on the I2C bus are active low. The data is transmitted in
the form of packets which comprises 9 bits. The sequence of these bits are –
1. Start Condition – 1 bit
2. Slave Address – 8 bit
3. Acknowledge – 1 bit
Start and Stop Conditions :
START and STOP can be generated by keeping the SCL line high and changing the level of SDA.
To generate START condition the SDA is changed from high to low while keeping the SCL high.
To generate STOP condition SDA goes from low to high while keeping the SCL high, as shown in
the figure below.
5
1
Unit-III
(P) 2348-0017
3. To develop it ( Implementation).
5
2
(P) 2348-0017
1. EDLC is essential for understanding the scope (fesilities) and complexity of the work involved in
embedded systems development.
3. EDLC defines interaction and activities among various groups of a product development phase.
5
3
(P) 2348-0017
1. The ultimate aim of any embedded product in a commercial production setup is to produce Marginal
benefit.
3. The investment for product development includes initial investment, manpower, infra structure
investment etc.
Quality in any product development is Return On Investment (ROI) achieved by the product.
1. Initial Investment
2. Developer recruiting.
3. Training
5
4. Infra structure requirement. 4
Risk minimization defect prevention in product development through project management
Productivity in which, when, product is increased then investment is fall down. Saving man
power.
5
5
Phases of EDLC.
2. Product Re-engineering
3. Product Maintenance.
Conceptualization phase:
It defines the scope of concept. It performs cost benefit analysis and prepare project
management and risk management plans & feasibility study.
Activities in conceptualization:
2. Cost Benefit Analysis (CBA) : Revealing and assessing the total development cost and profit
expected from the product.
3. Product scope : Deals with the activities involved in the product to be made.
4. Planning Activities: It requires various plans to be developed first, before development like resource
planning & Risk management plans.
Analysis Phase :
The product is defined in detailed with respect to the inputs, processes, outputs and interfaces
at a functional level.
Activities in Analysis:
1. Analysis & Documentation: It specifies the business needs of the product under development.
· Operational requirements.
· Maintenance requirements
· General assumptions.
5
6
Defining Test plan and procedures phase :
In product development there are various types of testing is performed they are (P) 2348-0017
◊ System Testing : Testing functional aspects (or) functional requirements of the product after
integration.
◊ User acceptance testing : Testing the product to meet the end user requirements.
Design phase:
It identifies application environment and creates an over all architecture for the product.
§ On completion it resembles a “black box” , that defines only the inputs and outputs.
§ The operational manual design, maintenance manual design, product Training material Design all
together called the “Detailed Design Document”.
Development means designing the particular product into hardware and software.
v Unit testing
v Integration testing
v System testing
Deployment Phase:
Support phase:
The support deals with the operational & maintenance of the product in the production
environment.
Upgrades Phase:
Deals with the development of up grades (new version) for the product, which is already present
in the market.
During the upgrade phase the system is subject to design modification in major areas.
Retirement/Disposal;
1.Processor Trends:
5
8
There is a points of difference between the first generation of processor/controller and today’s
processor/controller. (P) 2348-0017
Today’s processors with VLSI technology can pack (together) ten of thousands of IC/gates
per processor.
Early processors need different components like timers, DAC/ADC separately interfaced.
Today’s processors have all these components on the same chip as the processor.
4. Speed of execution:
Today’s processor with advanced architecture support features like instruction pipeline,
improving the execution speed.
5.Clock Frequency:
This concept makes possible to integrate all functional systems required to build an embedded
product into a single chip.
SOC are now available for a wide variety of diverse applications as Media players, PDA etc.
This concept specifies multiple cores on the same processor chip, operating at the same
clock frequency and battery.
v Tri core-3cores
5
v Quad core-4 cores. 9
Each core implements pipelining and multi threading.
The advancements in processor technology caused a major change in the Embedded operating
System Industry.
There are lots of options for Embedded operating System to select both commercial and open
source.
There are two aspects to Development languages w.r.to Embedded systems Development.
i. Embedded Firmware:
ii Embedded Software;
It is the software that is responsible for interfacing with the Embedded System.
It is the user application that executes on top of the Embedded system on a Host Computer.
Early languages available for Embedded systems development were limited, they are C &
C++ only.
Open Source Standards and frame works Specific to the mobile hand set industry.
OMA (Open Mobile Alliance) is a standard body for creating open standards for mobile
industry.
6
1
(P) 2348-0017
The total design of data and control units can be done by using Software only, Hardware only or
Hardware/Software Co design methodologies. The selection of design methodology can be done by
using different non functional constraints like area, speed, power, cost etc. The software design
methodology can be selected for the systems with specifications as less timing related issues and less
area constraints. Using the software design system less area and low speed systems can be designed.
To design a system with high speed, timing issues 6 need to be considered. The hardware design
2
methodology is one solution to design high speed systems with more area compared to software
designs. Because of present SoC designs, systems with high speed, less area, portability, low power
(P) 2348-0017
have created the need of combining the hardware and software design methodologies called as
Hardware/Software Co-Design. The co-design can be defined as the process of designing and
integrating different components on to a single IC or a system. The components can be a hardware
component like ASIC, software component like microprocessor, microcontroller, electrical
component or a mechanical component etc.
6
3
The Software design methodology for a microprocessor with design flow is explained in section II
and the hardware design methodology for an FPGA with design flow is explained in section III. The
Hardware/Software Co-Design methodology issues are explained by using design flow in section IV
then conclusion and references.
SOFTWARE DESIGN METHODOLOGY
In general the design of a system with software based needs a design entry as
programming language like c, c++ etc. The design flow is shown in Fig.2.
In this methodology the constraints are with respect to area but not speed.
The system design information can be specified by using user requirements to
the system designer. The user requirements are verified according to the
target board (like processor), area, speed and other non functional constraints.
If the user requirements satisfy existing elements then the design will move
forward, otherwise user has to refine the requirements. General programming
languages like c, c++ etc can be used as the design entry and compilation will
be done to check the functionality is with respect to specifications or not.
Finally hex file or bit file is generated according to the target device.
Fig.2: Software Based Design Flow
The advantage of this design process is easy to design and implement with less area but timing issues
and speed cannot be improved. The timing issues and speed can be considered by using the hardware
based design methodology.
HARDWARE DESIGN METHODOLOGY
The systems with hardware components considering timing can be designed by using a programmable
devices like PLA, PAL, PGA, FPGA or a non programmable device like ASIC. The systems behavior
can be expressed by using a Hardware Description Language like Verilog HDL, VHDL etc. instead of
a programming language. These HDL languages describe the timing behavior of the hardware
elements. The design flow for an FPGA is shown in Fig.3.
2
The advantage of hardware based design methodology is the timing information can be specified by
using HDL and high speed systems can be designed compared to software based methods.
A. Specifications
The specifications can be refined from the user
requirements such that the target system can fit into
any one of the available hardware component or
software element. This caring of specifications is
not available in the HW or SW design
methodologies. Because of the HW/SW elements in
the target system specifications must be properly
selected.
Fig 4: Generic Co-Design Flow
B. Design Entry
The specifications can be expressed by using different types of models, languages etc. One best
method of design entry is combining some programming language features with hardware description
language features or vice versa. This combination of different languages leads to a new co-design
language. The design entry can be selected based on the following criteria.
If the specifications can not be partitioned /separated into hardware blocks or software blocks
then use this co-design language.
The languages can be combined based on the performance criteria i.e. primal approach or dual
approach.
The number of registers of the target processor is also a constraint in the language selection.
The language selection can be based on target compiler availability also.
Some of the co-design specification languages are like LOTOS, SDL, and HardwareC etc.
3
C. Co-Simulation
The system functionality of a hardware system can be verified by simulation; software system can be
verified by using compilation. But functionality of a system with both hardware and software parts
can not be verified by using simulation or compilation. This is due to the following reasons.
The system feature with HDL language elements can not be verified by using compilation.
The system feature with programming language can not be verified by using simulation.
The present available compilers can not be used for the verification because of register
widths, processor capacity and new features because of multiple systems integration.
Hence, to verify the HW/SW co-design system functionality a new tool called as co-simulation is
required. The design of a co-simulator is also a complex process. After the co simulation, the design
can be applied to HW/SW portioning block.
D. HW/SW Partitioning
After the co simulation of the system some of the elements can be portioned into hardware/software
elements. This partitioning consists of following three portions to avoid functionality mismatch.
Hardware Part
Software Part
Communication Synthesis
The system is partitioned into hardware part which consists of hardware elements and software part
which consists of software elements. The integration of these hardware and software parts to maintain
the functionality can be done by using communication synthesis.
E. Hardware Part
The hardware part consists of hardware specifications that can be observed from the given system
specifications. The hardware specifications can be converted into hardware elements by using
synthesis, placement and routing. This process is similar to normal hardware design methodology.
F. Software Part
The software part consists of software specifications that can be observed from the given system
specifications. The software specifications can be mapped to software elements by using compilation,
software implementation model with respect to the target processor. This process is similar to normal
software design methodology.
G. Communication Synthesis
The communication synthesis acts as a controller in between hardware part and software part. This block
integrates the signals of both hardware and software parts to avoid functionality mismatches. The design of
communication synthesis is complex because of communication between different blocks.
H. HW/SW System
The total system can be designed by generating the final bit file for the entire hardware block,
software block and communication synthesis blocks etc. This block generates combined bit file for the
entire system for the given specifications.
4
The hardware software co design based system can be designed by using the partitioning of hardware and software
resources using partitioning techniques. After the partitioning the design uses hardware flow and software flows for
the concerned steps and at the end these two blocks are communicated to complete the total system. The
partitioning of the co design system is done based on the optimization goal. The optimization goals can be
approach.area, speed, power etc. Two major approaches are used for partitioning, i.e. Primal approach and Dual
PROGRAM MODELS
In this model, each phase of EDLC is executed in sequence and the flow is unidirectional with
output of one phase serving as the input to the next phase. The feedback of each pulse is available
locally and only after they are executed.
Review mechanisms are employed to ensure that the process flow in right
direction.
Bugs are not fixed immediately and they are postponed to support phase.
Advantages:
Rich documentation
52
The incremental model is a superset of iterative model where the requirementsare known at
the beginning.
53
The short comings of the protomodel after each cycle are evaluated and it isfixed
in the next cycle
After the initial requirement analysis, design is made and development process is
started. Then this prototype is sent to the customer for evaluation. The customer
provides the feedback to the developer for further improvement.
Then the developer repeat the process with some additional features and finally
delivered to the outside world
Advantages:
Spiral Model:
Spiral model is best suited for the development of complex embedded products &
situations where the requirements are changing from customer side
Risk evaluation in each stage helps in reducing risk
54
Spiral model is best suited for the development of complex embedded products &
situations where the requirements are changing from customer side
Risk evaluation in each stage helps in reducing risk
It is the combination of linear & prototype models to give the best possible risk
minimized EDLC model. The activities in the spiral model present in the 4
quadrants are:
o Key concepts hardware and software developed at the same time on parallel
Concurrent:
paths
o Integrated: interaction between hardware and software developments to
produce designs that meet performance criteria and functional specifications Fundamental
issues:
The problem statement is hardware software co-design and its issues. Some of theissues are:
3. The finite state machine datapath – this architecture combines the controller
architecture with datapath architecture. The controller generates the control input,
whereas the datapath processes the data.
4. The complex instruction set computing (CISC) – this architecture uses an instruction set
for solving complex operations. The use of a single complex instruction in place of multiple
simple instructions greatly reduces the program memory access & program memory size
requirement. On the other hand, Reduced Instruction Set Computing (RISC) architecture uses
the multiple RISC instructions to perform a complex operation. RISC architecture supports
extensive pipelining
units in the datapath
5. The Very Long Instruction Word (VLIW) – this architecture implements functional
6. Parallel processing architecture – implements multiple concurrent processing elements and each
processing element may associate a datapath containing register & local memory. Single Instruction
Multiple Data (SIMD) & Multiple Instruction Multiple Data (MIMD) architectures are examples for
parallel processing architecture. SIMD – eg: Reconfigurable process, MIMD – eg: Multiprocessor
systems
56
verilog, etc. for hardware implementations. C++ is a good language for capturing anobject oriented
model.
A DFG model is said to be either acyclic DFG (does not contain multiple input values &
multiple output values) or non-acyclic DFG (output is feedback to the input).
The functions are executed in a sequential order, which is same as the conventional procedural
programming. The program instructions are iterated and executed with condition and the data gets
transformed through a series of operations. The tools for sequential program model are FSM &
flowcharts. Consider an example ‗Seat Belt warning system‘ programming.
# define ON 1 #
define OFF 0#
define YES 1#
define NO 0
Void seatbelt_caution ()
{
Waiting ( );
If (checkIgnition ( ) = = ON)
{
If (checkseat belt ( ) = = OFF)
{
58
SetTimes (3); Start
Alarm ( );
While ((check seat belt ( ) = = OFF) && (check Ignition ( ) = = OFF) &&(Timer Expire ( )
= = NO));
Stop Alarm ( );
}
}
}
This model executes the processes concurrently. It is easier to implement than the
conventional sequential execution. Sequential execution leads to poor processor utilization. Concurrent
processing model requires additional overheads in task scheduling, task synchronization and
communication. Now consider the example of seat belt warning system in concurrent processing model.
We can split the tasks into:
1. Timer task for waiting 10 seconds
2. Task for checking the ignition key status
3. Task for checking the seat belt status
4. Task for starting & stopping the alarm
5. Alarm timer task for waiting 3 seconds
These tasks are needed to synchronize.
59
Figure: Concurrent Processing program model for seat belt warning system.
The concurrent processing model is commonly used for the modeling of real timesystem.
(v) Object – oriented model:
It is an object based model
It splits the complex software requirement into well defined pieces called objects
It brings re-usability, maintainability & productivity in system design
Each object is characterized by a set of unique behavior & state. A class is anabstract of a
set of objects.
A class represents the state of an object through member variables and object
Advantages:
The advantages of real-time operating systems are as follows-
1. Maximum consumption –
Maximum utilization of devices and systems. Thus more output from all the resources.
2. Task Shifting –
Time assigned for shifting tasks in these systems is very less. For example, in older systems, it
takes about 10 microseconds. Shifting one task to another and in the latest systems, it takes 3
microseconds.
3. Focus On Application –
Focus on running applications and less importance to applications that are in the queue.
5. Error Free –
These types of systems are error-free.
6. Memory Allocation –
Memory allocation is best managed in these types of systems.
Disadvantages:
The disadvantages of real-time operating systems are as follows-
1. Limited Tasks –
Very few tasks run simultaneously, and their concentration is very less on few applications to
avoid errors.
5. Thread Priority –
It is not good to set thread priority as these systems are very less prone to switching tasks.
1. Hard real-time system: This type of system can never miss its deadline. Missing the deadline
may have disastrous consequences. The usefulness of results produced by a hard real-time system
decreases abruptly and may become negative if tardiness increases. Tardiness means how late a
real-time system completes its task with respect to its deadline. Example: Flight controller
system.
2. Soft real-time system: This type of system can miss its deadline occasionally with some
acceptably low probability. Missing the deadline have no disastrous consequences. The usefulness
of results produced by a soft real-time system decreases gradually with an increase in tardiness.
Example: Telephone switches.
1. Job: A job is a small piece of work that can be assigned to a processor and may or may not
require resources.
2. Task: A set of related jobs that jointly provide some system functionality.
3. Release time of a job: It is the time at which the job becomes ready for execution.
4. Execution time of a job: It is the time taken by the job to finish its execution.
5. Deadline of a job: It is the time by which a job should finish its execution. Deadline is of two
types: absolute deadline and relative deadline.
6. Response time of a job: It is the length of time from the release time of a job to the instant
when it finishes.
7. The maximum allowable response time of a job is called its relative deadline.
8. The absolute deadline of a job is equal to its relative deadline plus its release time.
9. Processors are also known as active resources. They are essential for the execution of a job. A
job must have one or more processors in order to execute and proceed towards completion.
Example: computer, transmission links.
10. Resources are also known as passive resources. A job may or may not require a resource
during its execution. Example: memory, mutex
11. Two resources are identical if they can be used interchangeably else they are heterogeneous.
Multiprocessing refers to the hardware (i.e., the CPU units) rather than the software (i.e., running
processes). If the underlying hardware provides more than one processor then that is multiprocessing.
It is the ability of the system to leverage multiple processors’ computing power.
Difference between Multi programming and Multi processing –
A System can be both multi programmed by having multiple programs running at the same
time and multiprocessing by having more than one physical processor. The difference between
multiprocessing and multi programming is that Multiprocessing is basically executing multiple
processes at the same time on multiple processors, whereas multi programming is keeping several
programs in main memory and executing them concurrently using a single CPU only.
Multiprocessing occurs by means of parallel processing whereas Multi programming occurs by
switching from one process to other (phenomenon called as context switching).
3. Multitasking –
As the name itself suggests, multi tasking refers to execution of multiple tasks (say processes,
programs, threads etc.) at a time. In the modern operating systems, we are able to play MP3 music,
edit documents in Microsoft Word, surf the Google Chrome all simultaneously, this is accomplished
by means of multi tasking.
Multitasking is a logical extension of multi programming. The major way in which multitasking
differs from multi programming is that multi programming works solely on the concept of context
switching whereas multitasking is based on time sharing alongside the concept of context switching.
Advantages:
1. Better for long process
2. Simple method
3. No starvation
Disadvantages:
1. Convoy effect occurs. Even very small process should wait for its turn to come to
utilize the CPU. Short process behind long process results in lower CPU utilization.
2. Throughput is not emphasized.
2. Shortest Job First Scheduling (SJF):
This algorithm associated with each process the length of the next CPU burst. Shortest job first
scheduling is also called shortest process next (SPN). The process with the shortest expected processing
time is selected for execution among the available process in the ready queue. Thus, a short process will
jump to the head of the queue over long jobs.
If the next CPU bursts of two processes are the same then FCFS scheduling is cued to break the tie. SJF
scheduling algorithm is probably optimal. It gives the minimum average time for a given set of processes.
It cannot be implemented at the level of short
63
term CPU scheduling. There is no way of knowing the shortest CPU burst. SJF can be preemptive or non-
preemptive.
A preemptive SJF algorithm will preempt the currently executing process, if the next CPU burst of
newly arrived process may be shorter than what is left to the currently executing process.
A non-preemptive SJF algorithm will allow the currently running process to finish. Preemptive SJF
scheduling is sometimes called shortest remaining time first algorithm.
Advantages:
1. It gives superior turnaround time performance to shortest process next because
a short job is given immediate preference to a running longer job.
2. Throughput is high.
Disadvantages:
In preemptive mode, currently running process may be interrupted and forces the currently active
process to release the CPU on certain events such as a clock interrupt, some I/O interrupts or a system call
and they moved to the ready state by the OS.
When a new process arrives or when a interrupt occurs, preemptive policies may incur greater
overhead than non-preemptive version but preemptive version may provide better results.
It is desirable to maximize CPU utilization and throughput and to minimize turnaround time,
waiting time and response time.
The various types of pre-emptive scheduling are
1. Priority – Based Scheduling:
64
Each process is assigned a priority. The ready list contains an entry for each process ordered by
its priority. The process at the beginning of the list (highest priority)is picked first.
A variation of this scheme allows preemption of the current process when a higher priority
process arrives.
Another variation of the policy adds an aging scheme, whether the priority of a process increases
as it remains in the ready queue. Hence, this will eventually execute to completion.
If the equal priority process is in running state, after the completion of the present running
process CPU is allocated to this, even though one more equal priority processis to arrive.
Advantage:
Very good response for the highest priority process over non-pre-emptive versionof it.
Disadvantage:
Interrupt Mechanism
Instead of polling the device or entering a wait state, the CPU continuously executing its
instruction and performing useful work.
When the I/O device is ready to transfer data, it sends an interrupt request to the CPU.
This is done via a dedicated signal on the control bus.
65
Scenario of Interrupt service Routine in RTOS:
Embedded application running on top of real time operating systems require Interrupt Service
Routines (ISRs) to handle interrupt generated by external event. External events can be caused by just
about anything, form an asynchronous character arrival on a UART to a periodic timer interrupt.
ISRs have the responsibility of acknowledging the hardware condition and provide the initial
handling of data sent or received as required by the interrupt.
An ISR often is responsible for providing the RTOS with information necessary to provide services to
application threads. Examples include moving data into a buffer for processing, adding an entry to a
queue for processing, setting a value to indicate that an event has occurred and so on.
Since application code execution is interrupted during the execution of an ISR, most application
minimize the amount of code in the ISR and rely instead on non- ISR code (Thread or Task) to
complete the processing. This allows the highest priority application code to be executed as
quickly as possible and delayed as little as possible, even in situations with intense interrupt activity.
Interrupt Routines in RTOS Environment and Handling of Interrupt source calls:
ISRS have the higher priorities over the RTOS function and the tasks. So
ISR should not wait for a semaphore, mailbox, message or queue message.
An ISR should not also wait for mutex else it has to wait for othercritical
section code to finish before the critical codes in the ISR can run.
Only the IPC accept function for these events can be used, not the postfunction.
There are 3 alternative systems for the RTOS is to respond to the
hardware source calls from the interrupts.
1. Direct call to an ISR by an interrupting source and ISR sending an
ISR Enter message:
On an interrupt, the process running at the CPU is interrupted and the
ISR corresponding to that source starts executing (1).
66
A hardware source calls an ISR directly. The ISR just sends an ISR enter message to the RTOS.
ISR enter message is to inform the RTOS than an ISR has taken control of the CPU (2).
The case involves the two function such as ISR and OS function in two memory block.
ISR code can send into a mailbox or message queue(3), but the task waiting for a
mailbox or message queue does not start before the return from the ISR (4).
When ISR finishes, it sends Exit message to OS.
On return from ISR by retrieving saved context, the RTOS later on returns to the interrupted
process or reschedules the process.
RTOS action depends on the event messages, whether the task waiting for the event messages
from the ISR is a task of higher priority than the interrupted task on the interrupt.
The special ISR semaphore used in this case is OSISRSemPost ( ) which
executes the ISR. OS ensures that OSISRSemPost is returned after any system call
67
Figure: System 2 (Three memory
blocks)
This case involves the one ISR function (ISR k) and two processes (OS and pth task) in three memory
blocks other than the interrupted Nth task.
When the interrupt source k is interrupted (1), OS finishes the critical code till the
pre emption point and calls the ISR routine for interrupt k called as ISRk (3) after saving the context of a
previous task N onto a stack (2)
After executing the ISRk routine, the ISR in step (4) can post the event ormessage to the OS for
initiating the Nth or P th task after the return (5) from the ISR and after retrieving the Nth or Pth task
context.
The OS initiates the Nth or Pth task based upon their priorities.
The ISR must be short and it must put post the messages for another task.
3. RTOS First Interrupting on an Interrupt, then RTOS initiating the ISR and
then an ISR:
The two levels of ISR in RTOSes are Fast Level ISR (FLISR) and Slow Level ISR (SLISR).
FLISR is also called as hardware interrupt ISR and SLISR is also called as software interrupt ISR. FLISR
is just the ISR in RTOS and SLISR is called as Interrupt
Service Thread (IST).
FLISR reduces the interrupt latency and jitter for an interrupt service. A kth IST is a thread to
service an kth interrupt source call. An IST function is referred as deferred procedure call of the ISR.
68
When an interrupt source k is interrupted (1), OS finishes the critical code till thepre emption
point and calls the ISR routine for interrupt k called as ISRk (3) after saving
the context of a previous task N onto a stack (2)
The ISR during execution can send one or more outputs for the events and messages
into the mailboxes or queues for the ISTs (4). The IST executes the device and platform
independent code.
The ISR just before the end enables further pre-emption from the same or other
hardware sources (5). The ISR can post messages into the FIFO for the ISTs after recognizing the
interrupt source and its priority. The ISTs in the FIFO that have received the messages from the
ISR executes (6) as per their priorities on return (5) from the ISR.
The ISR has the highest priority and preempts all pending ISTs and tasks, when
no ISR or IST is pending execution in the FIFO, the interrupted task runs on return (7).
i) PROCESS
Defn: Process is defined as a computational unit that processes on a CPU and whose state changes under
the control of kernel of an OS. It has a state ,which at an instance defines by the process status(running,
blocked or finished),process structure –its data, objects and resources and process control block.
A process runs on scheduling by OS (kernel) which gives the control of CPU to the process.
Process runs instructions and the continuous changes of its state take place as the Program counter
changes.
69
Fig: Processes
Process control block
PCB is a data structure having the information using which the OS controls the process state. The PCB
stores in the protected memory addresses at kernel.The PCB consists of the following information about
the process state.
1. Process ID,process priority,parent process,child process and address to the next process PCB
which will run next.
2. Allocated program memory address blocks in physical memory and in secondary
memory for the process codes.
3. Allocated process-specific data address blocks.
4. Allocated process heap addresses.
5. Allocated process stack addresses for the functions called during running of theprocess.
6. Allocated addresses of the CPU register
7. Process-stae sugnal mask.
8. Signals dispatch table
9. OS-allocated resources descriptors
10. Security restrictions and permissions.
ii) THREAD
Application program can be said to consist of a number of threads or a number ofprocesses and
threads
70
Fig :Threads
A multiprocessing OS runs more than one process. When a process consists ofmultiple threads, it
is called multithreaded process.
A thread can be considered as a daughter process.
A thread defines a minimum unit of a multithreaded process that an OS
schedules onto the CPU and allocates the other system resources.
Different threads of a process may share a common process structure.
Multiple threads can share the data of the process.
Thread is a concept used in Java or Unix.
Thread is a process controlled entity
iii) TASKS
Task is the term used for the process in the RTOSes for the embedded systems. A task is similar to a
process or thread in an OS.
Defn: Task is defined as an embedded program computational unit that runs on a CPU under the state-
control of kernel of an OS. It has a state, which at an instance defines by status ( running, blocked or
finished),structure – its data, objects and resources and control block.
Fig:
OS. Tasks
A task consists of a sequentially executable program under a state-control by an
The state information of a task is represented by the task state (running, blocked
or finished),structure – its data, objects and resources and task control block.
Embedded software for an application may consist of a number of tasks .
Each task is independent in that it takes control of the CPU as scheduled by the
scheduler at the OS.
A task is an independent process
71
No task can call another task
The task can send signals and messages that can let another task waiting for this
signal.
Task states
1. Idle(created)state
2. Ready(active)state
3. Running state
4. Blocked(waiting)state
5. Deleted(finished)state
In unitasking environments, only one task can exist at any given time.
In multitasking OS, multiple tasks are allowed to exist simultaneously.
Threads are created within the context of a task and depending on the OS the
task can own one or more threads
Threads of a task share the same resources like working directories, files, I/O
devices, etc., but have their own PCs, stack and scheduling information.
space orAcan
task can contain atmany
contain leastthreads
one thread executing
executing differentone program
portions of onein one address
program inone address
space.
Multitasking OS
Task 1
Program1
Program 1
Task 1 Registers
Task 1 Stack
OS
Program 2
Process 2
Tasks and threads
Program1
….. Task 2 Registers
Task 2 Stack
72
Process 3
Program 2
Task 3 Stack
Thread 1
Part of Program1
Task 1 Thread 2
Program1 Part of Program1
Program 1 Task 1
Registers Thread 3
Program 2 Part of Program1
Memor
Process 2 y
OS Program1
….. Task 2
Registers
Process 3
Program 2
Task 3
Registers
Multitasking and process management
Therefore multitasking embedded OSs must find some way of allocating each task a
certain amount of time to use the master CPU and switching the master processor between
the various tasks
This is done through task implementation, scheduling, synchronization and inters task
communication.
process1
process2
Time
process3
process1
Process 1 Process 2 Process 3
Process 4
process2
process3
OS process1
process3
process1
process4
process3
process4
process3
73
Task hierarchy
OS Initial Task
Tasks are structured as a hierarchy of parent and child tasks and when anembedded kernel
starts up only one task exists.
All tasks create their child task through system calls.
The OS gains control and creates the Task Control Block (TCB)
Memory is allocated for the new child task ,its TCB and the code to be executedby the child task.
After the task is set up to run, the system call returns and the OS releases controlback to the main
program.
Types of Multitasking:
Multitasking involves the switching of execution among multiple tasks. It can beclassified into
different types.
SEMAPHORE
Suppose that there are two trains. Assume that they use an identical track. When the
first train A is to start on the track, a signal or token for A is set and the signal or token for the
other train B is reset.
Semaphore is used for signaling or notifying of a certain action and also for notifying the
acceptance of the notice or signal.
Release of a token is the occurrence of the event and acceptance of the token is taking
note of that from
s increments event.
0 to 1 for signaling or notifying occurrence of an event from asection of codes
in a task or thread.
Let a Boolean variable, s represent a semaphore.
s decrements from 1 to 0 when the event is taken note by a section in anothertask waiting for that
event and the waiting task codes start at another action
75
Fig: Action on the function call in a program, Action on pre-emption of task A by B,
program counter assignments
Binary Semaphore
A semaphore is called binary semaphore when its value is 0, it is assumed that it has been
taken or accepted and when it is 1, it is assumed that it has been released or sent
or posted
Anand
ISRno
cantask has taken
release it yet.
the token, A task can release the token as well accept thetoken or wait for
taking the token.
Example
Consider an Automatic Chocolate Vending Machine(ACVM).After the task delivers the chocolate , it has
to notify to the display task to run a waiting section of the code to display , ―Collect the nice chocolate,
Thank you, Visit Again‖. The waiting section for the display of the thank you message takes this notice
and then it starts the display of thank you message.
MAILBOX
76
A message mailbox is for an IPC message that can be used only by asingle destined
task.
The mailbox message is a message pointer or can be a message.
The source(mail sender) is the task that sends the message pointer to acreated mailbox .
The destination is the place where the OSMBoxPend function waits for themailbox message
and reads it when received.
Example:
A mobile phone LCD display task
In the mailbox, when the time and data message from a clock-process
arrives , the time is displayed at side corner on top line.
When the message is from another task to display a phone number, it isdisplayed at
the middle.
When the message is to display the signal strength of the antenna, it isdisplayed at
the vertical bar on the left.
Mailbox types at the different operating systems (OSes)
Even if the messages are inserted in a different priority, the deletion is as perthe assigned
priority parameter.
Write(Post)
Accept
Read(Pend)
Query
77
RTOS functions for the Mailbox
1. OSMBoxCreate : Creates a box and initializes the mailbox contents with a NULL
pointer
2. OSMBoxPost: Sends a message to the box
3. OSMBoxAccept: Reads the current message pointer after checking thepresence
yes or no.Deletes the mailbox when read.
4. OSMBoxWait:Waits for a mailbox message , which is read when received.
5. OSMBoxQuery: Queries the mailbox when read and not needed later.
PIPE
A message-pipe is a device for inserting (writing) and deleting(reading) from thatbetween two given
interconnected tasks or two set of tasks. Writing and reading from a
pipe is like using a C command fwrite with a file name to write into a named file, and fread with
a file name to read from the named file. Pipes are also like Java PipeInputOutputStreams.
6. Write short notes on i) shared memory, ii) message passing, iii) priority
inheritance iv) priority inversion.
Shared Memory:
79
Shared memory is a feature supported by UNIX system 5, including Linux, Sun OS and Solaris.
One process must explicitly ask for an area, using a key to be shared by other processes. This process
will be called the server. All other processes, the clients that know the shared area can access it. However,
there is no protection to a shared memory and any process that knows it can access it freely. To protect a
shared memory from being accessed at the same time by several processes, a synchronization protocol
must be setup.
A shared memory segment is identified by a unique integer, the shared memory ID. The shared
memory itself is described by a structure of type shmid-ds in header file sys / shm.h. To use this file, files
sys / types.h and sys / ipc.h must be included. Therefore, your program should start with the following
lines:
# include <sys / types.h>#
include <sys / ipc.h>
For aserver, it should be started before any client. The server should perform the
following tasks:
1. Ask for a shared memory with a memory key and memorize the returned
shared memory ID. This is performed by system call shmget ().
2. Attach this shared memory to the server's address space with system callshmat
().
3. Initialize the shared memory, if necessary.
4.
6. Remove the Shared
Do something andmemory with
wait for all system
client'scall shmctl ().
completion. For the
client part,
5. the procedure
Detach is almost
the shared the same:
memory with system call shmdt ().
1. Ask for a shared memory with the same memory key and memorize the
returned shared memory ID.
2. Attach this shared memory to the client's address space.
3. Use the memory.
4. Detach all shared memory segments, if necessary.
5. Exit.
Message Passing:
Most general purpose OS actually copy messages as twice as they transfer there fromtask to task via a
message queue. In RTOS, the OS copies a pointer to the message,
80
delivers the pointer to the message - receiver task and then deletes the copy of thepointer with
message sender task.
memory lots of data can be shared where as only limited amount of info / data is passed through message
passing. Also message passing is relatively fast and free from the synchronisation overheads compared to
shared memory.
Message passing constructs:
There are 2 basic message passing primitives such as send and receive.
Send primitive: Sends a message on a specified channel from one process toanother,
Receive primitive: Receives a message on a specified channel from otherprocesses.
Message passing is classified into message queue, Mail box and signalling.
Message Queue:
The process which wants to talk to another process posts the message to a First-
In-First-Out queue called message queue, which stores the messages temporarily in a system defined
memory object to pass it to the desired process.
Messages are sent and received through send and receive methods. the messages are exchanged
through a message queue.
The message mechanism is classified into synchronous and asynchronous based on the
behaviour of the message posting thread. In asynchronous messaging, the message posting
thread just posts the message to the queueand it will not wait for an acceptance from the thread
to which the message is posted.
In synchronous messaging, the thread which posts a message enters waiting state and waits for
the message result from the thread to which the message is
81
posted.
The features of a message queue IPC are
Q HEAD and
Q TAIL
1. OSQ Create 2. OSQ POST 3. OSQ PEND 4. OSQ ACCEPT 5. OSQ FLUSH 6.OSQ QUERY 7.
OSQ POST Front.
Priority Inversion
Priority inversion is the byproduct of the combination of blocking based process synchronization
and preemptive priority scheduling. Priority inversion is the condition in which a high priority task
needs to wait for a low priority task to release a resource which is share between the high priority
task and the low priority task and a medium priority task which doesn‘t require the shared resource
continue its execution by pre emptying the low priority task.
Priority based preemptive scheduling technique ensures that a high priority task is always
executed first, whereas the lock based process synchronization mechanism ensures that a process will
not access a shared resource, which is currently in use by
82
another process. The synchronization technique is used to avoid conflients in the concurrent access of the
shared resources.
Let process A, process B and process C be three processes with priorities High, Medium and Low
respectively. Process A and Process C share a variable X and the access to this variable is
synchronized through a mutual exclusion mechanism like Binary semaphore.
Imagine a situation where process C is ready and is picked up for execution by the schedules and
Process C tries to access the shared variable X.
Immediately after process C acquires the semaphore S, Process B enters the Ready state. Since
Process B is of higher priority compared to process C. Process C is preempted and Process B
starts executing.\
Now process A is of higher priority than process B, Process B is preempted and process A is
scheduled for execution. Process A tries to access shared variable X which is currently accessed
by process C. So Process A will not be able to access if and then it enters into the blocked state.
Now process B gets the CPU and it continued its execution until it relinquishes the CPU
voluntarily or enters a wait state or preempted by another high priority task.
Process A has to wait till process C gets a chance to execute and release the semaphore. This
produces unwanted delay in the execution of the high priority task which is supposed to be
executed immediately when it was ready.
Priority Inversion may be sporadic in nature but can lead to potential damages as a result of
missing critical dead lines.
83
Priority Inheritance
A low-priority task that is currently accessing (by holding the lock) a shared resource requested
by high priority task temporarily ‗inherits‘ the priority of that high- priority task, from the moment the
high-priority task raises the request Boosting the priority of the low priority task to that of the priority of
the task which requested the shared resource holding by the low priority task eliminates the preemption of
the low priority task by other task whose priority are below that of the task requested the shared resource
and thereby reduces the delay in waiting to get the resource requested by the high priority task. The
priority of the low priority task which is temporarily boosted to high is brought to the original value
when it relaeases the shared resource. Implementation of priority inheritance work around in the
priority inversion problem discussed for
process A, Process B and process C example will change the execution sequence as shown in
figure.
Priority inheritance is only a work around and it will not eliminate the delay in waiting
the high priority task to get the resource from the low priority task. The only thing is that it helps
the low priority task to continue its execution and release the shared resource as soon as
possible. The moment, at which the low priority task releases the shared resource, the high
priority task kicks the low priority task out and grabs the CPI – A true form of selfishness.
Priority inheritance handles priority inversion at the cost of run-time overhead at schedules. It
imposes the overhead of checking the priorities of all tasks which tries to access shared
resources and adjust.
84
7. Write about the features of µC/OS- II , Vx
Works and RT Linux .
i) µC/OS – II
µC/OS – II is a highly portable, ROMable, very scalable, preemptive real time,deterministic,
multitasking kernel.
It can manage up to 64 tasks (56 uses task available)
It has connectivity with µc/GUI and µc/ FS (GUI and file systems for µc/OS – II) It is
ported to more than 100 microprocessors and microcontrollers.
It is simple to use and simple to implement but very effective compared to theprice/performance
ratio.
It supports all type of processors from 8-bit to 64-bit.
Task Management Services:
Task features
Task creation
Task stack and stack checkingTask
deletion
Change a task‘s priority Suspend
and resume a taskGet information
about a task
Task feature:
µc/OS- II can manage up to 64 tasks.
The four highest priority tasks and the four lowest priority tasks are reserved forits own use.
This leaves us with 56 application tasks.
The lower the value of the priority, the higher the priority of the task.
85
Under these assumptions, let n be the number of tasks, Ei be the execution time of task i,
and Ti be the period of task i. Then, all deadlines will be met if the following inequality is
satisfied.
ΣEi/Ti ≤ n(2 1/n – 1)
Example: suppose we have 3 tasks. Task 1 runs at 100Hz and task 2 ms. Task 2 runs at
50Hz and takes 1ms. Task 3 runs at 66.7 Hz and takes 7 ms. ApplyRMS theory.
(2/10) + (1/20) + (7/15) = 0.707 ≤ 3(2 1/3 – 1) = 0.780
Thus, all the deadlines will be met.
General solution:
As n goes infinity, the right hand side of the inequality goes to in (2) = 0.6931.
Thus you should design your system to use less than 60 – 70% of the CPU.
Task creation:
o OS task create ( )
o OS task create E X t ( )
Task Management:
After the task is created, the task has to get a stack in which it will store its
data.
A stack must consist of contiguous memory locations.
It is necessary to determine how much stack space a task actually uses. Deleting a task means
the task will be returned to its dormant state and does
not mean that the code for the task will be deleted. The calling task can delete itself. If
another task tries to delete the current task, the resources are not freed andthus are lost. So the task has
to delete itself after it uses its resources.
Priority of the calling task or another task can be changed at run time.
A task can suspend itself or another task; a suspended task can resume itself.
86
A task can obtain information about itself or other tasks. This information canbe used to
know what the task is doing at a particular time.
Memory Management:
The memory management includes:
1. Initializing the memory manager
2. Creating a memory partition
3. Obtaining status of a memory partition
4. Obtaining a memory block
5. Returning a memory block
6. Waiting for memory blocks from a memory partition.
Each memory partition consists of several fixed – sized memory blocks.
A task obtains memory blocks from the memory partition.
A task must create a memory partition before it can be used.
Allocation and de-allocation of these fixed – sized memory blocks is done inconstant
time and is deterministic.
Multiple memory partitions can exist, so a task can obtain memory blocks ofdifferent
sizes.
A specific memory block should be returned to its memory partitions from which itcame.
Time management:
Clock Tick: A clock tick is a periodic time source to keep track of time delays andtime
outs.
o Time intervals: 10~100 ms
o The faster the tick rate, the higher the overhead imposed on the system.
87
Inter task or inter process communication in µC/OS takes place using, Semaphore
Message mailbox
Message queues
Tasks and interrupt service routines (ISR) can interact with each other through an ECB(Event Control
Block)
Tasks can wait and signal along with an optional time out.
88
µC/OS – II message mailbox: an µC/OS – II object that allows a task or ISR tosend a pointer
sized variable (pointing to a message) to another task.
Available services: create, post (FIFO), postfront (LIFO), pend, accept – query,flush.
N = Addition of entries in the queue: queue full if post or post front called N times beforea pend or
accept.
89
ii) Vx Works RTOS:
Introduction:
Vx works is a real time operating system developed as proprietary software by windriver systems. It in
a high performance, Unix like, scalable RTOS and supports ARM,
Pentium, Intel X-scale, super H and other popular processors for embedded system design. Vx
works design is hierarchical and well suited for real time applications. It support kernel mode
execution of tasks for fast execution of application codes. Vx works is supported with powerful
development tools that make it easy and efficient to use.
Many simulation tools, time performance analysis tools, debug and test tools are provided.
Making Vx works as an RTOS that supports development of almost any embedded application,
providing a complete solution for all stages of the design cycle. The latest version Vx works 6.9
in the first commercial grade RTOS to fully support both 32-bit and 64-bit processing on Intel
Architecture.
Basic Features:
90
12. Network derivers for shared memory and Ethernet.
13. RAM dist drivers for memory resident files.
14. Processor arbitration layer to enable application system design by user whenusing
new versions of processor architecture.
Architecture:
Vx Works was initially a development and network environment for VRTX. Later wind River systems
developed. Their own micro kernal. So the Vx works is of "client-server" architecture from the beginning.
The heart of the Vx works run-time system is the wind microkernel. This micro kernel supports a full
range of real-time features including multi- tasking, scheduling. Inter task synchronization
communication and memorymanagement. All the other functionality is implemented as processes.
Vx Works is highly scalable. By including or excluding various models, Vx works can be
configured for the use in small embedded system with tough memory constraints to complex
systems where more functions are needed. Furthermore, individual modules themselves are
scalable. Individual functions may be removed from the library or specific kernel
synchronization objects may be omitted if they are not required by the application.
Task Management:
The Vx works real-time kernels provides a basic multitasking environment. Vx works offers both posix
and a proprietary scheduling mechanisms. Both preemptive priority and round robin scheduling
mechanism are available. The difference between POSIX and wind scheduling is that wind scheduling
is that wind scheduling mechanism are
available.
91
The difference between a POSIX and wind scheduling is that wind scheduling applies the scheduling
algorithm on a system wide basis, whereas POSIX scheduling algorithms are applied on a process by
process basis.
In Vx works, the states encountered by the task are of 8 different types.
1. Suspended: Idle state just after creation or stated where execution is inhibited.
2. Ready: Waiting for running and CPU access in case scheduled by the scholar but not
waiting for a message through IPC.
3. Pending: The task is blocked as it waits for a message from the IPC or from a
resource only then will the CPO be able to process further.
4. Delayed: Send to sleep for a certain time interval.
5. Delayed + suspended: Delayed and then suspended if it is not pre-emptied
during the delay period.
6. Pended for an IPC _ suspended: Pended and then suspended if the blocked
state does not change.
7. Pended for an IPC + delayed: Pended and than pre-emptied after the delayed
time interval.
8. Pended for an IPC + suspended: Pended and suspended after delayed time
interval.
Kernel library functions are included in the header file 'Vx works.h' and 'kernel Lib.h'. Task and
system library functions are included in 'task Lib.h' and 'sys Lib.h' User task priorities are
between 101 and 255. Lowest priority means task of highest priority number (255). System
tasks have the priorities from 0 to 99. For tasks, the highest priority is 100 by default..
3. Task deletion and deletion protection function: Task Delete (task Id): this
permanently inhibits the execution f the task identified by task Id and cancels theallocations of
the memory block for the task stack and TCB.
92
Many time each task should itself execute the codes for the following:
Memory de-allocation.
Ensure that the waiting task gets the desired IPC
Close a file, which was opened there.
Delete child tasks when the parent task executes the exit ( ) function.
4. Delaying a task to let a lower priority task get access:
intSysClkRateGet ( ) returns the frequency of the system ticks. Therefore to delay by
0.25 seconds, the function task Delay (SysclkRateGet ( ) /4) is used.
Memory Management:
In Vx works, all systems and all application tasks share the same address space. Thismeans that
faulty application could accidently access system resources and
compromise the stability of entire system. An optional tool named Vx VMI is available that can
be used to allow each task to have its own address space. Default physical page size used is 8
KB. Virtual memory support is available with Vx VMI tool. Vx works does not offer privilege
protection. The privilege level is always 0.
Interrupts:
To achieve the fastest possible response to external interrupts, Interrupt service routines in Vx
works run in a special context outside of any thread's context, so that there are no thread
context switches involved. The C function that the user attaches to a interrupt vector is not
actual ISR. Interrupts cannot directly vector to C functions.
The ISR's address is stored in the interrupt vector table and is called directly from the hardware.
The ISR performs some initial work and then calls the C function that was attached by the user.
For
task this reason, we use the term interrupt handler to designate the
design.
The features of the ISR in Vx works are:
user installed C handler function. Vx Works uses an ISR design that is different from a
1. ISRs have the highest priorities and can pre-empt any running task.
2. An ISR inhibits the execution of tasks till return.
3. An ISR does not execute like a task and does not have regular task context.
4. An ISR should not use mutex semaphore.
5. ISR should just write the required data at the memory or buffer.
6. ISR should not use floating – point functions as these take longer time to
execute.
Performance:
93
Real time performance: Capable of dealing with the most demanding time constraints, Vx
works is a high-performance RTOS tuned for both determinism and responsiveness.
Reliability: A high – reliability RTOS, Vx works provides certification evidence required
by strict security standard. Even for non-safety – critical systems, Vx works is counted on to run
forever, error free.
Scalability: An indispensable RTOS foundation for very small – scale devices, large scale
networking systems and everything in between, Vx works is the first RTOS to provide full 64-bit
processing to support the over growing data requirements for embedded real time systems. Vx works is
scalable in terms of memory foot print and functionality so that it can be tuned as per the requirements of
the project.
Interrupt latencies: The time elapsed between the execution of the last instruction of
the interrupted thread and the first instruction in the interrupts handler to the next task
scheduled to run is interrupt dispatch latency. Vx works exhibits an Interrupt latency of
Foot print: Vx works has a completely configurable and tunable small memory foot
print for today's memory – constrained systems. The user can control how much of the
operating system he needs.
Applications:
Vx Works RTOS is widely used in the market, for a great variety of applications. Its
Helicopter, Boeing 787, 747-8 and Airbus A 400 M. It is also used in on ground avionic systems such as
reliability makes it a popular choice for safety critical applications Vx works has been
in both civilian and military radar stations. Another safety critical application that entrusts Vx works is
BMW's i – Drive system.
success fully used in both military and civilian avionics, including the Apache Attack
However, Vx works is also widely used in non-safety – critical applications where performance
is at premium. The xerox phasor, a post – script printer is controlled by a Vx works powered platform
link sys wireless routers use Vx works for operating switches.
Vx works has been used in several space application's. In space crafts, where design challenges are
greatly increased by the need of extremely low power consumption and lack of access to regular
maintenance, Vx works RTOs can be chosen as the operating
94
system for on Board Computer (OBC). For example 'clementine' launched in 1994 is running Vx works
5.1 on a MIPS – based CPU responsible for the star Tracker and image processing algorithms. The 'spirt'
and opportunity mars exploration rovers were installed with Vx works. Vx works is also used as operating
system in several industrial robots and distributed control systems.
Summary:
The need to develop for real-time embedded applications is always a challenge, especially when
expensive hardware is at risk. The complex nature of such systems require many special design
considerations an understanding of physical systems, and efficient Management of limited resources
perhaps one of the most difficult choice the embedded system designers have to make in which operating
system they are going ot
use. It is critical to have operating system that will be able to be fail-safe, secure, scalable, fast
and robust in multi task management, while being friendly to the application developers, Vx
works is an RTOs which meets almost all of these requirements.
iii) RT Linux
RT linux is a hard real time RTOS microkernel that runs the entire linux operating system as a
fully preemptive process. It was developed by Victor Yodaiken, Michael Barabanov and others
at the New Mexico Institute of Mining and Technology and then as a commercial product at
FSM Labs. FSM Labs has 2 editions of RT Linux.
RT Linux pro and RT Linux free. RT Linux pro is the priced edition and RT Linux is the
open source release. RT Linux support hard real time applications. The Li nux kernel has been
modified by adding a layer of software between the hardware and the
95
In RT Linux location of the various files are:
RT Linux will be installed in the directory/usr/rtlinux-XXX, where XXX is the
version name.
/usr/rtlinux/include contains all the include files necessary for development project.
By default, the RT Linux tasks do not have access to the computer‘s floatingpoints
unit. Hence need to explicitly set the permissions for every RT Linux task.
RT Linux Modules:
RT files
into object Linux programe
using are not created
the gcc command as stand-alone
with the argument C flag. Inunits,
the Cthey are
file the created
main ( as
modules. Which
) function gets are loaded
replced with theinto the linux
following lines.kernel space. The C source files are complied
Int init-module ( ).
Void cleanup_module ( ).
Init-module is called when the module is first loaded into the kernel. This functionreturns O if the
module is successfully loaded. It returns a negative value in case offailure. When the module is loaded is
to be unloaded, the cleanup_module ( ) is called. Executing the RT Linux Modules:
In RT Linux, Load and stop user modules are using the RT Linux command. Using this
command, we can obtain status information about RT Linux modules. The command syntax is:
96
$ rtlinux start my-program
$ rtlinux stop my-program $
rtlinux status my-programCreating RT
Linux POSIX Threads
A real time program generally consists of a number of threads. Each thread share a common
address space. Pthread_create () function is used to create a new real-time thread. The corresponding
header file is
# include <pthread.h>
To achieve real time performance, the various POSIX compliant API functioncalls are
used. There function calls are related to create and cancel semaphores.
To implement mutex, we have to include the header file <rtl-mutex.h) in the C
program.
To cancel a thread, the system call is pthread cancel.
Timer Management
A number of internal clocks are available in RT Linux to manage the timers. Thecurrent clock
reading is obtained using command is:
Clock-set time ( ) function
Clock-id gives the identification of the clock to be read.
97
UNIT-V
EMBEDDED SYSTEM APPLICATION DEVELOPMENT
98
To let each section of codes, tasks and ISRS run and gain access to the CPU one after the other
sequentially or concurrently, following a scheduling strategy, so that there is a predictable operation at
any instance.
8. List the characteristics of multi – state system.
The system will operate in two or m ore states.
Each state may be associated with one or more function calls.
Transitions between states may be controlled by the passage of time, bysystem inputs or
by a combination of time and inputs.
Transition between states may also involve function calls.
9. What is an adaptive control algorithm?
An adaptive control algorithm refers to algorithm parameters which adapt to the present
status of the control inputs in place of a constant set of mathematical parameters in
algorithmic equations.
resetTask
task_Read Port
task_PW
task_Appl
UNIT – 5
1. Discuss in deeply about the case study of washing machine design.
PART-B(16 marks)
Automatic washing machine is a Multi-state Input/Timed system. The characteristics of
99
Outline design of inputs and outputs:
Start
Water
Switch
Value
Water
Selector Heater
Dial
Water
Pump
Water
level
Drum
Motor
Temperature
sensor Washing
Detergent LED or LCD
Machine
Hatch
Controller indicators
PIC18F series microcontroller acts as a washing machine controller. Single phase motor is
considered for the design. Front panel consists of a keypad and LCD display. Keypad provides automatic
and manual wash options to the user. LCD displayis convenient to convey machine information to user.
Modern washing machines are designed with BLDC motors owing to efficiency and energy conversation.
But in his case, single phase universal motor has been used to design prototype.
Design Specifications:
This include both hardware and software specifications.
1. The system should provide fully automatic mode, semi automatic mode andmanual mode.
Modes should be selected by a keypad.
2. Under fully automatic mode, user intervention requirement should be zero.
Once the system is started in this mode, it should perform its work independently and after the completion
of work it should notify the user about the completion of work. This mode instantaneously should sense
cloth quality and requirement of water, water temperature, detergent, load, wash cycle time and perform
operation accordingly.
3. In semi – automatic mode also, user requirement should be nil. But user has to
choose any one of the semi automatic mode in which washing conditions are predefined. Once
the predefined mode is started, the system should perform its job and after completion, it
should inform the user.
4. In manual mode, continuous intervention of user is required. For example, a user
needs to choose wash mode, wash time, amount of water and the load. After these data are
entered, the user should start the machine.
100
5. When the lid is open, system should not work. If door is accidently opened in
between wash operation, then the system should stop working in minimum possible time.
6. The system should provide all the basic features of a washing machine like washing,
rinsing, spinning, drying, cold wash, hot wash etc.
7. The system should provide easy option for upgrading the new features.
8. The system should work on single phase AC from 190V AC to 250V AC. The system
should protect itself from power supply voltage variations.
9. In the event of power failure, the washing machine should automatically start its
cycle from the point of interruption when power is resumed.
Hardware Design:
PIC18F452 is a heart of the system. Most of the peripheral features have been utilized to
implement the design. Controlling the motor is very crucial part of the design. The PWM feature of the
microcontroller controls motor speed. PWM output is feed to driver circuit and then to motor.
To rotate the motor in two different directions forward and reverse direction, control blocks
are used. Motor speed sensor is interfaced to microcontroller. Microcontroller reads the speed of the
motor and approximately controls the speed of the motor in different phases of washing using PWM
output. Door sensor, pressure sensor, keypad are also interfaced to microcontroller. EEPROM and RTC
are interfaced to MSSP module of controller. In-circuit serial programming facility is provided for quick
and easy programming and debugging.
101
Washing machine parameters are stored in external EEPROM and internal EEPROM of the PIC.
RTC (Real Time Clock) is interfaced to SPI (Serial Peripheral Interface) port of the microcontroller.
It is used as a timing reference for all timing calculation of machine.
Door sensor is connected to external interrupt 0. High priority is assigned to this interrupt. Thus
opening of the door causes triggering of INT0 and INT0 ISR immediately to stop the machine and
informs the user.
All the sensor outputs are connected to the analog pins of PIC (AN0, AN1, AN2 etc.) Keypad is
connected to port D. when any of the keys is pressed; output becomes high and INT1 triggers. Int1
ISR does a keypad scan and approximately performs the operation.
Motor speed sensor is given to T1, CLK which is an external clock input to timer 1 / timer 3. Timer is
configured in counter mode for calculating the speed. Speed is calculated by counting pulse output from
the sensor for one second.
Motor driver circuit determines the direction of the motor corresponding to the output obtaining from
the microcontroller.
Speed of the motor is controlled by the PWM generation from the microcontroller. The duty
cycle of PWM pulses are changed according to the output obtained from the speed sensor to maintain
the desired response during wash cycles.
Dedicated LCD with 3 wire interface is used, which consist of data line, clock and chip select.
Backlight control is also provided.
Software Design:
A provisional list of functions that could be used to develop a washing machine
are:
Read_Select_Dial ( )
Read_Start_Switch ( )
102
Read_Water_Level ( )
Read_Water_Temperature ( )
Control_Detergent_Hatch ( )
Control_Door_Lock ( )
Control_Motor ( )
Control_Pump ( )
Control_Water_Heater ( )
Control_Water_Valve ( )
Frame Work:
1. System states – Initialization, start, fill drum, heat water, Wash 1, Wash 2, Error.
2. User defined data – a) Maximum Fill duration – 1000 seconds. b) Maximum
water heat duration – 1000 seconds. c) Maximum wash 1 duration – 3000 seconds.
3. Functions involved in each state or function call
Initialization:
Control_Motor (OFF)
Control_Pump (OFF)
Control_Water_Heater (OFF)
Control_Water_Valve (OFF)
Read_Select_Dial (ON)
Now switch on to start state.
Start:
Control_Door_Lock (ON)
Control_Detergent_Hatch (ON)
Control_Water_Valve (ON)
Now switch on to fill drum state.
Fill Drum:
Read_Water_Level (ON)
Control_Water_Heater (ON)
Now switch on to either heat water state or Wash 1 state depends upon thecondition.
Heat Water:
Read_Water_Temperature (ON) Now
switch on to Wash 1 state.
103
Wash 1:
Control_Motor (ON)
After the completion of duration, the system switches to the wash 2 state.
Wash 2:
In Wash 2 state, the system performs the washing operation until its duration is expired.
Error:
In any crash or error happens between the states, the system goes to thedefault state called
error state. It restarts the particular state, where the error occurs.
4. Function definitions:
Thus the software design is clearly explained with states and functions.
a. Resolution
b. Performance
c. Process deadlines
d. User interfaces
e. Extendibility
f. Engineering cost
g. Manufacturing cost
8. Test and validation conditions
The comparison and decision subunit sends outputs which are inputs toadjustable
systems.
Class diagram
ACC system measurements of front end car range, distance and error estimations and adaptive control can
be modeled by two class diagrams of abstract classes, Task_ACC and Task_Control
105
.
1.Task_ACC is an abstract class from which extended classes like
Task_Align,Task_Signal,Task_ReadRange, Task_RangeRate and Task_Algorithm are
derived to measure range and errors.
106
ACC Software
For the ACC systemsArchitectur
Basic Conformance Class I (BCCI) is used.The following tablelists the BCCI
tasks,functions and IPCs
108
Requirements:
Assume a contact less smart card for bank transactions. Let it not be magnetic.Requirements of Smart card
communication system with a host are.
1. Purpose:
Enabling authentication and verification of card and card holder by a host and enabling GUI at host
machine to interact with the card holder / user for the required transactions: for example, financial
transactions with a bank or credit card transaction.
2. System Functioning:
1. The cards inserts at host machine. The radiations from the host activate a chargepump at card.
2. On power up, system reset signals reset task to start. The reset task sends the messages - request
Header and request start for waiting task. task_ReadPort.
3. task_Read Port sends requests for host identification and reads through the port_IO the host -
identification and reads the request start from host for card identification.
4. The task_PW sends through Port_IO the requested card identification after
2. Code Size: Code size generated should be optimum. The card system memory needs should not
exceed 64 KB Memory.
3. File System(s): Three layered file system for the data. One file for the master file to store all file
headers. A header has strings for file status, access conditions and file-lock. The second file is a dedicated
file to hold a file grouping and heads. The third file is the elementary file to hold the file header and file
data.
4. File Management: There is either a fixed length file management or variable file length
management with each file with a predefined offset.
5. Micro controller hardware: Generates distinct coded physical addresses for the program and
data logical addresses. Protected once writable memory space.
6. Validity: System is embedded with expiry date, after which the card authorizations through the
hosts disable.
7. Extendibility: The system expiry date is extendable by transactions and
Task_card communication is an abstract class from which extended is class derive to read port
and authenticate. The tasks are the instances of the classes Task_Appl, Task_Reset, Task_Read Port and
Task_Reac Range.
Task_Read Port interfaces ISR1_Port_IO
The task_PW is object of Task_PW and interfaces ISR2_Port_IO. Task_Appl interfaces ISR3-
Port_IO
Hardware and Software Architecture:
Software using Java card provides one solution. JVM has thread scheduler built in. No separate
multitasking OS in thus needed when using Java because all Java byte codes run in JVM environment.
Java provides the features to support (i) security using class java.lang. Security Manager, (ii)
cryptographic needs. Java provides support to connections, datagrams, IO streams and network sockets.
111
Java mix is a new technology in which the native applications of the card run in C or C++ and
downloadable applications run in Java Card. The system OS and JVM both. Smart OS in an assumed
hypothetical OS in this example, as RTOS in the card.
Remember that a similar OS function name is used for understanding purpose identical to MUCOS but
actual smart OS has to be different from MUCOS. Its files structure in different. It has two function as
follows.
The function unsigned than ( ) smart OS encrypy (unsigned char * applstr, EnType type) encrypts as per
encryptes method, EnType = "RSA" or "DES" algorithm chosen and returns the encrypted string.
112
Synchronization Model:
Following are the actions on the card places near the host machine antenna in a machine
slot.
Step 1: Receive from the host, on card installation, the radiation of carrier frequency or
clock signals in case of contact with the card. Extract charge for the system power
supply for the modem, processor, memories and port IO device.
Step 2: Execute codes for a boot up task on reset resetTask. Let us code in a similar
way as the codes for First task. The codes begin to execute from the main and the main
creates and initiates this task and starts the smart OS.