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: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:10
Drag each label to the correct location on the imagelist the do’s and don’ts of safeguarding your password.keep yourself loggedin when you leave your computer.don’t write your password down and leave it whereothers can find it.share your password with your friends.each time you visit a website,retain the cookies on your computer.use a long password with mixed characters.
Answers: 1
question
Computers and Technology, 22.06.2019 20:40
Write a program that begins by reading in a series of positive integers on a single line of input and then computes and prints the product of those integers. integers are accepted and multiplied until the user enters an integer less than 1. this final number is not part of the product. then, the program prints the product. if the first entered number is negative or 0, the program must print “bad input.” and terminate immediately. next, the program determines and prints the prime factorization of the product, listing the factors in increasing order. if a prime number is not a factor of the product, then it
Answers: 2
question
Computers and Technology, 23.06.2019 03:50
Iam a bacterium. i cause stomach cramps and diarrhea. i am caused by eating rotten foodssuch as chicken, fish, or eggs. sometimes turtles carry my bacteria.what am i?
Answers: 2
question
Computers and Technology, 23.06.2019 07:00
Why is investing in a mutual fund less risky than investing in a particular company's stock? a. mutual funds only invest in blue-chip stocks. b. investments in mutual funds are more liquid. c. mutual funds hold a diversified portfolio of stocks. d. investments in mutual funds offer a higher rate of return.
Answers: 2
You know the right answer?
Consider the following program that monitors two sensors. Here sensor1 and sensor2 denote
the...
Questions
question
Mathematics, 29.10.2019 03:31
question
Mathematics, 29.10.2019 03:31
Questions on the website: 13722363