CH 15
CH 15
al-t
cont
ol
Actua
tor
Actu
tor
Actsy
tor
Ac
to
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 8
Senso
Ac
to
Sensor/actuator processes
Stim
ulus
Senso
Da
ta
olpr R
e
Ac
contrto
oces
co
ols
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 9
System elements
Sensor control processes
• Collect information from sensors. May buffer
information collected in response to a sensor
stimulus.
Data processor
• Carries out processing of collected information
and computes the system response.
Actuator control processes
• Generates control signals for the actuators.
inser
ted Initiali
Reading
do:
do: reade
init
get
display
details C
W
a a Hose
Card
Card
iting
do:
V displa
lidating
do: Ready
credit o
rem
O
Deli
welcom
valid
do:
Nozzca
deliv
upda
T
imeout trigge
Invalid
Noz
No
Stop
Resettin c
Pdo:
C
error
P
a
ayment
do: displ
ying
Hose a
deb
C holst
©Ian Sommerville 2004
acco
Software Engineering, 7th edition. Chapter 15 Slide 19
Real-time operating systems
Real-time operating systems are specialised
operating systems which manage the processes in
the RTS.
Responsible for process management and
resource (processor and memory) allocation.
May be based on a standard kernel which
is used unchanged or modified for a particular
application.
Do not normally include facilities such as file
management.
14
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 20
Operating system components
Real-time clock
• Provides information for process scheduling.
Interrupt handler
• Manages aperiodic requests for service.
Scheduler
• Chooses the next process to be run.
Resource manager
• Allocates memory and processor resources.
Dispatcher
• Starts process execution.
al-time
Inte
Sched
han
Pr Pr
ocess
r
e
R
eesour
ce
ement
ocessesquir
ce A
v
a
bl
sour e
ila
raewR iting
cesmana
R
e
y
elyist
adger
sour
R
e
pradr
ecesou
list
lease
ocesse
rces
sour
Pr
oces
Despa
tcher
list
©Ian Sommerville 2004
Ex
ecutin
ocess
Software Engineering, 7th edition. Chapter 15 Slide 23
Process priority
The processing of some types of stimuli must
sometimes take priority.
Interrupt level priority. Highest priority which is
allocated to processes requiring a very fast
response.
Clock level priority. Allocated to periodic
processes.
Within these, further levels of priority may be
assigned.
Schedu
R
Choosee
ce
ocesssou
Allo
te De
Sta
foxercutio
and
ocestx
emme
c
e avbloc
eil
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 28
Process switching
The scheduler chooses the next process to
be executed by the processor. This depends
on a scheduling strategy which may take the
process priority into account.
The resource manager allocates memory
and a processor for the process to be
executed.
The dispatcher takes the process from ready
list, loads it onto a processor and starts
execution.
S2
P
S3(S2)P
(A
Cont
P(S1)
proc
P A
(A
A
Cont
proce
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 32
Burglar alarm system
A system is required to monitor sensors on
doors and windows to detect the presence of
intruders in a building.
When a sensor indicates a break-in, the
system switches on lights around the area
and calls police automatically.
The system should include provision for
operation without a mains power supply.
detectorpr
ocess
pr
oces
Detecto
tus
5
6 Sensor
0tus
prSenso
mtus
Alar
Hz
Buildin
Com sy
unic
ocesstion
pr
oces
P
ow
eeP
row
pr failur
R
interrupt
e o
umber
witch
r
ocess om
Building
Alar
m
s
pr syst
Aler
t
ocessge n
me
Alar
m A
uprle
mmRo
umber
Alar
dib
ocess om
system
R
oAlar
m
syste
umbe
om
Lightin
alar
olV
pr opr
ocesser n
sy
ice
oces n
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 38
Building_monitor process 1
class BuildingMonitor extends Thread {
BuildingMonitor()
{
// initialise all the sensors and start the processes
siren.start () ; lights.start () ;
synthesizer.start () ; windows.start () ;
doors.start () ; movements.start () ; pm.start () ;
}
} // run
} //BuildingMonitor
ocess
50T
0
hSens
v
a lues
most
ter
pr Hz
ocess
Switch
R
o
umbe
50Hea
0pr
terom
Hz
T
h
most
t
oces
ocesser
ol con
F pr
con
uol n
rnp
oce
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 43
Data acquisition systems
Collect data from sensors for subsequent
processing and analysis.
Data collection processes and processing
processes may have different periods and
deadlines.
Data collection may be faster than processing
e.g. collecting information about an explosion.
Circular or ring buffers are a mechanism for
smoothing speed differences.
da
taDi
y
s3
s4va Sens
Senso
iden
identif
va
lue lue
Sensor
s5
pr Senso
ta
ocess
s6 b
u
ferPr
foce
da
ta
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 45
Reactor data collection
A system collects data from a set of sensors
monitoring the neutron flux from a nuclear
reactor.
Flux data is placed in a ring buffer for later
processing.
The ring buffer is itself implemented as a
concurrent process so that the collection and
Neutron
Sensor
identif
flux
alue
A-DFlux
ta
conver
tor Pr
oce
f
lv
eux
Flux
bufer Op
fprocl
v
disd
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 47
Pr
oducer
pr
ocess
A ring buffer
Co
pr
oc
©Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 15 Slide 48
Mutual exclusion
Producer processes collect data and add it to
the buffer. Consumer processes take data
from the buffer and make elements available.
Producer and consumer processes must be
mutually excluded from accessing the same
element.
The buffer must stop producer processes
adding information to a full buffer and
consumer processes trying to take information
from an empty buffer.
CircularBuffer (int n) {
bufsize = n ;
store = new SensorRecord [bufsize] ;
} // CircularBuffer