Real-Time Systems: June 2012
Real-Time Systems: June 2012
net/publication/307175668
Real-Time Systems
CITATIONS READS
5 4,252
1 author:
Anand Raj S N
Jawaharlal Nehru National College of Engineering
6 PUBLICATIONS 6 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Anand Raj S N on 29 August 2016.
This note of Real-time systems covers five major units of the syllabi and the
students can answer for 100 marks in the theory examination. Each time I taught the
subject, I actually felt that providing very good notes can minimize the burden of
students who are in the verge of improving their percentile and also i have used my
own way of giving real-life examples for the clear understanding of the concepts of
the subject.
The students following this note are expected to be familiar with basics of
computer architecture, programming, computer communications, computer hardware
and operating systems.
Finally, I wish all the very best to the student community who are the future
engineers of modern India.
Syllabus covered:
PART - A
UNIT - 1
UNIT - 2
UNIT - 3
PART - B
UNIT - 5 & 6
Unit-1
Historical Background:
Consider the hot- air blower as an example to illustrate the various operations of a
computer control system. The following section explains about the operations of hot-air
blower.
A centrifugal fan blows air over a heating element and into a tube
A thermostat is used to detect the temperature
The position of the air-inlet cover to the fan is adjusted by a reversible DC motor
(constant speed)
A potentiometer is attached to the air-inlet cover
Two 8-switches are used to detect when the cover is fully open or fully closed
The operator is provided with a panel from which the control system can be
switched from automatic to manual control panel. Lights indicate: Fan ON, Heater
ON, Cover fully-open, Cover fully-closed, Auto/Manual status.
The information is available from the plant instrument in the following two forms:
– Analog signals: Air Temp., Fan-inlet cover position.
– Digital signals: Fan-inlet cover position (Fully-open, Fully-closed)
– Status signals: Auto/Manual, Fan motor ON, Heater ON
The operation of this simple plant using a computer requires a computer software
be provided to support monitoring, control and actuation of the plant.
Monitoring involves obtaining information about the current state of the plant
Control involves the digital equivalent of continuous feedback control for the DDC.
“A real-time system is the one whose output is not only dependent on the input
of the system but also depends on the timeliness of the system”
OR
“Any system. in which the time at which the output is produced is significant.
This is usually because the input corresponds to some movement in the physical
world, and the output has to relate to that some movement. The lag from input time
to output time must be sufficiently small for acceptable timeliness”
OR
“Real-Time systems are those which must produce correct responses within a
definite time limit. Should computer responses exceed these time bounds then
performance degradation and/or malfunction results”
Real-Time Program:
“A program for which the correctness of operation depends both on the logical
results of the computation and at which the results are produced”
Fact: All real-time systems are embedded systems but all embedded systems are not
real-time systems.
RTS are classified based on the tasks into the following three categories:
Synchronization between the external processes and internal actions (tasks) carried out
by the computer may be defined in terms of the passage of time, or the actual time of
day, in which case the system is said to be “Clock-based system” or it may be defined in
terms of events, and the system is said to be “Event-based system”.
If the relationship between the actions in the computer and the system is much more
loosely defined, then the system is said to be “interactive system”.
Based on timing constraints real-time tasks are classified into two types
Hard real-time(these are systems that must satisfy the deadlines on each and
every occasion)
Soft real-time (these are systems for which an occasional failure to meet a
deadline does not comprise the correctness of the system)
Classification Of Programs:
Sequential
Multi-tasking
Real-time
Sequential:
- Actions are ordered as a time sequence, the program behaviour depends only on the
effects of the individual actions and their order but not on the time taken to perform
those actions
Multi-tasking:
-Actions are not necessarily disjoint in time, it may be necessary for several actions to be
performed in parallel. Hence in multitasking programs various tasks are executed con-
currently and communicate through shared variables and synchronization signals
Real-Time:
- Actions are not necessarily disjoint in time, and the sequence of some of program
actions is not determined by the designer but the environment (by events occurring in the
outside world which occur in real-time and without reference to the internal operations
of the computer).
Summary:
UNIT - 2
CONCEPTS OF COMPUTER CONTROL:
The chapter covers the various concepts of computer that is used to control and
co-ordinate the various activities of a plant (external environment or controlled
environment)
Computer controlled applications are mainly classified into:
Batch
Continuous
Laboratory (or test)
The activities being carried out by a computer, in a RTS, will include the following:
Data acquisition.
Sequence control.
Direct digital control (DDC).
Supervisory control (SC).
Data analysis.
Data storage.
Human – computer interface (HCI).
Sequence control:
1. Open valve A.
2. Check the level of chemical 1.
3. Start the stirrer to mix the chemical reactor.
4. Repeat steps 1 and 2 with valve B.
5. Switch ON the PID controller.
6. Monitor the reaction temp, when it reaches the set-point, start a timer.
7. When the timer indicates that the reaction is complete, switch OFF the
controller and open valve C to cool down the reactor contents. Switch OFF the
stirrer.
8. Monitor the temp, when the contents have cooled, open valve E to remove the
product from the reactor.
Typical reactor vessel for this purpose is illustrated in the below figure 2.1
All the above actions and timings are based on software, for a large
chemical plant, such sequences can become lengthy and complicated to ensure
efficient operating; several sequences take place in parallel.
In this process, two reactor vessels (R1 and R2) are used alternatively, so
that the processes of preparing for next batch production and cleaning up
after the production can be carried out in parallel.
Assuming R1 has filled with the mixture and the catalyst and the reaction is
in progress.
At the same time vessel R2 will be cleaned-the wash down sequence – and the next
batch of raw material will be measured and mixed in the mixing tank.
In parallel the previous batch will be thinned down and transferred to the
appropriate storage tank and if any change in the composition is required, the thin
down tank will be cleaned.
Once this is done the next batch can be loaded into R2 and then assuming that the
reaction in R1 is complete, the contents of R1 will be transferred to the thin down
tank and the wash down procedure for R1 is initiated.
The various sequences of operations required can become complex and there may
also be complex decisions to be made as to when to begin a sequence.
The sequence initiation may be left to a human operator or the computer may be
programmed to supervise the operations.
Consider the float glass process shown in the below figure 2.3.
In direct digital control (DDC) the computer is in feedback loop as shown in the
below fig 2.4. A consequence of the computer being used in the feedback loop is that it
forms a critical component in terms of the reliability of the system and hence great care
is needed to ensure that in the event of failure or malfunctioning the plant must remain
in safe condition.
The usual means of ensuring safety is to limit DDC unit to make incremental
changes to the actuators on the plant and to limit the rate of changes of the
actuator.
A- Actuator: An actuator is a type of motor for moving or controlling a mechanism
or system. It is operated by a source of energy, usually in the form of an electric
current, hydraulic fluid pressure or pneumatic pressure, and converts that energy
into some kind of motion. An actuator is the mechanism by which an agent acts
upon an environment. The agent can be either an artificial intelligence agent or
any other autonomous being (human, other animal, etc.).
Advantages of DDC are as follows:
DDC applications:
A signal from the controller which monitors the combustion flames directly is
added to the air flow signal to provide the input to the air flow controller.
DDC technique Are also used for inferential, feed-forward and adaptive or self tuning
controller.
Inferential controller:
The above fig. 2.6 illustrate the general structure of inferential control
configuration, some measurements can be measure directly but some measurements
cannot be done directly, hence some other process measurement is made and from this
the value of the controlled variables is inferred.
The four independent variables usually controlled are liquid levels Ha and Hb in
the accumulator and reboiler, compositions X a and Xb of the top and bottom
products
The compositions can be measured directly by spectrographic techniques but it is
more usual to measure the temperature at point Y a and Yb near the top and
bottom of the column and pressure P in the column.
The temperature represents the boiling points of the mixture at the position in
the column.
From measurements of pressure and temperature the composition can be
inferred.
Feed forward control:
The general structure of feed forward system is as shown in the above fig 2.8
Example: in the hot rolling of sheet steel, if the temperature of the billet is
known as it approaches the first stage mill, the initial setting of the roll gap can
be calculated accurately and estimates of the reduction at each stage of the mill
can be made, hence initial gap for the subsequent stages can also be calculated.
If this is done time taken to get the gauge of the steel within tolerance can be
reduced and hence quantity of scrap steel is reduced.
The effect of introducing feed forward control is to speed up the response of the
system to disturbances.
Adaptive control:
Adaptive control can take several forms, three among the most common are as
follows
The adaptive are adjustment mechanism makes preset changes on the basis of
changes in auxillary process measurements.
The above fig 2.9 illustrates programmed adaptive control for auxillary process
measurements.
Example:
Example:
In an aircraft auto- stabiliser control parameters may be changed according to
the external air pressure.
Supervisory control:
Computers are not only used to directly control the operation the plant, but also
it can provide managers and engineers with a comprehensive picture of the status
of the plant operators. It is the supervisory role.
The basic idea is as shown in the below fig.2.11
Two evaporators are connected in parallel and material which is in liquid form
(solution) is fed to each unit.
The purpose of the plant is to evaporator as much as water as possible in the
solution.
Steam is supplied to a heat exchanger linked to the first evaporator and the
steam for the second evaporator is supplied from the vapours boiled of from the
first stage.
To achieve maximum evaporation the pressures in the chambers must be as high
as safety permits
Also it is necessary to achieve a balance between the two evaporators.
A supervisory control scheme can be design to balance the operation of the two
evaporators to obtain the best overall evaporation rate.
Supervisory are based upon the steady state characteristics of the plant. In some
plants control algorithms have also been used to increase plant profitability.
currently, expert system (an expert system is an interactive computer based
decision tool that uses both facts and heuristics to solve difficult decision making
problems, based on knowledge acquired from an expert) are used for supervisory
control.
A general purpose computer can be program to perform all the require tasks, the
timing differences and the security requirements for the various categories of the
task make the programming job difficult.
Around 1970s the cost of the computer hardware had reduced to such an extent
that it became feasible to consider the use of dual computer system as shown in
the fig 2.13 below
In the event of failure of one of the computers the other takes over.
In some schemes the change over is manual in others automatic failure detection
and change over is incorporated.
These schemes have number of contemporary issues like
Cabling and interface equipment is not usually duplicated
Automatic failure and change over equipment when used becomes itself a
critical component.
Designing, programming, testing and maintaining software becomes very
difficult.
Multicomputer systems are of two types namely
Hierarchical system
Distributed system
Hierarchical system:
Tasks are divided according to function example one computer is used for DDC
calculations and other is used for supervisory control etc.
Typical company decision making structure is shown in the below fig 2.14
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
Each decision element receives commands from the level above and sends
information back to that level.
On the basis of information received from the elements below and from
constraints imposed by elements at the same level, sends commands to the
elements below and information to the elements of same level.
At the bottom of the hierarchy, a fast response to simple problems is required.
As system progresses up, the complexity of the calculation increases as does the
time allowed for the response.
A typical example of hierarchical system is the batch system as shown in the fig
2.15
This system has three levels which are called as manager, supervisor and unit
control. It is assumed that single computer is used for the managerial role and
supervisory role and each process is controlled by unit control (computers which
are connected through data highway).
At the managerial level function such as resource allocation, production
scheduling and process accounting are carried out.
The important information may be sales order, stock levels, selling cost,
operating cost, etc..,
The information regarding the production schedule is transferred to the
supervisor.
It is assumed that supervisor has a store of the operation sequences for making
the product when particular unit is selected, the information are loaded into the
unit controller, also supervisors will receive information regarding status reports
of the productions.
At the lowest level the unit controllers will operate the plant and will report the
same to the level above them.
Distributed system:
Unit 3
In this chapter we will discuss the hardware requirements and various issues
related to the design of real time systems also an effort is being made to explain the
concept like interrupts, real time clock and data transfer techniques.
3. Addressing method
4. Number of registers
5. Information transfer rates
6. Interrupt structure
The basic instruction set of the CPU is also important in determining its overall
performance. Features which are desirable are
1. Flexible addressing modes for direct and immediate addressing,
2. Relative addressing modes
3. Address modification by the use of index registers,
4. Instructions to transfer variable length blocks of data between storage units
or locations within memory single commands to carry out multiple
operations.
These features reduce the number of instructions required perform housekeeping
operations and hence both reduce storage requirements and improve over all speed
of operation by reducing the number of accesses to main memory required to carry
out the operations.
Storage:
The storage used on computer control system divides into two main categories,
1. Fast access storage
2. Auxillary storage
The fast access memory is that part of memory which contains data, programmes
and results which are currently being operated on.
In addition to RAM it is now common to have ROM, PROM or EPROM for the
storage of critical code or predefined functions.
The use of ROM has eased the problem of memory protection to prevent loss of
programs through power failure or corruption by mall functioning of the software.
An alternative to ROM is the use of memory mapping technique the trap the
instructions which attempt to store in protected area.
The auxillary storage medium is typically disk or magnetic tape. These devices
provide bulk storage for programs or data which are required infrequently at
much lower cost than fast access memory.
The disadvantage is a much longer access time and need for interface boards and
software to connect them to the cpu.
For real time system use of cpu to carry out the transfer is not desirable as it is
slow and no other computation can take place during transfer.
For efficiency of transfer it is sensible to transfer large blocks of data rather than
a single word or byte. The approach frequently used is direct memory access
(DMA).
Input and output:
The input/output (I/O) interface is one of the most complex areas the computer
system.
The part of complication arises because of the wide verity of the devices which
have to be connected and wide variations in the rates of data transfers.
The i/o system of most control computers can be divided into three sections
1. Process i/o
2. Operator i/o
3. Computer i/o
Bus structure:
Parallel computers:
Many different forms of parallel computer architecture have been device, they can
be summerised as belonging to one of the four categories
1. SIMD – Single instruction stream, multiple data stream
2. MISD- multiple instruction stream, Single data stream
3. MIMD- multiple instruction stream, multiple data stream
4. SISD- Single instruction stream, Single data stream
Among all MIMD system are most powerful class of parallel computers as each
processor can pottentialy be excuting a different program on a different data set.
The most widly used MIMD system is the INMOS transputer.
Each transputer chip has a CPU, on board memory, an external memory interface
and communication links for direct point to point connection to other transputer.
An individual chip can be used as a standalone computer, however power of the
transputer is obtained when several transputer are interconnected to form a
parallel processing network.
INMOS developed a special programming language, OCCAM for use with the
transputer.
Digital signal processor:
In applications such as speech processing, telecommunications, radar and hi-fi
systems analog techniques have been used for modifying the signal characteristics.
There are advantages to be gained if such processing can be done using digital
techniques in that the digital devices are inherently more reliable and do not drift.
Special purpose integrated digital circuits optimised to meet the signal processing
requirements have been developed.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
They use Harvard architecture in which separate paths are provided for data and
for instructions.
They are difficult to program as few high level language compilers are available.
DSPs typically use fixed point airthametic and the instruction set contains
instructions for manipulating complex numbers.
Process related interfaces:
In many operations there is a need to convert digital quatity to a physical quantity
or vice versa. Most devices can be allocated to one of the following four categories
1. Digital quantities
2. Analog quantities
3. Pulses and pulse rates
4. Telemetry
Digital quantities: These can be either binary or generalized digital quantity i.e, a
valve open or closed, a switch on or off etc..,
Analog quantities: The characteristics of these signals is that they are continous
variables and have to be both sampled and digitized. Examples are output from
thermocouples, strain guage etc..,
Pulses and pulse rates: A number of measuring instruments like flow meters,
provide output in the form of pulse trains. Stepping motors as actuators requires
the provision of pulse outputs.
Telemetry: The data may be transmitted by landline, radio or the public telephone
network, it is characterized by sending data in serial form usually encoded in
standard ASCII characters. For small quantities of data the transmission is usually
asynchronous.
Digital signal interfaces:
A simple digital input interface is shown in fig 3.4
It is assume that the plant output are logic signal which appear on lines connected
to the digital input register.
It is usual to transfer one word at a time to the computer, so normally the digital
input register will have the same number of input lines as the number of bits in the
computer word.
To read the lines connected to the digital input register computer as to place
address of the register on the address bus and address decoder selects the
appropriate digital input register.
In addition to the SELECT signal, an ENABLE signal may also be required
In response to select and enable signals the digital input register enables its output
gates and puts data on to the computer data bus.
The timing of the transfer of information will be governed by cpu timing. A typical
example is shown in fig 3.5
For this system, it is assume that the transfer requires three cycles T1,T2 and T3.
The address lines begin to change at the commencement of the cycle T1 and sure
to be valid by the start of the cycle T2, also at the start of T2 the READ line
becomes active.
For correct read operation the digital input register has to provide stable data at
the negative going edge of the clock during T1.
A digital output interface requires a register or latch which can hold the data
output from the computer.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
The enable signal is used to indicate the device that data is stable on the bus and
can be read.
The output from the latch is a set of logic level typically from 0 to 5v.
If this logic levels are not adequate to operate actuators, some conversion is done
this conversion is often performed by using low level signals to operate relays
which carry higher voltage signals.
An advantage of using relays is that there is electrical isolation between plant and
the computer system.
Pulse interfaces:
In its simplest form, a pulse input interface consists of a counter connected to a
line from the plant.
The counter is reset under program control and after fixed length of time the
contents are read by the computer.
Fig 3.7 shows a simple pulse input and output interface.
For type 1 the computer turns a pulse generator on or off, or loads a register with
the number of pulses to be transmitted. The pulse output is sent to the process
and used to decrement the register contents, when the register reaches zero the
pulse output is turned off. Example controlling a stepper motor.
For type 2 the computer raises or lowers a logic line and thus sends a variable
length pulse to the plant. Example controlling of valves.
For type 3 Pulse width modulation (PWM), special purpose interface chip are used
to generate the pulses.
Close the related to pulse counters are hardware timers. The hardware timer is
normally a continuously running accurate pulse generator.
Hardware timers can be used to set the maximum time allowed for the response
from an external device, a special form of this is the watch-dog timer.
Watch-dog timer is often used on process control computers. The timer is reset at
fixed intervals, usually when the OS kernel is entered, if the watch-dog timer
„times-out‟ it indicates that for some reason the OS kernel as not been entered at
the correct time.
Analog interfaces:
The analog measurements are converted to digital measurements in two steps like
Sampling and quantization.
Fig 3.8 shows simple analog input interface.
Sample and hold unit is used to prevent a change in the quantity being measured
while it is being converted to a discrete quantity.
To operate the analog input interface the computer issues a start or sample signal,
typically a short pulse and in response ADC switches the sample-hold into sample
for a short period after which quantization begins.
On completion of the conversion the ADC raises a ready or complete line which is
either polled by computer or is used to generate interrupt.
Multiplexer is used to switch the input from several input lines to single ADC since
using a separate ADC for each analog input is expensive.
For high level (0 to 10V) signals, the multiplexer usually used is a solid state
device.
For low level signals, a programmable gain amplifier is usually used between
multiplexer and sample-hold unit.
Digital to analog conversion is simpler than analog to digital conversion and it is
also possible to provide one convertor for each output.
A simple analog output system is shown in the fig 3.9
Real-time clock:
A real-time clock is a vital supporting device for control computer systems. The
hardware unit given the name real-time clock is a pulse generator with a precisely
control frequency.
A common form of the clock is based on using the AC supply line to generate pulses
at 50 or 60 times per second.
By using slightly more complicated circuitry higher pulse rates can be generated.
The pulses are used to generate interrupt and the interrupt handling software
counts the interrupts and hence keeps time.
A fixed frequency pulse generator decrements a counter which, when it reaches
zero, generates an interrupt and reloads the count value.
The interrupt activates the real-time clock software.
The interval at which the timer generates an interrupt and precision of clock is
control by the count value loaded into the hardware timer.
The choice of basic clock interval is a compromise between timing accuracy and
load on the cpu.
If small interval is chosen i.e., higher precision, then cpu will spend a large
proportion of its time simply servicing the clock and will not be able to perform
any other work.
The RTC based on the use of an interval timer and interrupt driven software
suffers from the disadvantage that the clock stops when the power is lost and the
restart the current value of the real time as to be entered.
But at the present time, RTC units with battery backup are available which saves
the time even when the power goes off.
RTCs are also used in batch processing and online computer system.
In batch processing systems, they are used to provide date and time on printouts
and for accounting purposes in online system user expects the terminal to appear
as if it is the only terminal connected to the system.
Programmed transfer is the method in which direct control of the interface devices
by computer and involves use of CPU.
Programmed transfer gives maximum flexibility of operation but because of
difference in operating speed in CPU and many interfacing devices it is inefficient.
Another approach is DMA-direct memory access, the transfer requirements are
setup using program control but data transfer takes place directly between the
device and memory without disturbing the operation of CPU.
In online computing, buffers have been used to collect information before invoking
the program requesting the input.
This approach is now being extended through the provision of i/o processor for
real-time systems.
A major problem with data transfer is timing. In program transfer the computer
can make unconditional transfer i.e., the computer can read or write at any time
to the device.
Another transfer is the conditional transfer where the computer must be sure that
the device ready to accept the next data.
Conditional transfer can be used for digital inputs.
Unconditional transfer can be used for analog inputs and pulse inputs.
Polling:
Considering the example of printer, the computer will first find whether the device
is ready, if the device is ready then transfer take place. If not, the computer will
keep on checking the status of the device. Hence most of the time is wasted in
waiting rather than performing actual job.
A software timing loop can be used as an alternate method to a status line on the
interface.
For example, a delay can be created by loading the register with a number and
repeatedly decrementing register until it reads zero.
Code snippet- LD B,25 ; Load register B with time delay
LOOP DEC B ; Decrement B
JR NZ, LOOP; Repeat until B is zero
To ensure that no transfer is made before peripheral is ready, time delay must be
slightly greater than maximum delay, thus this method also inefficient in terms of
CPU use. But reduces the cost.
An alternate arrangement for conditional transfer is the one shown in fig 3.11
Here the computer instead of waiting for the device to get ready, checks the
status of the device if ready, transfer takes place if not continuous with the
process and comes back after some time interval to check the status of the device.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
Interrupts:
An interrupt is a mechanism by which the flow of program can be temporarily
stopped to allow a special piece of software (ISR) interrupt service routine to run.
When the routine has finished, the program which was temporarily stopped is
resumed.
The use of automatic storage of the working registers is an efficient method if all
register are to be used.
The machine status must be restored on exit from the interrupt routine.
Interrupt input mechanism:
A simple form of interrupt input is shown in fig 3.13
In between each instruction CPU checks the IRQ line, if it is active, which indicates
interrupt is present, and the interrupt service routine is entered.
If it is not active then next instruction is fetched and cycle repeats.
A common arrangement is to have interrupt lines as shown in the fig 3.14
One of the lines IRQ is enabled and disabled using software and hence the
computer can run in a mode in which external events cannot disturb the processing
A second interrupt line is provided; this interrupt cannot be turned off by software
and hence it is said to be a non maskable interrupt(NMI)
NMI is typically used to provide the power failure detect interrupt.
The cpu may respond to the interrupt in any of the following methods
1. Transfer control to a specified address usually in the form of CALL
instruction.
2. Load the program counter a new alue from a specified register or
memory location.
3. Excecute a CALL instruction but to an address supplied from the external
system.
4. Use an output signal- an interrupt acknowledge to fetch an instruction
from an external device.
Method 1&2 are said to be software biased that is external hardware are not much
involved and rely on software to determine the interrupt source and appropriate
ISR .
Methods 3&4 are said to be hardware biased i.e they require external hardware
but can identify the interrupt source and can directly transfer the control to ISR.
Each unit has an IEI pin (interrupt enable input) and an IEO pin (interrupt enable
output)both pins are active high pins .
The first IEI is always set high and for any device IEO is high only when interrupt is
not present .
If IEI is high and IIEO is low,then the device is requesting service .
If devices requesting any service but IEI pin is low then those devices are not
serviced .
The above diagram illustrates various devices connected in daisy chain interrupt
structure and the services provided according to the device priority.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
In daisy chain arrangement the device priority is determined by the position of the
device in the chain and cannot be changed by software.
The determination of interrupt priority can be performed using priority encoder
circuits.
In this system an interrupt occurring on any line causes the interrupt line (IRQ) to
become active and also places a 3bit code specifying the number of interrupt line
which is active on the data bus.
In the event of more than one line being active the priority encoder supplies the
number of the highest priority interrupt.
Multilevel interrupts:
In most of real-time systems a single interrupt level is unacceptable;
A typical multilevel interrupt is shown in the fig.3.17
The interrupts are now enabled and actual servicing of interrupts starts.
When servicing are completed, interrupts are disabled, previous mask register
values are restored and working environment is resumed.
Interrupts can be enabled now and interrupt service routine are exited.
Data transfers take place directly between the device and memory without
disturbing operation of CPU.
Three methods are normally used-burst, distributed mode and cycle stealing.
In burst mode, the DMA controller takes over the data highways of the computer
and locks out the CPU for period of time.
In distributed mode the DMA controller takes occasional machine cycles from the
CPU control and uses each cycle to transfer a byte of information between fast
memory and backing memory.
The cycle stealing method only transfers data during cycles when the CPU is not
using the data bus. Therefore the program proceeds at the normal rate and is
completely unaffected by the DMA data transfers.
Communications:
The use of distributed computer system implies the need of communication
between the instruments of plant and lower level computers.
At the plant level, communication system involve parallel analog and digital signal
transmission since the distances involved are small and high speed is required.
At higher level, serial communication is used as communication distances are more
hence use of parallel communication increases the cost.
Parallel digital systems are also limited for short distances as it increases the cost
when used for long distances.
Fig.3.20 illustrate data transmission links.
The line will be completely idle when an EOT(end of transmission) character has
been sent by the transmitter.
The text is broken up into blocks and each block is preceded by an STX character
and ended by ETX character. Followed by ETX will be an integrity check on the
data.
There are two main standards of synchronous transmission systems,
BISYNC- binary synchronous communication
HDLC- high level data link control
With synchronous transmission there is no need to transmit extra bits to enable
receiver clock hence data transmission rate is high.
The advantage of block transmission is that a much higher ratio of data bits to
control bits can be obtained.
Local and wide area networks:
Wide area network operate over wide geographical area at moderate speeds.
Local area network operate at a wide range of transmission media such as a
twisted pair, co-axial cable, and fibre optics; they use range of different protocols
and topologies.
Fig.3.23 LAN topologies: (a) data bus; (b)star; (c)hierarchy or tree; (d)ring; (e)mesh.
Data bus: is the simplest of all the LAN topologies. The bus is normally passive and
all the devices are connected to transmitting medium.
Star network: depends on a central switching node to which all other nodes are
connected by a bidirectional link.
Hierarchy: the system as many switching nodes, the addition of new nodes is
difficult.
Ring: this is most used network the ring is typically an active transmission system
i.e, ring itself contains regeneration circuit which amplifies the signal.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
Mesh: this topologies allows for random interconnections between the various
nodes it provides a means by which alternative routes between nodes can be
found. The prevailing standard is now the HDLC protocol.
Standard interfaces:
The ISO(international organization for standardisation) have formulated a standard
protocol system in the OSI model.
This is a layered model with seven layers running from the basic physical
connection to the highest application protocol.
General structure is illustrated in fig.3.25
Unit 5&6
Operating system
Access to the hardware of the system and I/O devices is through operating
systems.
In addition to supporting and controlling the basic activities, operating systems
provide utility programs for example loaders, linkers, assemblers, and debuggers
as well as real-time support for high level language.
A general purpose operating systems will provide facilities that are not required in
a particular applications, such features can be omitted during installation.
Recently, operating systems which provide only a minimum kernel have become
popular, additional features can be added.
Until early 1980s there was a clear distinction between operating systems designed
for use in real-time applications and other types of operating systems.
But in recent years this distinction has become less.
The function of a multiuser operating system is as shown in fig.5.5
Also tasks may need to be invoked by external events. Hence operating system
must support interrupts.
Also tasks may need to share data and may need to access hardware and software
components.
As a whole real-time multi-tasking operating system can be summarized as follows
1. Task Management: the allocation of memory and processor time
(scheduling) to tasks.
2. Memory Management: control of memory allocation.
3. Resource control: control of all shared resources.
4. Intertask communication and synchronisation.
Along with the above functions, the system provides standard features such as disk
files, basic input/output device drivers and utility programs.
Task management module has the overall control which is responsible for
allocating the use of CPU. This module is often referred to as the monitor or as the
executive control program.
At the user level, system tasks is also shown since in many operating system some
operations performed by the operating system and the utility programs run in the
memory space allocated to the user or applications- this space is sometimes called
working memory.
Scheduling strategies:
Cyclic Strategy:
The task uses the CPU for as long as it wishes.
It is a very simple strategy which is highly efficient in that it minimizes the time
lost in switching between tasks.
It is an efficient strategy for small embedded systems for which the execution
times for each task run are carefully calculated and for which the software is
carefully divided into appropriate task segments.
This approach is too restrictive since it requires that the task units have similar
execution times.
It is difficult to deal with random events using this approach.
Pre-emptive Strategies:
There are many pre-emptive strategies; all involve the possibility that a task will
be interrupted before it has completed a particular invocation.
The simplest form of pre-emptive scheduling is to use a time slicing approach.
Using this strategy each task is allocated a fixed amount of CPU time (number of
clock ticks), and at the end of this time it is stopped and the next task in the list is
run.
If a task completes before the end of its time slice, the next task in the list is run
immediately.
A common strategy used in real-time operating system is Priority Scheduling
Mechanism.
Tasks are allocated a priority level and at the end of a predetermined time slice,
the task with highest priority of those ready to run is chosen and is given control of
the CPU.
Task priorities may be fixed (static priority system) or may be changed during
system execution (dynamic priority system).
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
Dynamic priority schemes can increase the flexibility of the system. Changing
priorities is risky as it makes it much harder to predict and test the behavior of the
system.
The task management system has to deal with the handling of interrupts. These
may be hardware interrupts caused by external events, or software interrupts
generated by a running task.
Priority structures:
In a real-time system the designer has to assign priorities to the tasks in the system.
The priority will depend on how quickly a task will have to respond to a particular
event.
Most RTOSs provide facilities such that tasks can be divided into three board
levels:
1. Base level
2. Clock level
3. Interrupt level
Clock Level: At this level are the tasks which require accurate timing and
repetitive processing, such as the sampling and control tasks.
One interrupt level task will be the real-time clock.
Base Level: tasks at this level are of low priority and either have no deadlines to
meet or are allowed a wide margin of error in their timing. Tasks at this level may
be allocated priorities or may all run at a single priority level.
Cyclic Tasks:
Cyclic tasks are ordered in a priority which reflects the accuracy of timing required
for the task, those which require high accuracy being given the highest priority
Tasks of lower priority within clock level will have some jitter since they will have
to await completion of the higher-level tasks.
Three tasks A, B, and C are required to run at 20 msec, 40 msec and 80 msec
intervals. If the clock interrupt rate is set at 20 msec. if the task priority order is
set as A,B,and C with A as the highest priority.
The following figures 5.8 and shows task activation diagram for this example in two
cases;
Case (a): Task priorities are: A, B, then C.
Case (b): Task priorities are: C, A, then B.
Fig 5.7 task activation diagram for case(a0 and case (b)
Now assume that task C takes 25 msec to complete, task A takes 1 msec and task B
takes 6 msec. if task C is allowed to run until completion then the activity diagram
is given bellow.
Task A will be delayed by 11 msec at every fourth invocation.
Task States:
The real-time clock handler and the scheduler for the clock level task must be
carefully design as they run at frequent intervals.
System commands which change tasks status (transition commands).
The range of system commands affecting task status varies with the operating
system.
Tasks which are suspended awaiting the passage of time these tasks are marked as
delayed and those tasks waiting for an event or a system resource are marked as
locked out.
The system does not support base level tasks but lowest four priority level of the
clock level tasks can be used to create a base level system.
Typical states and commands are shown in fig.5.11
Other systems which permit dynamic allocation of memory allow the tasks
themselves to initiate program segment transfer either by chaining or overlaying.
Task chaining involves division of task into several segments which run
sequentially. On completion of one segment the next segment is loaded from
memory into the area occupied by the previous segment.
Task swapping involves one task invoking another task.
The first task is transferred to backing store and the second task brought into
memory and made available to run.
Task chaining and swapping is shown in fig.5.16
Code sharing:
In many applications same actions have to be carried out in several different tasks.
In a convential program the action would be coded as a subroutine and one copy of
the subroutine would be included in the program.
In a multitasking system each task must have its own copy of the subroutine or
some mechanism must be provided to prevent one task interfering with the use of
code by another task.
The problem which can arise are illustrated in fig.5.19
If two task share subroutine S. if task A is using S before it finishes some event
occurs which causes rescheduling of the tasks and task B runs and uses S, then
when a return is made to task A, the locally held data will be changed.
Two methods can be used to overcome this problem:
1. Serially reusable code, and
2. Re-entrant code.
Re-entrant code:
If the subroutine can be coded such that it does not hold within it any data i.e., a
pure code (data like intermediate results are stored in the calling task are in a
stack).
Then the subroutine (pure code) is said to be re-entrant.
Task descriptor for each task contains a pointer to a data area, swapping between
tasks will not cause any problems.
Re-entrant routines can be shared between several tasks since they contain no
data relevant to a particular task and hence can be stopped and restarted at a
different point in the routine without any loss of information.
Device drivers in conventional operating system are frequently implemented using
re-entrant code.
Resource Control:
One of the most difficult areas of programming is the transfer of information to
and from external devices.
The availability of a well-designed and implemented I/O subsystem (IOSS) in an OS
is essential for efficient programming.
This enables programmer to perform input output by means of system calls either
from a HLL or from the assembler.
The IOSS handles all the details of the devices.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
In buffered request, the higher priority task including the very high priority task 5
will not gain access to the printer until task 76 releases it.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
If the tasks have made a non buffered request they will be locked out until they
reach the head of the printer queue.
However if task 5 has made a buffered request it will be able to continue and if it
runs frequently, then after short period of time the printer queue will continue
several request from tasks 5.
Task co-operation and communication:
In real-time system tasks are designed to full fill a common purpose and hence
they need to communicate with each other.
For task co-operation and communication we have the following solutions:
1. Mutual exclusion (MUTEX)
2. Synchronization and
3. Data transfer.
Mutual exclusion: a multitasking operating system allows the sharing of resources
between several concurrently active tasks.
The use of some resources is restricted to only one task at a time.
Some problems can arise if two tasks share a data area and both tasks can write
the data area.
In abstract terms mutual exclusion can be expressed in the form of
Remainder1
Pre-protocol (necessary over head)
Critical section
Post protocol (necessary over head)
Remainder2
Remainder1 and remainder2 represents sequential code does not require access to
particular resource are to a common area of memory.
Critical section is the part of the code which must be protected from interference
from another task.
Pre-protocol and post-protocol called before and after the critical sections are
code segment that will ensure that the critical section is executed so as to
exclude all other tasks.
Critical section and protocols must be much shorter than the remainders.
The protocols represent the over head which has to be paid in order to obtain
concurrency.
In considering solutions to MUTEX problem it is normal to assume that a number of
so called primitive instructions exists.
The most widely used form of primitive for the purpose of binary semaphore.
The semaphore mechanism was first proposed by E.W.Dijkstra in 1968.
A binary semaphore is condition flag which records wheather or not a resource is
available.
If for a binary semaphore s, s=1, then the resource is available and the task may
proceed.
If s=0, then the resource is unavailable and the task must wait.
Anand Raj S N, Asst Professor, JNNCE, Shivamogga
RTS notes-2013
The monitor:
Inter-task communication:
We can divide the issues of Synchronisation and communication into three areas.
1. Synchronisation without data transfer.
2. Data transfer without Synchronization.
3. Synchronization with data transfer.
Task Synchronisation without data transfer
Signal is a mechanism which is used to inform about the task status.
Signal is defined as a binary variable such that if s=1, then a signal has been sent
but not yet being received .
Associated with a signal is a queue.
Permissible operations on a signal are initialize, wait and send.
Differences between signal and semaphore: clearly a signal is similar to
semaphore. The following are the differences;
1. A semaphore is used to secure and release a resource and as
such the calls will both be made by one task.
2. A signal is used to synchronize the activities of two tasks and
one task will issue the send and the other task the wait.
Data transfer without Synchronization:
RTOS support pool and channel mechanism for the transfer or sharing of data
between tasks.
Pool holds data common to several tasks, the write operations on a pool is
destructive and the read operation is non destructive.
Channel support communication between producers and consumer of data the read
operation is destructive in channel where as write operation is non destructive.
Channels provide a direct communication link between tasks, normally on a one to
one basis.
One task is seen as the producer and the other as the consumer.
There are two basic implementation mechanism for a channel:
1. Queue (linked list) and
2. Circular buffer
The advantage of the queue is that number of successive messages held in a
channel is not fixed.
The length of the channel can grow only limit is amount of available memory.
The disadvantage of the queue is that access time increases as the length of the
queue increases.
The circular buffer uses a fixed amount of memory, the being defined by the
design of the application.
Synchronization with data transfer:
The two main forms of Synchronization with data transfer are
1. The message from the producer task.
2. The signal for consumer task indicating exchange of data.
Signal is sent each time a message is placed in the channel, either a semaphore or
signal that counts the number of sends and waits, or a counter has to be used.
Liveness:
Livelock is the condition under which the tasks requiring mutually exclusive access
to a set of resources, both enter busy wait routines but neither can get out of the
busy wait because they are waiting for each other. The CPU appears to be doing
useful work and hence the term livelock.
Deadlock is the condition in which a set of tasks are in a state such that it is
impossible for any of them to proceed.
The CPU free but they are no tasks to run.
Indefinite postponement is the condition that occurs when a task is unable to gain
access to the resource because some other tasks always gains access ahead of it.