subject

Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote
the variables storing the readouts from two sensors. The actual read is performed by the
functions readSensor1() and readSensor2(), respectively, which are called in the interrupt
service routine ISR.

char flag = 0;
char* display;
short sensor1, sensor2;

void ISR() {
if (flag) {
sensor1 = readSensor1();
} else {
sensor2 = readSensor2();
}
}

int main() {

// ... set up interrupts ...
// ... enable interrupts ...
while(1) {
if (flag) {
if isFaulty2(sensor2) {
display = "Sensor2 Faulty";
}
} else {
if isFaulty1(sensor1) {
display = "Sensor1 Faulty";
}
}
flag = !flag;
}

}

Functions isFaulty1() and isFaulty2() check the sensor readings for any discrepancies,
returning 1 if there is a fault and 0 otherwise. Assume that the variable display defines what is
shown on the monitor to alert a human operator about faults. Also, you may assume that flag
is modified only in the body of main. Answer the following questions:
a) Is it possible for the ISR to update the value of sensor1 while the main function is
checking whether sensor1 is faulty? Why or why not?
b) Suppose a spurious error occurs that causes sensor1 or sensor2 to be a faulty value for
one measurement. Is it possible for that this code would not report "Sensor1 faulty" or
"Sensor2 faulty"?
c) Assuming the interrupt source for ISR() is timer-driven, what conditions would cause this
code to never check whether the sensors are faulty?

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:30
Technician a says that a shop towel should never be used to clean around the flange area before replacing an automatic transmission filter. technician b says that a dimpled transmission fluid pan can be repaired. who is right
Answers: 3
question
Computers and Technology, 24.06.2019 01:00
How can the temperature of a room be raised by 5degreesf?
Answers: 1
question
Computers and Technology, 24.06.2019 18:00
Which of the following is an example of synchronous communication? a) e-mail b) voicemail c) telephone conversation d) text message.
Answers: 1
question
Computers and Technology, 25.06.2019 08:20
The internet backbone is a foundation network linked with
Answers: 1
You know the right answer?
Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote
the...
Questions
question
English, 16.10.2020 04:01
question
English, 16.10.2020 04:01
question
Biology, 16.10.2020 04:01
Questions on the website: 13722361