• Home
  • Textbooks
  • Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX
  • Low-level programming

Real-Time Systems and Programming Languages: Ada, Real-Time Java and C/Real-Time POSIX

Alan Burns, Andy Wellings

Chapter 14

Low-level programming - all with Video Answers

Educators


Chapter Questions

Problem 1

Consider a computer which is embedded in a patient-monitoring system (assume the simple I/O system given in this chapter). The system is arranged so that an interrupt is generated at the highest hardware priority, through vector location 100 (octal) every time the patient's heart beats. In addition, a mild electric shock can be administered via a device control register, the address of which is 177760 (octal). The register is set up so that every time an integer value $\mathrm{x}$ is assigned to it the patient receives $\mathrm{x}$ volts over a small period of time.
If no heartbeat is recorded within a 5 second period the patient's life is in danger. Two actions should be taken when the patient's heart fails: the first is that a 'supervisor' task should be notified so that it may sound the hospital alarm, and the second is that a single electric shock of 5 volts should be administered. If the patient fails to respond, the voltage should be increased by 1 volt for every further 5 seconds.
Write an Ada program which monitors the patient's heart and initiates the actions described above. You may assume that the supervisor task is given by the following specification:
task Supervisor is
entry Sound_Alarm;
end Supervisor;

Check back soon!

Problem 2

The Spanish government is considering introducing charges for the use of motorways. One possible mechanism is that detector stations can be set up at regular intervals along all motorways; as a vehicle passes the detector station its details are logged and a road charge is recorded. At the end of each month the vehicle owner can be sent a bill for his or her motorway usage.
Each vehicle will require an interface device which interrupts an on-board computer when a detector station requests its details. The computer has a word size of 16 bits and has memory-mapped I/O, with all I/O registers 16 bits in length. Interrupts are vectored, and the address of the interrupt vector associated with the detector station is $8 \# 60 \#$. After an interrupt has been received, a read-only input register located at $8 \# 177760 \#$ contains the basic cost of using the current stretch of motorway (in euros). The hardware priority of the interrupt is 4 . The computer software must respond to the interrupt within a period of 5 seconds, and pass its ownership details to the detector station via the interface device. It does this by writing to a bank of five control and status registers located at 8\#177762\#. The structure of these registers is shown in Table 14.1.
TABLE CAN'T COPY.
The bank of 'control and status' registers (CSR) is write-only.
Write an Ada task to interface with the detector station. The task should respond to interrupts from the interface device and be responsible for sending the correct vehicle details. It should also read the data register containing the cost of the road usage, and pass the current total cost of the journey to a task which will output it on a visual display unit on the vehicle's dashboard. You may assume the following is available:
package Journey..Details is
Registration_Number : constant String(1..8) :=
"....... ";
type Travel_Details is
(Business, Pleasure, Overseas_Tourist,
Police, Military, Emergency_Service);
for Trave1_Details use
(Business $\Rightarrow 1$, Pleasure $\Rightarrow 2$,
Overseas_Tourist $\Rightarrow 3$, Police $\Rightarrow 4$,
Military $\Rightarrow 5$, Emergency_Service $\Rightarrow$ 6) ;
subtype Security_Code is Integer range 0 .. 2047;
function Current_Journey return Travel_Details;
function Code return Security_Code;
end Journey_Details;
package Display_Interface is
task Display_Driver is
entry Put_Cost (C : Integer);
-- prints the cost on the dashboard display
end Display_Driver;
end Display_Interface;
Assume that the compiler represents the type Character as an 8-bit value and the type Integer as a 16-bit value.

Check back soon!

Problem 3

Rewrite your answer to Exercise 14.2 in Real-Time Java.

Check back soon!

Problem 4

The British government is concerned about the speed of cars using motorways. In the future, beacons will be set up at regular intervals along all motorways; they will continuously transmit the current speed limit. New cars will contain computers which will monitor the current speed limit and inform the driver when he or she exceeds the limit. One car currently being designed (the Yorkmobile) already has the necessary hardware interfaces. They are as follows.
- Each car has a 'speed control' 16-bit computer which has memory-mapped $\mathrm{I} / \mathrm{O}$, with all $\mathrm{I} / \mathrm{O}$ registers 16 bits in length.
- A register located at octal location 177760 interfaces to a device which monitors the roadside beacons. The register always contains the value of the last speed limit received from the roadside beacons.
- A pair of registers interface to an intelligent speedometer device which checks the speed of the car against a set limit. If the speed limit is broken, the device generates an interrupt through octal location 60 . The priority of the interrupt is 5 . This interrupt is repeated every 5 seconds until the car is no longer speeding.
- The register pair consists of a CSR, and a data buffer register (DBR). The structure of the CSR register is shown in Table 14.2.
The CSR register may be both read from and written to, and resides at address octal 177762. The DBR register simply contains an integer value representing the car's speed limit to be set. If this value falls outside the
$$
\begin{array}{ll}
\hline \text { Bits } & \text { Meaning } \\
\hline 0 & \text { enable device } \\
1 & \begin{array}{l}
\text { when set the value found in the DBR } \\
\text { is used as the car's current speed limit }
\end{array} \\
5-2 & \text { not used } \\
6 & \text { interrupt enable } \\
11-7 & \text { not used } \\
15-12 & \text { error bits }(0=\text { no error, > } 0 \text { illegal limit }) \\
\hline
\end{array}
$$
range $0-70$ then an illegal limit has been specified, and the device continues with the current limit. The address of the DBR register is octal 177764.
- A flashing light (on the car dashboard) can be turned on by setting the register, located at octal address 177750 , to 1 . The light will flash for 5 seconds only. A zero value turns the light off.

Design an Ada and Real-Time Java device driver which will implement the following speed control algorithm.
Every 60 seconds the current speed limit should be read from the roadside beacon by the speed control computer. This value is passed unchecked to the speedometer device which interrupts if the car exceeds the set speed limit or if the speed limit is illegal. If the car exceeds the limit then the dashboard light should be flashed until the car returns to the current limit.

Check back soon!