Qualcomm Interview Question
Software Engineer / DevelopersI am not sure whether I sound right here...But, here is my solution..
Given, the timer interrupts the system every 20ms..
Before going into this problem I say whats needed here..
We need system clk(which might be the one mentioned here, or there is a system clk in every system) and two global volatile variables(gv1 and gv2).
Whenever the timer interrupts the system, and before ISR starts, I will take the current value of clk(store it in gv1) and compare with the gv2(will have the updated value of clk (everytime when the clock is running))...This comparison will be performed in ISR, once the difference > 20ms, we found out that 20ms exceeded. Now after exiting ISR I will reset gv1 and gv2.
Implement through some sort of a watchDog mechanism. Have a task that monitors the state of all the interrupts installed in the system. The monitoring variable has 3 enum states { Intr_None, Intr_Progress, Intr_Done}
System will have the above flags for each of the interrupts installed. The monitoring task will initialize the flags as "Intr_None" and will be running in the background at regular intervals. As soon as the interrupt occurs, the interrupt will marks its flag as "Intr_Progress. Interrupt will also have to mark the flag to "Intr_Done" after it is done with the interrupts.
The monitoring tasks, on discovering "Intr_Progress", will start the timer to monitor that flag. If the flag is not set to "Intr_Done" even after the 20ms, Monitor will have reset the system. If the flag changes to "Intr_Done" before 20ms, monitor will set the flag to "Intr_none".
intitially, a flag is unset before turning on interrupts.
- Anonymous April 06, 2010iinterrupt happens, ISR invoked.
now don't disable interrupts.
set a flag at beginning of ISR. check if flag is set during ISR. perform ISR task. unset the flag.
if the flag is set when ISR is executing, it means ISR runs > 20s.