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, 23.06.2019 00:30
Write the html code to make a link out of the text “all about puppies”. it should link to a pdf called “puppies.pdf” inside the “documents” folder. the pdf should open in a new window.
Answers: 2
question
Computers and Technology, 23.06.2019 05:20
What did creator markus “notch" persson initially call his game
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
1. which of these is not true about torsion bars? a. they can be used to adjust ride height b. they can be adjusted anytime since they don't affect alignment angles c. they attach between the frame and the lower control arm d. they twist to produce a spring effect
Answers: 1
question
Computers and Technology, 24.06.2019 12:00
An npn transistor is correctly biased and turned on if the a. base is negative. b. collector is negative. c. collector is positive with respect to the emitter and negative with respect to the base. d. collector is the most positive lead followed by the base.
Answers: 1
You know the right answer?
Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote
the...
Questions
question
Mathematics, 19.10.2021 09:40
question
Mathematics, 19.10.2021 09:40
question
Mathematics, 19.10.2021 09:40