Question
Study the following software example which shows data sharing between an ISR and the background main task. 1) Is this software prone to data corruption
Study the following software example which shows data sharing between an ISR and the background main task.
1) Is this software prone to data corruption due to a shared data bug?
2) If yes, explain the problem using an example.
3) How would you resolve this?
static int iMinutes, iSeconds; //global variables
Void main (void) {
int TotalSeconds;
iSeconds = 0;
iMinutes = 0;
while(TRUE)
{
TotalSeconds = (iMinutes * 60) + iSeconds;
!! Print TotalSeconds onto serial port.
} }
void interrupt vTimeUpdate(void) //Timer ISR which runs every one second {
!! ISR book keeping, clearing flag, scheduling next interrupt, etc.
iSeconds++;
if (iSeconds>59)
{ iSeconds = 0;
iMinutes++;
}
}
static int iMinutes, iSeconds; Iglobal variables Void main (void) int TotalSeconds; iSeconds 0 iMinutes-0 while(TRUE) TotalSeconds (iMinutes 60)+iSeconds !! Print TotalSeconds onto serial port. void interrupt vTimeUpdate(void) /Timer ISR which runs every one second !! ISR book keeping, clearing flag, scheduling next interrupt, etc iSeconds++; if (iSeconds>59) [iSeconds 0: iMinutes++Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started