Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Study the following software example which shows data sharing between an ISR and

ID: 3713168 • Letter: S

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 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++

Explanation / Answer

1.) Yes, this software is prone to data corruption due to a shared data bug in case the interrupt execution time is greater than a second.

2.)In case Interrupt takes more than a second to execute the software might lose on the seconds track. Suppose for example at iMinutes 5, and iSeconds 40, the interrupt takes more than a second for execution because of some internal issue then the void will print total seconds as 341(60*5+41) instead of the real 342.

3.) You can handle this case by implementing spinLock.